From b96e0c7b928cffec7af1735ca355e5ce0f4f3d1c Mon Sep 17 00:00:00 2001 From: Domas Mituzas Date: Mon, 14 Jan 2008 10:23:48 +0000 Subject: [PATCH] * Shortcutted Title::userCanRead() for public wikis * Moved redirects code in OutputPage before skins and ajax stuff, to handle likely scenario better * Stripped off lots of fat (like... 30-50% of execution time) from Special:Randompage - mwahaha... ha... hahaha... --- includes/OutputPage.php | 35 ++++++++++++---------- includes/SpecialPage.php | 3 +- includes/SpecialRandompage.php | 55 +++++++++++++++++++--------------- includes/Title.php | 8 +++-- 4 files changed, 57 insertions(+), 44 deletions(-) diff --git a/includes/OutputPage.php b/includes/OutputPage.php index a0f3fca6ca..0503e2a136 100644 --- a/includes/OutputPage.php +++ b/includes/OutputPage.php @@ -592,22 +592,6 @@ class OutputPage { } $fname = 'OutputPage::output'; wfProfileIn( $fname ); - $sk = $wgUser->getSkin(); - - if ( $wgUseAjax ) { - $this->addScript( "\n" ); - - wfRunHooks( 'AjaxAddScript', array( &$this ) ); - - if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) { - $this->addScript( "\n" ); - $this->addScript( "\n" ); - } - - if( $wgAjaxWatch && $wgUser->isLoggedIn() ) { - $this->addScript( "\n" ); - } - } if ( '' != $this->mRedirect ) { if( substr( $this->mRedirect, 0, 4 ) != 'http' ) { @@ -691,6 +675,25 @@ class OutputPage { $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] ); } + $sk = $wgUser->getSkin(); + + if ( $wgUseAjax ) { + $this->addScript( "\n" ); + + wfRunHooks( 'AjaxAddScript', array( &$this ) ); + + if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) { + $this->addScript( "\n" ); + $this->addScript( "\n" ); + } + + if( $wgAjaxWatch && $wgUser->isLoggedIn() ) { + $this->addScript( "\n" ); + } + } + + + # Buffer output; final headers may depend on later processing ob_start(); diff --git a/includes/SpecialPage.php b/includes/SpecialPage.php index 83e0df4d1d..e152c77b05 100644 --- a/includes/SpecialPage.php +++ b/includes/SpecialPage.php @@ -89,7 +89,7 @@ class SpecialPage 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ), 'Listusers' => array( 'SpecialPage', 'Listusers' ), 'Statistics' => array( 'SpecialPage', 'Statistics' ), - 'Randompage' => array( 'SpecialPage', 'Randompage' ), + 'Randompage' => 'Randompage', 'Lonelypages' => array( 'SpecialPage', 'Lonelypages' ), 'Uncategorizedpages' => array( 'SpecialPage', 'Uncategorizedpages' ), 'Uncategorizedcategories' => array( 'SpecialPage', 'Uncategorizedcategories' ), @@ -408,7 +408,6 @@ class SpecialPage $par = $bits[1]; } $page = SpecialPage::getPageByAlias( $name ); - # Nonexistent? if ( !$page ) { if ( !$including ) { diff --git a/includes/SpecialRandompage.php b/includes/SpecialRandompage.php index 427342745e..0e8e47716d 100644 --- a/includes/SpecialRandompage.php +++ b/includes/SpecialRandompage.php @@ -8,41 +8,30 @@ * @license GNU General Public Licence 2.0 or later */ -/** - * Main execution point - * @param $par Namespace to select the page from - */ -function wfSpecialRandompage( $par = null ) { - global $wgOut, $wgContLang; - - $rnd = new RandomPage(); - $rnd->setNamespace( $wgContLang->getNsIndex( $par ) ); - $rnd->setRedirect( false ); - - $title = $rnd->getRandomTitle(); - - if( is_null( $title ) ) { - $wgOut->addWikiText( wfMsg( 'randompage-nopages' ) ); - return; - } - - $wgOut->reportTime(); - $wgOut->redirect( $title->getFullUrl() ); -} - - /** * Special page to direct the user to a random page * * @addtogroup SpecialPage */ -class RandomPage { +class RandomPage extends SpecialPage { private $namespace = NS_MAIN; // namespace to select pages from private $redirect = false; // select redirects instead of normal pages? public function getNamespace ( ) { return $this->namespace; } + + function getTitle($par=null) { + return SpecialPage::getTitleFor("Randompage"); + } + + function getLocalName() { + return SpecialPage::getLocalNameFor("Randompage"); + } + + public function setHeaders() {} + public function outputHeader() {} + public function setNamespace ( $ns ) { if( $ns < NS_MAIN ) $ns = NS_MAIN; $this->namespace = $ns; @@ -53,6 +42,24 @@ class RandomPage { public function setRedirect ( $redirect ) { $this->redirect = $redirect; } + + public function execute( $par = null ) { + global $wgOut, $wgContLang; + + if ($par) + $this->setNamespace( $wgContLang->getNsIndex( $par ) ); + $this->setRedirect( false ); + + $title = $this->getRandomTitle(); + + if( is_null( $title ) ) { + $wgOut->addWikiText( wfMsg( 'randompage-nopages' ) ); + return; + } + + $wgOut->redirect( $title->getFullUrl() ); + } + /** * Choose a random title. diff --git a/includes/Title.php b/includes/Title.php index 517941b958..61f7c9a9a6 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -1370,8 +1370,12 @@ class Title { * @todo fold these checks into userCan() */ public function userCanRead() { - global $wgUser; - + global $wgUser, $wgGroupPermissions; + + # Shortcut for public wikis, allows skipping quite a bit of code path + if ($wgGroupPermissions['*']['read']) + return true; + $result = null; wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) ); if ( $result !== null ) { -- 2.20.1