46 $feed = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::Feed );
47 $feedClasses = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::FeedClasses );
48 if ( $output ===
null ) {
55 $output->addWikiMsg(
'feed-unavailable' );
59 if ( !isset( $feedClasses[
$type] ) ) {
60 $output->addWikiMsg(
'feed-invalid' );
76 public static function formatDiff( $row, $formattedComment =
null ) {
78 $timestamp =
wfTimestamp( TS_MW, $row->rc_timestamp );
80 if ( $row->rc_type ==
RC_LOG ) {
84 if ( $row->rc_deleted & RevisionRecord::DELETED_COMMENT ) {
85 $formattedComment =
wfMessage(
'rev-deleted-comment' )->escaped();
86 } elseif ( $formattedComment ===
null ) {
91 $row->rc_last_oldid, $row->rc_this_oldid,
112 $comment, $actiontext =
''
114 $formattedComment = MediaWikiServices::getInstance()->getCommentFormatter()
115 ->format( $comment );
117 $formattedComment, $actiontext );
133 $formattedComment, $actiontext =
''
135 $feedDiffCutoff = MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::FeedDiffCutoff );
138 $unwrappedText = implode(
140 array_filter( [ $actiontext, $formattedComment ] )
148 $services = MediaWikiServices::getInstance();
149 $permManager = $services->getPermissionManager();
150 $accErrors = $permManager->getPermissionErrors(
158 if (
$title->getNamespace() < 0 || $accErrors || !$newid ) {
159 return $completeText;
162 $revLookup = $services->getRevisionLookup();
163 $contentHandlerFactory = $services->getContentHandlerFactory();
167 if ( $feedDiffCutoff > 0 ) {
168 $revRecord = $revLookup->getRevisionById( $oldid );
175 $context->setTitle(
$title );
177 $model = $revRecord->getSlot(
181 $contentHandler = $contentHandlerFactory->getContentHandler( $model );
182 $de = $contentHandler->createDifferenceEngine( $context, $oldid, $newid );
183 $lang = $mainContext->getLanguage();
184 $user = $mainContext->getUser();
185 $diffText = $de->getDiff(
186 $mainContext->msg(
'previousrevision' )->text(),
187 $mainContext->msg(
'revisionasof',
188 $lang->userTimeAndDate( $timestamp, $user ),
189 $lang->userDate( $timestamp, $user ),
190 $lang->userTime( $timestamp, $user ) )->text() );
194 if ( $feedDiffCutoff <= 0 || ( strlen( $diffText ) > $feedDiffCutoff ) ) {
197 } elseif ( $diffText ===
false ) {
202 "Can't load revision $newid"
206 $diffText = UtfNormal\Validator::cleanUp( $diffText );
210 $revRecord = $revLookup->getRevisionById( $newid );
211 if ( $feedDiffCutoff <= 0 || $revRecord ===
null ) {
212 $newContent = $contentHandlerFactory
213 ->getContentHandler(
$title->getContentModel() )
214 ->makeEmptyContent();
216 $newContent = $revRecord->getContent( SlotRecord::MAIN );
221 $text = $newContent->getText();
223 if ( $feedDiffCutoff <= 0 || strlen( $text ) > $feedDiffCutoff ) {
226 $html = nl2br( htmlspecialchars( $text ) );
236 if ( $html ===
null ) {
249 $completeText .= $diffText;
251 return $completeText;
264 $queryParameters = [
'diff' => $newid ];
265 if ( $oldid !=
null ) {
266 $queryParameters[
'oldid'] = $oldid;
268 $diffUrl =
$title->getFullURL( $queryParameters );
271 wfMessage(
'showdiff' )->inContentLanguage()->text() );
286 'diff' =>
'background-color: #fff; color: #202122;',
287 'diff-otitle' =>
'background-color: #fff; color: #202122; text-align: center;',
288 'diff-ntitle' =>
'background-color: #fff; color: #202122; text-align: center;',
289 'diff-addedline' =>
'color: #202122; font-size: 88%; border-style: solid; '
290 .
'border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; '
291 .
'vertical-align: top; white-space: pre-wrap;',
292 'diff-deletedline' =>
'color: #202122; font-size: 88%; border-style: solid; '
293 .
'border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; '
294 .
'vertical-align: top; white-space: pre-wrap;',
295 'diff-context' =>
'background-color: #f8f9fa; color: #202122; font-size: 88%; '
296 .
'border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; '
297 .
'border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;',
298 'diffchange' =>
'font-weight: bold; text-decoration: none;',
301 foreach ( $styles as $class => $style ) {
302 $text = preg_replace(
'/(<\w+\b[^<>]*)\bclass=([\'"])(?:[^\'"]*\s)?' .
303 preg_quote( $class ) .
'(?:\s[^\'"]*)?\2(?=[^<>]*>)/',
304 '$1style="' . $style .
'"', $text );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
if(!defined( 'MW_NO_SESSION') &&! $wgCommandLineMode) $wgOut
Helper functions for feeds.
static formatDiffRow( $title, $oldid, $newid, $timestamp, $comment, $actiontext='')
Really format a diff for the newsfeed.
static formatDiffRow2( $title, $oldid, $newid, $timestamp, $formattedComment, $actiontext='')
Really really format a diff for the newsfeed.
static formatDiff( $row, $formattedComment=null)
Format a diff for the newsfeed.
static applyDiffStyle( $text)
Hacky application of diff styles for the feeds.
static getDiffLink(Title $title, $newid, $oldid=null)
Generates a diff link.
static checkFeedOutput( $type, $output=null)
Check whether feeds can be used and that $type is a valid feed type.
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
A class containing constants representing the names of configuration variables.
static getMain()
Get the RequestContext object associated with the main request.
Content object implementation for representing flat text.
Represents a title within MediaWiki.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
if(!isset( $args[0])) $lang