[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/Ui/ -> PageRevisions.php (source)

   1  <?php
   2  
   3  namespace dokuwiki\Ui;
   4  
   5  use dokuwiki\ChangeLog\PageChangeLog;
   6  use dokuwiki\ChangeLog\RevisionInfo;
   7  use dokuwiki\Form\Form;
   8  
   9  /**
  10   * DokuWiki PageRevisions Interface
  11   *
  12   * @package dokuwiki\Ui
  13   */
  14  class PageRevisions extends Revisions
  15  {
  16      /* @var PageChangeLog */
  17      protected $changelog;
  18  
  19      /**
  20       * PageRevisions Ui constructor
  21       *
  22       * @param string $id  id of page
  23       */
  24      public function __construct($id = null)
  25      {
  26          global $INFO;
  27          if (!isset($id)) $id = $INFO['id'];
  28          parent::__construct($id);
  29      }
  30  
  31      /** @inheritdoc */
  32      protected function setChangeLog()
  33      {
  34          $this->changelog = new PageChangeLog($this->id);
  35      }
  36  
  37      /**
  38       * Display list of old revisions of the page
  39       *
  40       * @author Andreas Gohr <andi@splitbrain.org>
  41       * @author Ben Coburn <btcoburn@silicodon.net>
  42       * @author Kate Arzamastseva <pshns@ukr.net>
  43       * @author Satoshi Sahara <sahara.satoshi@gmail.com>
  44       *
  45       * @param int $first  skip the first n changelog lines
  46       * @return void
  47       */
  48      public function show($first = 0)
  49      {
  50          global $lang, $REV;
  51          $changelog =& $this->changelog;
  52  
  53          // get revisions, and set correct pagination parameters (first, hasNext)
  54          if ($first === null) $first = 0;
  55          $hasNext = false;
  56          $revisions = $this->getRevisions($first, $hasNext);
  57  
  58          // print intro
  59          print p_locale_xhtml('revisions');
  60  
  61          // create the form
  62          $form = new Form([
  63                  'id' => 'page__revisions',
  64                  'class' => 'changes',
  65          ]);
  66          $form->addTagOpen('div')->addClass('no');
  67  
  68          // start listing
  69          $form->addTagOpen('ul');
  70          foreach ($revisions as $info) {
  71              $rev = $info['date'];
  72              $RevInfo = new RevisionInfo($info);
  73              $RevInfo->isCurrent($changelog->isCurrentRevision($rev));
  74  
  75              $class = ($RevInfo->val('type') === DOKU_CHANGE_TYPE_MINOR_EDIT) ? 'minor' : '';
  76              $form->addTagOpen('li')->addClass($class);
  77              $form->addTagOpen('div')->addClass('li');
  78  
  79              if ($RevInfo->isCurrent()) {
  80                  $form->addCheckbox('rev2[]')->val($rev);
  81              } elseif ($rev == $REV) {
  82                  $form->addCheckbox('rev2[]')->val($rev)->attr('checked','checked');
  83              } elseif (page_exists($this->id, $rev)) {
  84                  $form->addCheckbox('rev2[]')->val($rev);
  85              } else {
  86                  $form->addCheckbox('')->val($rev)->attr('disabled','disabled');
  87              }
  88              $form->addHTML(' ');
  89  
  90              $html = implode(' ', [
  91                  $RevInfo->showEditDate(true),      // edit date and time
  92                  $RevInfo->showIconCompareWithCurrent(),  // link to diff view icon
  93                  $RevInfo->showFileName(),          // name of page or media
  94                  $RevInfo->showEditSummary(),       // edit summary
  95                  $RevInfo->showEditor(),            // editor info
  96                  $RevInfo->showSizechange(),        // size change indicator
  97                  $RevInfo->showCurrentIndicator(),  // current indicator (only when k=1)
  98              ]);
  99              $form->addHTML($html);
 100              $form->addTagClose('div');
 101              $form->addTagClose('li');
 102          }
 103          $form->addTagClose('ul');  // end of revision list
 104  
 105          // show button for diff view
 106          $form->addButton('do[diff]', $lang['diff2'])->attr('type', 'submit');
 107  
 108          $form->addTagClose('div'); // close div class=no
 109  
 110          print $form->toHTML('Revisions');
 111  
 112          // provide navigation for paginated revision list (of pages and/or media files)
 113          print $this->navigation($first, $hasNext, function ($n) {
 114              return array('do' => 'revisions', 'first' => $n);
 115          });
 116      }
 117  }