r62221 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62220‎ | r62221 | r62222 >
Date:04:13, 10 February 2010
Author:tstarling
Status:ok
Tags:
Comment:
* Fix for r60163: in RC/RCL, hash together all the options, not just namespace, in order to form the cache key.
* Removed Crb from the credits since none of his code remains.
* Fixed two bugs which both broke feed links on RCL: $this->mTargetTitle not initialised when setTopText() is called, and $out->setFeedAppendQuery() in setBottomText() overridden by a subsequent call to setSyndicated(). Fixed both by rearranging data flow, using memoized accessors instead of setup functions to eliminate bugs due to execution order.
* Renamed a few variables which were unclear ($feed and $feedObj).
Modified paths:
  • /trunk/phase3/CREDITS (modified) (history)
  • /trunk/phase3/includes/ChangesFeed.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRecentchanges.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRecentchangeslinked.php (modified) (history)

Diff [purge]

Index: trunk/phase3/CREDITS
@@ -74,7 +74,6 @@
7575 * Brianna Laugher
7676 * Carlin
7777 * Conrad Irwin
78 -* Crb
7978 * Dan Nessett
8079 * Daniel Arnold
8180 * Denny Vrandecic
Index: trunk/phase3/includes/ChangesFeed.php
@@ -40,14 +40,11 @@
4141 *
4242 * @param $feed ChannelFeed subclass object (generally the one returned by getFeedObject())
4343 * @param $rows ResultWrapper object with rows in recentchanges table
44 - * @param $limit Integer: number of rows in $rows (only used for the cache key)
45 - * @param $hideminor Boolean: whether to hide minor edits (only used for the cache key)
4644 * @param $lastmod Integer: timestamp of the last item in the recentchanges table (only used for the cache key)
47 - * @param $target String: target's name; for Special:RecentChangesLinked (only used for the cache key)
48 - * @param $namespace Integer: namespace id (only used for the cache key)
 45+ * @param $opts FormOptions as in SpecialRecentChanges::getDefaultOptions()
4946 * @return null or true
5047 */
51 - public function execute( $feed, $rows, $limit=0, $hideminor=false, $lastmod=false, $target='', $namespace='' ) {
 48+ public function execute( $feed, $rows, $lastmod, $opts ) {
5249 global $messageMemc, $wgFeedCacheTimeout;
5350 global $wgSitename, $wgLang;
5451
@@ -56,7 +53,8 @@
5754 }
5855
5956 $timekey = wfMemcKey( $this->type, $this->format, 'timestamp' );
60 - $key = wfMemcKey( $this->type, $this->format, $limit, $hideminor, $target, $wgLang->getCode(), $namespace );
 57+ $optionsHash = md5( serialize( $opts->getAllValues() ) );
 58+ $key = wfMemcKey( $this->type, $this->format, $wgLang->getCode(), $optionsHash );
6159
6260 FeedUtils::checkPurge($timekey, $key);
6361
@@ -173,4 +171,4 @@
174172 wfProfileOut( __METHOD__ );
175173 }
176174
177 -}
\ No newline at end of file
 175+}
Index: trunk/phase3/includes/specials/SpecialRecentchangeslinked.php
@@ -5,6 +5,7 @@
66 * @ingroup SpecialPage
77 */
88 class SpecialRecentchangeslinked extends SpecialRecentchanges {
 9+ var $rclTargetTitle;
910
1011 function __construct(){
1112 SpecialPage::SpecialPage( 'Recentchangeslinked' );
@@ -26,7 +27,6 @@
2728 public function feedSetup() {
2829 global $wgRequest;
2930 $opts = parent::feedSetup();
30 - # Feed is cached on limit,hideminor,target; other params would randomly not work
3131 $opts['target'] = $wgRequest->getVal( 'target' );
3232 return $opts;
3333 }
@@ -34,7 +34,7 @@
3535 public function getFeedObject( $feedFormat ){
3636 $feed = new ChangesFeed( $feedFormat, false );
3737 $feedObj = $feed->getFeedObject(
38 - wfMsgForContent( 'recentchangeslinked-title', $this->mTargetTitle->getPrefixedText() ),
 38+ wfMsgForContent( 'recentchangeslinked-title', $this->getTargetTitle()->getPrefixedText() ),
3939 wfMsgForContent( 'recentchangeslinked-feed' )
4040 );
4141 return array( $feed, $feedObj );
@@ -55,7 +55,6 @@
5656 $wgOut->wrapWikiMsg( "<div class=\"errorbox\">\n$1</div><br style=\"clear: both\" />", 'allpagesbadtitle' );
5757 return false;
5858 }
59 - $this->mTargetTitle = $title;
6059
6160 $wgOut->setPageTitle( wfMsg( 'recentchangeslinked-title', $title->getPrefixedText() ) );
6261
@@ -197,18 +196,37 @@
198197 return $extraOpts;
199198 }
200199
 200+ function getTargetTitle() {
 201+ if ( $this->rclTargetTitle === null ) {
 202+ $opts = $this->getOptions();
 203+ if ( isset( $opts['target'] ) && $opts['target'] !== '' ) {
 204+ $this->rclTargetTitle = Title::newFromText( $opts['target'] );
 205+ } else {
 206+ $this->rclTargetTitle = false;
 207+ }
 208+ }
 209+ return $this->rclTargetTitle;
 210+ }
 211+
201212 function setTopText( OutputPage $out, FormOptions $opts ) {
202213 global $wgUser;
203214 $skin = $wgUser->getSkin();
204 - if( isset( $this->mTargetTitle ) && is_object( $this->mTargetTitle ) )
205 - $out->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $this->mTargetTitle,
206 - $this->mTargetTitle->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
 215+ $target = $this->getTargetTitle();
 216+ if( $target )
 217+ $out->setSubtitle( wfMsg( 'recentchangeslinked-backlink', $skin->link( $target,
 218+ $target->getPrefixedText(), array(), array( 'redirect' => 'no' ) ) ) );
207219 }
208220
209 - function setBottomText( OutputPage $out, FormOptions $opts ){
210 - if( isset( $this->mTargetTitle ) && is_object( $this->mTargetTitle ) ){
211 - $out->setFeedAppendQuery( "target=" . urlencode( $this->mTargetTitle->getPrefixedDBkey() ) );
 221+ public function getFeedQuery() {
 222+ $target = $this->getTargetTitle();
 223+ if( $target ) {
 224+ return "target=" . urlencode( $target->getPrefixedDBkey() );
 225+ } else {
 226+ return false;
212227 }
 228+ }
 229+
 230+ function setBottomText( OutputPage $out, FormOptions $opts ) {
213231 if( isset( $this->mResultEmpty ) && $this->mResultEmpty ){
214232 $out->addWikiMsg( 'recentchangeslinked-noresult' );
215233 }
Index: trunk/phase3/includes/specials/SpecialRecentchanges.php
@@ -5,6 +5,8 @@
66 * @ingroup SpecialPage
77 */
88 class SpecialRecentChanges extends SpecialPage {
 9+ var $rcOptions, $rcSubpage;
 10+
911 public function __construct() {
1012 parent::__construct( 'Recentchanges' );
1113 $this->includable( true );
@@ -40,7 +42,7 @@
4143 }
4244
4345 /**
44 - * Get a FormOptions object with options as specified by the user
 46+ * Create a FormOptions object with options as specified by the user
4547 *
4648 * @return FormOptions
4749 */
@@ -60,7 +62,7 @@
6163 }
6264
6365 /**
64 - * Get a FormOptions object sepcific for feed requests
 66+ * Create a FormOptions object specific for feed requests and return it
6567 *
6668 * @return FormOptions
6769 */
@@ -74,12 +76,26 @@
7577 }
7678
7779 /**
 80+ * Get the current FormOptions for this request
 81+ */
 82+ public function getOptions() {
 83+ if ( $this->rcOptions === null ) {
 84+ global $wgRequest;
 85+ $feedFormat = $wgRequest->getVal( 'feed' );
 86+ $this->rcOptions = $feedFormat ? $this->feedSetup() : $this->setup( $this->rcSubpage );
 87+ }
 88+ return $this->rcOptions;
 89+ }
 90+
 91+
 92+ /**
7893 * Main execution point
7994 *
80 - * @param $parameters string
 95+ * @param $subpage string
8196 */
82 - public function execute( $parameters ) {
 97+ public function execute( $subpage ) {
8398 global $wgRequest, $wgOut;
 99+ $this->rcSubpage = $subpage;
84100 $feedFormat = $wgRequest->getVal( 'feed' );
85101
86102 # 10 seconds server-side caching max
@@ -90,12 +106,11 @@
91107 return;
92108 }
93109
94 - $opts = $feedFormat ? $this->feedSetup() : $this->setup( $parameters );
 110+ $opts = $this->getOptions();
95111 $this->setHeaders();
96112 $this->outputHeader();
97113
98114 // Fetch results, prepare a batch link existence check query
99 - $rows = array();
100115 $conds = $this->buildMainQueryConds( $opts );
101116 $rows = $this->doMainQuery( $conds, $opts );
102117 if( $rows === false ){
@@ -114,10 +129,9 @@
115130 }
116131 $batch->execute();
117132 }
118 - $target = isset($opts['target']) ? $opts['target'] : ''; // RCL has targets
119133 if( $feedFormat ) {
120 - list( $feed, $feedObj ) = $this->getFeedObject( $feedFormat );
121 - $feed->execute( $feedObj, $rows, $opts['limit'], $opts['hideminor'], $lastmod, $target, $opts['namespace'] );
 134+ list( $changesFeed, $formatter ) = $this->getFeedObject( $feedFormat );
 135+ $changesFeed->execute( $formatter, $rows, $lastmod, $opts );
122136 } else {
123137 $this->webOutput( $rows, $opts );
124138 }
@@ -131,12 +145,12 @@
132146 * @return array
133147 */
134148 public function getFeedObject( $feedFormat ){
135 - $feed = new ChangesFeed( $feedFormat, 'rcfeed' );
136 - $feedObj = $feed->getFeedObject(
 149+ $changesFeed = new ChangesFeed( $feedFormat, 'rcfeed' );
 150+ $formatter = $changesFeed->getFeedObject(
137151 wfMsgForContent( 'recentchanges' ),
138152 wfMsgForContent( 'recentchanges-feed-description' )
139153 );
140 - return array( $feed, $feedObj );
 154+ return array( $changesFeed, $formatter );
141155 }
142156
143157 /**
@@ -355,7 +369,7 @@
356370 }
357371
358372 // And now for the content
359 - $wgOut->setSyndicated( true );
 373+ $wgOut->setFeedAppendQuery( $this->getFeedQuery() );
360374
361375 if( $wgAllowCategorizedRecentChanges ) {
362376 $this->filterByCategories( $rows, $opts );
@@ -403,6 +417,14 @@
404418 }
405419
406420 /**
 421+ * Get the query string to append to feed link URLs.
 422+ * This is overridden by RCL to add the target parameter
 423+ */
 424+ public function getFeedQuery() {
 425+ return false;
 426+ }
 427+
 428+ /**
407429 * Return the text to be displayed above the changes
408430 *
409431 * @param $opts FormOptions

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r60163(bug 21535) Add 'namespace' to cache key for RecentChanges RSS feed. Patch b...happy-melon15:42, 17 December 2009

Status & tagging log