Allow User::isAllowed() to take varargs. "is allowed X or Y" is by far the more...
authorHappy-melon <happy-melon@users.mediawiki.org>
Fri, 18 Mar 2011 14:48:21 +0000 (14:48 +0000)
committerHappy-melon <happy-melon@users.mediawiki.org>
Fri, 18 Mar 2011 14:48:21 +0000 (14:48 +0000)
includes/Article.php
includes/HistoryPage.php
includes/ImagePage.php
includes/ProtectionForm.php
includes/Title.php
includes/User.php
includes/api/ApiFileRevert.php
includes/specials/SpecialImport.php

index bcb3305..254403c 100644 (file)
@@ -3458,7 +3458,7 @@ class Article {
                        $flags |= EDIT_MINOR;
                }
 
-               if ( $bot && ( $wgUser->isAllowed( 'markbotedits' ) || $wgUser->isAllowed( 'bot' ) ) ) {
+               if ( $bot && ( $wgUser->isAllowed( 'markbotedits', 'bot' ) ) ) {
                        $flags |= EDIT_FORCE_BOT;
                }
 
index 63b14b1..d5991aa 100644 (file)
@@ -510,7 +510,7 @@ class HistoryPager extends ReverseChronologicalPager {
 
                $del = '';
                // Show checkboxes for each revision
-               if ( $wgUser->isAllowed( 'deleterevision' ) || $wgUser->isAllowed( 'revisionmove' ) ) {
+               if ( $wgUser->isAllowed( 'deleterevision', 'revisionmove' ) ) {
                        $this->preventClickjacking();
                        // If revision was hidden from sysops, disable the checkbox
                        // However, if the user has revisionmove rights, we cannot disable the checkbox
index cbac9dc..183e933 100644 (file)
@@ -930,7 +930,7 @@ class ImageHistoryList {
                        . $navLinks . "\n"
                        . Xml::openElement( 'table', array( 'class' => 'wikitable filehistory' ) ) . "\n"
                        . '<tr><td></td>'
-                       . ( $this->current->isLocal() && ( $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deletedhistory' ) ) ? '<td></td>' : '' )
+                       . ( $this->current->isLocal() && ( $wgUser->isAllowed( 'delete', 'deletedhistory' ) ) ? '<td></td>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-datetime' ) . '</th>'
                        . ( $this->showThumb ? '<th>' . wfMsgHtml( 'filehist-thumb' ) . '</th>' : '' )
                        . '<th>' . wfMsgHtml( 'filehist-dimensions' ) . '</th>'
@@ -961,7 +961,7 @@ class ImageHistoryList {
                $row = $selected = '';
 
                // Deletion link
-               if ( $local && ( $wgUser->isAllowed( 'delete' ) || $wgUser->isAllowed( 'deletedhistory' ) ) ) {
+               if ( $local && ( $wgUser->isAllowed( 'delete', 'deletedhistory' ) ) ) {
                        $row .= '<td>';
                        # Link to remove from history
                        if ( $wgUser->isAllowed( 'delete' ) ) {
index c836352..5f9d5d8 100644 (file)
@@ -133,7 +133,7 @@ class ProtectionForm {
                                // Prevent users from setting levels that they cannot later unset
                                if( $val == 'sysop' ) {
                                        // Special case, rewrite sysop to either protect and editprotected
-                                       if( !$wgUser->isAllowed('protect') && !$wgUser->isAllowed('editprotected') )
+                                       if( !$wgUser->isAllowed( 'protect', 'editprotected' ) )
                                                continue;
                                } else {
                                        if( !$wgUser->isAllowed($val) )
@@ -527,7 +527,7 @@ class ProtectionForm {
                        //don't let them choose levels above their own (aka so they can still unprotect and edit the page). but only when the form isn't disabled
                        if( $key == 'sysop' ) {
                                //special case, rewrite sysop to protect and editprotected
-                               if( !$wgUser->isAllowed('protect') && !$wgUser->isAllowed('editprotected') && !$this->disabled )
+                               if( !$wgUser->isAllowed( 'protect', 'editprotected' ) && !$this->disabled )
                                        continue;
                        } else {
                                if( !$wgUser->isAllowed($key) && !$this->disabled )
index 635c759..9141474 100644 (file)
@@ -1999,7 +1999,7 @@ class Title {
         */
        public function userCanEditCssSubpage() {
                global $wgUser;
-               return ( ( $wgUser->isAllowed( 'editusercssjs' ) && $wgUser->isAllowed( 'editusercss' ) )
+               return ( ( $wgUser->isAllowedAll( 'editusercssjs', 'editusercss' ) )
                        || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
        }
 
@@ -2012,7 +2012,7 @@ class Title {
         */
        public function userCanEditJsSubpage() {
                global $wgUser;
-               return ( ( $wgUser->isAllowed( 'editusercssjs' ) && $wgUser->isAllowed( 'edituserjs' ) )
+               return ( ( $wgUser->isAllowedAll( 'editusercssjs', 'edituserjs' ) )
                           || preg_match( '/^' . preg_quote( $wgUser->getName(), '/' ) . '\//', $this->mTextform ) );
        }
 
index 9d981ac..4fb0d1e 100644 (file)
@@ -2245,10 +2245,39 @@ class User {
 
        /**
         * Check if user is allowed to access a feature / make an action
-        * @param $action String action to be checked
-        * @return Boolean: True if action is allowed, else false
+        * @param varargs String permissions to test
+        * @return Boolean: True if user is allowed to perform *any* of the given actions
         */
-       function isAllowed( $action = '' ) {
+       public function isAllowed( /*...*/ ){
+               $permissions = func_get_args();
+               foreach( $permissions as $permission ){
+                       if( $this->isAllowedInternal( $permission ) ){
+                               return true;
+                       }
+               }
+               return false;
+       }
+
+       /**
+        * @param varargs String
+        * @return bool True if the user is allowed to perform *all* of the given actions
+        */
+       public function isAllowedAll( /*...*/ ){
+               $permissions = func_get_args();
+               foreach( $permissions as $permission ){
+                       if( !$this->isAllowedInternal( $permission ) ){
+                               return false;
+                       }
+               }
+               return true;
+       }
+
+       /**
+        * Internal mechanics of testing a permission
+        * @param $action String
+        * @return bool
+        */
+       private function isAllowedInternal( $action = '' ) {
                if ( $action === '' ) {
                        return true; // In the spirit of DWIM
                }
@@ -2269,7 +2298,7 @@ class User {
         */
        public function useRCPatrol() {
                global $wgUseRCPatrol;
-               return( $wgUseRCPatrol && ( $this->isAllowed( 'patrol' ) || $this->isAllowed( 'patrolmarks' ) ) );
+               return $wgUseRCPatrol && $this->isAllowedAny( 'patrol', 'patrolmarks' );
        }
 
        /**
@@ -2278,7 +2307,7 @@ class User {
         */
        public function useNPPatrol() {
                global $wgUseRCPatrol, $wgUseNPPatrol;
-               return( ( $wgUseRCPatrol || $wgUseNPPatrol ) && ( $this->isAllowed( 'patrol' ) || $this->isAllowed( 'patrolmarks' ) ) );
+               return( ( $wgUseRCPatrol || $wgUseNPPatrol ) && ( $this->isAllowedAny( 'patrol', 'patrolmarks' ) ) );
        }
 
        /**
index 3a183a4..2cf3b90 100644 (file)
@@ -78,7 +78,7 @@ class ApiFileRevert extends ApiBase {
         * @param $user User The user to check.
         */
        protected function checkPermissions( $user ) {
-               $permission = $user->isAllowed( 'edit' ) && $user->isAllowed( 'upload' );
+               $permission = $user->isAllowedAll( 'edit', 'upload' );
 
                if ( $permission !== true ) {
                        if ( !$user->isLoggedIn() ) {
index 73416a8..b1292d2 100644 (file)
@@ -144,7 +144,7 @@ class SpecialImport extends SpecialPage {
 
        private function showForm() {
                global $wgUser, $wgOut, $wgImportSources, $wgExportMaxLinkDepth;
-               if( !$wgUser->isAllowed( 'import' ) && !$wgUser->isAllowed( 'importupload' ) )
+               if( !$wgUser->isAllowed( 'import', 'importupload' ) )
                        return $wgOut->permissionRequired( 'import' );
 
                $action = $this->getTitle()->getLocalUrl( array( 'action' => 'submit' ) );