From: Sam Reed Date: Tue, 22 Jun 2010 12:10:26 +0000 (+0000) Subject: Resolve fixme of r66539 X-Git-Tag: 1.31.0-rc.0~36417 X-Git-Url: http://git.cyclocoop.org/%22%20.%20generer_url_ecrire%28%22articles%22%2C%22id_article=%24id_article%22%29%20.%20%22?a=commitdiff_plain;h=928ff2b273151dd074c4e9d14abb42b313d6983a;p=lhc%2Fweb%2Fwiklou.git Resolve fixme of r66539 Move getWatchlistUser to ApiBase --- diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 3262f40d5f..3656c2c2e7 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -1082,6 +1082,30 @@ abstract class ApiBase { return false; } + /** + * Gets the user for whom to get the watchlist + * + * @returns User + */ + public function getWatchlistUser( $params ) { + global $wgUser; + if ( !is_null( $params['owner'] ) && !is_null( $params['token'] ) ) { + $user = User::newFromName( $params['owner'], false ); + if ( !$user->getId() ) { + $this->dieUsage( 'Specified user does not exist', 'bad_wlowner' ); + } + $token = $user->getOption( 'watchlisttoken' ); + if ( $token == '' || $token != $params['token'] ) { + $this->dieUsage( 'Incorrect watchlist token provided -- please set a correct token in Special:Preferences', 'bad_wltoken' ); + } + } elseif ( !$wgUser->isLoggedIn() ) { + $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); + } else { + $user = $wgUser; + } + return $user; + } + /** * Returns a list of all possible errors returned by the module * @return array in the format of array( key, param1, param2, ... ) or array( 'code' => ..., 'info' => ... ) diff --git a/includes/api/ApiQueryWatchlist.php b/includes/api/ApiQueryWatchlist.php index aecfc88def..b027cd9fff 100644 --- a/includes/api/ApiQueryWatchlist.php +++ b/includes/api/ApiQueryWatchlist.php @@ -57,7 +57,7 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { $params = $this->extractRequestParams(); - $user = ApiQueryWatchlist::getWatchlistUser( $params ); + $user = $this->getWatchlistUser( $params ); if ( !is_null( $params['prop'] ) && is_null( $resultPageSet ) ) { $prop = array_flip( $params['prop'] ); @@ -258,7 +258,9 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { } if ( $this->fld_notificationtimestamp ) { - $vals['notificationtimestamp'] = ( $row->wl_notificationtimestamp == null ) ? '' : wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp ); + $vals['notificationtimestamp'] = ( $row->wl_notificationtimestamp == null ) + ? '' + : wfTimestamp( TS_ISO_8601, $row->wl_notificationtimestamp ); } if ( $this->fld_comment && isset( $row->rc_comment ) ) { @@ -273,30 +275,6 @@ class ApiQueryWatchlist extends ApiQueryGeneratorBase { return $vals; } - /** - * Gets the user for whom to get the watchlist - * - * @returns User - */ - public static function getWatchlistUser( $params ) { - global $wgUser; - if ( !is_null( $params['owner'] ) && !is_null( $params['token'] ) ) { - $user = User::newFromName( $params['owner'], false ); - if ( !$user->getId() ) { - $this->dieUsage( 'Specified user does not exist', 'bad_wlowner' ); - } - $token = $user->getOption( 'watchlisttoken' ); - if ( $token == '' || $token != $params['token'] ) { - $this->dieUsage( 'Incorrect watchlist token provided -- please set a correct token in Special:Preferences', 'bad_wltoken' ); - } - } elseif ( !$wgUser->isLoggedIn() ) { - $this->dieUsage( 'You must be logged-in to have a watchlist', 'notloggedin' ); - } else { - $user = $wgUser; - } - return $user; - } - public function getAllowedParams() { return array( 'allrev' => false, diff --git a/includes/api/ApiQueryWatchlistRaw.php b/includes/api/ApiQueryWatchlistRaw.php index bc2a9a7958..3354cc47fa 100644 --- a/includes/api/ApiQueryWatchlistRaw.php +++ b/includes/api/ApiQueryWatchlistRaw.php @@ -53,7 +53,7 @@ class ApiQueryWatchlistRaw extends ApiQueryGeneratorBase { $params = $this->extractRequestParams(); - $user = ApiQueryWatchlist::getWatchlistUser( $params ); + $user = $this->getWatchlistUser( $params ); $prop = array_flip( (array)$params['prop'] ); $show = array_flip( (array)$params['show'] );