From 63ed4ac0e4357a6ac8516fb23c703d7e1f7b4c95 Mon Sep 17 00:00:00 2001 From: Marius Hoch Date: Wed, 3 Oct 2012 17:22:40 +0200 Subject: [PATCH] Deprecate static User::edits() in favour of User::getEditCount() Moved the logic from the old static User::edits() into User::getEditCount() and deprecated User::edits() as it's not following the class hierarchy. Change-Id: Id2b939ffb903accb8f4dc132a6ac6b6576f81beb --- includes/Linker.php | 7 ++++-- includes/User.php | 60 +++++++++++++++++++++++---------------------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/includes/Linker.php b/includes/Linker.php index 97b03be800..f6b4a69f33 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -1075,8 +1075,11 @@ class Linker { // check if the user has an edit $attribs = array(); if ( $redContribsWhenNoEdits ) { - $count = !is_null( $edits ) ? $edits : User::edits( $userId ); - if ( $count == 0 ) { + if ( intval( $edits ) === 0 && $edits !== 0 ) { + $user = User::newFromId( $userId ); + $edits = $user->getEditCount(); + } + if ( $edits === 0 ) { $attribs['class'] = 'new'; } } diff --git a/includes/User.php b/includes/User.php index 8216914266..7bb5b214ce 100644 --- a/includes/User.php +++ b/includes/User.php @@ -816,39 +816,16 @@ class User { /** * Count the number of edits of a user - * @todo It should not be static and some day should be merged as proper member function / deprecated -- domas * * @param $uid Int User ID to check * @return Int the user's edit count + * + * @deprecated since 1.21 in favour of User::getEditCount */ public static function edits( $uid ) { - wfProfileIn( __METHOD__ ); - $dbr = wfGetDB( DB_SLAVE ); - // check if the user_editcount field has been initialized - $field = $dbr->selectField( - 'user', 'user_editcount', - array( 'user_id' => $uid ), - __METHOD__ - ); - - if( $field === null ) { // it has not been initialized. do so. - $dbw = wfGetDB( DB_MASTER ); - $count = $dbr->selectField( - 'revision', 'count(*)', - array( 'rev_user' => $uid ), - __METHOD__ - ); - $dbw->update( - 'user', - array( 'user_editcount' => $count ), - array( 'user_id' => $uid ), - __METHOD__ - ); - } else { - $count = $field; - } - wfProfileOut( __METHOD__ ); - return $count; + wfDeprecated( __METHOD__, '1.21' ); + $user = self::newFromId( $uid ); + return $user->getEditCount(); } /** @@ -2465,7 +2442,32 @@ class User { if( $this->getId() ) { if ( !isset( $this->mEditCount ) ) { /* Populate the count, if it has not been populated yet */ - $this->mEditCount = User::edits( $this->mId ); + wfProfileIn( __METHOD__ ); + $dbr = wfGetDB( DB_SLAVE ); + // check if the user_editcount field has been initialized + $count = $dbr->selectField( + 'user', 'user_editcount', + array( 'user_id' => $this->mId ), + __METHOD__ + ); + + if( $count === null ) { + // it has not been initialized. do so. + $dbw = wfGetDB( DB_MASTER ); + $count = $dbr->selectField( + 'revision', 'count(*)', + array( 'rev_user' => $this->mId ), + __METHOD__ + ); + $dbw->update( + 'user', + array( 'user_editcount' => $count ), + array( 'user_id' => $this->mId ), + __METHOD__ + ); + } + wfProfileOut( __METHOD__ ); + $this->mEditCount = $count; } return $this->mEditCount; } else { -- 2.20.1