pagerev.php 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2004-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 defines routines for displaying page revisions. It
  8. is included by default from the stdconfig.php script.
  9. */
  10. function LinkSuppress($pagename,$imap,$path,$title,$txt,$fmt=NULL)
  11. { return $txt; }
  12. SDV($DiffShow['minor'],(@$_REQUEST['minor']!='n')?'y':'n');
  13. SDV($DiffShow['source'],(@$_REQUEST['source']=='y')?'y':'n');
  14. SDV($DiffMinorFmt, ($DiffShow['minor']=='y') ?
  15. "<a href='{\$PageUrl}?action=diff&amp;source=".$DiffShow['source']."&amp;minor=n'>$[Hide minor edits]</a>" :
  16. "<a href='{\$PageUrl}?action=diff&amp;source=".$DiffShow['source']."&amp;minor=y'>$[Show minor edits]</a>" );
  17. SDV($DiffSourceFmt, ($DiffShow['source']=='y') ?
  18. "<a href='{\$PageUrl}?action=diff&amp;source=n&amp;minor=".$DiffShow['minor']."'>$[Show changes to output]</a>" :
  19. "<a href='{\$PageUrl}?action=diff&amp;source=y&amp;minor=".$DiffShow['minor']."'>$[Show changes to markup]</a>");
  20. SDV($PageDiffFmt,"<h2 class='wikiaction'>$[{\$FullName} History]</h2>
  21. <p>$DiffMinorFmt - $DiffSourceFmt</p>
  22. ");
  23. SDV($DiffStartFmt,"
  24. <div class='diffbox'><div class='difftime'>\$DiffTime
  25. \$[by] <span class='diffauthor' title='\$DiffHost'>\$DiffAuthor</span> - \$DiffChangeSum</div>");
  26. SDV($DiffDelFmt['a'],"
  27. <div class='difftype'>\$[Deleted line \$DiffLines:]</div>
  28. <div class='diffdel'>");
  29. SDV($DiffDelFmt['c'],"
  30. <div class='difftype'>\$[Changed line \$DiffLines from:]</div>
  31. <div class='diffdel'>");
  32. SDV($DiffAddFmt['d'],"
  33. <div class='difftype'>\$[Added line \$DiffLines:]</div>
  34. <div class='diffadd'>");
  35. SDV($DiffAddFmt['c'],"</div>
  36. <div class='difftype'>$[to:]</div>
  37. <div class='diffadd'>");
  38. SDV($DiffEndDelAddFmt,"</div>");
  39. SDV($DiffEndFmt,"</div>");
  40. SDV($DiffRestoreFmt,"
  41. <div class='diffrestore'><a href='{\$PageUrl}?action=edit&amp;restore=\$DiffId&amp;preview=y'>$[Restore]</a></div>");
  42. SDV($HandleActions['diff'], 'HandleDiff');
  43. SDV($HandleAuth['diff'], 'read');
  44. SDV($ActionTitleFmt['diff'], '| $[History]');
  45. SDV($HTMLStylesFmt['diff'], "
  46. .diffbox { width:570px; border-left:1px #999999 solid; margin-top:1.33em; }
  47. .diffauthor { font-weight:bold; }
  48. .diffchangesum { font-weight:bold; }
  49. .difftime { font-family:verdana,sans-serif; font-size:66%;
  50. background-color:#dddddd; }
  51. .difftype { clear:both; font-family:verdana,sans-serif;
  52. font-size:66%; font-weight:bold; }
  53. .diffadd { border-left:5px #99ff99 solid; padding-left:5px; }
  54. .diffdel { border-left:5px #ffff99 solid; padding-left:5px; }
  55. .diffrestore { clear:both; font-family:verdana,sans-serif;
  56. font-size:66%; margin:1.5em 0px; }
  57. .diffmarkup { font-family:monospace; } ");
  58. function PrintDiff($pagename) {
  59. global $DiffShow,$DiffStartFmt,$TimeFmt,$DiffDelFmt,$DiffAddFmt,
  60. $DiffEndDelAddFmt,$DiffEndFmt,$DiffRestoreFmt,$FmtV, $LinkFunctions;
  61. $page = ReadPage($pagename);
  62. if (!$page) return;
  63. krsort($page); reset($page);
  64. $lf = $LinkFunctions;
  65. $LinkFunctions['http:'] = 'LinkSuppress';
  66. $LinkFunctions['https:'] = 'LinkSuppress';
  67. foreach($page as $k=>$v) {
  68. if (!preg_match("/^diff:(\d+):(\d+):?([^:]*)/",$k,$match)) continue;
  69. $diffclass = $match[3];
  70. if ($diffclass=='minor' && $DiffShow['minor']!='y') continue;
  71. $diffgmt = $match[1]; $FmtV['$DiffTime'] = strftime($TimeFmt,$diffgmt);
  72. $diffauthor = @$page["author:$diffgmt"];
  73. if (!$diffauthor) @$diffauthor=$page["host:$diffgmt"];
  74. if (!$diffauthor) $diffauthor="unknown";
  75. $FmtV['$DiffChangeSum'] = htmlspecialchars(@$page["csum:$diffgmt"]);
  76. $FmtV['$DiffHost'] = @$page["host:$diffgmt"];
  77. $FmtV['$DiffAuthor'] = $diffauthor;
  78. $FmtV['$DiffId'] = $k;
  79. echo FmtPageName($DiffStartFmt,$pagename);
  80. $difflines = explode("\n",$v."\n");
  81. $in=array(); $out=array(); $dtype='';
  82. foreach($difflines as $d) {
  83. if ($d>'') {
  84. if ($d[0]=='-' || $d[0]=='\\') continue;
  85. if ($d[0]=='<') { $out[]=substr($d,2); continue; }
  86. if ($d[0]=='>') { $in[]=substr($d,2); continue; }
  87. }
  88. if (preg_match("/^(\\d+)(,(\\d+))?([adc])(\\d+)(,(\\d+))?/",
  89. $dtype,$match)) {
  90. if (@$match[7]>'') {
  91. $lines='lines';
  92. $count=$match[1].'-'.($match[1]+$match[7]-$match[5]);
  93. } elseif ($match[3]>'') {
  94. $lines='lines'; $count=$match[1].'-'.$match[3];
  95. } else { $lines='line'; $count=$match[1]; }
  96. if ($match[4]=='a' || $match[4]=='c') {
  97. $txt = str_replace('line',$lines,$DiffDelFmt[$match[4]]);
  98. $FmtV['$DiffLines'] = $count;
  99. echo FmtPageName($txt,$pagename);
  100. if ($DiffShow['source']=='y')
  101. echo "<div class='diffmarkup'>",
  102. str_replace("\n","<br />",htmlspecialchars(join("\n",$in))),
  103. "</div>";
  104. else echo MarkupToHTML($pagename,
  105. preg_replace('/\\(:.*?:\\)/e',"Keep(PSS('$0'))",join("\n",$in)));
  106. }
  107. if ($match[4]=='d' || $match[4]=='c') {
  108. $txt = str_replace('line',$lines,$DiffAddFmt[$match[4]]);
  109. $FmtV['$DiffLines'] = $count;
  110. echo FmtPageName($txt,$pagename);
  111. if ($DiffShow['source']=='y')
  112. echo "<div class='diffmarkup'>",
  113. str_replace("\n","<br />",htmlspecialchars(join("\n",$out))),
  114. "</div>";
  115. else echo MarkupToHTML($pagename,
  116. preg_replace('/\\(:.*?:\\)/e',"Keep(PSS('$0'))",join("\n",$out)));
  117. }
  118. echo FmtPageName($DiffEndDelAddFmt,$pagename);
  119. }
  120. $in=array(); $out=array(); $dtype=$d;
  121. }
  122. echo FmtPageName($DiffEndFmt,$pagename);
  123. echo FmtPageName($DiffRestoreFmt,$pagename);
  124. }
  125. $LinkFunctions = $lf;
  126. }
  127. function HandleDiff($pagename, $auth='read') {
  128. global $HandleDiffFmt, $PageStartFmt, $PageDiffFmt, $PageEndFmt;
  129. $page = RetrieveAuthPage($pagename, $auth, true);
  130. if (!$page) { Abort("?cannot diff $pagename"); }
  131. PCache($pagename, $page);
  132. SDV($HandleDiffFmt,array(&$PageStartFmt,
  133. &$PageDiffFmt,"<div id='wikidiff'>", 'function:PrintDiff', '</div>',
  134. &$PageEndFmt));
  135. PrintFmt($pagename,$HandleDiffFmt);
  136. }