X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/api/ApiQueryProtectedTitles.php diff --git a/includes/api/ApiQueryProtectedTitles.php b/includes/api/ApiQueryProtectedTitles.php index d2d2b869..b69a2996 100644 --- a/includes/api/ApiQueryProtectedTitles.php +++ b/includes/api/ApiQueryProtectedTitles.php @@ -1,10 +1,10 @@ .@home.nl + * Copyright © 2009 Roan Kattouw ".@gmail.com" * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,11 +24,6 @@ * @file */ -if ( !defined( 'MEDIAWIKI' ) ) { - // Eclipse helper - will be ignored in production - require_once( 'ApiQueryBase.php' ); -} - /** * Query module to enumerate all create-protected pages. * @@ -36,7 +31,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { */ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { - public function __construct( $query, $moduleName ) { + public function __construct( ApiQuery $query, $moduleName ) { parent::__construct( $query, $moduleName, 'pt' ); } @@ -48,28 +43,60 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { $this->run( $resultPageSet ); } + /** + * @param ApiPageSet $resultPageSet + * @return void + */ private function run( $resultPageSet = null ) { $params = $this->extractRequestParams(); $this->addTables( 'protected_titles' ); - $this->addFields( array( 'pt_namespace', 'pt_title', 'pt_timestamp' ) ); + $this->addFields( [ 'pt_namespace', 'pt_title', 'pt_timestamp' ] ); $prop = array_flip( $params['prop'] ); $this->addFieldsIf( 'pt_user', isset( $prop['user'] ) || isset( $prop['userid'] ) ); - $this->addFieldsIf( 'pt_reason', isset( $prop['comment'] ) || isset( $prop['parsedcomment'] ) ); $this->addFieldsIf( 'pt_expiry', isset( $prop['expiry'] ) ); $this->addFieldsIf( 'pt_create_perm', isset( $prop['level'] ) ); - $this->addWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] ); + if ( isset( $prop['comment'] ) || isset( $prop['parsedcomment'] ) ) { + $commentStore = new CommentStore( 'pt_reason' ); + $commentQuery = $commentStore->getJoin(); + $this->addTables( $commentQuery['tables'] ); + $this->addFields( $commentQuery['fields'] ); + $this->addJoinConds( $commentQuery['joins'] ); + } + + $this->addTimestampWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] ); $this->addWhereFld( 'pt_namespace', $params['namespace'] ); $this->addWhereFld( 'pt_create_perm', $params['level'] ); + // Include in ORDER BY for uniqueness + $this->addWhereRange( 'pt_namespace', $params['dir'], null, null ); + $this->addWhereRange( 'pt_title', $params['dir'], null, null ); + + if ( !is_null( $params['continue'] ) ) { + $cont = explode( '|', $params['continue'] ); + $this->dieContinueUsageIf( count( $cont ) != 3 ); + $op = ( $params['dir'] === 'newer' ? '>' : '<' ); + $db = $this->getDB(); + $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) ); + $continueNs = (int)$cont[1]; + $this->dieContinueUsageIf( $continueNs != $cont[1] ); + $continueTitle = $db->addQuotes( $cont[2] ); + $this->addWhere( "pt_timestamp $op $continueTimestamp OR " . + "(pt_timestamp = $continueTimestamp AND " . + "(pt_namespace $op $continueNs OR " . + "(pt_namespace = $continueNs AND " . + "pt_title $op= $continueTitle)))" + ); + } + if ( isset( $prop['user'] ) ) { $this->addTables( 'user' ); $this->addFields( 'user_name' ); - $this->addJoinConds( array( 'user' => array( 'LEFT JOIN', + $this->addJoinConds( [ 'user' => [ 'LEFT JOIN', 'user_id=pt_user' - ) ) ); + ] ] ); } $this->addOption( 'LIMIT', $params['limit'] + 1 ); @@ -77,16 +104,22 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { $count = 0; $result = $this->getResult(); + + $titles = []; + foreach ( $res as $row ) { - if ( ++ $count > $params['limit'] ) { - // We've reached the one extra which shows that there are additional pages to be had. Stop here... - $this->setContinueEnumParameter( 'start', wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) ); + if ( ++$count > $params['limit'] ) { + // We've reached the one extra which shows that there are + // additional pages to be had. Stop here... + $this->setContinueEnumParameter( 'continue', + "$row->pt_timestamp|$row->pt_namespace|$row->pt_title" + ); break; } $title = Title::makeTitle( $row->pt_namespace, $row->pt_title ); if ( is_null( $resultPageSet ) ) { - $vals = array(); + $vals = []; ApiQueryBase::addTitleInfo( $vals, $title ); if ( isset( $prop['timestamp'] ) ) { $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->pt_timestamp ); @@ -96,31 +129,33 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { $vals['user'] = $row->user_name; } - if ( isset( $prop['user'] ) ) { - $vals['userid'] = $row->pt_user; + if ( isset( $prop['userid'] ) || /*B/C*/isset( $prop['user'] ) ) { + $vals['userid'] = (int)$row->pt_user; } if ( isset( $prop['comment'] ) ) { - $vals['comment'] = $row->pt_reason; + $vals['comment'] = $commentStore->getComment( $row )->text; } if ( isset( $prop['parsedcomment'] ) ) { - global $wgUser; - $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $row->pt_reason, $title ); + $vals['parsedcomment'] = Linker::formatComment( + $commentStore->getComment( $row )->text, $titles + ); } if ( isset( $prop['expiry'] ) ) { - $vals['expiry'] = Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 ); + $vals['expiry'] = ApiResult::formatExpiry( $row->pt_expiry ); } if ( isset( $prop['level'] ) ) { $vals['level'] = $row->pt_create_perm; } - $fit = $result->addValue( array( 'query', $this->getModuleName() ), null, $vals ); + $fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals ); if ( !$fit ) { - $this->setContinueEnumParameter( 'start', - wfTimestamp( TS_ISO_8601, $row->pt_timestamp ) ); + $this->setContinueEnumParameter( 'continue', + "$row->pt_timestamp|$row->pt_namespace|$row->pt_title" + ); break; } } else { @@ -129,7 +164,10 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { } if ( is_null( $resultPageSet ) ) { - $result->setIndexedTagName_internal( array( 'query', $this->getModuleName() ), $this->getModulePrefix() ); + $result->addIndexedTagName( + [ 'query', $this->getModuleName() ], + $this->getModulePrefix() + ); } else { $resultPageSet->populateFromTitles( $titles ); } @@ -137,7 +175,7 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { public function getCacheMode( $params ) { if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) { - // formatComment() calls wfMsg() among other things + // formatComment() calls wfMessage() among other things return 'anon-public-user-private'; } else { return 'public'; @@ -145,40 +183,40 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { } public function getAllowedParams() { - global $wgRestrictionLevels; - return array( - 'namespace' => array( + return [ + 'namespace' => [ ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_TYPE => 'namespace', - ), - 'level' => array( + ], + 'level' => [ ApiBase::PARAM_ISMULTI => true, - ApiBase::PARAM_TYPE => array_diff( $wgRestrictionLevels, array( '' ) ) - ), - 'limit' => array ( + ApiBase::PARAM_TYPE => array_diff( $this->getConfig()->get( 'RestrictionLevels' ), [ '' ] ) + ], + 'limit' => [ ApiBase::PARAM_DFLT => 10, ApiBase::PARAM_TYPE => 'limit', ApiBase::PARAM_MIN => 1, ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1, ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2 - ), - 'dir' => array( + ], + 'dir' => [ ApiBase::PARAM_DFLT => 'older', - ApiBase::PARAM_TYPE => array( - 'older', - 'newer' - ) - ), - 'start' => array( + ApiBase::PARAM_TYPE => [ + 'newer', + 'older' + ], + ApiBase::PARAM_HELP_MSG => 'api-help-param-direction', + ], + 'start' => [ ApiBase::PARAM_TYPE => 'timestamp' - ), - 'end' => array( + ], + 'end' => [ ApiBase::PARAM_TYPE => 'timestamp' - ), - 'prop' => array( + ], + 'prop' => [ ApiBase::PARAM_ISMULTI => true, ApiBase::PARAM_DFLT => 'timestamp|level', - ApiBase::PARAM_TYPE => array( + ApiBase::PARAM_TYPE => [ 'timestamp', 'user', 'userid', @@ -186,43 +224,25 @@ class ApiQueryProtectedTitles extends ApiQueryGeneratorBase { 'parsedcomment', 'expiry', 'level' - ) - ), - ); - } - - public function getParamDescription() { - return array( - 'namespace' => 'Only list titles in these namespaces', - 'start' => 'Start listing at this protection timestamp', - 'end' => 'Stop listing at this protection timestamp', - 'dir' => 'The direction in which to list', - 'limit' => 'How many total pages to return', - 'prop' => array( - 'Which properties to get', - ' timestamp - Adds the timestamp of when protection was added', - ' user - Adds the user to add the protection', - ' userid - Adds the user id to add the protection', - ' comment - Adds the comment for the protection', - ' parsedcomment - Adds the parsed comment for the protection', - ' expiry - Adds the timestamp of when the protection will be lifted', - ' level - Adds the protection level', - ), - 'level' => 'Only list titles with these protection levels', - ); - } - - public function getDescription() { - return 'List all titles protected from creation'; + ], + ApiBase::PARAM_HELP_MSG_PER_VALUE => [], + ], + 'continue' => [ + ApiBase::PARAM_HELP_MSG => 'api-help-param-continue', + ], + ]; } - protected function getExamples() { - return array( - 'api.php?action=query&list=protectedtitles', - ); + protected function getExamplesMessages() { + return [ + 'action=query&list=protectedtitles' + => 'apihelp-query+protectedtitles-example-simple', + 'action=query&generator=protectedtitles&gptnamespace=0&prop=linkshere' + => 'apihelp-query+protectedtitles-example-generator', + ]; } - public function getVersion() { - return __CLASS__ . ': $Id$'; + public function getHelpUrls() { + return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protectedtitles'; } }