Blob


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