You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

195 lines
5.5 KiB

  1. <?php
  2. use dokuwiki\Extension\AdminPlugin;
  3. use dokuwiki\ChangeLog\PageChangeLog;
  4. /**
  5. * All DokuWiki plugins to extend the admin function
  6. * need to inherit from this class
  7. */
  8. class admin_plugin_revert extends AdminPlugin
  9. {
  10. protected $cmd;
  11. // some vars which might need tuning later
  12. protected $max_lines = 800; // lines to read from changelog
  13. protected $max_revs = 20; // numer of old revisions to check
  14. /**
  15. * Constructor
  16. */
  17. public function __construct()
  18. {
  19. $this->setupLocale();
  20. }
  21. /**
  22. * access for managers
  23. */
  24. public function forAdminOnly()
  25. {
  26. return false;
  27. }
  28. /**
  29. * return sort order for position in admin menu
  30. */
  31. public function getMenuSort()
  32. {
  33. return 40;
  34. }
  35. /**
  36. * handle user request
  37. */
  38. public function handle()
  39. {
  40. }
  41. /**
  42. * output appropriate html
  43. */
  44. public function html()
  45. {
  46. global $INPUT;
  47. echo $this->locale_xhtml('intro');
  48. $this->printSearchForm();
  49. if (is_array($INPUT->param('revert')) && checkSecurityToken()) {
  50. $this->revertEdits($INPUT->arr('revert'), $INPUT->str('filter'));
  51. } elseif ($INPUT->has('filter')) {
  52. $this->listEdits($INPUT->str('filter'));
  53. }
  54. }
  55. /**
  56. * Display the form for searching spam pages
  57. */
  58. protected function printSearchForm()
  59. {
  60. global $lang, $INPUT;
  61. echo '<form action="" method="post"><div class="no">';
  62. echo '<label>' . $this->getLang('filter') . ': </label>';
  63. echo '<input type="text" name="filter" class="edit" value="' . hsc($INPUT->str('filter')) . '" /> ';
  64. echo '<button type="submit">' . $lang['btn_search'] . '</button> ';
  65. echo '<span>' . $this->getLang('note1') . '</span>';
  66. echo '</div></form><br /><br />';
  67. }
  68. /**
  69. * Start the reversion process
  70. */
  71. protected function revertEdits($revert, $filter)
  72. {
  73. echo '<hr /><br />';
  74. echo '<p>' . $this->getLang('revstart') . '</p>';
  75. echo '<ul>';
  76. foreach ($revert as $id) {
  77. global $REV;
  78. // find the last non-spammy revision
  79. $data = '';
  80. $pagelog = new PageChangeLog($id);
  81. $old = $pagelog->getRevisions(0, $this->max_revs);
  82. if ($old !== []) {
  83. foreach ($old as $REV) {
  84. $data = rawWiki($id, $REV);
  85. if (strpos($data, (string) $filter) === false) break;
  86. }
  87. }
  88. if ($data) {
  89. saveWikiText($id, $data, 'old revision restored', false);
  90. printf('<li><div class="li">' . $this->getLang('reverted') . '</div></li>', $id, $REV);
  91. } else {
  92. saveWikiText($id, '', '', false);
  93. printf('<li><div class="li">' . $this->getLang('removed') . '</div></li>', $id);
  94. }
  95. @set_time_limit(10);
  96. flush();
  97. }
  98. echo '</ul>';
  99. echo '<p>' . $this->getLang('revstop') . '</p>';
  100. }
  101. /**
  102. * List recent edits matching the given filter
  103. */
  104. protected function listEdits($filter)
  105. {
  106. global $conf;
  107. global $lang;
  108. echo '<hr /><br />';
  109. echo '<form action="" method="post"><div class="no">';
  110. echo '<input type="hidden" name="filter" value="' . hsc($filter) . '" />';
  111. formSecurityToken();
  112. $recents = getRecents(0, $this->max_lines);
  113. echo '<ul>';
  114. $cnt = 0;
  115. foreach ($recents as $recent) {
  116. if ($filter) {
  117. if (strpos(rawWiki($recent['id']), (string) $filter) === false) continue;
  118. }
  119. $cnt++;
  120. $date = dformat($recent['date']);
  121. echo ($recent['type'] === DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
  122. echo '<div class="li">';
  123. echo '<input type="checkbox" name="revert[]" value="' . hsc($recent['id']) .
  124. '" checked="checked" id="revert__' . $cnt . '" />';
  125. echo ' <label for="revert__' . $cnt . '">' . $date . '</label> ';
  126. echo '<a href="' . wl($recent['id'], "do=diff") . '">';
  127. $p = [];
  128. $p['src'] = DOKU_BASE . 'lib/images/diff.png';
  129. $p['width'] = 15;
  130. $p['height'] = 11;
  131. $p['title'] = $lang['diff'];
  132. $p['alt'] = $lang['diff'];
  133. $att = buildAttributes($p);
  134. echo "<img $att />";
  135. echo '</a> ';
  136. echo '<a href="' . wl($recent['id'], "do=revisions") . '">';
  137. $p = [];
  138. $p['src'] = DOKU_BASE . 'lib/images/history.png';
  139. $p['width'] = 12;
  140. $p['height'] = 14;
  141. $p['title'] = $lang['btn_revs'];
  142. $p['alt'] = $lang['btn_revs'];
  143. $att = buildAttributes($p);
  144. echo "<img $att />";
  145. echo '</a> ';
  146. echo html_wikilink(':' . $recent['id'], (useHeading('navigation')) ? null : $recent['id']);
  147. echo ' – ' . htmlspecialchars($recent['sum']);
  148. echo ' <span class="user">';
  149. echo $recent['user'] . ' ' . $recent['ip'];
  150. echo '</span>';
  151. echo '</div>';
  152. echo '</li>';
  153. @set_time_limit(10);
  154. flush();
  155. }
  156. echo '</ul>';
  157. echo '<p>';
  158. echo '<button type="submit">' . $this->getLang('revert') . '</button> ';
  159. printf($this->getLang('note2'), hsc($filter));
  160. echo '</p>';
  161. echo '</div></form>';
  162. }
  163. }
  164. //Setup VIM: ex: et ts=4 :