* 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...
}
$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' ) {
$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();
'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' ),
$par = $bits[1];
}
$page = SpecialPage::getPageByAlias( $name );
-
# Nonexistent?
if ( !$page ) {
if ( !$including ) {
* @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;
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.
* @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 ) {