compat1x.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2004 Patrick R. Michaud (pmichaud@pobox.com)
  3. This file is part of PmWiki; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published
  5. by the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version. See pmwiki.php for full details.
  7. This file attempts to ease conversions of PmWiki 1.x installations
  8. to PmWiki 2. This is definitely a preliminary implementation and
  9. still probably needs some work.
  10. The major components are UseV1WikiD($path) and ConvertV1WikiD($path).
  11. UseV1WikiD tells PmWiki to make use of an existing PmWiki 1.x wiki.d/
  12. directory, converting PmWiki 1 markup into PmWiki 2 markup as the
  13. page is read. Pages are then saved in the PmWiki 2 installation's wiki.d/
  14. directory, which should be separate from the original wiki.d/.
  15. The intent is that a wiki administrator can install, configure, and
  16. test a PmWiki 2 installation on an existing set of PmWiki 1.x pages
  17. without losing or modifying the 1.x page files.
  18. ConvertV1WikiD($path) is a function that allows pages to be converted
  19. from a 1.x wiki.d/ into the 2.0 directory all at once.
  20. Details on this are being maintained at the UpgradingFromPmWiki1 page
  21. http://www.pmwiki.org/wiki/PmWiki/UpgradingFromPmWiki1 .
  22. */
  23. SDVA($Compat1x,array(
  24. # [[para:]] markup from cookbook recipe
  25. '/\\[\\[para:(.*?)\\]\\]/' => '(:para $1:)',
  26. # [[tocauto]] from cookbook recipe
  27. '/\\[\\[tocauto(.*?)\\]\\]/' => '(:toc$1:)',
  28. # nolinebreaks
  29. "/\\[\\[((no)?linebreaks)\\]\\]/" => '(:$1:)',
  30. # noheader, nofooter, etc.
  31. "/\\[\\[(noheader|nofooter|nogroupheader|nogroupfooter|notitle|spacewikiwords)\\]\\]/" => '(:$1:)',
  32. # include, redirect
  33. "/\\[\\[(include|redirect):(.*?)\\]\\]/" => '(:$1 $2:)',
  34. # table, cell, cellnr, endtable
  35. "/\\[\\[(table|cell|cellnr|tableend)(\\s.*?)?\\]\\]\n?/" => "(:$1$2:)\n",
  36. # [[$Title]]
  37. "/\\[\\[\\\$Title\\]\\]/" => '{$Name}',
  38. "/\\[\\[\\\$Titlespaced\\]\\]/" => '{$Namespaced}',
  39. # [[$pagecount]], from SimplePageCount cookbook script
  40. "/\\[\\[\\\$pagecount\\]\\]/" => '{$PageCount}',
  41. # [[$Group]], [[$Version]], etc.
  42. "/\\[\\[\\$(Group|Version|Author|LastModified|LastModifiedBy|LastModifiedHost)\\]\\]/" => '{$$1}',
  43. # [[$Edit text]], [[$Diff text]]
  44. "/\\[\\[\\\$Edit\\s(.*?)\\]\\]/" => '[[{$Name}?action=edit |$1]]',
  45. "/\\[\\[\\\$Diff\\s(.*?)\\]\\]/" => '[[{$Name}?action=diff |$1]]',
  46. # [[$Search]], [[$SearchResults]], [[$Attachlist]]
  47. "/\\[\\[\\\$Search\\]\\]/" => '(:searchbox:)',
  48. "/\\[\\[\\\$Searchresults\\]\\]/" => '(:searchresults:)',
  49. "/\\[\\[\\\$Attachlist(\\s.*?)?\\]\\]/" => '(:attachlist$1:)',
  50. # [[Drawing:]] from PmWikiDraw (javajunky on #pmwiki)
  51. "/\\[\\[Drawing:(.*?)\\]\\]/" => '(:drawing $1:)',
  52. # [[target linktext]]
  53. "/\\[\\[((\\w|\\#)[^$UrlExcludeChars\\s]*)\\s((.|\\\n)*?)\\]\\]/"
  54. => '[[$1 |$3]]',
  55. # [[target]]
  56. "/\\[\\[(\\w[^$UrlExcludeChars\\s]*)\\]\\]/" => '[[$1 |#]]',
  57. # [[Group.{{free link}} link text]]
  58. "/\\[\\[($GroupPattern([\\/.]))?\\{\\{(~?\\w[-\\w\\s.\\/]*)\\}\\}([-#\\w]*)\\s((.|\\\n)*?)\\]\\]/" => '[[$1$3$4 |$5]]',
  59. # [[Group.{{free link|s}} link text]]
  60. "/\\[\\[($GroupPattern([\\/.]))?\\{\\{(~?\\w[-\\w\\s.\\/]*)\\|([-\\w\\s]*)\\}\\}([-#\\w]*)\\s(.*?)\\]\\]/" => '[[$1$3$4$5 |$6]]',
  61. # Group.{{free link}}ext
  62. "/($GroupPattern([\\/.]))?\\{\\{(~?\\w[-\\w\\s.\\/]*)\\}\\}([-\\w]*)/"
  63. => '[[$1$3]]$4',
  64. # Group.{{free link|s}}ext
  65. "/($GroupPattern([\\/.]))?\\{\\{(~?\\w[-\\w\\s.\\/]*)\\|([-\\w\\s]*)\\}\\}([-\\w]*)/" => '[[$1$3($4)]]$5',
  66. # :: lists
  67. "/^(:+)(:[^:\n]*)$/m" => '$1 $2',
  68. ));
  69. class PageStore1x extends PageStore {
  70. function read($pagename) {
  71. global $Compat1x,$KeepToken;
  72. $page = parent::read($pagename);
  73. if ($page) {
  74. $page['text'] = preg_replace('/(\\[([=@]).*?\\2\\])/se',"Keep(PSS('$1'))",
  75. @$page['text']);
  76. $page['text'] = preg_replace(array_keys($Compat1x),
  77. array_values($Compat1x), $page['text']);
  78. $page['text'] = preg_replace("/$KeepToken(\\d.*?)$KeepToken/e",
  79. '$GLOBALS[\'KPV\'][\'$1\']',$page['text']);
  80. }
  81. return $page;
  82. }
  83. }
  84. function UseV1WikiD($path) {
  85. global $WikiLibDirs;
  86. if (!is_dir($path)) {
  87. Abort("?$path is not an accessible directory");
  88. exit();
  89. }
  90. array_splice($WikiLibDirs,1,0,
  91. array(new PageStore1x("$path/\$FullName")));
  92. }
  93. function ConvertV1WikiD($path) {
  94. global $WikiDir;
  95. Lock(2);
  96. if (!is_dir($path)) {
  97. Abort("?$path is not an accessible directory");
  98. exit();
  99. }
  100. $WikiV1Dir = new PageStore1x("$path/\$FullName");
  101. $oldlist = $WikiV1Dir->ls();
  102. $newlist = ListPages();
  103. $bothlist = array_intersect($oldlist,$newlist); sort($bothlist);
  104. $difflist = array_diff($oldlist,$newlist); sort($difflist);
  105. $bcount = count($bothlist);
  106. $dcount = count($difflist);
  107. echo "
  108. <html>
  109. <head>
  110. <title>Convert v1 pages to v2</title>
  111. </head>
  112. <body>
  113. <h2>Convert and Copy PmWiki v1.x pages into v2.x</h2>
  114. ";
  115. $copy = array();
  116. if (@$_POST['copydiff']) $copy = $difflist;
  117. if (@$_POST['copyboth']) $copy = array_merge($copy,$bothlist);
  118. if (@$_POST['copy']) $copy = array_merge($copy,$_POST['copy']);
  119. if (@$copy) {
  120. echo "<p>Okay, I'm now converting the pages you've requested.
  121. When this is finished, you can see if anything else needs to
  122. be converted, otherwise you can get rid of the
  123. <tt>include_once('scripts/compat1x.php');</tt> and
  124. <tt>ConvertV1WikiD()</tt> lines that are in your
  125. local/config.php file.</p>";
  126. $copy = array_unique($copy);
  127. foreach($copy as $p) {
  128. echo "<li>Converting $p</li>\n";
  129. $page = $WikiV1Dir->read($p);
  130. WritePage($p,$page);
  131. }
  132. echo "<p>Converted ", count($copy), " pages.</p>\n";
  133. } else {
  134. echo "
  135. <p>This function will migrate pages from a 1.x wiki.d/ directory ($path)
  136. into your 2.x wiki.d/ directory, converting markups as it proceeds.
  137. Note that the files in your 1.x wiki.d/ directory are not affected
  138. by this script, so if the conversion doesn't work out for any reason
  139. you still have your original pages lying around.</p>
  140. ";
  141. }
  142. /* now rebuild the lists */
  143. $oldlist = $WikiV1Dir->ls();
  144. $newlist = ListPages();
  145. $bothlist = array_intersect($oldlist,$newlist); sort($bothlist);
  146. $difflist = array_diff($oldlist,$newlist); sort($difflist);
  147. $bcount = count($bothlist);
  148. $dcount = count($difflist);
  149. echo " <form method='post'> ";
  150. echo "<h3>Migrate pages from v1 to v2 (don't overwrite existing
  151. v2 pages)</h3>";
  152. if ($difflist) {
  153. echo "
  154. <p>The following $dcount pages exist only in the version 1
  155. wiki.d/ directory. </p>
  156. <dd><input type='submit' name='copydiff' value='Copy and convert all
  157. pages that do not already exist' /></dd>
  158. <p>or</p><dd><input type='submit' name='copyindv' value='Copy and convert
  159. pages checked in the list below' /><p></p></dd>
  160. ";
  161. foreach($difflist as $p)
  162. echo "<dd><input type='checkbox' name='copy[]' value='$p' /> $p</dd>\n";
  163. } else {
  164. echo "<p>There aren't any pages in your version 1 wiki.d/ directory that
  165. are not already in your version 2 directory.</p>";
  166. }
  167. echo "<h3>Migrate pages from v1 to v2 (overwrite existing v2 pages)</h3>
  168. <p>The following $bcount pages exist in <em>both</em> the version 1 and
  169. version 2 wiki.d/ directories. If you use one of the buttons below,
  170. then your converted version 1 pages will <em>overwrite</em> the existing
  171. version 2 pages, and you will lose any edits that you might have made
  172. in the version 2 installation (it's possible that
  173. this is what you want).</p>
  174. <dd><input type='submit' name='copyboth' value='Convert and overwrite
  175. pages that do already exist' /></dd>
  176. <p>or</p><dd><input type='submit' name='copyindv' value='Convert and
  177. overwrite pages checked in the list below' /><p></p></dd>
  178. ";
  179. foreach($bothlist as $p)
  180. echo "<dd><input type='checkbox' name='copy[]' value='$p' /> $p</dd>\n";
  181. echo "</form></body></html>\n";
  182. exit();
  183. }