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
|
|
|
|
|
*/
|
|
|
|
|
|
2018-02-16 18:23:45 +00:00
|
|
|
use MediaWiki\MediaWikiServices;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\RevisionAccessException;
|
|
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
use MediaWiki\Revision\RevisionStore;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2018-02-16 18:23:45 +00:00
|
|
|
|
2011-06-06 14:50:34 +00:00
|
|
|
/**
|
|
|
|
|
* @ingroup API
|
|
|
|
|
*/
|
|
|
|
|
class ApiFeedContributions extends ApiBase {
|
|
|
|
|
|
2018-02-16 18:23:45 +00:00
|
|
|
/** @var RevisionStore */
|
|
|
|
|
private $revisionStore;
|
|
|
|
|
|
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() {
|
2018-02-16 18:23:45 +00:00
|
|
|
$this->revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
|
|
|
|
|
|
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();
|
|
|
|
|
if ( !$config->get( '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
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
$feedClasses = $config->get( 'FeedClasses' );
|
|
|
|
|
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
|
|
|
|
2014-01-24 02:51:11 +00:00
|
|
|
if ( $params['showsizediff'] && $this->getConfig()->get( '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
|
|
|
|
2012-08-20 14:55:28 +00:00
|
|
|
$msg = wfMessage( 'Contributions' )->inContentLanguage()->text();
|
2015-09-28 11:15:17 +00:00
|
|
|
$feedTitle = $config->get( 'Sitename' ) . ' - ' . $msg .
|
|
|
|
|
' [' . $config->get( 'LanguageCode' ) . ']';
|
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 = SpecialPage::getTitleFor( 'Contributions', $params['user'] )->getFullURL();
|
2011-06-06 14:50:34 +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
|
|
|
$target = $params['user'] == 'newbies'
|
2013-11-14 12:40:22 +00:00
|
|
|
? 'newbies'
|
|
|
|
|
: Title::makeTitleSafe( NS_USER, $params['user'] )->getText();
|
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,
|
|
|
|
|
htmlspecialchars( $msg ),
|
|
|
|
|
$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 );
|
|
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$pager = new ContribsPager( $this->getContext(), [
|
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
|
|
|
'target' => $target,
|
|
|
|
|
'namespace' => $params['namespace'],
|
2017-06-04 01:12:21 +00:00
|
|
|
'start' => $params['start'],
|
|
|
|
|
'end' => $params['end'],
|
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
|
|
|
'tagFilter' => $params['tagfilter'],
|
|
|
|
|
'deletedOnly' => $params['deletedonly'],
|
|
|
|
|
'topOnly' => $params['toponly'],
|
2014-02-26 20:57:58 +00:00
|
|
|
'newOnly' => $params['newonly'],
|
2015-10-07 11:04:09 +00:00
|
|
|
'hideMinor' => $params['hideminor'],
|
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
|
|
|
'showSizeDiff' => $params['showsizediff'],
|
2016-02-17 09:09:32 +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
|
|
|
$feedLimit = $this->getConfig()->get( 'FeedLimit' );
|
|
|
|
|
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;
|
|
|
|
|
$hookResult = Hooks::run(
|
|
|
|
|
'ApiFeedContributions::feedItem',
|
2016-02-17 09:09:32 +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
|
2012-05-05 14:08:47 +00:00
|
|
|
$title = Title::makeTitle( intval( $row->page_namespace ), $row->page_title );
|
2013-09-20 15:33:07 +00:00
|
|
|
if ( $title && $title->userCan( 'read', $this->getUser() ) ) {
|
2011-06-06 14:50:34 +00:00
|
|
|
$date = $row->rev_timestamp;
|
|
|
|
|
$comments = $title->getTalkPage()->getFullURL();
|
2018-02-16 18:23:45 +00:00
|
|
|
$revision = $this->revisionStore->newRevisionFromRow( $row );
|
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 ) {
|
2018-12-02 18:06:53 +00:00
|
|
|
$msg = wfMessage( 'colon-separator' )->inContentLanguage()->text();
|
|
|
|
|
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".
|
|
|
|
|
$html = nl2br( htmlspecialchars( $content->getNativeData() ) );
|
|
|
|
|
} 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.
|
|
|
|
|
// Compare also FeedUtils::formatDiffRow.
|
|
|
|
|
$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 .
|
|
|
|
|
htmlspecialchars( FeedItem::stripComment( $comment ? $comment->text : '' ) ) .
|
|
|
|
|
"</p>\n<hr />\n<div>" . $html . '</div>';
|
2011-06-06 14:50:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getAllowedParams() {
|
2014-01-24 02:51:11 +00:00
|
|
|
$feedFormatNames = array_keys( $this->getConfig()->get( 'FeedClasses' ) );
|
2013-11-14 12:40:22 +00:00
|
|
|
|
2016-02-17 09:09:32 +00:00
|
|
|
$ret = [
|
|
|
|
|
'feedformat' => [
|
2011-06-06 14:50:34 +00:00
|
|
|
ApiBase::PARAM_DFLT => 'rss',
|
|
|
|
|
ApiBase::PARAM_TYPE => $feedFormatNames
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'user' => [
|
2011-06-06 14:50:34 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'user',
|
|
|
|
|
ApiBase::PARAM_REQUIRED => true,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'namespace' => [
|
2012-02-24 04:29:50 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'namespace'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'year' => [
|
2011-06-06 14:50:34 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'month' => [
|
2011-06-06 14:50:34 +00:00
|
|
|
ApiBase::PARAM_TYPE => 'integer'
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
'tagfilter' => [
|
2011-06-06 14:50:34 +00:00
|
|
|
ApiBase::PARAM_ISMULTI => true,
|
|
|
|
|
ApiBase::PARAM_TYPE => array_values( ChangeTags::listDefinedTags() ),
|
|
|
|
|
ApiBase::PARAM_DFLT => '',
|
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' => [
|
2014-09-18 17:38:23 +00:00
|
|
|
ApiBase::PARAM_DFLT => false,
|
2016-02-17 09:09:32 +00:00
|
|
|
],
|
|
|
|
|
];
|
2011-06-06 14:50:34 +00:00
|
|
|
|
2014-09-18 17:38:23 +00:00
|
|
|
if ( $this->getConfig()->get( 'MiserMode' ) ) {
|
|
|
|
|
$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
|
|
|
}
|
2011-10-27 00:46:17 +00:00
|
|
|
}
|