From b12875c8c4b4ae7e42ccafba2b2ff2f63162c1b6 Mon Sep 17 00:00:00 2001 From: Daniel Friesen Date: Sun, 3 Apr 2011 05:46:42 +0000 Subject: [PATCH] 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. --- includes/SpecialPage.php | 37 +++++++++++--- includes/specials/SpecialAllpages.php | 19 +++++--- includes/specials/SpecialNewimages.php | 15 +++--- includes/specials/SpecialNewpages.php | 57 +++++++++------------- includes/specials/SpecialRecentchanges.php | 46 ++++++++--------- 5 files changed, 93 insertions(+), 81 deletions(-) diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 5da2ef7cbb..10a016bcb9 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -621,6 +621,14 @@ class SpecialPage { static function capturePath( &$title ) { global $wgOut, $wgTitle, $wgUser; + // preload the skin - Sometimes the SpecialPage loads it at a bad point in time making a includable special page override the skin title + // This hack is ok for now. The plan is for + // - Skin to stop storing it's own title + // - includable special pages to stop using $wgTitle and $wgOut + // - and OutputPage to store it's own skin object instead of askin $wgUser + // Once just about any of those are implemented preloading will not be necessarily + $wgOut->getSkin(); + $oldTitle = $wgTitle; $oldOut = $wgOut; $wgOut = new OutputPage; @@ -862,18 +870,21 @@ class SpecialPage { * Output an error message telling the user what access level they have to have */ function displayRestrictionError() { - global $wgOut; - $wgOut->permissionRequired( $this->mRestriction ); + $this->getOutput()->permissionRequired( $this->mRestriction ); } /** * Sets headers - this should be called from the execute() method of all derived classes! */ function setHeaders() { - global $wgOut; - $wgOut->setArticleRelated( false ); - $wgOut->setRobotPolicy( "noindex,nofollow" ); - $wgOut->setPageTitle( $this->getDescription() ); + if ( $this->including() ) { + // Don't set these headers when special page is being included into an article + return; + } + $out = $this->getOutput(); + $out->setArticleRelated( false ); + $out->setRobotPolicy( "noindex,nofollow" ); + $out->setPageTitle( $this->getDescription() ); } /** @@ -909,7 +920,7 @@ class SpecialPage { * @param $summaryMessageKey String: message key of the summary */ function outputHeader( $summaryMessageKey = '' ) { - global $wgOut, $wgContLang; + global $wgContLang; if( $summaryMessageKey == '' ) { $msg = $wgContLang->lc( $this->name() ) . '-summary'; @@ -917,7 +928,7 @@ class SpecialPage { $msg = $summaryMessageKey; } if ( !wfMessage( $msg )->isBlank() and ! $this->including() ) { - $wgOut->wrapWikiMsg( "
\n$1\n
", $msg ); + $this->getOutput()->wrapWikiMsg( "
\n$1\n
", $msg ); } } @@ -1043,6 +1054,16 @@ class SpecialPage { return $this->getOutput()->getSkin(); } + /** + * Shortcut to call OutputPage::allowClickjacking(); which also takes + * transclusion into account. + */ + public function allowClickjacking() { + if ( !$this->including() ) { + $this->getOutput()->allowClickjacking(); + } + } + /** * Wrapper around wfMessage that sets the current context. Currently this * is only the title. diff --git a/includes/specials/SpecialAllpages.php b/includes/specials/SpecialAllpages.php index ec049ac55a..bb4c1d7384 100644 --- a/includes/specials/SpecialAllpages.php +++ b/includes/specials/SpecialAllpages.php @@ -64,7 +64,7 @@ class SpecialAllpages extends IncludableSpecialPage { $this->setHeaders(); $this->outputHeader(); - $out->allowClickjacking(); + $this->allowClickjacking(); # GET values $from = $request->getVal( 'from', null ); @@ -73,12 +73,17 @@ class SpecialAllpages extends IncludableSpecialPage { $namespaces = $wgContLang->getNamespaces(); - $out->setPagetitle( - ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces) ) ) ? - wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) : - wfMsg( 'allarticles' ) - ); - $out->addModuleStyles( 'mediawiki.special' ); + if( !$this->including() ) { + $out->setPagetitle( + ( $namespace > 0 && in_array( $namespace, array_keys( $namespaces) ) ) ? + wfMsg( 'allinnamespace', str_replace( '_', ' ', $namespaces[$namespace] ) ) : + wfMsg( 'allarticles' ) + ); + // Note: The following will not end up in the parser output cache as + // a result even if we wanted to load it on pages including the + // special page it would be unstable. + $out->addModuleStyles( 'mediawiki.special' ); + } if( isset($par) ) { $this->showChunk( $namespace, $par, $to ); diff --git a/includes/specials/SpecialNewimages.php b/includes/specials/SpecialNewimages.php index 7dceb24c48..123b9b82e9 100644 --- a/includes/specials/SpecialNewimages.php +++ b/includes/specials/SpecialNewimages.php @@ -27,17 +27,20 @@ class SpecialNewFiles extends IncludableSpecialPage { } public function execute( $par ){ - global $wgOut; - $this->setHeaders(); $this->outputHeader(); $pager = new NewFilesPager( $par ); - $form = $pager->getForm(); - $form->prepareForm(); - $form->displayForm( '' ); - $wgOut->addHTML( $pager->getBody() . $pager->getNavigationBar() ); + if ( !$this->including() ) { + $form = $pager->getForm(); + $form->prepareForm(); + $form->displayForm( '' ); + } + $this->getOutput()->addHTML( $pager->getBody() ); + if ( !$this->including() ) { + $this->getOutput()->addHTML( $pager->getNavigationBar() ); + } } } diff --git a/includes/specials/SpecialNewpages.php b/includes/specials/SpecialNewpages.php index 79c1af9de6..92fb4fb084 100644 --- a/includes/specials/SpecialNewpages.php +++ b/includes/specials/SpecialNewpages.php @@ -35,11 +35,6 @@ class SpecialNewpages extends IncludableSpecialPage { */ protected $opts; - /** - * @var Skin - */ - protected $skin; - // Some internal settings protected $showNavigation = false; @@ -48,16 +43,16 @@ class SpecialNewpages extends IncludableSpecialPage { } protected function setup( $par ) { - global $wgRequest, $wgUser, $wgEnableNewpagesUserFilter; + global $wgEnableNewpagesUserFilter; // Options $opts = new FormOptions(); $this->opts = $opts; // bind $opts->add( 'hideliu', false ); - $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'newpageshidepatrolled' ) ); + $opts->add( 'hidepatrolled', $this->getUser()->getBoolOption( 'newpageshidepatrolled' ) ); $opts->add( 'hidebots', false ); $opts->add( 'hideredirs', true ); - $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) ); + $opts->add( 'limit', (int)$this->getUser()->getOption( 'rclimit' ) ); $opts->add( 'offset', '' ); $opts->add( 'namespace', '0' ); $opts->add( 'username', '' ); @@ -65,7 +60,7 @@ class SpecialNewpages extends IncludableSpecialPage { $opts->add( 'tagfilter', '' ); // Set values - $opts->fetchValuesFromRequest( $wgRequest ); + $opts->fetchValuesFromRequest( $this->getRequest() ); if ( $par ) $this->parseParams( $par ); // Validate @@ -73,9 +68,6 @@ class SpecialNewpages extends IncludableSpecialPage { if( !$wgEnableNewpagesUserFilter ) { $opts->setValue( 'username', '' ); } - - // Store some objects - $this->skin = $wgUser->getSkin(); } protected function parseParams( $par ) { @@ -128,7 +120,7 @@ class SpecialNewpages extends IncludableSpecialPage { * @return String */ public function execute( $par ) { - global $wgOut; + $out = $this->getOutput(); $this->setHeaders(); $this->outputHeader(); @@ -156,14 +148,14 @@ class SpecialNewpages extends IncludableSpecialPage { if ( $this->showNavigation ) { $navigation = $pager->getNavigationBar(); } - $wgOut->addHTML( $navigation . $pager->getBody() . $navigation ); + $out->addHTML( $navigation . $pager->getBody() . $navigation ); } else { - $wgOut->addWikiMsg( 'specialpage-empty' ); + $out->addWikiMsg( 'specialpage-empty' ); } } protected function filterLinks() { - global $wgGroupPermissions, $wgUser, $wgLang; + global $wgGroupPermissions, $wgLang; // show/hide links $showhide = array( wfMsgHtml( 'show' ), wfMsgHtml( 'hide' ) ); @@ -182,7 +174,7 @@ class SpecialNewpages extends IncludableSpecialPage { unset( $filters['hideliu'] ); } - if ( !$wgUser->useNPPatrol() ) { + if ( !$this->getUser()->useNPPatrol() ) { unset( $filters['hidepatrolled'] ); } @@ -193,7 +185,7 @@ class SpecialNewpages extends IncludableSpecialPage { $self = $this->getTitle(); foreach ( $filters as $key => $msg ) { $onoff = 1 - $this->opts->getValue( $key ); - $link = $this->skin->link( $self, $showhide[$onoff], array(), + $link = $this->getSkin()->link( $self, $showhide[$onoff], array(), array( $key => $onoff ) + $changed ); $links[$key] = wfMsgHtml( $msg, $link ); @@ -203,7 +195,7 @@ class SpecialNewpages extends IncludableSpecialPage { } protected function form() { - global $wgOut, $wgEnableNewpagesUserFilter, $wgScript; + global $wgEnableNewpagesUserFilter, $wgScript; // Consume values $this->opts->consumeValue( 'offset' ); // don't carry offset, DWIW @@ -272,13 +264,13 @@ class SpecialNewpages extends IncludableSpecialPage { $hidden . Xml::closeElement( 'form' ); - $wgOut->addHTML( $form ); + $this->getOutput()->addHTML( $form ); } protected function setSyndicated() { - global $wgOut; - $wgOut->setSyndicated( true ); - $wgOut->setFeedAppendQuery( wfArrayToCGI( $this->opts->getAllValues() ) ); + $out = $this->getOutput(); + $out->setSyndicated( true ); + $out->setFeedAppendQuery( wfArrayToCGI( $this->opts->getAllValues() ) ); } /** @@ -314,14 +306,14 @@ class SpecialNewpages extends IncludableSpecialPage { $query['rcid'] = $result->rc_id; } - $plink = $this->skin->linkKnown( + $plink = $this->getSkin()->linkKnown( $title, null, array( 'class' => 'mw-newpages-pagename' ), $query, array( 'known' ) // Set explicitly to avoid the default of 'known','noclasses'. This breaks the colouration for stubs ); - $histLink = $this->skin->linkKnown( + $histLink = $this->getSkin()->linkKnown( $title, wfMsgHtml( 'hist' ), array(), @@ -334,8 +326,8 @@ class SpecialNewpages extends IncludableSpecialPage { ']' ); - $ulink = $this->skin->revUserTools( $rev ); - $comment = $this->skin->revComment( $rev ); + $ulink = $this->getSkin()->revUserTools( $rev ); + $comment = $this->getSkin()->revComment( $rev ); if ( $this->patrollable( $result ) ) { $classes[] = 'not-patrolled'; @@ -366,8 +358,7 @@ class SpecialNewpages extends IncludableSpecialPage { * @return Boolean */ protected function patrollable( $result ) { - global $wgUser; - return ( $wgUser->useNPPatrol() && !$result->rc_patrolled ); + return ( $this->getUser()->useNPPatrol() && !$result->rc_patrolled ); } /** @@ -376,7 +367,7 @@ class SpecialNewpages extends IncludableSpecialPage { * @param $type String */ protected function feed( $type ) { - global $wgFeed, $wgFeedClasses, $wgFeedLimit, $wgOut; + global $wgFeed, $wgFeedClasses, $wgFeedLimit; if ( !$wgFeed ) { $wgOut->addWikiMsg( 'feed-unavailable' ); @@ -384,7 +375,7 @@ class SpecialNewpages extends IncludableSpecialPage { } if( !isset( $wgFeedClasses[$type] ) ) { - $wgOut->addWikiMsg( 'feed-invalid' ); + $this->getOut()->addWikiMsg( 'feed-invalid' ); return; } @@ -471,7 +462,7 @@ class NewPagesPager extends ReverseChronologicalPager { } function getQueryInfo() { - global $wgEnableNewpagesUserFilter, $wgGroupPermissions, $wgUser; + global $wgEnableNewpagesUserFilter, $wgGroupPermissions; $conds = array(); $conds['rc_new'] = 1; @@ -497,7 +488,7 @@ class NewPagesPager extends ReverseChronologicalPager { $conds['rc_user'] = 0; } # If this user cannot see patrolled edits or they are off, don't do dumb queries! - if( $this->opts->getValue( 'hidepatrolled' ) && $wgUser->useNPPatrol() ) { + if( $this->opts->getValue( 'hidepatrolled' ) && $this->getUser()->useNPPatrol() ) { $conds['rc_patrolled'] = 0; } if( $this->opts->getValue( 'hidebots' ) ) { diff --git a/includes/specials/SpecialRecentchanges.php b/includes/specials/SpecialRecentchanges.php index dced986b59..936a0537f6 100644 --- a/includes/specials/SpecialRecentchanges.php +++ b/includes/specials/SpecialRecentchanges.php @@ -39,18 +39,17 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return FormOptions */ public function getDefaultOptions() { - global $wgUser; $opts = new FormOptions(); - $opts->add( 'days', (int)$wgUser->getOption( 'rcdays' ) ); - $opts->add( 'limit', (int)$wgUser->getOption( 'rclimit' ) ); + $opts->add( 'days', (int)$this->getUser()->getOption( 'rcdays' ) ); + $opts->add( 'limit', (int)$this->getUser()->getOption( 'rclimit' ) ); $opts->add( 'from', '' ); - $opts->add( 'hideminor', $wgUser->getBoolOption( 'hideminor' ) ); + $opts->add( 'hideminor', $this->getUser()->getBoolOption( 'hideminor' ) ); $opts->add( 'hidebots', true ); $opts->add( 'hideanons', false ); $opts->add( 'hideliu', false ); - $opts->add( 'hidepatrolled', $wgUser->getBoolOption( 'hidepatrolled' ) ); + $opts->add( 'hidepatrolled', $this->getUser()->getBoolOption( 'hidepatrolled' ) ); $opts->add( 'hidemyself', false ); $opts->add( 'namespace', '', FormOptions::INTNULL ); @@ -212,11 +211,10 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return String or false */ public function checkLastModified( $feedFormat ) { - global $wgOut, $wgUser; $dbr = wfGetDB( DB_SLAVE ); $lastmod = $dbr->selectField( 'recentchanges', 'MAX(rc_timestamp)', false, __METHOD__ ); - if( $feedFormat || !$wgUser->useRCPatrol() ) { - if( $lastmod && $wgOut->checkLastModified( $lastmod ) ) { + if( $feedFormat || !$this->getUser()->useRCPatrol() ) { + if( $lastmod && $this->getOutput()->checkLastModified( $lastmod ) ) { # Client cache fresh and headers sent, nothing more to do. return false; } @@ -231,8 +229,6 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return array */ public function buildMainQueryConds( FormOptions $opts ) { - global $wgUser; - $dbr = wfGetDB( DB_SLAVE ); $conds = array(); @@ -264,7 +260,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { $conds[] = 'rc_timestamp >= ' . $dbr->addQuotes( $cutoff ); - $hidePatrol = $wgUser->useRCPatrol() && $opts['hidepatrolled']; + $hidePatrol = $this->getUser()->useRCPatrol() && $opts['hidepatrolled']; $hideLoggedInUsers = $opts['hideliu'] && !$forcebot; $hideAnonymousUsers = $opts['hideanons'] && !$forcebot; @@ -276,10 +272,10 @@ class SpecialRecentChanges extends IncludableSpecialPage { if( $hideAnonymousUsers ) $conds[] = 'rc_user != 0'; if( $opts['hidemyself'] ) { - if( $wgUser->getId() ) { - $conds[] = 'rc_user != ' . $dbr->addQuotes( $wgUser->getId() ); + if( $this->getUser()->getId() ) { + $conds[] = 'rc_user != ' . $dbr->addQuotes( $this->getUser()->getId() ); } else { - $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $wgUser->getName() ); + $conds[] = 'rc_user_text != ' . $dbr->addQuotes( $this->getUser()->getName() ); } } @@ -315,13 +311,11 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @return database result or false (for Recentchangeslinked only) */ public function doMainQuery( $conds, $opts ) { - global $wgUser; - $tables = array( 'recentchanges' ); $join_conds = array(); $query_options = array( 'USE INDEX' => array('recentchanges' => 'rc_timestamp') ); - $uid = $wgUser->getId(); + $uid = $this->getUser()->getId(); $dbr = wfGetDB( DB_SLAVE ); $limit = $opts['limit']; $namespace = $opts['namespace']; @@ -334,7 +328,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { $join_conds['watchlist'] = array('LEFT JOIN', "wl_user={$uid} AND wl_title=rc_title AND wl_namespace=rc_namespace"); } - if ($wgUser->isAllowed("rollback")) { + if ($this->getUser()->isAllowed("rollback")) { $tables[] = 'page'; $join_conds['page'] = array('LEFT JOIN', 'rc_cur_id=page_id'); } @@ -397,7 +391,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @param $opts FormOptions */ public function webOutput( $rows, $opts ) { - global $wgOut, $wgUser, $wgRCShowWatchingUsers, $wgShowUpdatedMarker; + global $wgOut, $wgRCShowWatchingUsers, $wgShowUpdatedMarker; global $wgAllowCategorizedRecentChanges; $limit = $opts['limit']; @@ -414,13 +408,13 @@ class SpecialRecentChanges extends IncludableSpecialPage { $this->filterByCategories( $rows, $opts ); } - $showWatcherCount = $wgRCShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ); + $showWatcherCount = $wgRCShowWatchingUsers && $this->getUser()->getOption( 'shownumberswatching' ); $watcherCache = array(); $dbr = wfGetDB( DB_SLAVE ); $counter = 1; - $list = ChangesList::newFromUser( $wgUser ); + $list = ChangesList::newFromUser( $this->getUser() ); $s = $list->beginRecentChangesList(); foreach( $rows as $obj ) { @@ -664,14 +658,12 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @param $active Boolean: whether to show the link in bold */ function makeOptionsLink( $title, $override, $options, $active = false ) { - global $wgUser; - $sk = $wgUser->getSkin(); $params = $override + $options; if ( $active ) { - return $sk->link( $this->getTitle(), '' . htmlspecialchars( $title ) . '', + return $this->getSkin()->link( $this->getTitle(), '' . htmlspecialchars( $title ) . '', array(), $params, array( 'known' ) ); } else { - return $sk->link( $this->getTitle(), htmlspecialchars( $title ), array() , $params, array( 'known' ) ); + return $this->getSkin()->link( $this->getTitle(), htmlspecialchars( $title ), array() , $params, array( 'known' ) ); } } @@ -682,7 +674,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { * @param $nondefaults Array */ function optionsPanel( $defaults, $nondefaults ) { - global $wgLang, $wgUser, $wgRCLinkLimits, $wgRCLinkDays; + global $wgLang, $wgRCLinkLimits, $wgRCLinkDays; $options = $nondefaults + $defaults; @@ -740,7 +732,7 @@ class SpecialRecentChanges extends IncludableSpecialPage { $links[] = wfMsgHtml( 'rcshowhidebots', $botLink ); $links[] = wfMsgHtml( 'rcshowhideanons', $anonsLink ); $links[] = wfMsgHtml( 'rcshowhideliu', $liuLink ); - if( $wgUser->useRCPatrol() ) + if( $this->getUser()->useRCPatrol() ) $links[] = wfMsgHtml( 'rcshowhidepatr', $patrLink ); $links[] = wfMsgHtml( 'rcshowhidemine', $myselfLink ); $hl = $wgLang->pipeList( $links ); -- 2.20.1