[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/inc/Action/ -> Edit.php (source)

   1  <?php
   2  
   3  namespace dokuwiki\Action;
   4  
   5  use dokuwiki\Action\Exception\ActionAbort;
   6  use dokuwiki\Ui;
   7  
   8  /**
   9   * Class Edit
  10   *
  11   * Handle editing
  12   *
  13   * @package dokuwiki\Action
  14   */
  15  class Edit extends AbstractAction
  16  {
  17      /** @inheritdoc */
  18      public function minimumPermission()
  19      {
  20          global $INFO;
  21          if ($INFO['exists']) {
  22              return AUTH_READ; // we check again below
  23          } else {
  24              return AUTH_CREATE;
  25          }
  26      }
  27  
  28      /**
  29       * @inheritdoc falls back to 'source' if page not writable
  30       */
  31      public function checkPreconditions()
  32      {
  33          parent::checkPreconditions();
  34          global $INFO;
  35  
  36          // no edit permission? view source
  37          if ($INFO['exists'] && !$INFO['writable']) {
  38              throw new ActionAbort('source');
  39          }
  40      }
  41  
  42      /** @inheritdoc */
  43      public function preProcess()
  44      {
  45          global $ID;
  46          global $INFO;
  47  
  48          global $TEXT;
  49          global $RANGE;
  50          global $PRE;
  51          global $SUF;
  52          global $REV;
  53          global $SUM;
  54          global $lang;
  55          global $DATE;
  56  
  57          if (!isset($TEXT)) {
  58              if ($INFO['exists']) {
  59                  if ($RANGE) {
  60                      list($PRE, $TEXT, $SUF) = rawWikiSlices($RANGE, $ID, $REV);
  61                  } else {
  62                      $TEXT = rawWiki($ID, $REV);
  63                  }
  64              } else {
  65                  $TEXT = pageTemplate($ID);
  66              }
  67          }
  68  
  69          //set summary default
  70          if (!$SUM) {
  71              if ($REV) {
  72                  $SUM = sprintf($lang['restored'], dformat($REV));
  73              } elseif (!$INFO['exists']) {
  74                  $SUM = $lang['created'];
  75              }
  76          }
  77  
  78          // Use the date of the newest revision, not of the revision we edit
  79          // This is used for conflict detection
  80          if (!$DATE) $DATE = @filemtime(wikiFN($ID));
  81  
  82          //check if locked by anyone - if not lock for my self
  83          $lockedby = checklock($ID);
  84          if ($lockedby) {
  85              throw new ActionAbort('locked');
  86          }
  87          lock($ID);
  88      }
  89  
  90      /** @inheritdoc */
  91      public function tplContent()
  92      {
  93          (new Ui\Editor)->show();
  94      }
  95  
  96  }