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
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.
14
15    Transitions defined in this script:
16
17      $Transition['nosessionencode']    - turn off session encoding
18
19      $Transition['version'] < 2001967  - all transitions listed above
20
21      $Transition['wspre']              - leading spaces are pre text
22
23      $Transition['version'] < 2001941  - all transitions listed above
24
25      $Transition['wikiwords']          - 2.1-style WikiWord processing
26
27      $Transition['version'] < 2001924  - all transitions listed above
28
29      $Transition['abslinks']           - absolute links/page vars
30
31      $Transition['version'] < 2001901  - all transitions listed above
32
33      $Transition['vspace']             - restore <p class='vspace'></p>
34
35      $Transition['version'] < 2001006  - all transitions listed above
36
37      $Transition['fplbygroup']         - restore FPLByGroup function
38
39      $Transition['version'] < 2000915  - all transitions listed above
40
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
45
46      $Transition['version'] < 1999944  - all transitions listed above
47
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:
53
54            # Keep compatibility with PmWiki version 2.0.13
55            $Transition['version'] = 2000013;
56
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
61
62            $Transition['pageeditfmt'] = 1;
63
64    Script maintained by Petko YOTOV www.pmwiki.org/petko
65*/
66
67## if ?trans=0 is specified, then we don't do any fixups.
68if (@$_REQUEST['trans']==='0') return;
69
70## set a default Transition version if we don't have one
71SDV($Transition['version'], $VersionNum);
72
73## Transitions from 2.2.0-beta67
74if (@$Transition['version'] < 2001967)
75  SDVA($Transition, array('nosessionencode' => 1));
76
77if (@$Transition['nosessionencode']) {
78  $SessionEncode = NULL;
79  $SessionDecode = NULL;
80}
81
82## Transitions from 2.2.0-beta41
83if (@$Transition['version'] < 2001941)
84  SDVA($Transition, array('wspre' => 1));
85
86if (@$Transition['wspre']) SDV($EnableWSPre, 1);
87
88## Transitions from 2.2.0-beta24
89if (@$Transition['version'] < 2001924)
90  SDVA($Transition, array('wikiwords' => 1));
91
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.
96if (@$Transition['wikiwords']) {
97  SDV($EnableWikiWords, 1);
98  SDV($LinkWikiWords, 0);
99}
100
101## Transitions from 2.2.0-beta1
102if (@$Transition['version'] < 2001901)
103  SDVA($Transition, array('abslinks' => 1));
104
105## abslinks:
106##   This restores settings so that PmWiki treats all links
107##   as absolute (following the 2.1.x and earlier interpretation).
108if (@$Transition['abslinks']) {
109  SDV($EnableRelativePageLinks, 0);
110  SDV($EnableRelativePageVars, 0);
111}
112
113## Transitions from 2.1.12
114
115if (@$Transition['version'] < 2001012)
116  SDVA($Transition, array('nodivnest' => 1));
117
118## nodivnest:
119##   This restores the PmWiki 2.1.11 behavior that doesn't
120##   allow nesting of divs and tables.
121if (@$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']);
134    }
135    if ($name == 'div') {
136      $MarkupFrame[0]['closeall']['div'] = "</div>";
137      $out .= "<div $attr>";
138    }
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>";
147    }
148    return $out;
149  }
150
151  Markup('table', '<block',
152    '/^\\(:(table|cell|cellnr|tableend|div|divend)(\\s.*?)?:\\)/i',
153    "TCells");
154}
155
156
157## Transitions from 2.1.7
158
159if (@$Transition['version'] < 2001007)
160  SDVA($Transition, array('vspace' => 1));
161
162## vspace:
163##   This restores PmWiki's use of <p class='vspace'></p> to mark
164##   vertical space in the output.
165if (@$Transition['vspace']) $HTMLVSpace = "<p class='vspace'></p>";
166
167
168## Transitions from 2.1.beta15
169
170if (@$Transition['version'] < 2000915)
171  SDVA($Transition, array('fplbygroup' => 1));
172
173## fplbygroup:
174##   The FPLByGroup function was removed in 2.1.beta15, this restores it.
175if (@$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);
194    }
195    return FmtPageName($FPLByGroupStartFmt, $pagename) . $out .
196           FmtPageName($FPLByGroupEndFmt, $pagename);
197  }
198}
199
200## Transitions from 2.0.beta44
201
202if (@$Transition['version'] < 1999944)
203  SDVA($Transition, array('mainrc' => 1, 'mainapprovedurls' => 1,
204    'pageeditfmt' => 1, 'mainpages' => 1));
205
206## mainrc:
207##   2.0.beta44 switched Main.AllRecentChanges to be
208##   $SiteGroup.AllRecentChanges.  This setting keeps Main.AllRecentChanges
209##   if it exists.
210if (@$Transition['mainrc'] && PageExists('Main.AllRecentChanges')) {
211  SDV($RecentChangesFmt['Main.AllRecentChanges'],
212    '* [[$Group.$Name]]  . . . $CurrentTime $[by] $AuthorLink');
213}
214
215## siteapprovedurls:
216##   2.0.beta44 switched Main.ApprovedUrls to be $SiteGroup.ApprovedUrls .
217##   This setting keeps using Main.ApprovedUrls if it exists.
218if (@$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');
223}
224
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.
229if (@$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;
261
262
263function GUIEdit($pagename, &$page, &$new) {
264  global $EditMessageFmt;
265  $EditMessageFmt .= GUIButtonCode($pagename);
266}
267
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.
272if (@$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    ));
278}
279
280