MediaWiki  master
ChangesFeed.php
Go to the documentation of this file.
1 <?php
26 
32 class ChangesFeed {
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 }
FeedItem
A base class for outputting syndication feeds (e.g.
Definition: FeedItem.php:33
Revision\RevisionRecord
Page revision base class.
Definition: RevisionRecord.php:47
RC_EDIT
const RC_EDIT
Definition: Defines.php:126
MediaWiki\MediaWikiServices
MediaWikiServices is the service locator for the application scope of MediaWiki.
Definition: MediaWikiServices.php:173
ChangesFeed\$format
$format
Definition: ChangesFeed.php:33
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition: GlobalFunctions.php:1231
ChangesFeed\getFeedObject
getFeedObject( $title, $description, $url)
Get a ChannelFeed subclass object to use.
Definition: ChangesFeed.php:50
Wikimedia\Rdbms\IResultWrapper
Result wrapper for grabbing data queried from an IDatabase object.
Definition: IResultWrapper.php:24
$title
$title
Definition: testCompression.php:38
Title\makeTitle
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:626
$wgFeedClasses
$wgFeedClasses
Available feeds objects.
Definition: DefaultSettings.php:7502
ChangesFeed
Feed to Special:RecentChanges and Special:RecentChangesLinked.
Definition: ChangesFeed.php:32
RC_EXTERNAL
const RC_EXTERNAL
Definition: Defines.php:129
$wgLanguageCode
$wgLanguageCode
Site language code.
Definition: DefaultSettings.php:3196
$wgSitename
$wgSitename
Name of the site.
Definition: DefaultSettings.php:80
FeedUtils\formatDiff
static formatDiff( $row)
Format a diff for the newsfeed.
Definition: FeedUtils.php:73
ChangesFeed\buildItems
static buildItems( $rows)
Generate the feed items given a row from the database.
Definition: ChangesFeed.php:73
ChangesFeed\__construct
__construct( $format)
Definition: ChangesFeed.php:38