* @file
*/
+use MediaWiki\MediaWikiServices;
+use MediaWiki\Revision\RevisionAccessException;
+use MediaWiki\Revision\RevisionRecord;
+use MediaWiki\Revision\RevisionStore;
+use MediaWiki\Revision\SlotRecord;
+
/**
* @ingroup API
*/
class ApiFeedContributions extends ApiBase {
+ /** @var RevisionStore */
+ private $revisionStore;
+
/**
* This module uses a custom feed wrapper printer.
*
}
public function execute() {
+ $this->revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
+
$params = $this->extractRequestParams();
$config = $this->getConfig();
if ( $title && $title->userCan( 'read', $this->getUser() ) ) {
$date = $row->rev_timestamp;
$comments = $title->getTalkPage()->getFullURL();
- $revision = Revision::newFromRow( $row );
+ $revision = $this->revisionStore->newRevisionFromRow( $row );
return new FeedItem(
$title->getPrefixedText(),
}
/**
- * @param Revision $revision
+ * @since 1.32, takes a RevisionRecord instead of a Revision
+ * @param RevisionRecord $revision
* @return string
*/
- protected function feedItemAuthor( $revision ) {
- return $revision->getUserText();
+ protected function feedItemAuthor( RevisionRecord $revision ) {
+ $user = $revision->getUser();
+ return $user ? $user->getName() : '';
}
/**
- * @param Revision $revision
+ * @since 1.32, takes a RevisionRecord instead of a Revision
+ * @param RevisionRecord $revision
* @return string
*/
- protected function feedItemDesc( $revision ) {
- if ( $revision ) {
- $msg = wfMessage( 'colon-separator' )->inContentLanguage()->text();
- $content = $revision->getContent();
-
- 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 = '';
- }
+ protected function feedItemDesc( RevisionRecord $revision ) {
+ $msg = wfMessage( 'colon-separator' )->inContentLanguage()->text();
+ try {
+ $content = $revision->getContent( SlotRecord::MAIN );
+ } catch ( RevisionAccessException $e ) {
+ $content = null;
+ }
- return '<p>' . htmlspecialchars( $revision->getUserText() ) . $msg .
- htmlspecialchars( FeedItem::stripComment( $revision->getComment() ) ) .
- "</p>\n<hr />\n<div>" . $html . '</div>';
+ 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 = '';
}
- return '';
+ $comment = $revision->getComment();
+
+ return '<p>' . htmlspecialchars( $this->feedItemAuthor( $revision ) ) . $msg .
+ htmlspecialchars( FeedItem::stripComment( $comment ? $comment->text : '' ) ) .
+ "</p>\n<hr />\n<div>" . $html . '</div>';
}
public function getAllowedParams() {