38 private $commentStore;
41 private $commentFormatter;
55 parent::__construct( $query, $moduleName,
'pt' );
56 $this->commentStore = $commentStore;
57 $this->commentFormatter = $commentFormatter;
65 $this->run( $resultPageSet );
72 private function run( $resultPageSet =
null ) {
76 $this->
addFields( [
'pt_namespace',
'pt_title',
'pt_timestamp' ] );
78 $prop = array_fill_keys( $params[
'prop'],
true );
79 $this->
addFieldsIf(
'pt_user', isset( $prop[
'user'] ) || isset( $prop[
'userid'] ) );
80 $this->
addFieldsIf(
'pt_expiry', isset( $prop[
'expiry'] ) );
81 $this->
addFieldsIf(
'pt_create_perm', isset( $prop[
'level'] ) );
83 if ( isset( $prop[
'comment'] ) || isset( $prop[
'parsedcomment'] ) ) {
84 $commentQuery = $this->commentStore->getJoin(
'pt_reason' );
85 $this->
addTables( $commentQuery[
'tables'] );
86 $this->
addFields( $commentQuery[
'fields'] );
91 $this->
addWhereFld(
'pt_namespace', $params[
'namespace'] );
92 $this->
addWhereFld(
'pt_create_perm', $params[
'level'] );
95 $this->
addWhereRange(
'pt_namespace', $params[
'dir'],
null,
null );
96 $this->
addWhereRange(
'pt_title', $params[
'dir'],
null,
null );
98 if ( $params[
'continue'] !==
null ) {
100 $op = ( $params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
101 $db = $this->
getDB();
102 $this->
addWhere( $db->buildComparison( $op, [
103 'pt_timestamp' => $db->timestamp( $cont[0] ),
104 'pt_namespace' => $cont[1],
105 'pt_title' => $cont[2],
109 if ( isset( $prop[
'user'] ) ) {
117 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
120 if ( $resultPageSet ===
null ) {
122 if ( isset( $prop[
'parsedcomment'] ) ) {
123 $formattedComments = $this->commentFormatter->formatItems(
124 $this->commentFormatter->rows(
$res )
125 ->commentKey(
'pt_reason' )
126 ->namespaceField(
'pt_namespace' )
127 ->titleField(
'pt_title' )
137 foreach (
$res as $rowOffset => $row ) {
138 if ( ++$count > $params[
'limit'] ) {
142 "$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
147 $title = Title::makeTitle( $row->pt_namespace, $row->pt_title );
148 if ( $resultPageSet ===
null ) {
151 if ( isset( $prop[
'timestamp'] ) ) {
152 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->pt_timestamp );
155 if ( isset( $prop[
'user'] ) && $row->user_name !==
null ) {
156 $vals[
'user'] = $row->user_name;
159 if ( isset( $prop[
'userid'] ) || isset( $prop[
'user'] ) ) {
160 $vals[
'userid'] = (int)$row->pt_user;
163 if ( isset( $prop[
'comment'] ) ) {
164 $vals[
'comment'] = $this->commentStore->getComment(
'pt_reason', $row )->text;
167 if ( isset( $prop[
'parsedcomment'] ) ) {
169 $vals[
'parsedcomment'] = $formattedComments[$rowOffset];
172 if ( isset( $prop[
'expiry'] ) ) {
176 if ( isset( $prop[
'level'] ) ) {
177 $vals[
'level'] = $row->pt_create_perm;
180 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
183 "$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
192 if ( $resultPageSet ===
null ) {
193 $result->addIndexedTagName(
198 $resultPageSet->populateFromTitles( $titles );
203 if ( $params[
'prop'] !==
null && in_array(
'parsedcomment', $params[
'prop'] ) ) {
205 return 'anon-public-user-private';
214 ParamValidator::PARAM_ISMULTI =>
true,
215 ParamValidator::PARAM_TYPE =>
'namespace',
218 ParamValidator::PARAM_ISMULTI =>
true,
219 ParamValidator::PARAM_TYPE => array_diff(
220 $this->
getConfig()->
get( MainConfigNames::RestrictionLevels ), [
'' ] )
223 ParamValidator::PARAM_DEFAULT => 10,
224 ParamValidator::PARAM_TYPE =>
'limit',
225 IntegerDef::PARAM_MIN => 1,
230 ParamValidator::PARAM_DEFAULT =>
'older',
231 ParamValidator::PARAM_TYPE => [
237 'newer' =>
'api-help-paramvalue-direction-newer',
238 'older' =>
'api-help-paramvalue-direction-older',
242 ParamValidator::PARAM_TYPE =>
'timestamp'
245 ParamValidator::PARAM_TYPE =>
'timestamp'
248 ParamValidator::PARAM_ISMULTI =>
true,
249 ParamValidator::PARAM_DEFAULT =>
'timestamp|level',
250 ParamValidator::PARAM_TYPE => [
269 'action=query&list=protectedtitles'
270 =>
'apihelp-query+protectedtitles-example-simple',
271 'action=query&generator=protectedtitles&gptnamespace=0&prop=linkshere'
272 =>
'apihelp-query+protectedtitles-example-generator',
277 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protectedtitles';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
const LIMIT_BIG1
Fast query, standard limit.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only)
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
Query module to enumerate all create-protected pages.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
getHelpUrls()
Return links to more detailed help pages about the module.
executeGenerator( $resultPageSet)
Execute this module as a generator.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, RowCommentFormatter $commentFormatter)
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
static formatExpiry( $expiry, $infinity='infinity')
Format an expiry timestamp for API output.
A class containing constants representing the names of configuration variables.