From 44bb62c047100a14ca8cfbe64ed94086870b7b4c Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sun, 28 May 2006 03:47:28 +0000 Subject: [PATCH] * (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 --- RELEASE-NOTES | 3 + includes/PageHistory.php | 92 +++++++++++++++++++++++++++++++ includes/SpecialRecentchanges.php | 40 +++++++++----- languages/Messages.php | 6 ++ 4 files changed, 128 insertions(+), 13 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 609f25f40e..9f6f61b6a5 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -367,6 +367,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN 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 == diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 4cfee47a89..3e413c897e 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -71,6 +71,13 @@ class PageHistory { $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. @@ -562,6 +569,91 @@ class PageHistory { $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 ); + } } diff --git a/includes/SpecialRecentchanges.php b/includes/SpecialRecentchanges.php index 0c05104b26..74c6ebf4e6 100644 --- a/includes/SpecialRecentchanges.php +++ b/includes/SpecialRecentchanges.php @@ -614,27 +614,41 @@ function rcNamespaceForm( $namespace, $invert, $nondefaults, $categories_any ) { * 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 = '

' . htmlspecialchars( $row->rc_comment ) . "

\n"; + $skin = $wgUser->getSkin(); + $completeText = '

' . $skin->formatComment( $comment ) . "

\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 = '' . @@ -642,7 +656,7 @@ function rcFormatDiff( $row ) { ''; } elseif ( $diffText === false ) { // Error in diff engine, probably a missing revision - $diffText = "

Can't load revision $row->rc_this_oldid

"; + $diffText = "

Can't load revision $newid

"; } else { // Diff output fine, clean up any illegal UTF-8 $diffText = UtfNormal::cleanUp( $diffText ); @@ -650,7 +664,7 @@ function rcFormatDiff( $row ) { } wfProfileOut( "$fname-dodiff" ); } else { - $rev = Revision::newFromId( $row->rc_this_oldid ); + $rev = Revision::newFromId( $newid ); if( is_null( $rev ) ) { $newtext = ''; } else { diff --git a/languages/Messages.php b/languages/Messages.php index b9c7b9977f..6211b51047 100644 --- a/languages/Messages.php +++ b/languages/Messages.php @@ -251,6 +251,7 @@ See $1.', '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' => '-', @@ -589,6 +590,11 @@ there may be details in the [{{fullurl:Special:Log/delete|page={{PAGENAMEE}}}} d #'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', -- 2.20.1