* Shortcutted Title::userCanRead() for public wikis
authorDomas Mituzas <midom@users.mediawiki.org>
Mon, 14 Jan 2008 10:23:48 +0000 (10:23 +0000)
committerDomas Mituzas <midom@users.mediawiki.org>
Mon, 14 Jan 2008 10:23:48 +0000 (10:23 +0000)
* 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
includes/SpecialPage.php
includes/SpecialRandompage.php
includes/Title.php

index a0f3fca..0503e2a 100644 (file)
@@ -592,22 +592,6 @@ class OutputPage {
                }
                $fname = 'OutputPage::output';
                wfProfileIn( $fname );
-               $sk = $wgUser->getSkin();
-
-               if ( $wgUseAjax ) {
-                       $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
-
-                       wfRunHooks( 'AjaxAddScript', array( &$this ) );
-
-                       if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) {
-                               $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
-                               $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
-                       }
-
-                       if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
-                               $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\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( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
+
+                       wfRunHooks( 'AjaxAddScript', array( &$this ) );
+
+                       if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) {
+                               $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
+                               $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
+                       }
+
+                       if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
+                               $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
+                       }
+               }
+
+
+
                # Buffer output; final headers may depend on later processing
                ob_start();
 
index 83e0df4..e152c77 100644 (file)
@@ -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 ) {
index 4273427..0e8e477 100644 (file)
@@ -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.
index 517941b..61f7c9a 100644 (file)
@@ -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 ) {