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