Merge "Ensure that expiry times are given as integers"
[lhc/web/wiklou.git] / includes / Revision.php
index de69827..cad9f2c 100644 (file)
@@ -952,7 +952,7 @@ class Revision implements IDBAccessObject {
        }
 
        /**
-        * @param int $field one of DELETED_* bitfield constants
+        * @param int $field One of DELETED_* bitfield constants
         *
         * @return bool
         */
@@ -1569,7 +1569,7 @@ class Revision implements IDBAccessObject {
         * operations and other such meta-modifications.
         *
         * @param DatabaseBase $dbw
-        * @param int $pageId: ID number of the page to read from
+        * @param int $pageId ID number of the page to read from
         * @param string $summary Revision's summary
         * @param bool $minor Whether the revision should be considered as minor
         * @param User|null $user User object to use or null for $wgUser
@@ -1654,23 +1654,39 @@ class Revision implements IDBAccessObject {
         *                               self::DELETED_COMMENT = File::DELETED_COMMENT,
         *                               self::DELETED_USER = File::DELETED_USER
         * @param User|null $user User object to check, or null to use $wgUser
+        * @param Title|null $title A Title object to check for per-page restrictions on,
+        *                          instead of just plain userrights
         * @return bool
         */
-       public static function userCanBitfield( $bitfield, $field, User $user = null ) {
+       public static function userCanBitfield( $bitfield, $field, User $user = null ,
+               Title $title = null
+       ) {
                if ( $bitfield & $field ) { // aspect is deleted
+                       if ( $user === null ) {
+                               global $wgUser;
+                               $user = $wgUser;
+                       }
                        if ( $bitfield & self::DELETED_RESTRICTED ) {
-                               $permission = 'suppressrevision';
+                               $permissions = array( 'suppressrevision', 'viewsuppressed' );
                        } elseif ( $field & self::DELETED_TEXT ) {
-                               $permission = 'deletedtext';
+                               $permissions = array( 'deletedtext' );
                        } else {
-                               $permission = 'deletedhistory';
+                               $permissions = array( 'deletedhistory' );
                        }
-                       wfDebug( "Checking for $permission due to $field match on $bitfield\n" );
-                       if ( $user === null ) {
-                               global $wgUser;
-                               $user = $wgUser;
+                       $permissionlist = implode( ', ', $permissions );
+                       if ( $title === null ) {
+                               wfDebug( "Checking for $permissionlist due to $field match on $bitfield\n" );
+                               return call_user_func_array( array( $user, 'isAllowedAny' ), $permissions );
+                       } else {
+                               $text = $title->getPrefixedText();
+                               wfDebug( "Checking for $permissionlist on $text due to $field match on $bitfield\n" );
+                               foreach( $permissions as $perm ) {
+                                       if ( $title->userCan( $perm, $user ) ) {
+                                               return true;
+                                       }
+                               }
+                               return false;
                        }
-                       return $user->isAllowed( $permission );
                } else {
                        return true;
                }