From b3b309ebb9bf313194201abfe16129c0cb6f54c0 Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Sat, 12 Jan 2008 00:13:53 +0000 Subject: [PATCH] * Use only default options when generating RSS and Atom syndication links. This should help prevent infinite link loops that some software may follow, and will generally keep feed behavior cleaner. Combined duplicate link expansion from OutputPage and SkinTemplate into OutputPage::getSyndicationLinks() --- RELEASE-NOTES | 3 +++ includes/OutputPage.php | 42 ++++++++++++++++++++++++++------------- includes/PageHistory.php | 1 + includes/SkinTemplate.php | 18 +++-------------- 4 files changed, 35 insertions(+), 29 deletions(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 4dd9771bde..1ecb203fbf 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -298,6 +298,9 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * Do not log user rights change that didn't change anything * (bug 12584) Don't reset cl_timestamp when auto-updating sort key on move * (bug 12588) Fix selection in namespace selector on Special:Newpages +* Use only default options when generating RSS and Atom syndication links. + This should help prevent infinite link loops that some software may follow, + and will generally keep feed behavior cleaner. == Parser changes in 1.12 == diff --git a/includes/OutputPage.php b/includes/OutputPage.php index 6e50960ab6..7c5af28472 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -1298,25 +1298,17 @@ class OutputPage { $ret .= " />\n"; } - if( $this->isSyndicated() ) { + foreach( $this->getSyndicationLinks() as $format => $link ) { # Use the page name for the title (accessed through $wgTitle since # there's no other way). In principle, this could lead to issues # with having the same name for different feeds corresponding to # the same page, but we can't avoid that at this low a level. - global $wgTitle, $wgFeedClasses; - - if( is_string( $this->getFeedAppendQuery() ) ) { - $appendQuery = "&" . $this->getFeedAppendQuery(); - } else { - $appendQuery = ""; - } + global $wgTitle; - foreach( $wgFeedClasses as $format => $class ) { - $ret .= $this->feedLink( - $format, - $wgRequest->appendQuery( "feed=$format{$appendQuery}" ), - wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) ); - } + $ret .= $this->feedLink( + $format, + $link, + wfMsg( "page-{$format}-feed", $wgTitle->getPrefixedText() ) ); } # Recent changes feed should appear on every page @@ -1336,6 +1328,28 @@ class OutputPage { return $ret; } + /** + * Return URLs for each supported syndication format for this page. + * @return array associating format keys with URLs + */ + public function getSyndicationLinks() { + global $wgTitle, $wgFeedClasses; + $links = array(); + + if( $this->isSyndicated() ) { + if( is_string( $this->getFeedAppendQuery() ) ) { + $appendQuery = "&" . $this->getFeedAppendQuery(); + } else { + $appendQuery = ""; + } + + foreach( $wgFeedClasses as $format => $class ) { + $links[$format] = $wgTitle->getLocalUrl( "feed=$format{$appendQuery}" ); + } + } + return $links; + } + /** * Generate a for an RSS feed. */ diff --git a/includes/PageHistory.php b/includes/PageHistory.php index 9d8466528d..3c8c8a1270 100644 --- a/includes/PageHistory.php +++ b/includes/PageHistory.php @@ -67,6 +67,7 @@ class PageHistory { $wgOut->setArticleRelated( true ); $wgOut->setRobotpolicy( 'noindex,nofollow' ); $wgOut->setSyndicated( true ); + $wgOut->setFeedAppendQuery( 'action=history' ); $logPage = SpecialPage::getTitleFor( 'Log' ); $logLink = $this->mSkin->makeKnownLinkObj( $logPage, wfMsgHtml( 'viewpagelogs' ), 'page=' . $this->mTitle->getPrefixedUrl() ); diff --git a/includes/SkinTemplate.php b/includes/SkinTemplate.php index 9ba8030464..d013119009 100644 --- a/includes/SkinTemplate.php +++ b/includes/SkinTemplate.php @@ -219,22 +219,10 @@ class SkinTemplate extends Skin { $tpl->set( 'catlinks', $this->getCategories()); if( $wgOut->isSyndicated() ) { $feeds = array(); - foreach( $wgFeedClasses as $format => $class ) { - $linktext = $format; - if ( $format == "atom" ) { - $linktext = wfMsg( 'feed-atom' ); - } else if ( $format == "rss" ) { - $linktext = wfMsg( 'feed-rss' ); - } - if( is_string( $wgOut->getFeedAppendQuery() ) ) { - $appendQuery = "&" . $wgOut->getFeedAppendQuery(); - } else { - $appendQuery = ""; - } + foreach( $wgOut->getSyndicationLinks() as $format => $link ) { $feeds[$format] = array( - 'text' => $linktext, - 'href' => $wgRequest->appendQuery( "feed={$format}{$appendQuery}" ) - ); + 'text' => wfMsg( "feed-$format" ), + 'href' => $link ); } $tpl->setRef( 'feeds', $feeds ); } else { -- 2.20.1