r57119 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57118‎ | r57119 | r57120 >
Date:17:35, 30 September 2009
Author:werdna
Status:resolved (Comments)
Tags:
Comment:
Re-work feed exposure system.
* Includes a new, more flexible system which allows you to provide an array of format => URL, but also supports the older system of providing a URL suffix.
* Implemented it for the watchlist if a user has set their own token.
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialWatchlist.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -28,8 +28,9 @@
2929 var $mContainsOldMagic = 0, $mContainsNewMagic = 0;
3030 var $mIsArticleRelated = true;
3131 protected $mParserOptions = null; // lazy initialised, use parserOptions()
32 - var $mShowFeedLinks = false;
33 - var $mFeedLinksAppendQuery = false;
 32+
 33+ var $mFeedLinks = array();
 34+
3435 var $mEnableClientCache = true;
3536 var $mArticleBodyOnly = false;
3637
@@ -575,14 +576,30 @@
576577 public function isArticle() { return $this->mIsarticle; }
577578 public function setPrintable() { $this->mPrintable = true; }
578579 public function isPrintable() { return $this->mPrintable; }
579 - public function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
580 - public function isSyndicated() { return $this->mShowFeedLinks; }
581 - public function setFeedAppendQuery( $val ) { $this->mFeedLinksAppendQuery = $val; }
582580 public function getFeedAppendQuery() { return $this->mFeedLinksAppendQuery; }
583581 public function setOnloadHandler( $js ) { $this->mOnloadHandler = $js; }
584582 public function getOnloadHandler() { return $this->mOnloadHandler; }
585583 public function disable() { $this->mDoNothing = true; }
586584 public function isDisabled() { return $this->mDoNothing; }
 585+
 586+ public function setSyndicated( $show = true ) { $this->mShowFeedLinks = $show; }
 587+
 588+ public function setFeedAppendQuery( $val ) {
 589+ global $wgFeedClasses;
 590+
 591+ $this->mFeedLinks = array();
 592+
 593+ foreach( $wgFeedClasses as $type => $class ) {
 594+ $query = "feed=$type&".$val;
 595+ $this->mFeedLinks[$type] = $this->getTitle()->getLocalURL( $query );
 596+ }
 597+ }
 598+
 599+ public function addFeedLink( $format, $href ) {
 600+ $this->mFeedLinks[$format] = $href;
 601+ }
 602+
 603+ public function isSyndicated() { return count($this->mFeedLinks); }
587604
588605 public function setArticleRelated( $v ) {
589606 $this->mIsArticleRelated = $v;
@@ -1916,22 +1933,8 @@
19171934 * Return URLs for each supported syndication format for this page.
19181935 * @return array associating format keys with URLs
19191936 */
1920 - public function getSyndicationLinks() {
1921 - global $wgFeedClasses;
1922 - $links = array();
1923 -
1924 - if( $this->isSyndicated() ) {
1925 - if( is_string( $this->getFeedAppendQuery() ) ) {
1926 - $appendQuery = "&" . $this->getFeedAppendQuery();
1927 - } else {
1928 - $appendQuery = "";
1929 - }
1930 -
1931 - foreach( $wgFeedClasses as $format => $class ) {
1932 - $links[$format] = $this->getTitle()->getLocalUrl( "feed=$format{$appendQuery}" );
1933 - }
1934 - }
1935 - return $links;
 1937+ public function getSyndicationLinks() {
 1938+ return $this->mFeedLinks;
19361939 }
19371940
19381941 /**
Index: trunk/phase3/includes/specials/SpecialWatchlist.php
@@ -13,6 +13,21 @@
1414 global $wgUser, $wgOut, $wgLang, $wgRequest;
1515 global $wgRCShowWatchingUsers, $wgEnotifWatchlist, $wgShowUpdatedMarker;
1616 global $wgEnotifWatchlist;
 17+
 18+ // Add feed links
 19+ $wlToken = $wgUser->getOption( 'watchlisttoken' );
 20+ if ($wlToken) {
 21+ global $wgServer, $wgScriptPath, $wgFeedClasses;
 22+ $apiParams = array( 'action' => 'feedwatchlist', 'allrev' => 'allrev',
 23+ 'wlowner' => $wgUser->getName(), 'wltoken' => $wlToken );
 24+ $feedTemplate = $wgServer . '/' . $wgScriptPath . '/api.php?';
 25+
 26+ foreach( $wgFeedClasses as $format => $class ) {
 27+ $theseParams = $apiParams + array( 'feedformat' => $format );
 28+ $url = $feedTemplate . wfArrayToCGI( $theseParams );
 29+ $wgOut->addFeedLink( $format, $url );
 30+ }
 31+ }
1732
1833 $skin = $wgUser->getSkin();
1934 $specialTitle = SpecialPage::getTitleFor( 'Watchlist' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r57120Fix for r57119, remove double-/ in URLswerdna17:44, 30 September 2009
r61021* (bug 21738) Fix for r57119: OutputPage::setSyndicated() now works again (wa...ialex20:23, 13 January 2010

Comments

#Comment by Juliano (talk | contribs)   18:39, 5 December 2009

This change caused $wgOut->setSyndicated() to turn into a no-op (and $mShowFeedLinks is not used anywhere, and also its declaration is lacking from the class body).

As a consequence, Special:RecentChanges, Special:UnusedCategories and others don't have syndication links anymore. No syndication links are shown unless $wgOut->setFeedAppendQuery() is called, and these pages don't have anything to append to the feed query parameters.

#Comment by IAlex (talk | contribs)   20:25, 13 January 2010

I fixed this in r61021.

Status & tagging log