MediaWiki REL1_37
ChangesFeed.php
Go to the documentation of this file.
1<?php
26
33 private $format;
34
38 public function __construct( $format ) {
39 $this->format = $format;
40 }
41
50 public function getFeedObject( $title, $description, $url ) {
52
53 if ( !isset( $wgFeedClasses[$this->format] ) ) {
54 return false;
55 }
56
57 if ( !array_key_exists( $this->format, $wgFeedClasses ) ) {
58 // falling back to atom
59 $this->format = 'atom';
60 }
61
62 $feedTitle = "$wgSitename - {$title} [$wgLanguageCode]";
63 return new $wgFeedClasses[$this->format](
64 $feedTitle, htmlspecialchars( $description ), $url );
65 }
66
73 public static function buildItems( $rows ) {
74 $items = [];
75
76 # Merge adjacent edits by one user
77 $sorted = [];
78 $n = 0;
79 foreach ( $rows as $obj ) {
80 if ( $obj->rc_type == RC_EXTERNAL ) {
81 continue;
82 }
83
84 if ( $n > 0 &&
85 $obj->rc_type == RC_EDIT &&
86 $obj->rc_namespace >= 0 &&
87 $obj->rc_cur_id == $sorted[$n - 1]->rc_cur_id &&
88 $obj->rc_user_text == $sorted[$n - 1]->rc_user_text ) {
89 $sorted[$n - 1]->rc_last_oldid = $obj->rc_last_oldid;
90 } else {
91 $sorted[$n] = $obj;
92 $n++;
93 }
94 }
95
96 $nsInfo = MediaWikiServices::getInstance()->getNamespaceInfo();
97 foreach ( $sorted as $obj ) {
98 $title = Title::makeTitle( $obj->rc_namespace, $obj->rc_title );
99 $talkpage = $nsInfo->hasTalkNamespace( $obj->rc_namespace ) && $title->canExist()
100 ? $title->getTalkPage()->getFullURL()
101 : '';
102
103 // Skip items with deleted content (avoids partially complete/inconsistent output)
104 if ( $obj->rc_deleted ) {
105 continue;
106 }
107
108 if ( $obj->rc_this_oldid ) {
109 $url = $title->getFullURL( [
110 'diff' => $obj->rc_this_oldid,
111 'oldid' => $obj->rc_last_oldid,
112 ] );
113 } else {
114 // log entry or something like that.
115 $url = $title->getFullURL();
116 }
117
118 $items[] = new FeedItem(
119 $title->getPrefixedText(),
120 FeedUtils::formatDiff( $obj ),
121 $url,
122 $obj->rc_timestamp,
123 ( $obj->rc_deleted & RevisionRecord::DELETED_USER )
124 ? wfMessage( 'rev-deleted-user' )->escaped() : $obj->rc_user_text,
125 $talkpage
126 );
127 }
128
129 return $items;
130 }
131}
$wgLanguageCode
Site language code.
$wgSitename
Name of the site.
$wgFeedClasses
Available feeds objects.
const RC_EXTERNAL
Definition Defines.php:118
const RC_EDIT
Definition Defines.php:115
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:73
MediaWikiServices is the service locator for the application scope of MediaWiki.
Page revision base class.
Result wrapper for grabbing data queried from an IDatabase object.