MediaWiki REL1_35
ChangesFeed.php
Go to the documentation of this file.
1<?php
25
32 private $format;
33
37 public function __construct( $format ) {
38 $this->format = $format;
39 }
40
49 public function getFeedObject( $title, $description, $url ) {
51
52 if ( !isset( $wgFeedClasses[$this->format] ) ) {
53 return false;
54 }
55
56 if ( !array_key_exists( $this->format, $wgFeedClasses ) ) {
57 // falling back to atom
58 $this->format = 'atom';
59 }
60
61 $feedTitle = "$wgSitename - {$title} [$wgLanguageCode]";
62 return new $wgFeedClasses[$this->format](
63 $feedTitle, htmlspecialchars( $description ), $url );
64 }
65
72 public static function buildItems( $rows ) {
73 $items = [];
74
75 # Merge adjacent edits by one user
76 $sorted = [];
77 $n = 0;
78 foreach ( $rows as $obj ) {
79 if ( $obj->rc_type == RC_EXTERNAL ) {
80 continue;
81 }
82
83 if ( $n > 0 &&
84 $obj->rc_type == RC_EDIT &&
85 $obj->rc_namespace >= 0 &&
86 $obj->rc_cur_id == $sorted[$n - 1]->rc_cur_id &&
87 $obj->rc_user_text == $sorted[$n - 1]->rc_user_text ) {
88 $sorted[$n - 1]->rc_last_oldid = $obj->rc_last_oldid;
89 } else {
90 $sorted[$n] = $obj;
91 $n++;
92 }
93 }
94
95 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
96 foreach ( $sorted as $obj ) {
97 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
98 $talkpage = $nsInfo->hasTalkNamespace( $obj->rc_namespace ) && $title->canExist()
99 ? $title->getTalkPage()->getFullURL()
100 : '';
101
102 // Skip items with deleted content (avoids partially complete/inconsistent output)
103 if ( $obj->rc_deleted ) {
104 continue;
105 }
106
107 if ( $obj->rc_this_oldid ) {
108 $url = $title->getFullURL( [
109 'diff' => $obj->rc_this_oldid,
110 'oldid' => $obj->rc_last_oldid,
111 ] );
112 } else {
113 // log entry or something like that.
114 $url = $title->getFullURL();
115 }
116
117 $items[] = new FeedItem(
118 $title->getPrefixedText(),
119 FeedUtils::formatDiff( $obj ),
120 $url,
121 $obj->rc_timestamp,
122 ( $obj->rc_deleted & RevisionRecord::DELETED_USER )
123 ? wfMessage( 'rev-deleted-user' )->escaped() : $obj->rc_user_text,
124 $talkpage
125 );
126 }
127
128 return $items;
129 }
130}
$wgLanguageCode
Site language code.
$wgSitename
Name of the site.
$wgFeedClasses
Available feeds objects.
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Feed to Special:RecentChanges and Special:RecentChangesLinked.
getFeedObject( $title, $description, $url)
Get a ChannelFeed subclass object to use.
__construct( $format)
static buildItems( $rows)
Generate the feed items given a row from the database.
A base class for outputting syndication feeds (e.g.
Definition FeedItem.php:33
static formatDiff( $row)
Format a diff for the newsfeed.
Definition FeedUtils.php:64
MediaWikiServices is the service locator for the application scope of MediaWiki.
Page revision base class.
const RC_EXTERNAL
Definition Defines.php:135
const RC_EDIT
Definition Defines.php:132