2011-06-06 14:50:34 +00:00
|
|
|
<?php
|
|
|
|
|
/**
|
|
|
|
|
* Copyright © 2011 Sam Reed
|
|
|
|
|
*
|
|
|
|
|
* 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.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
|
|
|
|
* @file
|
|
|
|
|
*/
|
|
|
|
|
|
2024-09-25 16:17:29 +00:00
|
|
|
namespace MediaWiki\Api;
|
|
|
|
|
|
2021-06-19 12:57:42 +00:00
|
|
|
use MediaWiki\Cache\LinkBatchFactory;
|
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\CommentFormatter;
|
2024-05-19 18:33:58 +00:00
|
|
|
use MediaWiki\Content\TextContent;
|
2022-10-17 11:10:57 +00:00
|
|
|
use MediaWiki\Feed\FeedItem;
|
2021-06-19 12:57:42 +00:00
|
|
|
use MediaWiki\HookContainer\HookContainer;
|
|
|
|
|
use MediaWiki\Linker\LinkRenderer;
|
2022-04-10 15:34:45 +00:00
|
|
|
use MediaWiki\MainConfigNames;
|
2024-10-15 23:57:34 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2023-09-15 08:38:07 +00:00
|
|
|
use MediaWiki\Pager\ContribsPager;
|
2019-08-21 19:53:53 +00:00
|
|
|
use MediaWiki\ParamValidator\TypeDef\UserDef;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\RevisionAccessException;
|
|
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
use MediaWiki\Revision\RevisionStore;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2023-09-15 09:32:18 +00:00
|
|
|
use MediaWiki\SpecialPage\SpecialPage;
|
2023-09-18 14:17:28 +00:00
|
|
|
use MediaWiki\Title\NamespaceInfo;
|
2023-03-01 20:33:26 +00:00
|
|
|
use MediaWiki\Title\Title;
|
2023-09-19 16:42:44 +00:00
|
|
|
use MediaWiki\User\ExternalUserNames;
|
2021-08-25 03:21:09 +00:00
|
|
|
use MediaWiki\User\UserFactory;
|
2022-03-16 04:08:00 +00:00
|
|
|
use MediaWiki\User\UserRigorOptions;
|
2022-06-05 23:18:50 +00:00
|
|
|
use Wikimedia\ParamValidator\ParamValidator;
|
2023-04-19 15:35:34 +00:00
|
|
|
use Wikimedia\Rdbms\IConnectionProvider;
|
2018-02-16 18:23:45 +00:00
|
|
|
|
2011-06-06 14:50:34 +00:00
|
|
|
/**
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
|
|
|
|
class ApiFeedContributions extends ApiBase {
|
|
|
|
|
|
2023-08-28 15:32:58 +00:00
|
|
|
private RevisionStore $revisionStore;
|
|
|
|
|
private LinkRenderer $linkRenderer;
|
|
|
|
|
private LinkBatchFactory $linkBatchFactory;
|
|
|
|
|
private HookContainer $hookContainer;
|
|
|
|
|
private IConnectionProvider $dbProvider;
|
|
|
|
|
private NamespaceInfo $namespaceInfo;
|
|
|
|
|
private UserFactory $userFactory;
|
|
|
|
|
private CommentFormatter $commentFormatter;
|
|
|
|
|
private ApiHookRunner $hookRunner;
|
2021-06-19 12:57:42 +00:00
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
ApiMain $main,
|
2024-10-14 20:12:27 +00:00
|
|
|
string $action,
|
2021-06-19 12:57:42 +00:00
|
|
|
RevisionStore $revisionStore,
|
|
|
|
|
LinkRenderer $linkRenderer,
|
|
|
|
|
LinkBatchFactory $linkBatchFactory,
|
|
|
|
|
HookContainer $hookContainer,
|
2023-04-19 15:35:34 +00:00
|
|
|
IConnectionProvider $dbProvider,
|
2021-06-19 12:57:42 +00:00
|
|
|
NamespaceInfo $namespaceInfo,
|
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
|
|
|
UserFactory $userFactory,
|
|
|
|
|
CommentFormatter $commentFormatter
|
2021-06-19 12:57:42 +00:00
|
|
|
) {
|
|
|
|
|
parent::__construct( $main, $action );
|
|
|
|
|
$this->revisionStore = $revisionStore;
|
|
|
|
|
$this->linkRenderer = $linkRenderer;
|
|
|
|
|
$this->linkBatchFactory = $linkBatchFactory;
|
|
|
|
|
$this->hookContainer = $hookContainer;
|
2023-04-19 15:35:34 +00:00
|
|
|
$this->dbProvider = $dbProvider;
|
2021-06-19 12:57:42 +00:00
|
|
|
$this->namespaceInfo = $namespaceInfo;
|
2021-08-25 03:21:09 +00:00
|
|
|
$this->userFactory = $userFactory;
|
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;
|
2021-06-19 12:57:42 +00:00
|
|
|
|
|
|
|
|
$this->hookRunner = new ApiHookRunner( $hookContainer );
|
|
|
|
|
}
|
|
|
|
|
|
2011-06-06 14:50:34 +00:00
|
|
|
/**
|
|
|
|
|
* This module uses a custom feed wrapper printer.
|
2011-09-21 16:36:43 +00:00
|
|
|
*
|
|
|
|
|
* @return ApiFormatFeedWrapper
|
2011-06-06 14:50:34 +00:00
|
|
|
*/
|
|
|
|
|
public function getCustomPrinter() {
|
|
|
|
|
return new ApiFormatFeedWrapper( $this->getMain() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function execute() {
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
$params = $this->extractRequestParams();
|
2011-06-06 14:50:34 +00:00
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
$config = $this->getConfig();
|
2022-04-10 15:34:45 +00:00
|
|
|
if ( !$config->get( MainConfigNames::Feed ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'feed-unavailable' );
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
}
|
2011-06-06 14:50:34 +00:00
|
|
|
|
2022-04-10 15:34:45 +00:00
|
|
|
$feedClasses = $config->get( MainConfigNames::FeedClasses );
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( !isset( $feedClasses[$params['feedformat']] ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'feed-invalid' );
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
}
|
2011-06-06 14:50:34 +00:00
|
|
|
|
2022-04-10 15:34:45 +00:00
|
|
|
if ( $params['showsizediff'] && $this->getConfig()->get( MainConfigNames::MiserMode ) ) {
|
2016-10-19 16:54:25 +00:00
|
|
|
$this->dieWithError( 'apierror-sizediffdisabled' );
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
}
|
2011-06-06 14:50:34 +00:00
|
|
|
|
2025-04-18 02:31:34 +00:00
|
|
|
$msg = $this->msg( 'Contributions' )->inContentLanguage()->escaped();
|
2022-04-10 15:34:45 +00:00
|
|
|
$feedTitle = $config->get( MainConfigNames::Sitename ) . ' - ' . $msg .
|
|
|
|
|
' [' . $config->get( MainConfigNames::LanguageCode ) . ']';
|
2011-06-06 14:50:34 +00:00
|
|
|
|
2019-08-21 19:53:53 +00:00
|
|
|
$target = $params['user'];
|
|
|
|
|
if ( ExternalUserNames::isExternal( $target ) ) {
|
|
|
|
|
// Interwiki names make invalid titles, so put the target in the query instead.
|
|
|
|
|
$feedUrl = SpecialPage::getTitleFor( 'Contributions' )->getFullURL( [ 'target' => $target ] );
|
|
|
|
|
} else {
|
|
|
|
|
$feedUrl = SpecialPage::getTitleFor( 'Contributions', $target )->getFullURL();
|
2019-08-09 20:53:45 +00:00
|
|
|
}
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
$feed = new $feedClasses[$params['feedformat']] (
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
$feedTitle,
|
2025-04-18 02:31:34 +00:00
|
|
|
$msg,
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
$feedUrl
|
|
|
|
|
);
|
2011-06-06 14:50:34 +00:00
|
|
|
|
2017-06-04 01:12:21 +00:00
|
|
|
// Convert year/month parameters to end parameter
|
|
|
|
|
$params['start'] = '';
|
|
|
|
|
$params['end'] = '';
|
|
|
|
|
$params = ContribsPager::processDateFilter( $params );
|
|
|
|
|
|
2022-03-16 04:08:00 +00:00
|
|
|
$targetUser = $this->userFactory->newFromName( $target, UserRigorOptions::RIGOR_NONE );
|
2021-08-25 03:21:09 +00:00
|
|
|
|
2020-08-07 22:08:51 +00:00
|
|
|
$pager = new ContribsPager(
|
|
|
|
|
$this->getContext(), [
|
|
|
|
|
'target' => $target,
|
|
|
|
|
'namespace' => $params['namespace'],
|
|
|
|
|
'start' => $params['start'],
|
|
|
|
|
'end' => $params['end'],
|
|
|
|
|
'tagFilter' => $params['tagfilter'],
|
|
|
|
|
'deletedOnly' => $params['deletedonly'],
|
|
|
|
|
'topOnly' => $params['toponly'],
|
|
|
|
|
'newOnly' => $params['newonly'],
|
|
|
|
|
'hideMinor' => $params['hideminor'],
|
|
|
|
|
'showSizeDiff' => $params['showsizediff'],
|
|
|
|
|
],
|
2021-06-19 12:57:42 +00:00
|
|
|
$this->linkRenderer,
|
|
|
|
|
$this->linkBatchFactory,
|
|
|
|
|
$this->hookContainer,
|
2023-04-19 15:35:34 +00:00
|
|
|
$this->dbProvider,
|
2020-09-19 22:43:46 +00:00
|
|
|
$this->revisionStore,
|
2021-08-25 03:21:09 +00:00
|
|
|
$this->namespaceInfo,
|
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
|
|
|
$targetUser,
|
|
|
|
|
$this->commentFormatter
|
2020-08-07 22:08:51 +00:00
|
|
|
);
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
|
2022-04-10 15:34:45 +00:00
|
|
|
$feedLimit = $this->getConfig()->get( MainConfigNames::FeedLimit );
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $pager->getLimit() > $feedLimit ) {
|
|
|
|
|
$pager->setLimit( $feedLimit );
|
2012-12-21 22:40:45 +00:00
|
|
|
}
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$feedItems = [];
|
2013-04-19 18:03:05 +00:00
|
|
|
if ( $pager->getNumRows() > 0 ) {
|
2013-12-31 16:44:43 +00:00
|
|
|
$count = 0;
|
|
|
|
|
$limit = $pager->getLimit();
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
foreach ( $pager->mResult as $row ) {
|
2013-12-31 16:44:43 +00:00
|
|
|
// ContribsPager selects one more row for navigation, skip that row
|
|
|
|
|
if ( ++$count > $limit ) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-01-14 21:52:50 +00:00
|
|
|
$item = $this->feedItem( $row );
|
|
|
|
|
if ( $item !== null ) {
|
|
|
|
|
$feedItems[] = $item;
|
|
|
|
|
}
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
}
|
2012-03-17 02:23:06 +00:00
|
|
|
}
|
Revert r107309, r113601, r113704, r113742, r113792, r113838, r113859, r113893, r113894, r113952, r114047, r114252, r114256, r114257. This reverts the remaining 'new' revisions in core.
All of these revisions are tagged with 'gerritmigration' and will be resubmitted into Gerrit after the Gerrit switchover. See also http://lists.wikimedia.org/pipermail/wikitech-l/2012-March/059124.html
2012-03-21 00:16:50 +00:00
|
|
|
|
|
|
|
|
ApiFormatFeedWrapper::setResult( $this->getResult(), $feed, $feedItems );
|
2011-06-06 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function feedItem( $row ) {
|
2015-01-14 21:52:50 +00:00
|
|
|
// This hook is the api contributions equivalent to the
|
|
|
|
|
// ContributionsLineEnding hook. Hook implementers may cancel
|
|
|
|
|
// the hook to signal the user is not allowed to read this item.
|
|
|
|
|
$feedItem = null;
|
2021-06-19 12:57:42 +00:00
|
|
|
$hookResult = $this->hookRunner->onApiFeedContributions__feedItem(
|
Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.
General principles:
* Use DI if it is already used. We're not changing the way state is
managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
is a service, it's a more generic interface, it is the only
thing that provides isRegistered() which is needed in some cases,
and a HookRunner can be efficiently constructed from it
(confirmed by benchmark). Because HookContainer is needed
for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
SpecialPage and ApiBase have getHookContainer() and getHookRunner()
methods in the base class, and classes that extend that base class
are not expected to know or care where the base class gets its
HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
getHookRunner() methods, getting them from the global service
container. The point of this is to ease migration to DI by ensuring
that call sites ask their local friendly base class rather than
getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
methods did not seem warranted, there is a private HookRunner property
which is accessed directly. Very rarely (two cases), there is a
protected property, for consistency with code that conventionally
assumes protected=private, but in cases where the class might actually
be overridden, a protected accessor is preferred over a protected
property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
global code. In a few cases it was used for objects with broken
construction schemes, out of horror or laziness.
Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore
Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router
setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine
Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-03-19 02:42:09 +00:00
|
|
|
$row, $this->getContext(), $feedItem );
|
2015-01-14 21:52:50 +00:00
|
|
|
// Hook returned a valid feed item
|
|
|
|
|
if ( $feedItem instanceof FeedItem ) {
|
|
|
|
|
return $feedItem;
|
|
|
|
|
// Hook was canceled and did not return a valid feed item
|
|
|
|
|
} elseif ( !$hookResult ) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Hook completed and did not return a valid feed item
|
2019-02-25 00:38:33 +00:00
|
|
|
$title = Title::makeTitle( (int)$row->page_namespace, $row->page_title );
|
2019-05-18 16:58:24 +00:00
|
|
|
|
2021-01-11 15:26:02 +00:00
|
|
|
if ( $title && $this->getAuthority()->authorizeRead( 'read', $title ) ) {
|
2011-06-06 14:50:34 +00:00
|
|
|
$date = $row->rev_timestamp;
|
|
|
|
|
$comments = $title->getTalkPage()->getFullURL();
|
2019-10-10 18:32:39 +00:00
|
|
|
$revision = $this->revisionStore->newRevisionFromRow( $row, 0, $title );
|
2011-06-06 14:50:34 +00:00
|
|
|
|
|
|
|
|
return new FeedItem(
|
|
|
|
|
$title->getPrefixedText(),
|
|
|
|
|
$this->feedItemDesc( $revision ),
|
2016-02-17 09:09:32 +00:00
|
|
|
$title->getFullURL( [ 'diff' => $revision->getId() ] ),
|
2011-06-06 14:50:34 +00:00
|
|
|
$date,
|
|
|
|
|
$this->feedItemAuthor( $revision ),
|
|
|
|
|
$comments
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-11-14 12:40:22 +00:00
|
|
|
|
2012-08-21 18:55:48 +00:00
|
|
|
return null;
|
2011-06-06 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-02-16 18:23:45 +00:00
|
|
|
* @since 1.32, takes a RevisionRecord instead of a Revision
|
|
|
|
|
* @param RevisionRecord $revision
|
2011-06-06 14:50:34 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2018-02-16 18:23:45 +00:00
|
|
|
protected function feedItemAuthor( RevisionRecord $revision ) {
|
|
|
|
|
$user = $revision->getUser();
|
|
|
|
|
return $user ? $user->getName() : '';
|
2011-06-06 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2018-02-16 18:23:45 +00:00
|
|
|
* @since 1.32, takes a RevisionRecord instead of a Revision
|
|
|
|
|
* @param RevisionRecord $revision
|
2011-06-06 14:50:34 +00:00
|
|
|
* @return string
|
|
|
|
|
*/
|
2018-02-16 18:23:45 +00:00
|
|
|
protected function feedItemDesc( RevisionRecord $revision ) {
|
2025-04-18 02:31:34 +00:00
|
|
|
$msg = $this->msg( 'colon-separator' )->inContentLanguage()->escaped();
|
2018-12-02 18:06:53 +00:00
|
|
|
try {
|
|
|
|
|
$content = $revision->getContent( SlotRecord::MAIN );
|
|
|
|
|
} catch ( RevisionAccessException $e ) {
|
|
|
|
|
$content = null;
|
|
|
|
|
}
|
2018-02-16 18:23:45 +00:00
|
|
|
|
2018-12-02 18:06:53 +00:00
|
|
|
if ( $content instanceof TextContent ) {
|
|
|
|
|
// only textual content has a "source view".
|
2022-01-25 05:23:23 +00:00
|
|
|
$html = nl2br( htmlspecialchars( $content->getText(), ENT_COMPAT ) );
|
2018-12-02 18:06:53 +00:00
|
|
|
} else {
|
|
|
|
|
// XXX: we could get an HTML representation of the content via getParserOutput, but that may
|
|
|
|
|
// contain JS magic and generally may not be suitable for inclusion in a feed.
|
|
|
|
|
// Perhaps Content should have a getDescriptiveHtml method and/or a getSourceText method.
|
2022-10-17 11:10:57 +00:00
|
|
|
// Compare also MediaWiki\Feed\FeedUtils::formatDiffRow.
|
2018-12-02 18:06:53 +00:00
|
|
|
$html = '';
|
2011-06-06 14:50:34 +00:00
|
|
|
}
|
2013-11-14 12:40:22 +00:00
|
|
|
|
2018-12-02 18:06:53 +00:00
|
|
|
$comment = $revision->getComment();
|
|
|
|
|
|
|
|
|
|
return '<p>' . htmlspecialchars( $this->feedItemAuthor( $revision ) ) . $msg .
|
2022-08-14 01:10:31 +00:00
|
|
|
htmlspecialchars( FeedItem::stripComment( $comment->text ?? '' ) ) .
|
2018-12-02 18:06:53 +00:00
|
|
|
"</p>\n<hr />\n<div>" . $html . '</div>';
|
2011-06-06 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
2022-04-10 15:34:45 +00:00
|
|
|
$feedFormatNames = array_keys( $this->getConfig()->get( MainConfigNames::FeedClasses ) );
|
2013-11-14 12:40:22 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret = [
|
|
|
|
|
'feedformat' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => 'rss',
|
|
|
|
|
ParamValidator::PARAM_TYPE => $feedFormatNames
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'user' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'user',
|
Add 'temp' to allowed user types in various APIs
Why:
* Before this task, when an API parameter specifies allowed user
types, temporary users and permanent users are in the same
category: 'name'.
* However, it is useful to separate them out, and sometimes
allow a permanent user but not a temporary user (e.g.
ApiResetPassword, since temporary users don't have passwords).
* We therefore re-defined the 'name' type only to refer to
permanent (named) users, and add a new 'temp' type.
* This fixes params that currently intend to allow temp users,
and that use 'name' to do so, by adding 'temp'.
What:
* Based on a search for `UserDef::PARAM_ALLOWED_USER_TYPES`,
add the 'temp' type where necessary.
* The following were not updated, because they shouldn't apply
to temporary users:
- owners for includes/api/ApiQueryWatchlist.php,
includes/api/ApiQueryWatchlistRaw.php
- users for includes/api/ApiResetPassword.php,
includes/api/ApiUserrights.php,
includes/api/ApiValidatePassword.php
Bug: T350701
Change-Id: If5ccf1d469327791acff74d013343307e411cca9
2023-11-29 12:21:16 +00:00
|
|
|
UserDef::PARAM_ALLOWED_USER_TYPES => [ 'name', 'ip', 'temp', 'cidr', 'id', 'interwiki' ],
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_REQUIRED => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'namespace' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'namespace'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'year' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'integer'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'month' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_TYPE => 'integer'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'tagfilter' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_ISMULTI => true,
|
2024-10-15 23:57:34 +00:00
|
|
|
ParamValidator::PARAM_TYPE => array_values( MediaWikiServices::getInstance()
|
|
|
|
|
->getChangeTagsStore()->listDefinedTags()
|
|
|
|
|
),
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => '',
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
2011-06-06 14:50:34 +00:00
|
|
|
'deletedonly' => false,
|
|
|
|
|
'toponly' => false,
|
2014-02-26 20:57:58 +00:00
|
|
|
'newonly' => false,
|
2015-10-07 11:04:09 +00:00
|
|
|
'hideminor' => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
'showsizediff' => [
|
2022-06-05 23:18:50 +00:00
|
|
|
ParamValidator::PARAM_DEFAULT => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2011-06-06 14:50:34 +00:00
|
|
|
|
2022-04-10 15:34:45 +00:00
|
|
|
if ( $this->getConfig()->get( MainConfigNames::MiserMode ) ) {
|
2014-09-18 17:38:23 +00:00
|
|
|
$ret['showsizediff'][ApiBase::PARAM_HELP_MSG] = 'api-help-param-disabled-in-miser-mode';
|
|
|
|
|
}
|
2011-06-06 14:50:34 +00:00
|
|
|
|
2014-09-18 17:38:23 +00:00
|
|
|
return $ret;
|
2011-06-06 14:50:34 +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=feedcontributions&user=Example'
|
|
|
|
|
=> 'apihelp-feedcontributions-example-simple',
|
2016-02-17 09:09:32 +00:00
|
|
|
];
|
2011-06-06 14:50:34 +00:00
|
|
|
}
|
2023-10-12 19:58:30 +00:00
|
|
|
|
|
|
|
|
public function getHelpUrls() {
|
|
|
|
|
return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Feedcontributions';
|
|
|
|
|
}
|
2011-10-27 00:46:17 +00:00
|
|
|
}
|
2024-09-25 16:17:29 +00:00
|
|
|
|
|
|
|
|
/** @deprecated class alias since 1.43 */
|
|
|
|
|
class_alias( ApiFeedContributions::class, 'ApiFeedContributions' );
|