17use Wikimedia\Timestamp\TimestampFormat as TS;
32 parent::__construct( $query, $moduleName,
'pt' );
41 $this->run( $resultPageSet );
48 private function run( $resultPageSet =
null ) {
52 $this->
addFields( [
'pt_namespace',
'pt_title',
'pt_timestamp' ] );
54 $prop = array_fill_keys( $params[
'prop'],
true );
55 $this->
addFieldsIf(
'pt_user', isset( $prop[
'user'] ) || isset( $prop[
'userid'] ) );
56 $this->
addFieldsIf(
'pt_expiry', isset( $prop[
'expiry'] ) );
57 $this->
addFieldsIf(
'pt_create_perm', isset( $prop[
'level'] ) );
59 if ( isset( $prop[
'comment'] ) || isset( $prop[
'parsedcomment'] ) ) {
60 $commentQuery = $this->commentStore->getJoin(
'pt_reason' );
61 $this->
addTables( $commentQuery[
'tables'] );
62 $this->
addFields( $commentQuery[
'fields'] );
67 $this->
addWhereFld(
'pt_namespace', $params[
'namespace'] );
68 $this->
addWhereFld(
'pt_create_perm', $params[
'level'] );
71 $this->
addWhereRange(
'pt_namespace', $params[
'dir'],
null,
null );
72 $this->
addWhereRange(
'pt_title', $params[
'dir'],
null,
null );
74 if ( $params[
'continue'] !==
null ) {
76 $op = ( $params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
78 $this->
addWhere( $db->buildComparison( $op, [
79 'pt_timestamp' => $db->timestamp( $cont[0] ),
80 'pt_namespace' => $cont[1],
81 'pt_title' => $cont[2],
85 if ( isset( $prop[
'user'] ) ) {
93 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
94 $res = $this->
select( __METHOD__ );
96 if ( $resultPageSet ===
null ) {
98 if ( isset( $prop[
'parsedcomment'] ) ) {
99 $formattedComments = $this->commentFormatter->formatItems(
100 $this->commentFormatter->rows( $res )
101 ->commentKey(
'pt_reason' )
102 ->namespaceField(
'pt_namespace' )
103 ->titleField(
'pt_title' )
113 foreach ( $res as $rowOffset => $row ) {
114 if ( ++$count > $params[
'limit'] ) {
118 "$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
124 if ( $resultPageSet ===
null ) {
127 if ( isset( $prop[
'timestamp'] ) ) {
128 $vals[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->pt_timestamp );
131 if ( isset( $prop[
'user'] ) && $row->user_name !==
null ) {
132 $vals[
'user'] = $row->user_name;
135 if ( isset( $prop[
'userid'] ) || isset( $prop[
'user'] ) ) {
136 $vals[
'userid'] = (int)$row->pt_user;
139 if ( isset( $prop[
'comment'] ) ) {
140 $vals[
'comment'] = $this->commentStore->getComment(
'pt_reason', $row )->text;
143 if ( isset( $prop[
'parsedcomment'] ) ) {
144 $vals[
'parsedcomment'] = $formattedComments[$rowOffset];
147 if ( isset( $prop[
'expiry'] ) ) {
151 if ( isset( $prop[
'level'] ) ) {
152 $vals[
'level'] = $row->pt_create_perm;
155 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $vals );
158 "$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
167 if ( $resultPageSet ===
null ) {
168 $result->addIndexedTagName(
173 $resultPageSet->populateFromTitles( $titles );
179 if ( $params[
'prop'] !==
null && in_array(
'parsedcomment', $params[
'prop'] ) ) {
181 return 'anon-public-user-private';
191 ParamValidator::PARAM_ISMULTI =>
true,
192 ParamValidator::PARAM_TYPE =>
'namespace',
195 ParamValidator::PARAM_ISMULTI =>
true,
196 ParamValidator::PARAM_TYPE => array_diff(
200 ParamValidator::PARAM_DEFAULT => 10,
201 ParamValidator::PARAM_TYPE =>
'limit',
202 IntegerDef::PARAM_MIN => 1,
207 ParamValidator::PARAM_DEFAULT =>
'older',
208 ParamValidator::PARAM_TYPE => [
214 'newer' =>
'api-help-paramvalue-direction-newer',
215 'older' =>
'api-help-paramvalue-direction-older',
219 ParamValidator::PARAM_TYPE =>
'timestamp'
222 ParamValidator::PARAM_TYPE =>
'timestamp'
225 ParamValidator::PARAM_ISMULTI =>
true,
226 ParamValidator::PARAM_DEFAULT =>
'timestamp|level',
227 ParamValidator::PARAM_TYPE => [
247 'action=query&list=protectedtitles'
248 =>
'apihelp-query+protectedtitles-example-simple',
249 'action=query&generator=protectedtitles&gptnamespace=0&prop=linkshere'
250 =>
'apihelp-query+protectedtitles-example-generator',
256 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protectedtitles';
261class_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()