r85229 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r85228‎ | r85229 | r85230 >
Date:05:46, 3 April 2011
Author:dantman
Status:resolved (Comments)
Tags:
Comment:
Followup r85227. Convert all IncludableSpecialPages to use context properly (they are the worse offenders), and fix some bugs related to inculudable special pages and their context.
Modified paths:
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialAllpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialNewimages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialNewpages.php (modified) (history)
  • /trunk/phase3/includes/specials/SpecialRecentchanges.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialAllpages.php
@@ -64,7 +64,7 @@
6565
6666 $this->setHeaders();
6767 $this->outputHeader();
68 - $out->allowClickjacking();
 68+ $this->allowClickjacking();
6969
7070 # GET values
7171 $from = $request->getVal( 'from', null );
@@ -73,12 +73,17 @@
7474
7575 $namespaces = $wgContLang->getNamespaces();
7676
77 - $out->setPagetitle(
78 - ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces) ) ) ?
79 - wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) :
80 - wfMsg( 'allarticles' )
81 - );
82 - $out->addModuleStyles( 'mediawiki.special' );
 77+ if( !$this->including() ) {
 78+ $out->setPagetitle(
 79+ ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces) ) ) ?
 80+ wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) :
 81+ wfMsg( 'allarticles' )
 82+ );
 83+ // Note: The following will not end up in the parser output cache as
 84+ // a result even if we wanted to load it on pages including the
 85+ // special page it would be unstable.
 86+ $out->addModuleStyles( 'mediawiki.special' );
 87+ }
8388
8489 if( isset($par) ) {
8590 $this->showChunk( $namespace, $par, $to );
Index: trunk/phase3/includes/specials/SpecialNewpages.php
@@ -35,11 +35,6 @@
3636 */
3737 protected $opts;
3838
39 - /**
40 - * @var Skin
41 - */
42 - protected $skin;
43 -
4439 // Some internal settings
4540 protected $showNavigation = false;
4641
@@ -48,16 +43,16 @@
4944 }
5045
5146 protected function setup( $par ) {
52 - global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter;
 47+ global $wgEnableNewpagesUserFilter;
5348
5449 // Options
5550 $opts = new FormOptions();
5651 $this->opts = $opts; // bind
5752 $opts->add( 'hideliu', false );
58 - $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'newpageshidepatrolled' ) );
 53+ $opts->add( 'hidepatrolled', $this->getUser()->getBoolOption( 'newpageshidepatrolled' ) );
5954 $opts->add( 'hidebots', false );
6055 $opts->add( 'hideredirs', true );
61 - $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
 56+ $opts->add( 'limit', (int)$this->getUser()->getOption( 'rclimit' ) );
6257 $opts->add( 'offset', '' );
6358 $opts->add( 'namespace', '0' );
6459 $opts->add( 'username', '' );
@@ -65,7 +60,7 @@
6661 $opts->add( 'tagfilter', '' );
6762
6863 // Set values
69 - $opts->fetchValuesFromRequest( $wgRequest );
 64+ $opts->fetchValuesFromRequest( $this->getRequest() );
7065 if ( $par ) $this->parseParams( $par );
7166
7267 // Validate
@@ -73,9 +68,6 @@
7469 if( !$wgEnableNewpagesUserFilter ) {
7570 $opts->setValue( 'username', '' );
7671 }
77 -
78 - // Store some objects
79 - $this->skin = $wgUser->getSkin();
8072 }
8173
8274 protected function parseParams( $par ) {
@@ -128,7 +120,7 @@
129121 * @return String
130122 */
131123 public function execute( $par ) {
132 - global $wgOut;
 124+ $out = $this->getOutput();
133125
134126 $this->setHeaders();
135127 $this->outputHeader();
@@ -156,14 +148,14 @@
157149 if ( $this->showNavigation ) {
158150 $navigation = $pager->getNavigationBar();
159151 }
160 - $wgOut->addHTML( $navigation . $pager->getBody() . $navigation );
 152+ $out->addHTML( $navigation . $pager->getBody() . $navigation );
161153 } else {
162 - $wgOut->addWikiMsg( 'specialpage-empty' );
 154+ $out->addWikiMsg( 'specialpage-empty' );
163155 }
164156 }
165157
166158 protected function filterLinks() {
167 - global $wgGroupPermissions, $wgUser, $wgLang;
 159+ global $wgGroupPermissions, $wgLang;
168160
169161 // show/hide links
170162 $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) );
@@ -182,7 +174,7 @@
183175 unset( $filters['hideliu'] );
184176 }
185177
186 - if ( !$wgUser->useNPPatrol() ) {
 178+ if ( !$this->getUser()->useNPPatrol() ) {
187179 unset( $filters['hidepatrolled'] );
188180 }
189181
@@ -193,7 +185,7 @@
194186 $self = $this->getTitle();
195187 foreach ( $filters as $key => $msg ) {
196188 $onoff = 1 - $this->opts->getValue( $key );
197 - $link = $this->skin->link( $self, $showhide[$onoff], array(),
 189+ $link = $this->getSkin()->link( $self, $showhide[$onoff], array(),
198190 array( $key => $onoff ) + $changed
199191 );
200192 $links[$key] = wfMsgHtml( $msg, $link );
@@ -203,7 +195,7 @@
204196 }
205197
206198 protected function form() {
207 - global $wgOut, $wgEnableNewpagesUserFilter, $wgScript;
 199+ global $wgEnableNewpagesUserFilter, $wgScript;
208200
209201 // Consume values
210202 $this->opts->consumeValue( 'offset' ); // don't carry offset, DWIW
@@ -272,13 +264,13 @@
273265 $hidden .
274266 Xml::closeElement( 'form' );
275267
276 - $wgOut->addHTML( $form );
 268+ $this->getOutput()->addHTML( $form );
277269 }
278270
279271 protected function setSyndicated() {
280 - global $wgOut;
281 - $wgOut->setSyndicated( true );
282 - $wgOut->setFeedAppendQuery( wfArrayToCGI( $this->opts->getAllValues() ) );
 272+ $out = $this->getOutput();
 273+ $out->setSyndicated( true );
 274+ $out->setFeedAppendQuery( wfArrayToCGI( $this->opts->getAllValues() ) );
283275 }
284276
285277 /**
@@ -314,14 +306,14 @@
315307 $query['rcid'] = $result->rc_id;
316308 }
317309
318 - $plink = $this->skin->linkKnown(
 310+ $plink = $this->getSkin()->linkKnown(
319311 $title,
320312 null,
321313 array( 'class' => 'mw-newpages-pagename' ),
322314 $query,
323315 array( 'known' ) // Set explicitly to avoid the default of 'known','noclasses'. This breaks the colouration for stubs
324316 );
325 - $histLink = $this->skin->linkKnown(
 317+ $histLink = $this->getSkin()->linkKnown(
326318 $title,
327319 wfMsgHtml( 'hist' ),
328320 array(),
@@ -334,8 +326,8 @@
335327 ']'
336328 );
337329
338 - $ulink = $this->skin->revUserTools( $rev );
339 - $comment = $this->skin->revComment( $rev );
 330+ $ulink = $this->getSkin()->revUserTools( $rev );
 331+ $comment = $this->getSkin()->revComment( $rev );
340332
341333 if ( $this->patrollable( $result ) ) {
342334 $classes[] = 'not-patrolled';
@@ -366,8 +358,7 @@
367359 * @return Boolean
368360 */
369361 protected function patrollable( $result ) {
370 - global $wgUser;
371 - return ( $wgUser->useNPPatrol() && !$result->rc_patrolled );
 362+ return ( $this->getUser()->useNPPatrol() && !$result->rc_patrolled );
372363 }
373364
374365 /**
@@ -376,7 +367,7 @@
377368 * @param $type String
378369 */
379370 protected function feed( $type ) {
380 - global $wgFeed, $wgFeedClasses, $wgFeedLimit, $wgOut;
 371+ global $wgFeed, $wgFeedClasses, $wgFeedLimit;
381372
382373 if ( !$wgFeed ) {
383374 $wgOut->addWikiMsg( 'feed-unavailable' );
@@ -384,7 +375,7 @@
385376 }
386377
387378 if( !isset( $wgFeedClasses[$type] ) ) {
388 - $wgOut->addWikiMsg( 'feed-invalid' );
 379+ $this->getOut()->addWikiMsg( 'feed-invalid' );
389380 return;
390381 }
391382
@@ -471,7 +462,7 @@
472463 }
473464
474465 function getQueryInfo() {
475 - global $wgEnableNewpagesUserFilter, $wgGroupPermissions, $wgUser;
 466+ global $wgEnableNewpagesUserFilter, $wgGroupPermissions;
476467 $conds = array();
477468 $conds['rc_new'] = 1;
478469
@@ -497,7 +488,7 @@
498489 $conds['rc_user'] = 0;
499490 }
500491 # If this user cannot see patrolled edits or they are off, don't do dumb queries!
501 - if( $this->opts->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) {
 492+ if( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) {
502493 $conds['rc_patrolled'] = 0;
503494 }
504495 if( $this->opts->getValue( 'hidebots' ) ) {
Index: trunk/phase3/includes/specials/SpecialRecentchanges.php
@@ -39,18 +39,17 @@
4040 * @return FormOptions
4141 */
4242 public function getDefaultOptions() {
43 - global $wgUser;
4443 $opts = new FormOptions();
4544
46 - $opts->add( 'days', (int)$wgUser->getOption( 'rcdays' ) );
47 - $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) );
 45+ $opts->add( 'days', (int)$this->getUser()->getOption( 'rcdays' ) );
 46+ $opts->add( 'limit', (int)$this->getUser()->getOption( 'rclimit' ) );
4847 $opts->add( 'from', '' );
4948
50 - $opts->add( 'hideminor', $wgUser->getBoolOption( 'hideminor' ) );
 49+ $opts->add( 'hideminor', $this->getUser()->getBoolOption( 'hideminor' ) );
5150 $opts->add( 'hidebots', true );
5251 $opts->add( 'hideanons', false );
5352 $opts->add( 'hideliu', false );
54 - $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'hidepatrolled' ) );
 53+ $opts->add( 'hidepatrolled', $this->getUser()->getBoolOption( 'hidepatrolled' ) );
5554 $opts->add( 'hidemyself', false );
5655
5756 $opts->add( 'namespace', '', FormOptions::INTNULL );
@@ -212,11 +211,10 @@
213212 * @return String or false
214213 */
215214 public function checkLastModified( $feedFormat ) {
216 - global $wgOut, $wgUser;
217215 $dbr = wfGetDB( DB_SLAVE );
218216 $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ );
219 - if( $feedFormat || !$wgUser->useRCPatrol() ) {
220 - if( $lastmod && $wgOut->checkLastModified( $lastmod ) ) {
 217+ if( $feedFormat || !$this->getUser()->useRCPatrol() ) {
 218+ if( $lastmod && $this->getOutput()->checkLastModified( $lastmod ) ) {
221219 # Client cache fresh and headers sent, nothing more to do.
222220 return false;
223221 }
@@ -231,8 +229,6 @@
232230 * @return array
233231 */
234232 public function buildMainQueryConds( FormOptions $opts ) {
235 - global $wgUser;
236 -
237233 $dbr = wfGetDB( DB_SLAVE );
238234 $conds = array();
239235
@@ -264,7 +260,7 @@
265261 $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff );
266262
267263
268 - $hidePatrol = $wgUser->useRCPatrol() && $opts['hidepatrolled'];
 264+ $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled'];
269265 $hideLoggedInUsers = $opts['hideliu'] && !$forcebot;
270266 $hideAnonymousUsers = $opts['hideanons'] && !$forcebot;
271267
@@ -276,10 +272,10 @@
277273 if( $hideAnonymousUsers ) $conds[] = 'rc_user != 0';
278274
279275 if( $opts['hidemyself'] ) {
280 - if( $wgUser->getId() ) {
281 - $conds[] = 'rc_user != ' . $dbr->addQuotes( $wgUser->getId() );
 276+ if( $this->getUser()->getId() ) {
 277+ $conds[] = 'rc_user != ' . $dbr->addQuotes( $this->getUser()->getId() );
282278 } else {
283 - $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() );
 279+ $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $this->getUser()->getName() );
284280 }
285281 }
286282
@@ -315,13 +311,11 @@
316312 * @return database result or false (for Recentchangeslinked only)
317313 */
318314 public function doMainQuery( $conds, $opts ) {
319 - global $wgUser;
320 -
321315 $tables = array( 'recentchanges' );
322316 $join_conds = array();
323317 $query_options = array( 'USE INDEX' => array('recentchanges' => 'rc_timestamp') );
324318
325 - $uid = $wgUser->getId();
 319+ $uid = $this->getUser()->getId();
326320 $dbr = wfGetDB( DB_SLAVE );
327321 $limit = $opts['limit'];
328322 $namespace = $opts['namespace'];
@@ -334,7 +328,7 @@
335329 $join_conds['watchlist'] = array('LEFT JOIN',
336330 "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace");
337331 }
338 - if ($wgUser->isAllowed("rollback")) {
 332+ if ($this->getUser()->isAllowed("rollback")) {
339333 $tables[] = 'page';
340334 $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id');
341335 }
@@ -397,7 +391,7 @@
398392 * @param $opts FormOptions
399393 */
400394 public function webOutput( $rows, $opts ) {
401 - global $wgOut, $wgUser, $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
 395+ global $wgOut, $wgRCShowWatchingUsers, $wgShowUpdatedMarker;
402396 global $wgAllowCategorizedRecentChanges;
403397
404398 $limit = $opts['limit'];
@@ -414,13 +408,13 @@
415409 $this->filterByCategories( $rows, $opts );
416410 }
417411
418 - $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' );
 412+ $showWatcherCount = $wgRCShowWatchingUsers && $this->getUser()->getOption( 'shownumberswatching' );
419413 $watcherCache = array();
420414
421415 $dbr = wfGetDB( DB_SLAVE );
422416
423417 $counter = 1;
424 - $list = ChangesList::newFromUser( $wgUser );
 418+ $list = ChangesList::newFromUser( $this->getUser() );
425419
426420 $s = $list->beginRecentChangesList();
427421 foreach( $rows as $obj ) {
@@ -664,14 +658,12 @@
665659 * @param $active Boolean: whether to show the link in bold
666660 */
667661 function makeOptionsLink( $title, $override, $options, $active = false ) {
668 - global $wgUser;
669 - $sk = $wgUser->getSkin();
670662 $params = $override + $options;
671663 if ( $active ) {
672 - return $sk->link( $this->getTitle(), '<strong>' . htmlspecialchars( $title ) . '</strong>',
 664+ return $this->getSkin()->link( $this->getTitle(), '<strong>' . htmlspecialchars( $title ) . '</strong>',
673665 array(), $params, array( 'known' ) );
674666 } else {
675 - return $sk->link( $this->getTitle(), htmlspecialchars( $title ), array() , $params, array( 'known' ) );
 667+ return $this->getSkin()->link( $this->getTitle(), htmlspecialchars( $title ), array() , $params, array( 'known' ) );
676668 }
677669 }
678670
@@ -682,7 +674,7 @@
683675 * @param $nondefaults Array
684676 */
685677 function optionsPanel( $defaults, $nondefaults ) {
686 - global $wgLang, $wgUser, $wgRCLinkLimits, $wgRCLinkDays;
 678+ global $wgLang, $wgRCLinkLimits, $wgRCLinkDays;
687679
688680 $options = $nondefaults + $defaults;
689681
@@ -740,7 +732,7 @@
741733 $links[] = wfMsgHtml( 'rcshowhidebots', $botLink );
742734 $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink );
743735 $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink );
744 - if( $wgUser->useRCPatrol() )
 736+ if( $this->getUser()->useRCPatrol() )
745737 $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink );
746738 $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink );
747739 $hl = $wgLang->pipeList( $links );
Index: trunk/phase3/includes/specials/SpecialNewimages.php
@@ -27,17 +27,20 @@
2828 }
2929
3030 public function execute( $par ){
31 - global $wgOut;
32 -
3331 $this->setHeaders();
3432 $this->outputHeader();
3533
3634 $pager = new NewFilesPager( $par );
3735
38 - $form = $pager->getForm();
39 - $form->prepareForm();
40 - $form->displayForm( '' );
41 - $wgOut->addHTML( $pager->getBody() . $pager->getNavigationBar() );
 36+ if ( !$this->including() ) {
 37+ $form = $pager->getForm();
 38+ $form->prepareForm();
 39+ $form->displayForm( '' );
 40+ }
 41+ $this->getOutput()->addHTML( $pager->getBody() );
 42+ if ( !$this->including() ) {
 43+ $this->getOutput()->addHTML( $pager->getNavigationBar() );
 44+ }
4245 }
4346 }
4447
Index: trunk/phase3/includes/SpecialPage.php
@@ -621,6 +621,14 @@
622622 static function capturePath( &$title ) {
623623 global $wgOut, $wgTitle, $wgUser;
624624
 625+ // preload the skin - Sometimes the SpecialPage loads it at a bad point in time making a includable special page override the skin title
 626+ // This hack is ok for now. The plan is for
 627+ // - Skin to stop storing it's own title
 628+ // - includable special pages to stop using $wgTitle and $wgOut
 629+ // - and OutputPage to store it's own skin object instead of askin $wgUser
 630+ // Once just about any of those are implemented preloading will not be necessarily
 631+ $wgOut->getSkin();
 632+
625633 $oldTitle = $wgTitle;
626634 $oldOut = $wgOut;
627635 $wgOut = new OutputPage;
@@ -862,18 +870,21 @@
863871 * Output an error message telling the user what access level they have to have
864872 */
865873 function displayRestrictionError() {
866 - global $wgOut;
867 - $wgOut->permissionRequired( $this->mRestriction );
 874+ $this->getOutput()->permissionRequired( $this->mRestriction );
868875 }
869876
870877 /**
871878 * Sets headers - this should be called from the execute() method of all derived classes!
872879 */
873880 function setHeaders() {
874 - global $wgOut;
875 - $wgOut->setArticleRelated( false );
876 - $wgOut->setRobotPolicy( "noindex,nofollow" );
877 - $wgOut->setPageTitle( $this->getDescription() );
 881+ if ( $this->including() ) {
 882+ // Don't set these headers when special page is being included into an article
 883+ return;
 884+ }
 885+ $out = $this->getOutput();
 886+ $out->setArticleRelated( false );
 887+ $out->setRobotPolicy( "noindex,nofollow" );
 888+ $out->setPageTitle( $this->getDescription() );
878889 }
879890
880891 /**
@@ -909,7 +920,7 @@
910921 * @param $summaryMessageKey String: message key of the summary
911922 */
912923 function outputHeader( $summaryMessageKey = '' ) {
913 - global $wgOut, $wgContLang;
 924+ global $wgContLang;
914925
915926 if( $summaryMessageKey == '' ) {
916927 $msg = $wgContLang->lc( $this->name() ) . '-summary';
@@ -917,7 +928,7 @@
918929 $msg = $summaryMessageKey;
919930 }
920931 if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) {
921 - $wgOut->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
 932+ $this->getOutput()->wrapWikiMsg( "<div class='mw-specialpage-summary'>\n$1\n</div>", $msg );
922933 }
923934
924935 }
@@ -1044,6 +1055,16 @@
10451056 }
10461057
10471058 /**
 1059+ * Shortcut to call OutputPage::allowClickjacking(); which also takes
 1060+ * transclusion into account.
 1061+ */
 1062+ public function allowClickjacking() {
 1063+ if ( !$this->including() ) {
 1064+ $this->getOutput()->allowClickjacking();
 1065+ }
 1066+ }
 1067+
 1068+ /**
10481069 * Wrapper around wfMessage that sets the current context. Currently this
10491070 * is only the title.
10501071 *

Follow-up revisions

RevisionCommit summaryAuthorDate
r85231Followup r85227; Back out changes related to avoiding calls to OutputPage fro...dantman06:26, 3 April 2011
r85243Followup r85229; Drop this unnecessary reference on the user from ChangesList...dantman11:33, 3 April 2011
r89395Fix for r85229: getOutput() instead of getOut(), leftover $wgOut usage.demon04:22, 3 June 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r85227Start managing output and input context from special pages themselves instead...dantman04:36, 3 April 2011

Comments

#Comment by Siebrand (talk | contribs)   11:26, 3 April 2011

PHP Strict Standards: Only variables should be passed by reference in /www/w/includes/specials/SpecialRecentchanges.php on line 417

Status & tagging log