* Allow userCan to take null $user - and replace it with $wgUser if passed.
authorAndrew Garrett <werdna@users.mediawiki.org>
Sun, 9 Sep 2007 08:11:58 +0000 (08:11 +0000)
committerAndrew Garrett <werdna@users.mediawiki.org>
Sun, 9 Sep 2007 08:11:58 +0000 (08:11 +0000)
* (Bug 7027) Shift handling of deletion permissions-checking to getUserPermissionsErrors.

includes/Article.php
includes/Title.php

index 5167fd7..2e64b63 100644 (file)
@@ -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;
                }
 
index c4db417..7b8f173 100644 (file)
@@ -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' );
                }