48 parent::__construct( $query, $moduleName,
'pt' );
49 $this->commentStore = $commentStore;
50 $this->commentFormatter = $commentFormatter;
58 $this->run( $resultPageSet );
65 private function run( $resultPageSet =
null ) {
69 $this->
addFields( [
'pt_namespace',
'pt_title',
'pt_timestamp' ] );
71 $prop = array_fill_keys( $params[
'prop'],
true );
72 $this->
addFieldsIf(
'pt_user', isset( $prop[
'user'] ) || isset( $prop[
'userid'] ) );
73 $this->
addFieldsIf(
'pt_expiry', isset( $prop[
'expiry'] ) );
74 $this->
addFieldsIf(
'pt_create_perm', isset( $prop[
'level'] ) );
76 if ( isset( $prop[
'comment'] ) || isset( $prop[
'parsedcomment'] ) ) {
77 $commentQuery = $this->commentStore->getJoin(
'pt_reason' );
78 $this->
addTables( $commentQuery[
'tables'] );
79 $this->
addFields( $commentQuery[
'fields'] );
84 $this->
addWhereFld(
'pt_namespace', $params[
'namespace'] );
85 $this->
addWhereFld(
'pt_create_perm', $params[
'level'] );
88 $this->
addWhereRange(
'pt_namespace', $params[
'dir'],
null,
null );
89 $this->
addWhereRange(
'pt_title', $params[
'dir'],
null,
null );
91 if ( $params[
'continue'] !==
null ) {
93 $op = ( $params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
95 $this->
addWhere( $db->buildComparison( $op, [
96 'pt_timestamp' => $db->timestamp( $cont[0] ),
97 'pt_namespace' => $cont[1],
98 'pt_title' => $cont[2],
102 if ( isset( $prop[
'user'] ) ) {
110 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
111 $res = $this->
select( __METHOD__ );
113 if ( $resultPageSet ===
null ) {
115 if ( isset( $prop[
'parsedcomment'] ) ) {
116 $formattedComments = $this->commentFormatter->formatItems(
117 $this->commentFormatter->rows( $res )
118 ->commentKey(
'pt_reason' )
119 ->namespaceField(
'pt_namespace' )
120 ->titleField(
'pt_title' )
130 foreach ( $res as $rowOffset => $row ) {
131 if ( ++$count > $params[
'limit'] ) {
135 "$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
140 $title = Title::makeTitle( $row->pt_namespace, $row->pt_title );
141 if ( $resultPageSet ===
null ) {
144 if ( isset( $prop[
'timestamp'] ) ) {
145 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->pt_timestamp );
148 if ( isset( $prop[
'user'] ) && $row->user_name !==
null ) {
149 $vals[
'user'] = $row->user_name;
152 if ( isset( $prop[
'userid'] ) || isset( $prop[
'user'] ) ) {
153 $vals[
'userid'] = (int)$row->pt_user;
156 if ( isset( $prop[
'comment'] ) ) {
157 $vals[
'comment'] = $this->commentStore->getComment(
'pt_reason', $row )->text;
160 if ( isset( $prop[
'parsedcomment'] ) ) {
162 $vals[
'parsedcomment'] = $formattedComments[$rowOffset];
165 if ( isset( $prop[
'expiry'] ) ) {
169 if ( isset( $prop[
'level'] ) ) {
170 $vals[
'level'] = $row->pt_create_perm;
173 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
176 "$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
185 if ( $resultPageSet ===
null ) {
186 $result->addIndexedTagName(
191 $resultPageSet->populateFromTitles( $titles );
196 if ( $params[
'prop'] !==
null && in_array(
'parsedcomment', $params[
'prop'] ) ) {
198 return 'anon-public-user-private';
207 ParamValidator::PARAM_ISMULTI =>
true,
208 ParamValidator::PARAM_TYPE =>
'namespace',
211 ParamValidator::PARAM_ISMULTI =>
true,
212 ParamValidator::PARAM_TYPE => array_diff(
216 ParamValidator::PARAM_DEFAULT => 10,
217 ParamValidator::PARAM_TYPE =>
'limit',
218 IntegerDef::PARAM_MIN => 1,
223 ParamValidator::PARAM_DEFAULT =>
'older',
224 ParamValidator::PARAM_TYPE => [
230 'newer' =>
'api-help-paramvalue-direction-newer',
231 'older' =>
'api-help-paramvalue-direction-older',
235 ParamValidator::PARAM_TYPE =>
'timestamp'
238 ParamValidator::PARAM_TYPE =>
'timestamp'
241 ParamValidator::PARAM_ISMULTI =>
true,
242 ParamValidator::PARAM_DEFAULT =>
'timestamp|level',
243 ParamValidator::PARAM_TYPE => [
262 'action=query&list=protectedtitles'
263 =>
'apihelp-query+protectedtitles-example-simple',
264 'action=query&generator=protectedtitles&gptnamespace=0&prop=linkshere'
265 =>
'apihelp-query+protectedtitles-example-generator',
270 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protectedtitles';
275class_alias( ApiQueryProtectedTitles::class,
'ApiQueryProtectedTitles' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
A class containing constants representing the names of configuration variables.
const RestrictionLevels
Name constant for the RestrictionLevels setting, for use with Config::get()