admin.php 5.4 KB

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