1f21dad39SAndreas Gohr<?php 2f21dad39SAndreas Gohr 3f21dad39SAndreas Gohrnamespace dokuwiki\Action; 4f21dad39SAndreas Gohr 56723156fSAndreas Gohruse dokuwiki\Ui\Editor; 6f21dad39SAndreas Gohruse dokuwiki\Action\Exception\ActionAbort; 725dd2a2fSSatoshi Saharause dokuwiki\Ui; 8f21dad39SAndreas Gohr 9ab583a1bSAndreas Gohr/** 10ab583a1bSAndreas Gohr * Class Edit 11ab583a1bSAndreas Gohr * 12ab583a1bSAndreas Gohr * Handle editing 13ab583a1bSAndreas Gohr * 14ab583a1bSAndreas Gohr * @package dokuwiki\Action 15ab583a1bSAndreas Gohr */ 1625dd2a2fSSatoshi Saharaclass Edit extends AbstractAction 1725dd2a2fSSatoshi Sahara{ 18f21dad39SAndreas Gohr /** @inheritdoc */ 1925dd2a2fSSatoshi Sahara public function minimumPermission() 2025dd2a2fSSatoshi Sahara { 21f21dad39SAndreas Gohr global $INFO; 22f21dad39SAndreas Gohr if ($INFO['exists']) { 23f21dad39SAndreas Gohr return AUTH_READ; // we check again below 24f21dad39SAndreas Gohr } else { 25f21dad39SAndreas Gohr return AUTH_CREATE; 26f21dad39SAndreas Gohr } 27f21dad39SAndreas Gohr } 28f21dad39SAndreas Gohr 29ab583a1bSAndreas Gohr /** 30ab583a1bSAndreas Gohr * @inheritdoc falls back to 'source' if page not writable 31ab583a1bSAndreas Gohr */ 3225dd2a2fSSatoshi Sahara public function checkPreconditions() 3325dd2a2fSSatoshi Sahara { 34b2c9cd19SAndreas Gohr parent::checkPreconditions(); 35f21dad39SAndreas Gohr global $INFO; 36f21dad39SAndreas Gohr 37f21dad39SAndreas Gohr // no edit permission? view source 38f21dad39SAndreas Gohr if ($INFO['exists'] && !$INFO['writable']) { 39f21dad39SAndreas Gohr throw new ActionAbort('source'); 40f21dad39SAndreas Gohr } 41f21dad39SAndreas Gohr } 42f21dad39SAndreas Gohr 43ec701221SAndreas Gohr /** @inheritdoc */ 4425dd2a2fSSatoshi Sahara public function preProcess() 4525dd2a2fSSatoshi Sahara { 46f21dad39SAndreas Gohr global $ID; 47f21dad39SAndreas Gohr global $INFO; 48f21dad39SAndreas Gohr 49f21dad39SAndreas Gohr global $TEXT; 50f21dad39SAndreas Gohr global $RANGE; 51f21dad39SAndreas Gohr global $PRE; 52f21dad39SAndreas Gohr global $SUF; 53f21dad39SAndreas Gohr global $REV; 54f21dad39SAndreas Gohr global $SUM; 55f21dad39SAndreas Gohr global $lang; 56f21dad39SAndreas Gohr global $DATE; 57f21dad39SAndreas Gohr 58f21dad39SAndreas Gohr if (!isset($TEXT)) { 59f21dad39SAndreas Gohr if ($INFO['exists']) { 60f21dad39SAndreas Gohr if ($RANGE) { 616723156fSAndreas Gohr [$PRE, $TEXT, $SUF] = rawWikiSlices($RANGE, $ID, $REV); 62f21dad39SAndreas Gohr } else { 63f21dad39SAndreas Gohr $TEXT = rawWiki($ID, $REV); 64f21dad39SAndreas Gohr } 65f21dad39SAndreas Gohr } else { 66f21dad39SAndreas Gohr $TEXT = pageTemplate($ID); 67f21dad39SAndreas Gohr } 68f21dad39SAndreas Gohr } 69f21dad39SAndreas Gohr 70f21dad39SAndreas Gohr //set summary default 71f21dad39SAndreas Gohr if (!$SUM) { 72f21dad39SAndreas Gohr if ($REV) { 73f21dad39SAndreas Gohr $SUM = sprintf($lang['restored'], dformat($REV)); 74f21dad39SAndreas Gohr } elseif (!$INFO['exists']) { 75f21dad39SAndreas Gohr $SUM = $lang['created']; 76f21dad39SAndreas Gohr } 77f21dad39SAndreas Gohr } 78f21dad39SAndreas Gohr 79f21dad39SAndreas Gohr // Use the date of the newest revision, not of the revision we edit 80f21dad39SAndreas Gohr // This is used for conflict detection 81f21dad39SAndreas Gohr if (!$DATE) $DATE = @filemtime(wikiFN($ID)); 82f21dad39SAndreas Gohr 83f21dad39SAndreas Gohr //check if locked by anyone - if not lock for my self 84f21dad39SAndreas Gohr $lockedby = checklock($ID); 85f21dad39SAndreas Gohr if ($lockedby) { 86f21dad39SAndreas Gohr throw new ActionAbort('locked'); 8779a2d784SGerrit Uitslag } 88f21dad39SAndreas Gohr lock($ID); 89f21dad39SAndreas Gohr } 90f21dad39SAndreas Gohr 91ec701221SAndreas Gohr /** @inheritdoc */ 9225dd2a2fSSatoshi Sahara public function tplContent() 9325dd2a2fSSatoshi Sahara { 94*73022918SAndreas Gohr (new Editor())->show(); 95f21dad39SAndreas Gohr } 96f21dad39SAndreas Gohr} 97