transition.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2005-2017 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 script handles various "fixup transitions" that might need to
  8. occur to help existing sites smoothly upgrade to newer releases of
  9. PmWiki. Rather than put the workarounds in the main code files, we
  10. try to centralize them here so we can see what's deprecated and a
  11. simple switch (?trans=0 in the url) can tell the admin if his site
  12. is relying on an outdated feature or way of doing things.
  13. Transitions defined in this script:
  14. $Transition['nosessionencode'] - turn off session encoding
  15. $Transition['version'] < 2001967 - all transitions listed above
  16. $Transition['wspre'] - leading spaces are pre text
  17. $Transition['version'] < 2001941 - all transitions listed above
  18. $Transition['wikiwords'] - 2.1-style WikiWord processing
  19. $Transition['version'] < 2001924 - all transitions listed above
  20. $Transition['abslinks'] - absolute links/page vars
  21. $Transition['version'] < 2001901 - all transitions listed above
  22. $Transition['vspace'] - restore <p class='vspace'></p>
  23. $Transition['version'] < 2001006 - all transitions listed above
  24. $Transition['fplbygroup'] - restore FPLByGroup function
  25. $Transition['version'] < 2000915 - all transitions listed above
  26. $Transition['mainrc'] - keep using Main.AllRecentChanges
  27. $Transition['mainapprovedurls'] - keep using Main.ApprovedUrls
  28. $Transition['pageeditfmt'] - default $PageEditFmt value
  29. $Transition['mainpages'] - other default pages in Main
  30. $Transition['version'] < 1999944 - all transitions listed above
  31. To get all of the transitions for compatibility with a previous
  32. version of PmWiki, simply set $Transition['version'] in a local
  33. configuration file to the version number you want compatibility
  34. with. All of the transitions associated with that version will
  35. then be enabled. Example:
  36. # Keep compatibility with PmWiki version 2.0.13
  37. $Transition['version'] = 2000013;
  38. To explicitly enable or disable specific transitions, set
  39. the corresponding $Transition[] element to 1 or 0. This will
  40. override the $Transition['version'] item listed above. For
  41. example, to enable just the 'pageeditfmt' transition, use
  42. $Transition['pageeditfmt'] = 1;
  43. Script maintained by Petko YOTOV www.pmwiki.org/petko
  44. */
  45. ## if ?trans=0 is specified, then we don't do any fixups.
  46. if (@$_REQUEST['trans']==='0') return;
  47. ## set a default Transition version if we don't have one
  48. SDV($Transition['version'], $VersionNum);
  49. ## Transitions from 2.2.0-beta67
  50. if (@$Transition['version'] < 2001967)
  51. SDVA($Transition, array('nosessionencode' => 1));
  52. if (@$Transition['nosessionencode']) {
  53. $SessionEncode = NULL;
  54. $SessionDecode = NULL;
  55. }
  56. ## Transitions from 2.2.0-beta41
  57. if (@$Transition['version'] < 2001941)
  58. SDVA($Transition, array('wspre' => 1));
  59. if (@$Transition['wspre']) SDV($EnableWSPre, 1);
  60. ## Transitions from 2.2.0-beta24
  61. if (@$Transition['version'] < 2001924)
  62. SDVA($Transition, array('wikiwords' => 1));
  63. ## wikiwords:
  64. ## This restores the PmWiki 2.1 behavior for WikiWord processing.
  65. ## WikiWords aren't linked by default, but appear with
  66. ## <span class='wikiword'>...</span> tags around them.
  67. if (@$Transition['wikiwords']) {
  68. SDV($EnableWikiWords, 1);
  69. SDV($LinkWikiWords, 0);
  70. }
  71. ## Transitions from 2.2.0-beta1
  72. if (@$Transition['version'] < 2001901)
  73. SDVA($Transition, array('abslinks' => 1));
  74. ## abslinks:
  75. ## This restores settings so that PmWiki treats all links
  76. ## as absolute (following the 2.1.x and earlier interpretation).
  77. if (@$Transition['abslinks']) {
  78. SDV($EnableRelativePageLinks, 0);
  79. SDV($EnableRelativePageVars, 0);
  80. }
  81. ## Transitions from 2.1.12
  82. if (@$Transition['version'] < 2001012)
  83. SDVA($Transition, array('nodivnest' => 1));
  84. ## nodivnest:
  85. ## This restores the PmWiki 2.1.11 behavior that doesn't
  86. ## allow nesting of divs and tables.
  87. if (@$Transition['nodivnest']) {
  88. function TCells($m) {
  89. list($x, $name, $attr) = $m;
  90. global $MarkupFrame;
  91. $attr = preg_replace('/([a-zA-Z]=)([^\'"]\\S*)/',"\$1'\$2'",$attr);
  92. $tattr = @$MarkupFrame[0]['tattr'];
  93. $name = strtolower($name);
  94. $out = '<:block>';
  95. if (strncmp($name, 'cell', 4) != 0 || @$MarkupFrame[0]['closeall']['div']) {
  96. $out .= @$MarkupFrame[0]['closeall']['div'];
  97. unset($MarkupFrame[0]['closeall']['div']);
  98. $out .= @$MarkupFrame[0]['closeall']['table'];
  99. unset($MarkupFrame[0]['closeall']['table']);
  100. }
  101. if ($name == 'div') {
  102. $MarkupFrame[0]['closeall']['div'] = "</div>";
  103. $out .= "<div $attr>";
  104. }
  105. if ($name == 'table') $MarkupFrame[0]['tattr'] = $attr;
  106. if (strncmp($name, 'cell', 4) == 0) {
  107. if (strpos($attr, "valign=")===false) $attr .= " valign='top'";
  108. if (!@$MarkupFrame[0]['closeall']['table']) {
  109. $MarkupFrame[0]['closeall']['table'] = "</td></tr></table>";
  110. $out .= "<table $tattr><tr><td $attr>";
  111. } else if ($name == 'cellnr') $out .= "</td></tr><tr><td $attr>";
  112. else $out .= "</td><td $attr>";
  113. }
  114. return $out;
  115. }
  116. Markup('table', '<block',
  117. '/^\\(:(table|cell|cellnr|tableend|div|divend)(\\s.*?)?:\\)/i',
  118. "TCells");
  119. }
  120. ## Transitions from 2.1.7
  121. if (@$Transition['version'] < 2001007)
  122. SDVA($Transition, array('vspace' => 1));
  123. ## vspace:
  124. ## This restores PmWiki's use of <p class='vspace'></p> to mark
  125. ## vertical space in the output.
  126. if (@$Transition['vspace']) $HTMLVSpace = "<p class='vspace'></p>";
  127. ## Transitions from 2.1.beta15
  128. if (@$Transition['version'] < 2000915)
  129. SDVA($Transition, array('fplbygroup' => 1));
  130. ## fplbygroup:
  131. ## The FPLByGroup function was removed in 2.1.beta15, this restores it.
  132. if (@$Transition['fplbygroup'] && !function_exists('FPLByGroup')) {
  133. SDV($FPLFormatOpt['bygroup'], array('fn' => 'FPLByGroup'));
  134. function FPLByGroup($pagename, &$matches, $opt) {
  135. global $FPLByGroupStartFmt, $FPLByGroupEndFmt, $FPLByGroupGFmt,
  136. $FPLByGroupIFmt, $FPLByGroupOpt;
  137. SDV($FPLByGroupStartFmt,"<dl class='fplbygroup'>");
  138. SDV($FPLByGroupEndFmt,'</dl>');
  139. SDV($FPLByGroupGFmt,"<dt><a href='\$ScriptUrl/\$Group'>\$Group</a> /</dt>\n");
  140. SDV($FPLByGroupIFmt,"<dd><a href='\$PageUrl'>\$Name</a></dd>\n");
  141. SDVA($FPLByGroupOpt, array('readf' => 0, 'order' => 'name'));
  142. $matches = MakePageList($pagename,
  143. array_merge((array)$FPLByGroupOpt, $opt), 0);
  144. if (@$opt['count']) array_splice($matches, $opt['count']);
  145. if (count($matches)<1) return '';
  146. $out = '';
  147. foreach($matches as $pn) {
  148. $pgroup = FmtPageName($FPLByGroupGFmt, $pn);
  149. if ($pgroup != @$lgroup) { $out .= $pgroup; $lgroup = $pgroup; }
  150. $out .= FmtPageName($FPLByGroupIFmt, $pn);
  151. }
  152. return FmtPageName($FPLByGroupStartFmt, $pagename) . $out .
  153. FmtPageName($FPLByGroupEndFmt, $pagename);
  154. }
  155. }
  156. ## Transitions from 2.0.beta44
  157. if (@$Transition['version'] < 1999944)
  158. SDVA($Transition, array('mainrc' => 1, 'mainapprovedurls' => 1,
  159. 'pageeditfmt' => 1, 'mainpages' => 1));
  160. ## mainrc:
  161. ## 2.0.beta44 switched Main.AllRecentChanges to be
  162. ## $SiteGroup.AllRecentChanges. This setting keeps Main.AllRecentChanges
  163. ## if it exists.
  164. if (@$Transition['mainrc'] && PageExists('Main.AllRecentChanges')) {
  165. SDV($RecentChangesFmt['Main.AllRecentChanges'],
  166. '* [[$Group.$Name]] . . . $CurrentTime $[by] $AuthorLink');
  167. }
  168. ## siteapprovedurls:
  169. ## 2.0.beta44 switched Main.ApprovedUrls to be $SiteGroup.ApprovedUrls .
  170. ## This setting keeps using Main.ApprovedUrls if it exists.
  171. if (@$Transition['mainapprovedurls'] && PageExists('Main.ApprovedUrls')) {
  172. $ApprovedUrlPagesFmt = (array)$ApprovedUrlPagesFmt;
  173. if (PageExists(FmtPageName($ApprovedUrlPagesFmt[0], $pagename)))
  174. $ApprovedUrlPagesFmt[] = 'Main.ApprovedUrls';
  175. else array_unshift($ApprovedUrlPagesFmt, 'Main.ApprovedUrls');
  176. }
  177. ## pageeditfmt:
  178. ## 2.0.beta44 switched to using wiki markup forms for page editing.
  179. ## However, some sites and skins have customized values of $PageEdit.
  180. ## This setting restores the default values.
  181. if (@$Transition['pageeditfmt']) {
  182. SDV($PageEditFmt, "<div id='wikiedit'>
  183. <a id='top' name='top'></a>
  184. <h1 class='wikiaction'>$[Editing \$FullName]</h1>
  185. <form method='post' action='\$PageUrl?action=edit'>
  186. <input type='hidden' name='action' value='edit' />
  187. <input type='hidden' name='n' value='\$FullName' />
  188. <input type='hidden' name='basetime' value='\$EditBaseTime' />
  189. \$EditMessageFmt
  190. <textarea id='text' name='text' rows='25' cols='60'
  191. onkeydown='if (event.keyCode==27) event.returnValue=false;'
  192. >\$EditText</textarea><br />
  193. $[Author]: <input type='text' name='author' value='\$Author' />
  194. <input type='checkbox' name='diffclass' value='minor' \$DiffClassMinor />
  195. $[This is a minor edit]<br />
  196. <input type='submit' name='post' value=' $[Save] ' />
  197. <input type='submit' name='preview' value=' $[Preview] ' />
  198. <input type='reset' value=' $[Reset] ' /></form></div>");
  199. if (@$_POST['preview'])
  200. SDV($PagePreviewFmt, "<div id='wikipreview'>
  201. <h2 class='wikiaction'>$[Preview \$FullName]</h2>
  202. <p><b>$[Page is unsaved]</b></p>
  203. \$PreviewText
  204. <hr /><p><b>$[End of preview -- remember to save]</b><br />
  205. <a href='#top'>$[Top]</a></p></div>");
  206. SDV($HandleEditFmt, array(&$PageStartFmt,
  207. &$PageEditFmt, 'wiki:$[PmWiki.EditQuickReference]', &$PagePreviewFmt,
  208. &$PageEndFmt));
  209. $EditMessageFmt = implode('', $MessagesFmt) . $EditMessageFmt;
  210. if ($action=='edit' && IsEnabled($EnableGUIButtons, 0))
  211. array_push($EditFunctions, 'GUIEdit');
  212. } else $MessagesFmt[] = @$EditMessageFmt;
  213. function GUIEdit($pagename, &$page, &$new) {
  214. global $EditMessageFmt;
  215. $EditMessageFmt .= GUIButtonCode($pagename);
  216. }
  217. ## mainpages:
  218. ## In 2.0.beta44 several utility pages change location to the new Site
  219. ## group. These settings cause some skins (that use translations)
  220. ## to know to link to the new locations.
  221. if (@$Transition['mainpages']) {
  222. XLSDV('en', array(
  223. 'Main/SearchWiki' => XL('Site/Search'),
  224. 'PmWiki.EditQuickReference' => XL('Site/EditQuickReference'),
  225. 'PmWiki.UploadQuickReference' => XL('Site/UploadQuickReference'),
  226. ));
  227. }