Cookbook /
ConvertUseMod-Talk
Summary: Talk page for ConvertUseMod.
Maintainer: Pm
This space is for User-contributed commentary and notes. Please include your name and a date along with your comment.
Comments
- Great work, except this doesn't seem to import UseMod pages that have spaces (underscores) in the title. Anybody interested in trying that?
- I think I get it... the script imports the pages faithfully, but for some reason my PMWiki install refuses to "see" pages that have underscores. If I go to the shell and rename the files to something without underscores, I can see the content under the new title. Wonder how I can configure PM to "see" imported pages containing underscores?
- OK, I'm an idiot. I found AlternateNamingScheme and used the spacewikiwords.php. Now I see everything I imported.
- I got an error message saying that UseModStore's read method (args
$pagename
) is not compatible with PageStore's read method (args$pagename
, $since). -- Branko Collin, 6 Nov 2020 - I sent the following patch to the developer, but haven't heard anything back, so I am posting it here. The patch solves the following issues:
- As of PHP 7, using the \e modifier in preg_replace() causes an error. I have replaced these calls with preg_replace_callback() calls and inline functions.
- The PmWiki core method read() was called with one argument, but currently requires two. I have added this argument. --Branko Collin, 4 Oct 2021
--- C:/xampp/htdocs/pmwiki/cookbook/original-usemod.php.txt Sat Nov 7 16:49:36 2020 +++ C:/xampp/htdocs/pmwiki/cookbook/usemod.php Sat Nov 7 16:52:26 2020 @@ -39,7 +39,7 @@ "!<h3>(.*?)</h3>!" => "\n!!! $1", # =, ==, === headers - "/^(=+)(.*?)\\1/me" => "str_repeat('!',strlen('$1')).PSS('$2')", + ## "/^(=+)(.*?)\\1/me" => "str_repeat('!',strlen('$1')).PSS('$2')", # <b>, <i> "!<b>(.*?)</b>!" => "'''$1'''", @@ -49,13 +49,13 @@ "!<br>!" => "\\\\\n", # indented text: - "!^(:+)!em" => "str_repeat('-', strlen('$1')).'>'", + ## "!^(:+)!em" => "str_repeat('-', strlen('$1')).'>'", # Term + definition: - "!^(;+)(.*?):!em" => "str_repeat(':', strlen('$1')).PSS('$2').':'", + ## "!^(;+)(.*?):!em" => "str_repeat(':', strlen('$1')).PSS('$2').':'", # [bracketed links] - "/\\[(http:[^$UrlExcludeChars\\s]+)\\]/e" => "Keep(PSS('[[$1 |#]]'))", + ## "/\\[(http:[^$UrlExcludeChars\\s]+)\\]/e" => "Keep(PSS('[[$1 |#]]'))", "/\\[(http:.*?)\\s(.*?)\\]/" => '[[$1 | $2 ]]', # <font> @@ -78,7 +78,7 @@ $pagefile = preg_replace('!-([^-/]+)$!', '/$1', $pagefile); return $pagefile; } - function read($pagename) { + function read($pagename, $since=0) { global $UseModConversions, $KeepToken; $group = FmtPageName('$Group', $pagename); if ($group != $this->umgroup) return false; @@ -87,12 +87,24 @@ while (!feof($fp)) { $text .= fgets($fp, 4096); } fclose($fp); preg_match('/\\xb3[23]text\\xb33(.*?)\\xb33/s',$text,$match); - $text = preg_replace('!<nowiki>(.*?)</nowiki>!se', - "Keep(PSS('$1'))", $match[1]); - $text = preg_replace(array_keys($UseModConversions), - array_values($UseModConversions), $text); - $page['text'] = preg_replace("/$KeepToken(\\d.*?)$KeepToken/e", - "\$GLOBALS['KPV']['$1']", $text); + $text = preg_replace_callback('!<nowiki>(.*?)</nowiki>!s', function ($matches) { return Keep(PSS( $matches[1] )) ; }, $match[1]); + + $text = preg_replace(array_keys($UseModConversions), array_values($UseModConversions), $text); + + # =, ==, === headers + $text = preg_replace_callback( "/^(=+)(.*?)\\1/m", function ($matches) { return ( str_repeat('!', strlen($matches[1])) . PSS($matches[2]) ); }, $text); + + # indented text: + $text = preg_replace_callback( "!^(:+)!m", function ($matches) { return str_repeat('-', strlen( $matches[1] )).'>'; }, $text); + + # Term + definition: + $text = preg_replace_callback( "!^(;+)(.*?):!m", function ($matches) { return str_repeat(':', strlen( $matches[1] )) . PSS( $matches[2] ) . ':'; }, $text ); + + # [bracketed links] + global $UrlExcludeChars; + $text = preg_replace_callback( "/\\[(http:[^$UrlExcludeChars\\s]+)\\]/", function ($matches) { return Keep(PSS('[[' . $matches[1] . ' |#]]')); }, $text ); + + $page['text'] = preg_replace_callback("/$KeepToken(\\d.*?)$KeepToken/", function ($matches) { return $GLOBALS['KPV'][$matches[1]]; }, $text); } return @$page; } @@ -238,6 +250,3 @@ echo "</form></body></html>\n"; exit(); } - - -?>
Talk page for the ConvertUseMod recipe (users?).