2009-02-13 21:34:46 +00:00
|
|
|
<?php
|
2010-02-24 14:45:19 +00:00
|
|
|
/**
|
2023-03-16 17:27:37 +00:00
|
|
|
* Copyright © 2009 Roan Kattouw <roan.kattouw@gmail.com>
|
2009-02-13 21:34:46 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2009-02-13 21:34:46 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2009-02-13 21:34:46 +00:00
|
|
|
*/
|
|
|
|
|
|
2024-09-25 16:17:29 +00:00
|
|
|
namespace MediaWiki\Api;
|
|
|
|
|
|
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
|
|
|
use MediaWiki\CommentFormatter\RowCommentFormatter;
|
2022-12-28 21:50:03 +00:00
|
|
|
use MediaWiki\CommentStore\CommentStore;
|
2022-04-13 15:28:26 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2022-06-05 23:18:50 +00:00
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
|
|
|
|
use Wikimedia\ParamValidator\TypeDef\IntegerDef;
|
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
|
|
|
|
2009-02-13 21:34:46 +00:00
|
|
|
/**
|
2009-02-13 21:36:34 +00:00
|
|
|
* Query module to enumerate all create-protected pages.
|
2009-02-13 21:34:46 +00:00
|
|
|
*
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
|
|
|
|
class ApiQueryProtectedTitles extends ApiQueryGeneratorBase {
|
|
|
|
|
|
2023-08-28 15:32:58 +00:00
|
|
|
private CommentStore $commentStore;
|
|
|
|
|
private RowCommentFormatter $commentFormatter;
|
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
|
|
|
|
2021-04-23 14:51:18 +00:00
|
|
|
public function __construct(
|
|
|
|
|
ApiQuery $query,
|
2024-10-14 20:12:27 +00:00
|
|
|
string $moduleName,
|
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
|
|
|
CommentStore $commentStore,
|
|
|
|
|
RowCommentFormatter $commentFormatter
|
2021-04-23 14:51:18 +00:00
|
|
|
) {
|
2010-02-24 14:45:19 +00:00
|
|
|
parent::__construct( $query, $moduleName, 'pt' );
|
2021-04-23 14:51:18 +00:00
|
|
|
$this->commentStore = $commentStore;
|
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
|
|
|
$this->commentFormatter = $commentFormatter;
|
2009-02-13 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
|
|
|
|
$this->run();
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function executeGenerator( $resultPageSet ) {
|
|
|
|
|
$this->run( $resultPageSet );
|
2009-02-13 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
2011-02-19 00:30:18 +00:00
|
|
|
/**
|
2019-11-23 22:28:57 +00:00
|
|
|
* @param ApiPageSet|null $resultPageSet
|
2012-01-12 19:41:18 +00:00
|
|
|
* @return void
|
2011-02-19 00:30:18 +00:00
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
private function run( $resultPageSet = null ) {
|
2009-02-13 21:34:46 +00:00
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addTables( 'protected_titles' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addFields( [ 'pt_namespace', 'pt_title', 'pt_timestamp' ] );
|
2009-02-13 21:34:46 +00:00
|
|
|
|
2021-06-11 02:52:06 +00:00
|
|
|
$prop = array_fill_keys( $params['prop'], true );
|
2010-08-28 01:18:18 +00:00
|
|
|
$this->addFieldsIf( 'pt_user', isset( $prop['user'] ) || isset( $prop['userid'] ) );
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addFieldsIf( 'pt_expiry', isset( $prop['expiry'] ) );
|
|
|
|
|
$this->addFieldsIf( 'pt_create_perm', isset( $prop['level'] ) );
|
2009-02-13 21:34:46 +00:00
|
|
|
|
2017-06-06 17:39:14 +00:00
|
|
|
if ( isset( $prop['comment'] ) || isset( $prop['parsedcomment'] ) ) {
|
2021-04-23 14:51:18 +00:00
|
|
|
$commentQuery = $this->commentStore->getJoin( 'pt_reason' );
|
2017-06-06 17:39:14 +00:00
|
|
|
$this->addTables( $commentQuery['tables'] );
|
|
|
|
|
$this->addFields( $commentQuery['fields'] );
|
|
|
|
|
$this->addJoinConds( $commentQuery['joins'] );
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-06 20:46:24 +00:00
|
|
|
$this->addTimestampWhereRange( 'pt_timestamp', $params['dir'], $params['start'], $params['end'] );
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addWhereFld( 'pt_namespace', $params['namespace'] );
|
|
|
|
|
$this->addWhereFld( 'pt_create_perm', $params['level'] );
|
2010-02-24 14:45:19 +00:00
|
|
|
|
2013-12-24 20:26:47 +00:00
|
|
|
// Include in ORDER BY for uniqueness
|
|
|
|
|
$this->addWhereRange( 'pt_namespace', $params['dir'], null, null );
|
|
|
|
|
$this->addWhereRange( 'pt_title', $params['dir'], null, null );
|
|
|
|
|
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $params['continue'] !== null ) {
|
2022-10-31 22:26:14 +00:00
|
|
|
$cont = $this->parseContinueParamOrDie( $params['continue'], [ 'timestamp', 'int', 'string' ] );
|
2022-09-16 10:34:51 +00:00
|
|
|
$op = ( $params['dir'] === 'newer' ? '>=' : '<=' );
|
2013-12-24 20:26:47 +00:00
|
|
|
$db = $this->getDB();
|
2022-09-16 10:34:51 +00:00
|
|
|
$this->addWhere( $db->buildComparison( $op, [
|
2022-09-16 14:38:10 +00:00
|
|
|
'pt_timestamp' => $db->timestamp( $cont[0] ),
|
|
|
|
|
'pt_namespace' => $cont[1],
|
|
|
|
|
'pt_title' => $cont[2],
|
2022-09-16 10:34:51 +00:00
|
|
|
] ) );
|
2013-12-24 20:26:47 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-24 14:45:19 +00:00
|
|
|
if ( isset( $prop['user'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addTables( 'user' );
|
|
|
|
|
$this->addFields( 'user_name' );
|
2016-02-17 09:09:32 +00:00
|
|
|
$this->addJoinConds( [ 'user' => [ 'LEFT JOIN',
|
2009-02-13 21:34:46 +00:00
|
|
|
'user_id=pt_user'
|
2016-02-17 09:09:32 +00:00
|
|
|
] ] );
|
2009-02-13 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->addOption( 'LIMIT', $params['limit'] + 1 );
|
|
|
|
|
$res = $this->select( __METHOD__ );
|
2009-02-13 21:34:46 +00:00
|
|
|
|
2019-10-10 17:44:04 +00:00
|
|
|
if ( $resultPageSet === null ) {
|
|
|
|
|
$this->executeGenderCacheFromResultWrapper( $res, __METHOD__, 'pt' );
|
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
|
|
|
if ( isset( $prop['parsedcomment'] ) ) {
|
|
|
|
|
$formattedComments = $this->commentFormatter->formatItems(
|
|
|
|
|
$this->commentFormatter->rows( $res )
|
|
|
|
|
->commentKey( 'pt_reason' )
|
|
|
|
|
->namespaceField( 'pt_namespace' )
|
|
|
|
|
->titleField( 'pt_title' )
|
|
|
|
|
);
|
|
|
|
|
}
|
2019-10-10 17:44:04 +00:00
|
|
|
}
|
|
|
|
|
|
2009-02-13 21:34:46 +00:00
|
|
|
$count = 0;
|
|
|
|
|
$result = $this->getResult();
|
2011-02-24 23:03:00 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$titles = [];
|
2011-02-24 23:03:00 +00:00
|
|
|
|
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
|
|
|
foreach ( $res as $rowOffset => $row ) {
|
2013-11-14 12:56:06 +00:00
|
|
|
if ( ++$count > $params['limit'] ) {
|
2013-11-14 13:58:14 +00:00
|
|
|
// We've reached the one extra which shows that there are
|
|
|
|
|
// additional pages to be had. Stop here...
|
2013-12-24 20:26:47 +00:00
|
|
|
$this->setContinueEnumParameter( 'continue',
|
|
|
|
|
"$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
|
|
|
|
|
);
|
2009-02-13 21:34:46 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$title = Title::makeTitle( $row->pt_namespace, $row->pt_title );
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $resultPageSet === null ) {
|
2016-02-17 09:09:32 +00:00
|
|
|
$vals = [];
|
2010-01-11 15:55:52 +00:00
|
|
|
ApiQueryBase::addTitleInfo( $vals, $title );
|
2010-02-24 14:45:19 +00:00
|
|
|
if ( isset( $prop['timestamp'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$vals['timestamp'] = wfTimestamp( TS_ISO_8601, $row->pt_timestamp );
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( isset( $prop['user'] ) && $row->user_name !== null ) {
|
2009-02-13 21:34:46 +00:00
|
|
|
$vals['user'] = $row->user_name;
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-31 18:21:30 +00:00
|
|
|
if ( isset( $prop['userid'] ) || /*B/C*/isset( $prop['user'] ) ) {
|
2015-05-06 15:33:08 +00:00
|
|
|
$vals['userid'] = (int)$row->pt_user;
|
2010-08-28 01:18:18 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-24 14:45:19 +00:00
|
|
|
if ( isset( $prop['comment'] ) ) {
|
2021-04-23 14:51:18 +00:00
|
|
|
$vals['comment'] = $this->commentStore->getComment( 'pt_reason', $row )->text;
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
2010-01-31 23:06:35 +00:00
|
|
|
if ( isset( $prop['parsedcomment'] ) ) {
|
Introduce CommentFormatter
CommentParser:
* Move comment formatting backend from Linker to a CommentParser service.
Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
was used for.
* Rename the "autocomment" concept to "section link" in public
interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
static analysis and code review.
CommentFormatter:
* Add CommentFormatter and RowCommentFormatter services as a usable
frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.
Linker:
* Remove Linker::makeCommentLink() without deprecation -- nothing calls
it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
commentBlock() and revComment().
Caller migration:
* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager
Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-07-01 06:55:03 +00:00
|
|
|
// @phan-suppress-next-line PhanTypeArraySuspiciousNullable
|
|
|
|
|
$vals['parsedcomment'] = $formattedComments[$rowOffset];
|
2010-01-31 23:06:35 +00:00
|
|
|
}
|
2010-02-24 14:45:19 +00:00
|
|
|
|
|
|
|
|
if ( isset( $prop['expiry'] ) ) {
|
2017-01-11 19:04:41 +00:00
|
|
|
$vals['expiry'] = ApiResult::formatExpiry( $row->pt_expiry );
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( isset( $prop['level'] ) ) {
|
2009-02-13 21:34:46 +00:00
|
|
|
$vals['level'] = $row->pt_create_perm;
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$fit = $result->addValue( [ 'query', $this->getModuleName() ], null, $vals );
|
2010-01-31 23:06:35 +00:00
|
|
|
if ( !$fit ) {
|
2013-12-24 20:26:47 +00:00
|
|
|
$this->setContinueEnumParameter( 'continue',
|
|
|
|
|
"$row->pt_timestamp|$row->pt_namespace|$row->pt_title"
|
|
|
|
|
);
|
2009-02-13 21:34:46 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$titles[] = $title;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-06-20 17:48:21 +00:00
|
|
|
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $resultPageSet === null ) {
|
API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.
ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.
So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
Formatters are responsible for stripping it if necessary. "raw mode"
is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
question, and so on.
* New class for formatting warnings and errors using i18n messages, and
support for multiple errors and a more machine-readable format for
warnings. For the moment, though, the actual output will not be changing
yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
modules currently returning booleans will need to use
ApiResult::META_BC_BOOLS to preserve their current output.
Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.
Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2014-12-03 22:14:22 +00:00
|
|
|
$result->addIndexedTagName(
|
2016-02-17 09:09:32 +00:00
|
|
|
[ 'query', $this->getModuleName() ],
|
2013-11-14 13:58:14 +00:00
|
|
|
$this->getModulePrefix()
|
|
|
|
|
);
|
2010-02-24 14:45:19 +00:00
|
|
|
} else {
|
2010-01-11 15:55:52 +00:00
|
|
|
$resultPageSet->populateFromTitles( $titles );
|
2010-02-24 14:45:19 +00:00
|
|
|
}
|
2009-02-13 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
2010-07-23 07:17:56 +00:00
|
|
|
public function getCacheMode( $params ) {
|
2020-01-09 23:48:34 +00:00
|
|
|
if ( $params['prop'] !== null && in_array( 'parsedcomment', $params['prop'] ) ) {
|
2022-12-10 23:56:46 +00:00
|
|
|
// MediaWiki\CommentFormatter\CommentFormatter::formatItems() calls wfMessage() among other things
|
2010-07-23 07:17:56 +00:00
|
|
|
return 'anon-public-user-private';
|
|
|
|
|
} else {
|
|
|
|
|
return 'public';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-02-13 21:34:46 +00:00
|
|
|
public function getAllowedParams() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
|
|
|
|
'namespace' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
|
|
|
|
ParamValidator::PARAM_TYPE => 'namespace',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'level' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
|
|
|
|
ParamValidator::PARAM_TYPE => array_diff(
|
2022-04-13 15:28:26 +00:00
|
|
|
$this->getConfig()->get( MainConfigNames::RestrictionLevels ), [ '' ] )
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'limit' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => 10,
|
|
|
|
|
ParamValidator::PARAM_TYPE => 'limit',
|
|
|
|
|
IntegerDef::PARAM_MIN => 1,
|
|
|
|
|
IntegerDef::PARAM_MAX => ApiBase::LIMIT_BIG1,
|
|
|
|
|
IntegerDef::PARAM_MAX2 => ApiBase::LIMIT_BIG2
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'dir' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => 'older',
|
|
|
|
|
ParamValidator::PARAM_TYPE => [
|
2011-02-24 00:52:09 +00:00
|
|
|
'newer',
|
|
|
|
|
'older'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-param-direction',
|
2023-08-05 13:05:24 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG_PER_VALUE => [
|
|
|
|
|
'newer' => 'api-help-paramvalue-direction-newer',
|
|
|
|
|
'older' => 'api-help-paramvalue-direction-older',
|
|
|
|
|
],
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'start' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'timestamp'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'end' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'timestamp'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'prop' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
|
|
|
|
ParamValidator::PARAM_DEFAULT => 'timestamp|level',
|
|
|
|
|
ParamValidator::PARAM_TYPE => [
|
2009-02-13 21:34:46 +00:00
|
|
|
'timestamp',
|
|
|
|
|
'user',
|
2010-08-28 01:18:18 +00:00
|
|
|
'userid',
|
2009-02-13 21:34:46 +00:00
|
|
|
'comment',
|
2010-01-31 23:06:35 +00:00
|
|
|
'parsedcomment',
|
2009-02-13 21:34:46 +00:00
|
|
|
'expiry',
|
|
|
|
|
'level'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
ApiBase::PARAM_HELP_MSG_PER_VALUE => [],
|
|
|
|
|
],
|
|
|
|
|
'continue' => [
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_HELP_MSG => 'api-help-param-continue',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2009-02-13 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
2014-10-28 17:17:02 +00:00
|
|
|
protected function getExamplesMessages() {
|
2016-02-17 09:09:32 +00:00
|
|
|
return [
|
2014-09-18 17:38:23 +00:00
|
|
|
'action=query&list=protectedtitles'
|
|
|
|
|
=> 'apihelp-query+protectedtitles-example-simple',
|
|
|
|
|
'action=query&generator=protectedtitles&gptnamespace=0&prop=linkshere'
|
|
|
|
|
=> 'apihelp-query+protectedtitles-example-generator',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2009-02-13 21:34:46 +00:00
|
|
|
}
|
|
|
|
|
|
2011-07-17 17:02:06 +00:00
|
|
|
public function getHelpUrls() {
|
2017-04-04 22:52:57 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Protectedtitles';
|
2011-07-17 17:02:06 +00:00
|
|
|
}
|
2010-07-23 07:17:56 +00:00
|
|
|
}
|
2024-09-25 16:17:29 +00:00
|
|
|
|
|
|
|
|
/** @deprecated class alias since 1.43 */
|
|
|
|
|
class_alias( ApiQueryProtectedTitles::class, 'ApiQueryProtectedTitles' );
|