allow the including parser to do it.
* Fix {{int:}} to use content language, so it won't break caches and links
tables and randomly include data from the wrong language.
+* (bug 472) Syndication feeds for the last few edits of page history
+* Format edit comments in Recent Changes feed
+* Switch incorrectly ordered column headers on Recent Changes feed diffs
== Compatibility ==
$wgOut->setArticleFlag( false );
$wgOut->setArticleRelated( true );
$wgOut->setRobotpolicy( 'noindex,nofollow' );
+ $wgOut->setSyndicated( true );
+
+ $feedType = $wgRequest->getVal( 'feed' );
+ if( $feedType ) {
+ wfProfileOut( $fname );
+ return $this->feed( $feedType );
+ }
/*
* Fail if article doesn't exist.
$this->mTitle, $text,
wfArrayToCGI( $query, array( 'action' => 'history' )));
}
+
+
+ /**
+ * Output a subscription feed listing recent edits to this page.
+ * @param string $type
+ */
+ function feed( $type ) {
+ require_once 'Feed.php';
+ require_once 'SpecialRecentchanges.php';
+
+ global $wgFeedClasses;
+ if( !isset( $wgFeedClasses[$type] ) ) {
+ global $wgOut;
+ $wgOut->addWikiText( wfMsg( 'feed-invalid' ) );
+ return;
+ }
+
+ $feed = new $wgFeedClasses[$type](
+ $this->mTitle->getPrefixedText() . ' - ' . wfMsg( 'revhistory' ),
+ 'Revision history for this page on the wiki',
+ $this->mTitle->getFullUrl( 'action=history' ) );
+
+ $items = $this->fetchRevisions(10, 0, DIR_NEXT);
+ $feed->outHeader();
+ if( $items ) {
+ foreach( $items as $row ) {
+ $feed->outItem( $this->feedItem( $row ) );
+ }
+ } else {
+ $feed->outItem( $this->feedEmpty() );
+ }
+ $feed->outFooter();
+ }
+
+ function feedEmpty() {
+ global $wgOut;
+ return new FeedItem(
+ wfMsgForContent( 'nohistory' ),
+ $wgOut->parse( wfMsgForContent( 'history-feed-empty' ) ),
+ $this->mTitle->getFullUrl(),
+ wfTimestamp( TS_MW ),
+ '',
+ $this->mTitle->getTalkPage()->getFullUrl() );
+ }
+
+ /**
+ * Generate a 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).
+ *
+ * @param $row
+ * @return FeedItem
+ */
+ function feedItem( $row ) {
+ $rev = new Revision( $row );
+ $text = rcFormatDiffRow( $this->mTitle,
+ $this->mTitle->getPreviousRevisionID( $rev->getId() ),
+ $rev->getId(),
+ $rev->getTimestamp(),
+ $rev->getComment() );
+
+ if( $rev->getComment() == '' ) {
+ global $wgContLang;
+ $title = wfMsgForContent( 'history-feed-item-nocomment',
+ $rev->getUserText(),
+ $wgContLang->timeanddate( $rev->getTimestamp() ) );
+ } else {
+ $title = $rev->getUserText() . ": " . $this->stripComment( $rev->getComment() );
+ }
+
+ return new FeedItem(
+ $title,
+ $text,
+ $this->mTitle->getFullUrl( 'diff=' . $rev->getId() . '&oldid=prev' ),
+ $rev->getTimestamp(),
+ $rev->getUserText(),
+ $this->mTitle->getTalkPage()->getFullUrl() );
+ }
+
+ /**
+ * Quickie hack... strip out wikilinks to more legible form from the comment.
+ */
+ function stripComment( $text ) {
+ return preg_replace( '/\[\[([^]]*\|)?([^]]+)\]\]/', '\2', $text );
+ }
}
* Format a diff for the newsfeed
*/
function rcFormatDiff( $row ) {
- global $wgFeedDiffCutoff, $wgContLang;
+ $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
+ return rcFormatDiffRow( $titleObj,
+ $row->rc_last_oldid, $row->rc_this_oldid,
+ $row->rc_timestamp,
+ $row->rc_comment );
+}
+
+function rcFormatDiffRow( $title, $oldid, $newid, $timestamp, $comment ) {
+ global $wgFeedDiffCutoff, $wgContLang, $wgUser;
$fname = 'rcFormatDiff';
wfProfileIn( $fname );
require_once( 'DifferenceEngine.php' );
- $completeText = '<p>' . htmlspecialchars( $row->rc_comment ) . "</p>\n";
+ $skin = $wgUser->getSkin();
+ $completeText = '<p>' . $skin->formatComment( $comment ) . "</p>\n";
- if( $row->rc_namespace >= 0 ) {
- if( $row->rc_last_oldid ) {
+ if( $title->getNamespace() >= 0 ) {
+ if( $oldid ) {
wfProfileIn( "$fname-dodiff" );
- $titleObj = Title::makeTitle( $row->rc_namespace, $row->rc_title );
- $de = new DifferenceEngine( $titleObj, $row->rc_last_oldid, $row->rc_this_oldid );
- $diffText = $de->getDiff( wfMsg( 'revisionasof', $wgContLang->timeanddate( $row->rc_timestamp ) ),
- wfMsg( 'currentrev' ) );
+ $de = new DifferenceEngine( $title, $oldid, $newid );
+ #$diffText = $de->getDiff( wfMsg( 'revisionasof',
+ # $wgContLang->timeanddate( $timestamp ) ),
+ # wfMsg( 'currentrev' ) );
+ $diffText = $de->getDiff(
+ wfMsg( 'previousrevision' ), // hack
+ wfMsg( 'revisionasof',
+ $wgContLang->timeanddate( $timestamp ) ) );
+
if ( strlen( $diffText ) > $wgFeedDiffCutoff ) {
// Omit large diffs
- $diffLink = $titleObj->escapeFullUrl(
- 'diff=' . $row->rc_this_oldid .
- '&oldid=' . $row->rc_last_oldid );
+ $diffLink = $title->escapeFullUrl(
+ 'diff=' . $newid .
+ '&oldid=' . $oldid );
$diffText = '<a href="' .
$diffLink .
'">' .
'</a>';
} elseif ( $diffText === false ) {
// Error in diff engine, probably a missing revision
- $diffText = "<p>Can't load revision $row->rc_this_oldid</p>";
+ $diffText = "<p>Can't load revision $newid</p>";
} else {
// Diff output fine, clean up any illegal UTF-8
$diffText = UtfNormal::cleanUp( $diffText );
}
wfProfileOut( "$fname-dodiff" );
} else {
- $rev = Revision::newFromId( $row->rc_this_oldid );
+ $rev = Revision::newFromId( $newid );
if( is_null( $rev ) ) {
$newtext = '';
} else {
'viewdeleted' => 'View $1?',
'restorelink' => '{{PLURAL:$1|one deleted edit|$1 deleted edits}}',
'feedlinks' => 'Feed:',
+'feed-invalid' => 'Invalid subscription feed type.',
'sitenotice' => '-', # the equivalent to wgSiteNotice
'anonnotice' => '-',
#'rev-delundel' => 'del/undel',
'rev-delundel' => 'show/hide',
+'history-feed-item-nocomment' => '$1 at $2', # user at time
+'history-feed-empty' => 'The requested page doesn\'t exist.
+It may have been deleted from the wiki, or renamed.
+Try [[Special:Search|searching on the wiki]] for relevant new pages.',
+
# Revision deletion
#
'revisiondelete' => 'Delete/undelete revisions',