}
/**
- * @param int $field one of DELETED_* bitfield constants
+ * @param int $field One of DELETED_* bitfield constants
*
* @return bool
*/
* 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
* 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;
}