From: Aaron Schulz Date: Thu, 15 Oct 2009 11:31:33 +0000 (+0000) Subject: Refactored unmaintainable userCan() code by making central userCanBitfield() functions X-Git-Tag: 1.31.0-rc.0~39273 X-Git-Url: http://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/operations/recherche.php?a=commitdiff_plain;h=ffd4b0f837101ff0e9a062402e7b31432fc8f758;p=lhc%2Fweb%2Fwiklou.git Refactored unmaintainable userCan() code by making central userCanBitfield() functions --- diff --git a/includes/ChangesList.php b/includes/ChangesList.php index 1126c53ffd..70a5dcbbde 100644 --- a/includes/ChangesList.php +++ b/includes/ChangesList.php @@ -446,20 +446,10 @@ class ChangesList { * @return bool */ public static function userCan( $rc, $field ) { - if( $rc->mAttribs['rc_deleted'] & $field ) { - global $wgUser; - $permission = ''; - if ( $rc->mAttribs['rc_deleted'] & Revision::DELETED_RESTRICTED ) { - $permission = 'suppressrevision'; - } elseif ( $field & Revision::DELETED_TEXT ) { - $permission = 'deletedtext'; - } else { - $permission = 'deletedhistory'; - } - wfDebug( "Checking for $permission due to $field match on {$rc->mAttribs['rc_deleted']}\n" ); - return $wgUser->isAllowed( $permission ); + if( $rc->mAttribs['rc_type'] == RC_LOG ) { + return LogEventsList::userCanBitfield( $rc->mAttribs['rc_deleted'], $field ); } else { - return true; + return Revision::userCanBitfield( $rc->mAttribs['rc_deleted'], $field ); } } diff --git a/includes/LogEventsList.php b/includes/LogEventsList.php index 216a40e023..83c3eb726c 100644 --- a/includes/LogEventsList.php +++ b/includes/LogEventsList.php @@ -552,15 +552,26 @@ class LogEventsList { * @return Boolean */ public static function userCan( $row, $field ) { - if( $row->log_deleted & $field ) { + return self::userCanBitfield( $row->log_deleted, $field ); + } + + /** + * Determine if the current user is allowed to view a particular + * field of this log row, if it's marked as deleted. + * @param $bitfield Integer (current field) + * @param $field Integer + * @return Boolean + */ + public static function userCanBitfield( $bitfield, $field ) { + if( $bitfield & $field ) { global $wgUser; $permission = ''; - if ( $row->log_deleted & LogPage::DELETED_RESTRICTED ) { + if ( $bitfield & LogPage::DELETED_RESTRICTED ) { $permission = 'suppressrevision'; } else { $permission = 'deletedhistory'; } - wfDebug( "Checking for $permission due to $field match on $row->log_deleted\n" ); + wfDebug( "Checking for $permission due to $field match on $bitfield\n" ); return $wgUser->isAllowed( $permission ); } else { return true; diff --git a/includes/Revision.php b/includes/Revision.php index b7fb26981d..c4f8d617a1 100644 --- a/includes/Revision.php +++ b/includes/Revision.php @@ -977,24 +977,37 @@ class Revision { * @return bool */ public function userCan( $field ) { - if( $this->mDeleted & $field ) { + return self::userCanBitfield( $this->mDeleted, $field ); + } + + /** + * Determine if the current user is allowed to view a particular + * field of this revision, if it's marked as deleted. This is used + * by various classes to avoid duplication. + * @param int $bitfield (current field) + * @param int $field one of self::DELETED_TEXT = File::DELETED_FILE, + * self::DELETED_COMMENT = File::DELETED_COMMENT, + * self::DELETED_USER = File::DELETED_USER + * @return bool + */ + public static function userCanBitfield( $bitfield, $field ) { + if( $bitfield & $field ) { // aspect is deleted global $wgUser; $permission = ''; - if ( $this->mDeleted & self::DELETED_RESTRICTED ) { + if ( $bitfield & self::DELETED_RESTRICTED ) { $permission = 'suppressrevision'; } elseif ( $field & self::DELETED_TEXT ) { $permission = 'deletedtext'; } else { $permission = 'deletedhistory'; } - wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" ); + wfDebug( "Checking for $permission due to $field match on $bitfield\n" ); return $wgUser->isAllowed( $permission ); } else { return true; } } - /** * Get rev_timestamp from rev_id, without loading the rest of the row * @param Title $title diff --git a/includes/filerepo/ArchivedFile.php b/includes/filerepo/ArchivedFile.php index ebee2b664c..4e9d554a16 100644 --- a/includes/filerepo/ArchivedFile.php +++ b/includes/filerepo/ArchivedFile.php @@ -377,20 +377,6 @@ class ArchivedFile */ public function userCan( $field ) { $this->load(); - if( $this->deleted & $field ) { - global $wgUser; - $permission = ''; - if ( $this->deleted & File::DELETED_RESTRICTED ) { - $permission = 'suppressrevision'; - } elseif ( $field & File::DELETED_FILE ) { - $permission = 'deletedtext'; - } else { - $permission = 'deletedhistory'; - } - wfDebug( "Checking for $permission due to $field match on $this->deleted\n" ); - return $wgUser->isAllowed( $permission ); - } else { - return true; - } + return Revision::userCanBitfield( $this->deleted, $field ); } } diff --git a/includes/filerepo/OldLocalFile.php b/includes/filerepo/OldLocalFile.php index d2d78c9b12..35f3f9f2de 100644 --- a/includes/filerepo/OldLocalFile.php +++ b/includes/filerepo/OldLocalFile.php @@ -198,20 +198,6 @@ class OldLocalFile extends LocalFile { */ function userCan( $field ) { $this->load(); - if( isset($this->deleted) && ($this->deleted & $field) ) { - global $wgUser; - $permission = ''; - if ( $this->deleted & File::DELETED_RESTRICTED ) { - $permission = 'suppressrevision'; - } elseif ( $field & File::DELETED_FILE ) { - $permission = 'deletedtext'; - } else { - $permission = 'deletedhistory'; - } - wfDebug( "Checking for $permission due to $field match on $this->mDeleted\n" ); - return $wgUser->isAllowed( $permission ); - } else { - return true; - } + return Revision::userCanBitfield( $this->deleted, $field ); } } diff --git a/includes/specials/SpecialLog.php b/includes/specials/SpecialLog.php index d1ccc8c480..700cd59a83 100644 --- a/includes/specials/SpecialLog.php +++ b/includes/specials/SpecialLog.php @@ -60,6 +60,8 @@ function wfSpecialLog( $par = '' ) { $qc = array( 'ls_field' => 'target_author_id', 'ls_value' => $offender->getId() ); } else if( $offender && IP::isIPAddress( $offender->getName() ) ) { $qc = array( 'ls_field' => 'target_author_ip', 'ls_value' => $offender->getName() ); + } else { + $qc = array( "1 = 0" ); // empty } } # Create a LogPager item to get the results and a LogEventsList item to format them...