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