[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/revert/ -> admin.php (source)

   1  <?php
   2  // must be run within Dokuwiki
   3  if(!defined('DOKU_INC')) die();
   4  
   5  if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
   6  require_once (DOKU_PLUGIN.'admin.php');
   7  require_once (DOKU_INC.'inc/changelog.php');
   8  
   9  /**
  10   * All DokuWiki plugins to extend the admin function
  11   * need to inherit from this class
  12   */
  13  class admin_plugin_revert extends DokuWiki_Admin_Plugin {
  14      var $cmd;
  15      // some vars which might need tuning later
  16      var $max_lines = 800; // lines to read from changelog
  17      var $max_revs  = 20;  // numer of old revisions to check
  18  
  19  
  20      /**
  21       * Constructor
  22       */
  23      function admin_plugin_revert(){
  24          $this->setupLocale();
  25      }
  26  
  27      /**
  28       * return some info
  29       */
  30      function getInfo(){
  31          return array(
  32              'author' => 'Andreas Gohr',
  33              'email'  => 'andi@splitbrain.org',
  34              'date'   => '2008-05-94',
  35              'name'   => 'Revert Manager',
  36              'desc'   => 'Allows you to mass revert recent edits',
  37              'url'    => 'http://dokuwiki.org/plugin:revert',
  38          );
  39      }
  40  
  41      /**
  42       * access for managers
  43       */
  44      function forAdminOnly(){
  45          return false;
  46      }
  47  
  48      /**
  49       * return sort order for position in admin menu
  50       */
  51      function getMenuSort() {
  52          return 40;
  53      }
  54  
  55      /**
  56       * handle user request
  57       */
  58      function handle() {
  59      }
  60  
  61      /**
  62       * output appropriate html
  63       */
  64      function html() {
  65  
  66          echo $this->plugin_locale_xhtml('intro');
  67  
  68          $this->_searchform();
  69  
  70          if(is_array($_REQUEST['revert']) && checkSecurityToken()){
  71              $this->_revert($_REQUEST['revert'],$_REQUEST['filter']);
  72          }elseif(isset($_REQUEST['filter'])){
  73              $this->_list($_REQUEST['filter']);
  74          }
  75      }
  76  
  77      /**
  78       * Display the form for searching spam pages
  79       */
  80      function _searchform(){
  81          global $lang;
  82          echo '<form action="" method="post"><div class="no">';
  83          echo '<label>'.$this->getLang('filter').': </label>';
  84          echo '<input type="text" name="filter" class="edit" value="'.hsc($_REQUEST['filter']).'" />';
  85          echo '<input type="submit" class="button" value="'.$lang['btn_search'].'" />';
  86          echo ' <span>'.$this->getLang('note1').'</span>';
  87          echo '</div></form><br /><br />';
  88      }
  89  
  90      /**
  91       * Start the reversion process
  92       */
  93      function _revert($revert,$filter){
  94          global $conf;
  95  
  96          echo '<hr /><br />';
  97          echo '<p>'.$this->getLang('revstart').'</p>';
  98  
  99          echo '<ul>';
 100          foreach($revert as $id){
 101              global $REV;
 102  
 103              // find the last non-spammy revision
 104              $data = '';
 105              $old  = getRevisions($id, 0, $this->max_revs);
 106              if(count($old)){
 107                  foreach($old as $REV){
 108                      $data = rawWiki($id,$REV);
 109                      if(strpos($data,$filter) === false) break;
 110                  }
 111              }
 112  
 113              if($data){
 114                  saveWikiText($id,$data,'old revision restored',false);
 115                  printf('<li><div class="li">'.$this->getLang('reverted').'</div></li>',$id,$REV);
 116              }else{
 117                  saveWikiText($id,'','',false);
 118                  printf('<li><div class="li">'.$this->getLang('removed').'</div></li>',$id);
 119              }
 120              @set_time_limit(10);
 121              flush();
 122          }
 123          echo '</ul>';
 124  
 125          echo '<p>'.$this->getLang('revstop').'</p>';
 126      }
 127  
 128      /**
 129       * List recent edits matching the given filter
 130       */
 131      function _list($filter){
 132          global $conf;
 133          echo '<hr /><br />';
 134          echo '<form action="" method="post"><div class="no">';
 135          echo '<input type="hidden" name="filter" value="'.hsc($filter).'" />';
 136          formSecurityToken();
 137  
 138          $recents = getRecents(0,$this->max_lines);
 139          echo '<ul>';
 140  
 141  
 142          $cnt = 0;
 143          foreach($recents as $recent){
 144              if($filter){
 145                  if(strpos(rawWiki($recent['id']),$filter) === false) continue;
 146              }
 147  
 148              $cnt++;
 149              $date = strftime($conf['dformat'],$recent['date']);
 150  
 151              echo ($recent['type']===DOKU_CHANGE_TYPE_MINOR_EDIT) ? '<li class="minor">' : '<li>';
 152              echo '<div class="li">';
 153              echo '<input type="checkbox" name="revert[]" value="'.hsc($recent['id']).'" checked="checked" id="revert__'.$cnt.'" />';
 154              echo '<label for="revert__'.$cnt.'">'.$date.'</label> ';
 155  
 156              echo '<a href="'.wl($recent['id'],"do=diff").'">';
 157              $p = array();
 158              $p['src']    = DOKU_BASE.'lib/images/diff.png';
 159              $p['width']  = 15;
 160              $p['height'] = 11;
 161              $p['title']  = $lang['diff'];
 162              $p['alt']    = $lang['diff'];
 163              $att = buildAttributes($p);
 164              echo "<img $att />";
 165              echo '</a> ';
 166  
 167              echo '<a href="'.wl($recent['id'],"do=revisions").'">';
 168              $p = array();
 169              $p['src']    = DOKU_BASE.'lib/images/history.png';
 170              $p['width']  = 12;
 171              $p['height'] = 14;
 172              $p['title']  = $lang['btn_revs'];
 173              $p['alt']    = $lang['btn_revs'];
 174              $att = buildAttributes($p);
 175              echo "<img $att />";
 176              echo '</a> ';
 177  
 178              echo html_wikilink(':'.$recent['id'],$conf['useheading']?NULL:$recent['id']);
 179              echo ' &ndash; '.htmlspecialchars($recent['sum']);
 180  
 181              echo ' <span class="user">';
 182                  echo $recent['user'].' '.$recent['ip'];
 183              echo '</span>';
 184  
 185              echo '</div>';
 186              echo '</li>';
 187  
 188              @set_time_limit(10);
 189              flush();
 190          }
 191          echo '</ul>';
 192  
 193          echo '<p>';
 194          echo '<input type="submit" class="button" value="'.$this->getLang('revert').'" /> ';
 195          printf($this->getLang('note2'),hsc($filter));
 196          echo '</p>';
 197  
 198          echo '</div></form>';
 199      }
 200  
 201  }
 202  //Setup VIM: ex: et ts=4 enc=utf-8 :


Generated: Tue Dec 2 01:30:01 2008 Cross-referenced by PHPXref 0.7