17use Wikimedia\Timestamp\TimestampFormat as TS;
35 parent::__construct( $query, $moduleName,
'pt' );
36 $this->commentStore = $commentStore;
37 $this->commentFormatter = $commentFormatter;
46 $this->run( $resultPageSet );
53 private function run( $resultPageSet =
null ) {
57 $this->
addFields( [
'pt_namespace',
'pt_title',
'pt_timestamp' ] );
59 $prop = array_fill_keys( $params[
'prop'],
true );
60 $this->
addFieldsIf(
'pt_user', isset( $prop[
'user'] ) || isset( $prop[
'userid'] ) );
61 $this->
addFieldsIf(
'pt_expiry', isset( $prop[
'expiry'] ) );
62 $this->
addFieldsIf(
'pt_create_perm', isset( $prop[
'level'] ) );
64 if ( isset( $prop[
'comment'] ) || isset( $prop[
'parsedcomment'] ) ) {
65 $commentQuery = $this->commentStore->getJoin(
'pt_reason' );
66 $this->
addTables( $commentQuery[
'tables'] );
67 $this->
addFields( $commentQuery[
'fields'] );
72 $this->
addWhereFld(
'pt_namespace', $params[
'namespace'] );
73 $this->
addWhereFld(
'pt_create_perm', $params[
'level'] );
76 $this->
addWhereRange(
'pt_namespace', $params[
'dir'],
null,
null );
77 $this->
addWhereRange(
'pt_title', $params[
'dir'],
null,
null );
79 if ( $params[
'continue'] !==
null ) {
81 $op = ( $params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
83 $this->
addWhere( $db->buildComparison( $op, [
84 'pt_timestamp' => $db->timestamp( $cont[0] ),
85 'pt_namespace' => $cont[1],
86 'pt_title' => $cont[2],
90 if ( isset( $prop[
'user'] ) ) {
98 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
99 $res = $this->
select( __METHOD__ );
101 if ( $resultPageSet ===
null ) {
103 if ( isset( $prop[
'parsedcomment'] ) ) {
104 $formattedComments = $this->commentFormatter->formatItems(
105 $this->commentFormatter->rows( $res )
106 ->commentKey(
'pt_reason' )
107 ->namespaceField(
'pt_namespace' )
108 ->titleField(
'pt_title' )
118 foreach ( $res as $rowOffset => $row ) {
119 if ( ++$count > $params[
'limit'] ) {
123 "$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
129 if ( $resultPageSet ===
null ) {
132 if ( isset( $prop[
'timestamp'] ) ) {
133 $vals[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->pt_timestamp );
136 if ( isset( $prop[
'user'] ) && $row->user_name !==
null ) {
137 $vals[
'user'] = $row->user_name;
140 if ( isset( $prop[
'userid'] ) || isset( $prop[
'user'] ) ) {
141 $vals[
'userid'] = (int)$row->pt_user;
144 if ( isset( $prop[
'comment'] ) ) {
145 $vals[
'comment'] = $this->commentStore->getComment(
'pt_reason', $row )->text;
148 if ( isset( $prop[
'parsedcomment'] ) ) {
150 $vals[
'parsedcomment'] = $formattedComments[$rowOffset];
153 if ( isset( $prop[
'expiry'] ) ) {
157 if ( isset( $prop[
'level'] ) ) {
158 $vals[
'level'] = $row->pt_create_perm;
161 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
164 "$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
173 if ( $resultPageSet ===
null ) {
174 $result->addIndexedTagName(
179 $resultPageSet->populateFromTitles( $titles );
185 if ( $params[
'prop'] !==
null && in_array(
'parsedcomment', $params[
'prop'] ) ) {
187 return 'anon-public-user-private';
197 ParamValidator::PARAM_ISMULTI =>
true,
198 ParamValidator::PARAM_TYPE =>
'namespace',
201 ParamValidator::PARAM_ISMULTI =>
true,
202 ParamValidator::PARAM_TYPE => array_diff(
206 ParamValidator::PARAM_DEFAULT => 10,
207 ParamValidator::PARAM_TYPE =>
'limit',
208 IntegerDef::PARAM_MIN => 1,
213 ParamValidator::PARAM_DEFAULT =>
'older',
214 ParamValidator::PARAM_TYPE => [
220 'newer' =>
'api-help-paramvalue-direction-newer',
221 'older' =>
'api-help-paramvalue-direction-older',
225 ParamValidator::PARAM_TYPE =>
'timestamp'
228 ParamValidator::PARAM_TYPE =>
'timestamp'
231 ParamValidator::PARAM_ISMULTI =>
true,
232 ParamValidator::PARAM_DEFAULT =>
'timestamp|level',
233 ParamValidator::PARAM_TYPE => [
253 'action=query&list=protectedtitles'
254 =>
'apihelp-query+protectedtitles-example-simple',
255 'action=query&generator=protectedtitles&gptnamespace=0&prop=linkshere'
256 =>
'apihelp-query+protectedtitles-example-generator',
262 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protectedtitles';
267class_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()