transition.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2005-2006 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['vspace'] - restore <p class='vspace'></p>
  15. $Transition['version'] < 2001006 - all transitions listed above
  16. $Transition['fplbygroup'] - restore FPLByGroup function
  17. $Transition['version'] < 2000915 - all transitions listed above
  18. $Transition['mainrc'] - keep using Main.AllRecentChanges
  19. $Transition['mainapprovedurls'] - keep using Main.ApprovedUrls
  20. $Transition['pageeditfmt'] - default $PageEditFmt value
  21. $Transition['mainpages'] - other default pages in Main
  22. $Transition['version'] < 1999944 - all transitions listed above
  23. To get all of the transitions for compatibility with a previous
  24. version of PmWiki, simply set $Transition['version'] in a local
  25. configuration file to the version number you want compatibility
  26. with. All of the transitions associated with that version will
  27. then be enabled. Example:
  28. # Keep compatibility with PmWiki version 2.0.13
  29. $Transition['version'] = 2000013;
  30. To explicitly enable or disable specific transitions, set
  31. the corresponding $Transition[] element to 1 or 0. This will
  32. override the $Transition['version'] item listed above. For
  33. example, to enable just the 'pageeditfmt' transition, use
  34. $Transition['pageeditfmt'] = 1;
  35. */
  36. ## if ?trans=0 is specified, then we don't do any fixups.
  37. if (@$_REQUEST['trans']==='0') return;
  38. ## Transitions from 2.1.12
  39. if (@$Transition['version'] < 2001012)
  40. SDVA($Transition, array('nodivnest' => 1));
  41. ## nodivnest:
  42. ## This restores the PmWiki 2.1.11 behavior that doesn't
  43. ## allow nesting of divs and tables.
  44. if (@$Transition['nodivnest']) {
  45. function TCells($name,$attr) {
  46. global $MarkupFrame;
  47. $attr = preg_replace('/([a-zA-Z]=)([^\'"]\\S*)/',"\$1'\$2'",$attr);
  48. $tattr = @$MarkupFrame[0]['tattr'];
  49. $name = strtolower($name);
  50. $out = '<:block>';
  51. if (strncmp($name, 'cell', 4) != 0 || @$MarkupFrame[0]['closeall']['div']) {
  52. $out .= @$MarkupFrame[0]['closeall']['div'];
  53. unset($MarkupFrame[0]['closeall']['div']);
  54. $out .= @$MarkupFrame[0]['closeall']['table'];
  55. unset($MarkupFrame[0]['closeall']['table']);
  56. }
  57. if ($name == 'div') {
  58. $MarkupFrame[0]['closeall']['div'] = "</div>";
  59. $out .= "<div $attr>";
  60. }
  61. if ($name == 'table') $MarkupFrame[0]['tattr'] = $attr;
  62. if (strncmp($name, 'cell', 4) == 0) {
  63. if (strpos($attr, "valign=")===false) $attr .= " valign='top'";
  64. if (!@$MarkupFrame[0]['closeall']['table']) {
  65. $MarkupFrame[0]['closeall']['table'] = "</td></tr></table>";
  66. $out .= "<table $tattr><tr><td $attr>";
  67. } else if ($name == 'cellnr') $out .= "</td></tr><tr><td $attr>";
  68. else $out .= "</td><td $attr>";
  69. }
  70. return $out;
  71. }
  72. Markup('table', '<block',
  73. '/^\\(:(table|cell|cellnr|tableend|div|divend)(\\s.*?)?:\\)/ie',
  74. "TCells('$1',PSS('$2'))");
  75. }
  76. ## Transitions from 2.1.7
  77. if (@$Transition['version'] < 2001007)
  78. SDVA($Transition, array('vspace' => 1));
  79. ## vspace:
  80. ## This restores PmWiki's use of <p class='vspace'></p> to mark
  81. ## vertical space in the output.
  82. if (@$Transition['vspace']) $HTMLVSpace = "<p class='vspace'></p>";
  83. ## Transitions from 2.1.beta15
  84. if (@$Transition['version'] < 2000915)
  85. SDVA($Transition, array('fplbygroup' => 1));
  86. ## fplbygroup:
  87. ## The FPLByGroup function was removed in 2.1.beta15, this restores it.
  88. if (@$Transition['fplbygroup'] && !function_exists('FPLByGroup')) {
  89. SDV($FPLFormatOpt['bygroup'], array('fn' => 'FPLByGroup'));
  90. function FPLByGroup($pagename, &$matches, $opt) {
  91. global $FPLByGroupStartFmt, $FPLByGroupEndFmt, $FPLByGroupGFmt,
  92. $FPLByGroupIFmt, $FPLByGroupOpt;
  93. SDV($FPLByGroupStartFmt,"<dl class='fplbygroup'>");
  94. SDV($FPLByGroupEndFmt,'</dl>');
  95. SDV($FPLByGroupGFmt,"<dt><a href='\$ScriptUrl/\$Group'>\$Group</a> /</dt>\n");
  96. SDV($FPLByGroupIFmt,"<dd><a href='\$PageUrl'>\$Name</a></dd>\n");
  97. SDVA($FPLByGroupOpt, array('readf' => 0, 'order' => 'name'));
  98. $matches = MakePageList($pagename,
  99. array_merge((array)$FPLByGroupOpt, $opt), 0);
  100. if (@$opt['count']) array_splice($matches, $opt['count']);
  101. if (count($matches)<1) return '';
  102. $out = '';
  103. foreach($matches as $pn) {
  104. $pgroup = FmtPageName($FPLByGroupGFmt, $pn);
  105. if ($pgroup != @$lgroup) { $out .= $pgroup; $lgroup = $pgroup; }
  106. $out .= FmtPageName($FPLByGroupIFmt, $pn);
  107. }
  108. return FmtPageName($FPLByGroupStartFmt, $pagename) . $out .
  109. FmtPageName($FPLByGroupEndFmt, $pagename);
  110. }
  111. }
  112. ## Transitions from 2.0.beta44
  113. if (@$Transition['version'] < 1999944)
  114. SDVA($Transition, array('mainrc' => 1, 'mainapprovedurls' => 1,
  115. 'pageeditfmt' => 1, 'mainpages' => 1));
  116. ## mainrc:
  117. ## 2.0.beta44 switched Main.AllRecentChanges to be
  118. ## $SiteGroup.AllRecentChanges. This setting keeps Main.AllRecentChanges
  119. ## if it exists.
  120. if (@$Transition['mainrc'] && PageExists('Main.AllRecentChanges')) {
  121. SDV($RecentChangesFmt['Main.AllRecentChanges'],
  122. '* [[$Group.$Name]] . . . $CurrentTime $[by] $AuthorLink');
  123. }
  124. ## siteapprovedurls:
  125. ## 2.0.beta44 switched Main.ApprovedUrls to be $SiteGroup.ApprovedUrls .
  126. ## This setting keeps using Main.ApprovedUrls if it exists.
  127. if (@$Transition['mainapprovedurls'] && PageExists('Main.ApprovedUrls')) {
  128. $ApprovedUrlPagesFmt = (array)$ApprovedUrlPagesFmt;
  129. if (PageExists(FmtPageName($ApprovedUrlPagesFmt[0], $pagename)))
  130. $ApprovedUrlPagesFmt[] = 'Main.ApprovedUrls';
  131. else array_unshift($ApprovedUrlPagesFmt, 'Main.ApprovedUrls');
  132. }
  133. ## pageeditfmt:
  134. ## 2.0.beta44 switched to using wiki markup forms for page editing.
  135. ## However, some sites and skins have customized values of $PageEdit.
  136. ## This setting restores the default values.
  137. if (@$Transition['pageeditfmt']) {
  138. SDV($PageEditFmt, "<div id='wikiedit'>
  139. <a id='top' name='top'></a>
  140. <h1 class='wikiaction'>$[Editing \$FullName]</h1>
  141. <form method='post' action='\$PageUrl?action=edit'>
  142. <input type='hidden' name='action' value='edit' />
  143. <input type='hidden' name='n' value='\$FullName' />
  144. <input type='hidden' name='basetime' value='\$EditBaseTime' />
  145. \$EditMessageFmt
  146. <textarea id='text' name='text' rows='25' cols='60'
  147. onkeydown='if (event.keyCode==27) event.returnValue=false;'
  148. >\$EditText</textarea><br />
  149. $[Author]: <input type='text' name='author' value='\$Author' />
  150. <input type='checkbox' name='diffclass' value='minor' \$DiffClassMinor />
  151. $[This is a minor edit]<br />
  152. <input type='submit' name='post' value=' $[Save] ' />
  153. <input type='submit' name='preview' value=' $[Preview] ' />
  154. <input type='reset' value=' $[Reset] ' /></form></div>");
  155. if (@$_POST['preview'])
  156. SDV($PagePreviewFmt, "<div id='wikipreview'>
  157. <h2 class='wikiaction'>$[Preview \$FullName]</h2>
  158. <p><b>$[Page is unsaved]</b></p>
  159. \$PreviewText
  160. <hr /><p><b>$[End of preview -- remember to save]</b><br />
  161. <a href='#top'>$[Top]</a></p></div>");
  162. SDV($HandleEditFmt, array(&$PageStartFmt,
  163. &$PageEditFmt, 'wiki:$[PmWiki.EditQuickReference]', &$PagePreviewFmt,
  164. &$PageEndFmt));
  165. $EditMessageFmt = implode('', $MessagesFmt) . $EditMessageFmt;
  166. if ($action=='edit' && IsEnabled($EnableGUIButtons, 0))
  167. array_push($EditFunctions, 'GUIEdit');
  168. } else $MessagesFmt[] = @$EditMessageFmt;
  169. function GUIEdit($pagename, &$page, &$new) {
  170. global $EditMessageFmt;
  171. $EditMessageFmt .= GUIButtonCode($pagename);
  172. }
  173. ## mainpages:
  174. ## In 2.0.beta44 several utility pages change location to the new Site
  175. ## group. These settings cause some skins (that use translations)
  176. ## to know to link to the new locations.
  177. if ($Transition['mainpages']) {
  178. XLSDV('en', array(
  179. 'Main/SearchWiki' => XL('Site/Search'),
  180. 'PmWiki.EditQuickReference' => XL('Site/EditQuickReference'),
  181. 'PmWiki.UploadQuickReference' => XL('Site/UploadQuickReference'),
  182. ));
  183. }