Feed: Move feed-related classes to Feed/ and namespace them
Bug: T166010 Change-Id: Icdbe003e74d2f31b68b575acfa94c09c24d7aed5
This commit is contained in:
parent
68521d08ff
commit
f8bf3687f4
18 changed files with 87 additions and 38 deletions
10
autoload.php
10
autoload.php
|
|
@ -160,7 +160,7 @@ $wgAutoloadLocalClasses = [
|
|||
'ArrayUtils' => __DIR__ . '/includes/libs/ArrayUtils.php',
|
||||
'Article' => __DIR__ . '/includes/page/Article.php',
|
||||
'AssembleUploadChunksJob' => __DIR__ . '/includes/jobqueue/jobs/AssembleUploadChunksJob.php',
|
||||
'AtomFeed' => __DIR__ . '/includes/changes/AtomFeed.php',
|
||||
'AtomFeed' => __DIR__ . '/includes/Feed/AtomFeed.php',
|
||||
'AtomicSectionUpdate' => __DIR__ . '/includes/deferred/AtomicSectionUpdate.php',
|
||||
'AttachLatest' => __DIR__ . '/maintenance/attachLatest.php',
|
||||
'AuthManagerSpecialPage' => __DIR__ . '/includes/specialpage/AuthManagerSpecialPage.php',
|
||||
|
|
@ -241,7 +241,7 @@ $wgAutoloadLocalClasses = [
|
|||
'ChangesListSpecialPage' => __DIR__ . '/includes/specialpage/ChangesListSpecialPage.php',
|
||||
'ChangesListStringOptionsFilter' => __DIR__ . '/includes/changes/ChangesListStringOptionsFilter.php',
|
||||
'ChangesListStringOptionsFilterGroup' => __DIR__ . '/includes/changes/ChangesListStringOptionsFilterGroup.php',
|
||||
'ChannelFeed' => __DIR__ . '/includes/changes/ChannelFeed.php',
|
||||
'ChannelFeed' => __DIR__ . '/includes/Feed/ChannelFeed.php',
|
||||
'CheckBadRedirects' => __DIR__ . '/maintenance/checkBadRedirects.php',
|
||||
'CheckComposerLockUpToDate' => __DIR__ . '/maintenance/checkComposerLockUpToDate.php',
|
||||
'CheckDependencies' => __DIR__ . '/maintenance/checkDependencies.php',
|
||||
|
|
@ -478,8 +478,8 @@ $wgAutoloadLocalClasses = [
|
|||
'FauxResponse' => __DIR__ . '/includes/FauxResponse.php',
|
||||
'FauxSearchResult' => __DIR__ . '/includes/search/FauxSearchResult.php',
|
||||
'FauxSearchResultSet' => __DIR__ . '/includes/search/FauxSearchResultSet.php',
|
||||
'FeedItem' => __DIR__ . '/includes/changes/FeedItem.php',
|
||||
'FeedUtils' => __DIR__ . '/includes/FeedUtils.php',
|
||||
'FeedItem' => __DIR__ . '/includes/Feed/FeedItem.php',
|
||||
'FeedUtils' => __DIR__ . '/includes/Feed/FeedUtils.php',
|
||||
'FetchText' => __DIR__ . '/maintenance/fetchText.php',
|
||||
'Field' => __DIR__ . '/includes/libs/rdbms/field/Field.php',
|
||||
'File' => __DIR__ . '/includes/filerepo/file/File.php',
|
||||
|
|
@ -1292,7 +1292,7 @@ $wgAutoloadLocalClasses = [
|
|||
'RCFeedEngine' => __DIR__ . '/includes/rcfeed/FormattedRCFeed.php',
|
||||
'RCFeedFormatter' => __DIR__ . '/includes/rcfeed/RCFeedFormatter.php',
|
||||
'RESTBagOStuff' => __DIR__ . '/includes/libs/objectcache/RESTBagOStuff.php',
|
||||
'RSSFeed' => __DIR__ . '/includes/changes/RSSFeed.php',
|
||||
'RSSFeed' => __DIR__ . '/includes/Feed/RSSFeed.php',
|
||||
'RandomPage' => __DIR__ . '/includes/specials/SpecialRandomPage.php',
|
||||
'RangeChronologicalPager' => __DIR__ . '/includes/pager/RangeChronologicalPager.php',
|
||||
'RangeDifference' => __DIR__ . '/includes/diff/RangeDifference.php',
|
||||
|
|
|
|||
|
|
@ -6394,8 +6394,8 @@ config-schema:
|
|||
```
|
||||
FeedClasses:
|
||||
default:
|
||||
rss: RSSFeed
|
||||
atom: AtomFeed
|
||||
rss: MediaWiki\Feed\RSSFeed
|
||||
atom: MediaWiki\Feed\AtomFeed
|
||||
type: object
|
||||
description: |-
|
||||
Available feeds objects.
|
||||
|
|
|
|||
|
|
@ -22,6 +22,8 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
namespace MediaWiki\Feed;
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
|
||||
|
|
@ -114,3 +116,5 @@ class AtomFeed extends ChannelFeed {
|
|||
print "</feed>";
|
||||
}
|
||||
}
|
||||
|
||||
class_alias( AtomFeed::class, 'AtomFeed' );
|
||||
|
|
@ -22,8 +22,12 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
namespace MediaWiki\Feed;
|
||||
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use TemplateParser;
|
||||
use Title;
|
||||
|
||||
/**
|
||||
* Class to support the outputting of syndication feeds in Atom and RSS format.
|
||||
|
|
@ -139,3 +143,5 @@ abstract class ChannelFeed extends FeedItem {
|
|||
echo '<?xml version="1.0"?>' . "\n";
|
||||
}
|
||||
}
|
||||
|
||||
class_alias( ChannelFeed::class, 'ChannelFeed' );
|
||||
|
|
@ -21,8 +21,12 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
namespace MediaWiki\Feed;
|
||||
|
||||
use LanguageCode;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Title;
|
||||
|
||||
/**
|
||||
* @defgroup Feed Feed
|
||||
|
|
@ -227,3 +231,5 @@ class FeedItem {
|
|||
|
||||
/** #@- */
|
||||
}
|
||||
|
||||
class_alias( FeedItem::class, 'FeedItem' );
|
||||
|
|
@ -21,10 +21,22 @@
|
|||
* @ingroup Feed
|
||||
*/
|
||||
|
||||
namespace MediaWiki\Feed;
|
||||
|
||||
use CommentStore;
|
||||
use Html;
|
||||
use Linker;
|
||||
use LogFormatter;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
use MediaWiki\Revision\SlotRecord;
|
||||
use OutputPage;
|
||||
use RequestContext;
|
||||
use TextContent;
|
||||
use Title;
|
||||
use User;
|
||||
use UtfNormal;
|
||||
|
||||
/**
|
||||
* Helper functions for feeds
|
||||
|
|
@ -36,11 +48,11 @@ class FeedUtils {
|
|||
/**
|
||||
* Check whether feeds can be used and that $type is a valid feed type
|
||||
*
|
||||
* @since 1.36 $output parameter added
|
||||
*
|
||||
* @param string $type Feed type, as requested by the user
|
||||
* @param OutputPage|null $output Null falls back to $wgOut
|
||||
* @return bool
|
||||
* @since 1.36 $output parameter added
|
||||
*
|
||||
*/
|
||||
public static function checkFeedOutput( $type, $output = null ) {
|
||||
$feed = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::Feed );
|
||||
|
|
@ -67,7 +79,7 @@ class FeedUtils {
|
|||
/**
|
||||
* Format a diff for the newsfeed
|
||||
*
|
||||
* @param stdClass $row Row from the recentchanges table, including fields as
|
||||
* @param \stdClass $row Row from the recentchanges table, including fields as
|
||||
* appropriate for CommentStore
|
||||
* @param string|null $formattedComment rc_comment in HTML format, or null
|
||||
* to format it on demand.
|
||||
|
|
@ -98,8 +110,6 @@ class FeedUtils {
|
|||
/**
|
||||
* Really format a diff for the newsfeed
|
||||
*
|
||||
* @deprecated since 1.38 use formatDiffRow2
|
||||
*
|
||||
* @param Title $title
|
||||
* @param int $oldid Old revision's id
|
||||
* @param int $newid New revision's id
|
||||
|
|
@ -107,9 +117,11 @@ class FeedUtils {
|
|||
* @param string $comment New revision's comment
|
||||
* @param string $actiontext Text of the action; in case of log event
|
||||
* @return string
|
||||
* @deprecated since 1.38 use formatDiffRow2
|
||||
*
|
||||
*/
|
||||
public static function formatDiffRow( $title, $oldid, $newid, $timestamp,
|
||||
$comment, $actiontext = ''
|
||||
$comment, $actiontext = ''
|
||||
) {
|
||||
$formattedComment = MediaWikiServices::getInstance()->getCommentFormatter()
|
||||
->format( $comment );
|
||||
|
|
@ -130,7 +142,7 @@ class FeedUtils {
|
|||
* @return string
|
||||
*/
|
||||
public static function formatDiffRow2( $title, $oldid, $newid, $timestamp,
|
||||
$formattedComment, $actiontext = ''
|
||||
$formattedComment, $actiontext = ''
|
||||
) {
|
||||
$feedDiffCutoff = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::FeedDiffCutoff );
|
||||
|
||||
|
|
@ -283,19 +295,19 @@ class FeedUtils {
|
|||
*/
|
||||
public static function applyDiffStyle( $text ) {
|
||||
$styles = [
|
||||
'diff' => 'background-color: #fff; color: #202122;',
|
||||
'diff-otitle' => 'background-color: #fff; color: #202122; text-align: center;',
|
||||
'diff-ntitle' => 'background-color: #fff; color: #202122; text-align: center;',
|
||||
'diff-addedline' => 'color: #202122; font-size: 88%; border-style: solid; '
|
||||
'diff' => 'background-color: #fff; color: #202122;',
|
||||
'diff-otitle' => 'background-color: #fff; color: #202122; text-align: center;',
|
||||
'diff-ntitle' => 'background-color: #fff; color: #202122; text-align: center;',
|
||||
'diff-addedline' => 'color: #202122; font-size: 88%; border-style: solid; '
|
||||
. 'border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; '
|
||||
. 'vertical-align: top; white-space: pre-wrap;',
|
||||
'diff-deletedline' => 'color: #202122; font-size: 88%; border-style: solid; '
|
||||
. 'border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; '
|
||||
. 'vertical-align: top; white-space: pre-wrap;',
|
||||
'diff-context' => 'background-color: #f8f9fa; color: #202122; font-size: 88%; '
|
||||
'diff-context' => 'background-color: #f8f9fa; color: #202122; font-size: 88%; '
|
||||
. 'border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; '
|
||||
. 'border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;',
|
||||
'diffchange' => 'font-weight: bold; text-decoration: none;',
|
||||
'diffchange' => 'font-weight: bold; text-decoration: none;',
|
||||
];
|
||||
|
||||
foreach ( $styles as $class => $style ) {
|
||||
|
|
@ -308,3 +320,5 @@ class FeedUtils {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
class_alias( FeedUtils::class, 'FeedUtils' );
|
||||
|
|
@ -21,6 +21,8 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
namespace MediaWiki\Feed;
|
||||
|
||||
/**
|
||||
* Generate an RSS feed.
|
||||
*
|
||||
|
|
@ -90,3 +92,5 @@ class RSSFeed extends ChannelFeed {
|
|||
print "</channel></rss>";
|
||||
}
|
||||
}
|
||||
|
||||
class_alias( RSSFeed::class, 'RSSFeed' );
|
||||
|
|
@ -10252,8 +10252,8 @@ class MainConfigSchema {
|
|||
*/
|
||||
public const FeedClasses = [
|
||||
'default' => [
|
||||
'rss' => 'RSSFeed',
|
||||
'atom' => 'AtomFeed',
|
||||
'rss' => \MediaWiki\Feed\RSSFeed::class,
|
||||
'atom' => \MediaWiki\Feed\AtomFeed::class,
|
||||
],
|
||||
'type' => 'map',
|
||||
];
|
||||
|
|
|
|||
|
|
@ -21,6 +21,10 @@
|
|||
* @ingroup Actions
|
||||
*/
|
||||
|
||||
use MediaWiki\Feed\AtomFeed;
|
||||
use MediaWiki\Feed\FeedItem;
|
||||
use MediaWiki\Feed\FeedUtils;
|
||||
use MediaWiki\Feed\RSSFeed;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use Wikimedia\Rdbms\FakeResultWrapper;
|
||||
|
|
@ -426,7 +430,7 @@ class HistoryAction extends FormlessAction {
|
|||
}
|
||||
|
||||
/**
|
||||
* Generate a FeedItem object from a given revision table row
|
||||
* Generate a MediaWiki\Feed\FeedItem object from a given revision table row
|
||||
* Borrows Recent Changes' feed generation functions for formatting;
|
||||
* includes a diff to the previous revision (if any).
|
||||
*
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
use MediaWiki\Api\ApiHookRunner;
|
||||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\CommentFormatter\CommentFormatter;
|
||||
use MediaWiki\Feed\FeedItem;
|
||||
use MediaWiki\HookContainer\HookContainer;
|
||||
use MediaWiki\Linker\LinkRenderer;
|
||||
use MediaWiki\MainConfigNames;
|
||||
|
|
@ -282,7 +283,7 @@ class ApiFeedContributions extends ApiBase {
|
|||
// 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.
|
||||
// Compare also MediaWiki\Feed\FeedUtils::formatDiffRow.
|
||||
$html = '';
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
* @since 1.23
|
||||
*/
|
||||
|
||||
use MediaWiki\Feed\ChannelFeed;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\SpecialPage\SpecialPageFactory;
|
||||
use Wikimedia\ParamValidator\ParamValidator;
|
||||
|
|
@ -113,7 +114,7 @@ class ApiFeedRecentChanges extends ApiBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* Return a ChannelFeed object.
|
||||
* Return a MediaWiki\Feed\ChannelFeed object.
|
||||
*
|
||||
* @param string $feedFormat Feed's format (either 'rss' or 'atom')
|
||||
* @param string $specialPageName Relevant special page name (either 'Recentchanges' or
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
use MediaWiki\Feed\FeedItem;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use Wikimedia\ParamValidator\ParamValidator;
|
||||
use Wikimedia\ParamValidator\TypeDef\IntegerDef;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
use MediaWiki\Feed\ChannelFeed;
|
||||
use MediaWiki\Feed\FeedItem;
|
||||
|
||||
/**
|
||||
* This printer is used to wrap an instance of the Feed class
|
||||
* @ingroup API
|
||||
|
|
@ -56,7 +59,7 @@ class ApiFormatFeedWrapper extends ApiFormatBase {
|
|||
}
|
||||
|
||||
/**
|
||||
* ChannelFeed doesn't give us a method to print errors in a friendly
|
||||
* MediaWiki\Feed\ChannelFeed doesn't give us a method to print errors in a friendly
|
||||
* manner, so just punt errors to the default printer.
|
||||
* @return bool
|
||||
*/
|
||||
|
|
@ -67,7 +70,7 @@ class ApiFormatFeedWrapper extends ApiFormatBase {
|
|||
/**
|
||||
* This class expects the result data to be in a custom format set by self::setResult()
|
||||
* $result['_feed'] - an instance of one of the $wgFeedClasses classes
|
||||
* $result['_feeditems'] - an array of FeedItem instances
|
||||
* $result['_feeditems'] - an array of MediaWiki\Feed\FeedItem instances
|
||||
* @param bool $unused
|
||||
*/
|
||||
public function initPrinter( $unused = false ) {
|
||||
|
|
@ -91,7 +94,7 @@ class ApiFormatFeedWrapper extends ApiFormatBase {
|
|||
/**
|
||||
* This class expects the result data to be in a custom format set by self::setResult()
|
||||
* $result['_feed'] - an instance of one of the $wgFeedClasses classes
|
||||
* $result['_feeditems'] - an array of FeedItem instances
|
||||
* $result['_feeditems'] - an array of MediaWiki\Feed\FeedItem instances
|
||||
*/
|
||||
public function execute() {
|
||||
$data = $this->getResult()->getResultData();
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
namespace MediaWiki\Api\Hook;
|
||||
|
||||
// phpcs:disable Squiz.Classes.ValidClassName.NotCamelCaps
|
||||
use FeedItem;
|
||||
use IContextSource;
|
||||
use stdClass;
|
||||
|
||||
|
|
@ -16,20 +15,20 @@ use stdClass;
|
|||
*/
|
||||
interface ApiFeedContributions__feedItemHook {
|
||||
/**
|
||||
* Use this hook to convert the result of ContribsPager into a FeedItem instance
|
||||
* Use this hook to convert the result of ContribsPager into a MediaWiki\Feed\FeedItem instance
|
||||
* that ApiFeedContributions can consume. Implementors of this hook may cancel
|
||||
* the hook to signal that the item is not viewable in the provided context.
|
||||
*
|
||||
* @since 1.35
|
||||
*
|
||||
* @param stdClass $row A row of data from ContribsPager. The set of data returned by
|
||||
* ContribsPager can be adjusted by handling the ContribsPager::reallyDoQuery
|
||||
* hook.
|
||||
* @param IContextSource $context
|
||||
* @param FeedItem|null &$feedItem Set this to a FeedItem instance if the callback can handle the
|
||||
* @param \MediaWiki\Feed\FeedItem|null &$feedItem Set this to a FeedItem instance if the callback can handle the
|
||||
* provided row. This is provided to the hook as a null, if it is non-null then
|
||||
* another callback has already handled the hook.
|
||||
* @return bool|void True or no return value to continue or false to abort
|
||||
* @since 1.35
|
||||
*
|
||||
*/
|
||||
public function onApiFeedContributions__feedItem( $row, $context, &$feedItem );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,9 @@
|
|||
* @file
|
||||
*/
|
||||
|
||||
use MediaWiki\Feed\ChannelFeed;
|
||||
use MediaWiki\Feed\FeedItem;
|
||||
use MediaWiki\Feed\FeedUtils;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Revision\RevisionRecord;
|
||||
|
|
@ -41,12 +44,12 @@ class ChangesFeed {
|
|||
}
|
||||
|
||||
/**
|
||||
* Get a ChannelFeed subclass object to use
|
||||
* Get a MediaWiki\Feed\ChannelFeed subclass object to use
|
||||
*
|
||||
* @param string $title Feed's title
|
||||
* @param string $description Feed's description
|
||||
* @param string $url Url of origin page
|
||||
* @return ChannelFeed|bool ChannelFeed subclass or false on failure
|
||||
* @return ChannelFeed|bool MediaWiki\Feed\ChannelFeed subclass or false on failure
|
||||
*/
|
||||
public function getFeedObject( $title, $description, $url ) {
|
||||
$mainConfig = MediaWikiServices::getInstance()->getMainConfig();
|
||||
|
|
|
|||
|
|
@ -1913,8 +1913,8 @@ return [
|
|||
'OverrideSiteFeed' => [
|
||||
],
|
||||
'FeedClasses' => [
|
||||
'rss' => 'RSSFeed',
|
||||
'atom' => 'AtomFeed',
|
||||
'rss' => 'MediaWiki\\Feed\\RSSFeed',
|
||||
'atom' => 'MediaWiki\\Feed\\AtomFeed',
|
||||
],
|
||||
'AdvertisedFeedTypes' => [
|
||||
0 => 'atom',
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
use MediaWiki\Cache\LinkBatchFactory;
|
||||
use MediaWiki\Content\IContentHandlerFactory;
|
||||
use MediaWiki\Feed\FeedItem;
|
||||
use MediaWiki\MainConfigNames;
|
||||
use MediaWiki\Permissions\GroupPermissionsLookup;
|
||||
use MediaWiki\Revision\MutableRevisionRecord;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
<?php
|
||||
|
||||
use MediaWiki\Feed\FeedUtils;
|
||||
|
||||
/**
|
||||
* @covers \FeedUtils
|
||||
* @covers \MediaWiki\Feed\FeedUtils
|
||||
*/
|
||||
class FeedUtilsTest extends MediaWikiUnitTestCase {
|
||||
|
||||
Loading…
Reference in a new issue