From 82dcbbaaa70224df515cf7aacc89d05b63b22d9d Mon Sep 17 00:00:00 2001 From: Andrew Garrett Date: Sun, 9 Sep 2007 08:11:58 +0000 Subject: [PATCH] * Allow userCan to take null $user - and replace it with $wgUser if passed. * (Bug 7027) Shift handling of deletion permissions-checking to getUserPermissionsErrors. --- includes/Article.php | 25 ++++++++----------------- includes/Title.php | 8 ++++++-- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 5167fd7d9d..2e64b63dae 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -926,13 +926,11 @@ class Article { return; } - if ((!$wgUser->isAllowed('delete'))) { - $wgOut->permissionRequired( 'delete' ); - return; - } + $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser ); - if (wfReadOnly()) { - $wgOut->readOnlyPage(); + if (count($permission_errors)>0) + { + $wgOut->showPermissionsErrorPage( $permission_errors ); return; } @@ -1835,18 +1833,11 @@ class Article { # This code desperately needs to be totally rewritten # Check permissions - if( $wgUser->isAllowed( 'delete' ) ) { - if( $wgUser->isBlocked( !$confirm ) ) { - $wgOut->blockedPage(); - return; - } - } else { - $wgOut->permissionRequired( 'delete' ); - return; - } + $permission_errors = $this->mTitle->getUserPermissionsErrors( 'delete', $wgUser ); - if( wfReadOnly() ) { - $wgOut->readOnlyPage(); + if (count($permission_errors)>0) + { + $wgOut->showPermissionsErrorPage( $permission_errors ); return; } diff --git a/includes/Title.php b/includes/Title.php index c4db4172f6..7b8f1737f3 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1030,12 +1030,16 @@ class Title { * @param bool $doExpensiveQueries Set this to false to avoid doing unnecessary queries. * @return array Array of arrays of the arguments to wfMsg to explain permissions problems. */ - public function getUserPermissionsErrors( $action, $user, $doExpensiveQueries = true ) { + public function getUserPermissionsErrors( $action, $user = null, $doExpensiveQueries = true ) { $errors = $this->getUserPermissionsErrorsInternal( $action, $user, $doExpensiveQueries ); global $wgContLang; global $wgLang; + # Be kinder to people who forget to supply a user, assuming they mean $wgUser + if (!$user) + $user = $wgUser; + if ( wfReadOnly() && $action != 'read' ) { global $wgReadOnly; $errors[] = array( 'readonlytext', $wgReadOnly ); @@ -1043,7 +1047,7 @@ class Title { global $wgEmailConfirmToEdit, $wgUser; - if ( $wgEmailConfirmToEdit && !$wgUser->isEmailConfirmed() ) + if ( $wgEmailConfirmToEdit && !$user->isEmailConfirmed() ) { $errors[] = array( 'confirmedittext' ); } -- 2.20.1