pagerev.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php if (!defined('PmWiki')) exit();
  2. /* Copyright 2004 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. SDV($DiffShow['minor'],(@$_REQUEST['minor']!='n')?'y':'n');
  11. SDV($DiffShow['source'],(@$_REQUEST['source']=='y')?'y':'n');
  12. SDV($DiffMinorFmt, ($DiffShow['minor']=='y') ?
  13. "<a href='\$PageUrl?action=diff&amp;source=".$DiffShow['source']."&amp;minor=n'>$[Hide minor edits]</a>" :
  14. "<a href='\$PageUrl?action=diff&amp;source=".$DiffShow['source']."&amp;minor=y'>$[Show minor edits]</a>" );
  15. SDV($DiffSourceFmt, ($DiffShow['source']=='y') ?
  16. "<a href='\$PageUrl?action=diff&amp;source=n&amp;minor=".$DiffShow['minor']."'>$[Show changes to output]</a>" :
  17. "<a href='\$PageUrl?action=diff&amp;source=y&amp;minor=".$DiffShow['minor']."'>$[Show changes to markup]</a>");
  18. SDV($PageDiffFmt,"<h1 class='wikiaction'>$[\$PageName History]</h1>
  19. <p>$DiffMinorFmt - $DiffSourceFmt</p>
  20. ");
  21. SDV($DiffStartFmt,"
  22. <div class='diffbox'><div class='difftime'>\$DiffTime
  23. \$[by] <span class='diffauthor'>\$DiffAuthor</span></div>");
  24. SDV($DiffDelFmt['a'],"
  25. <div class='difftype'>\$[Deleted line \$DiffLines:]</div>
  26. <div class='diffdel'>");
  27. SDV($DiffDelFmt['c'],"
  28. <div class='difftype'>\$[Changed line \$DiffLines from:]</div>
  29. <div class='diffdel'>");
  30. SDV($DiffAddFmt['d'],"
  31. <div class='difftype'>\$[Added line \$DiffLines:]</div>
  32. <div class='diffadd'>");
  33. SDV($DiffAddFmt['c'],"</div>
  34. <div class='difftype'>$[to:]</div>
  35. <div class='diffadd'>");
  36. SDV($DiffEndDelAddFmt,"</div>");
  37. SDV($DiffEndFmt,"</div>");
  38. SDV($DiffRestoreFmt,"
  39. <div class='diffrestore'><a href='\$PageUrl?action=edit&amp;restore=\$DiffId&amp;preview=y'>$[Restore]</a></div>");
  40. SDV($DiffAuthorPageExistsFmt,"<a class='authorlink'
  41. href='\$ScriptUrl/\$DiffAuthorPage'>\$DiffAuthor</a>");
  42. SDV($DiffAuthorPageMissingFmt,"\$DiffAuthor");
  43. $HandleActions['diff']='HandleDiff';
  44. function PrintDiff($pagename) {
  45. global $DiffClass,$DiffId,$DiffTime,$DiffAuthor,$TimeFmt,
  46. $DiffStartFmt,$DiffEndFmt,$DiffAddFmt,$DiffDelFmt,
  47. $DiffEndDelAddFmt,$DiffRestoreFmt,$PatchFunction,$DiffShow,$GCount,
  48. $DiffAuthorPage,$DiffAuthorPageExistsFmt,$DiffAuthorPageMissingFmt,
  49. $AuthorGroup,$DiffChangeSum;
  50. $page = ReadPage($pagename);
  51. if (!$page) return;
  52. Lock(0);
  53. krsort($page); reset($page);
  54. foreach($page as $k=>$v) {
  55. if (!preg_match("/^diff:(\d+):(\d+):?([^:]*)/",$k,$match)) continue;
  56. $DiffClass = $match[3];
  57. if ($DiffClass=='minor' && $DiffShow['minor']!='y') continue;
  58. $DiffGmt = $match[1]; $DiffTime = strftime($TimeFmt,$DiffGmt);
  59. $DiffAuthor = @$page["author:$DiffGmt"];
  60. if (!$DiffAuthor) @$DiffAuthor=$page["host:$DiffGmt"];
  61. if (!$DiffAuthor) $DiffAuthor="unknown";
  62. if ($a = FreeLink('{{'.$DiffAuthor.'}}')) {
  63. $DiffAuthorPage="$AuthorGroup/".$a['name']; $GCount=0;
  64. if (PageExists($DiffAuthorPage))
  65. $DiffAuthor=FmtPageName($DiffAuthorPageExistsFmt,$pagename);
  66. else $DiffAuthor=FmtPageName($DiffAuthorPageMissingFmt,$pagename);
  67. }
  68. $DiffChangeSum = @$page["csum:$DiffGmt"];
  69. $DiffId = $k; $GCount=0;
  70. echo FmtPageName($DiffStartFmt,$pagename);
  71. $difflines = explode("\n",$v."\n");
  72. $in=array(); $out=array(); $dtype='';
  73. foreach($difflines as $d) {
  74. if ($d>'') {
  75. if ($d[0]=='-' || $d[0]=='\\') continue;
  76. if ($d[0]=='<') { $out[]=substr($d,2); continue; }
  77. if ($d[0]=='>') { $in[]=substr($d,2); continue; }
  78. }
  79. if (preg_match("/^(\\d+)(,(\\d+))?([adc])\\d/",$dtype,$match)) {
  80. if ($match[3]>'') { $lines='lines'; $count=$match[1].'-'.$match[3]; }
  81. else { $lines='line'; $count=$match[1]; }
  82. if ($match[4]=='a' || $match[4]=='c') {
  83. $txt = str_replace('line',$lines,$DiffDelFmt[$match[4]]);
  84. $txt = FmtPageName($txt,$pagename);
  85. echo str_replace('$DiffLines',$count,$txt);
  86. if ($DiffShow['source']=='y')
  87. echo "<code>",
  88. str_replace("\n","<br />",htmlspecialchars(join("\n",$in))),
  89. "</code>";
  90. else PrintText($pagename,join("\n",$in));
  91. }
  92. if ($match[4]=='d' || $match[4]=='c') {
  93. $txt = str_replace('line',$lines,$DiffAddFmt[$match[4]]);
  94. $txt = FmtPageName($txt,$pagename);
  95. echo str_replace('$DiffLines',$count,$txt);
  96. if ($DiffShow['source']=='y')
  97. echo "<code>",
  98. str_replace("\n","<br />",htmlspecialchars(join("\n",$out))),
  99. "</code>";
  100. else PrintText($pagename,join("\n",$out));
  101. }
  102. echo FmtPageName($DiffEndDelAddFmt,$pagename);
  103. }
  104. $in=array(); $out=array(); $dtype=$d;
  105. }
  106. echo FmtPageName($DiffEndFmt,$pagename);
  107. if ($PatchFunction) echo FmtPageName($DiffRestoreFmt,$pagename);
  108. }
  109. }
  110. function HandleDiff($pagename) {
  111. global $DiffAccessLevel,$HandleDiffFmt,
  112. $PageStartFmt,$PageDiffFmt,$PageEndFmt;
  113. SDV($DiffAccessLevel,'read');
  114. $page = RetrieveAuthPage($pagename,$DiffAccessLevel);
  115. if (!$page) { Abort("?cannot diff $pagename"); }
  116. SetPageVars($pagename,$page,"$pagename History");
  117. SDV($HandleDiffFmt,array(&$PageStartFmt,
  118. &$PageDiffFmt,'function:PrintDiff',
  119. &$PageEndFmt));
  120. PrintFmt($pagename,$HandleDiffFmt);
  121. }