Merge pull request #3346 from splitbrain/userrevert

Allow revert action for logged in users only
This commit is contained in:
Andreas Gohr 2020-11-25 21:03:29 +01:00 committed by GitHub
commit 769d8ef12d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 11 deletions

View File

@ -17,7 +17,7 @@ abstract class AbstractUserAction extends AbstractAclAction {
public function checkPreconditions() {
parent::checkPreconditions();
global $INPUT;
if(!$INPUT->server->str('REMOTE_USER')) {
if($INPUT->server->str('REMOTE_USER') === '') {
throw new ActionUserRequiredException();
}
}

View File

@ -12,10 +12,12 @@ use dokuwiki\Action\Exception\ActionException;
*
* @package dokuwiki\Action
*/
class Revert extends AbstractAction {
class Revert extends AbstractUserAction
{
/** @inheritdoc */
public function minimumPermission() {
public function minimumPermission()
{
return AUTH_EDIT;
}
@ -26,8 +28,9 @@ class Revert extends AbstractAction {
* @throws ActionException
* @todo check for writability of the current page ($INFO might do it wrong and check the attic version)
*/
public function preProcess() {
if(!checkSecurityToken()) throw new ActionException();
public function preProcess()
{
if (!checkSecurityToken()) throw new ActionException();
global $ID;
global $REV;
@ -37,14 +40,14 @@ class Revert extends AbstractAction {
// FIXME this feature is not exposed in the GUI currently
$text = '';
$sum = $lang['deleted'];
if($REV) {
if ($REV) {
$text = rawWiki($ID, $REV);
if(!$text) throw new ActionException(); //something went wrong
if (!$text) throw new ActionException(); //something went wrong
$sum = sprintf($lang['restored'], dformat($REV));
}
// spam check
if(checkwordblock($text)) {
if (checkwordblock($text)) {
msg($lang['wordblock'], -1);
throw new ActionException('edit');
}

View File

@ -7,15 +7,18 @@ namespace dokuwiki\Menu\Item;
*
* Quick revert to the currently shown page revision
*/
class Revert extends AbstractItem {
class Revert extends AbstractItem
{
/** @inheritdoc */
public function __construct() {
public function __construct()
{
global $REV;
global $INFO;
global $INPUT;
parent::__construct();
if(!$REV || !$INFO['writable']) {
if (!$REV || !$INFO['writable'] || $INPUT->server->str('REMOTE_USER') === '') {
throw new \RuntimeException('revert not available');
}
$this->params['rev'] = $REV;