r29725 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r29724‎ | r29725 | r29726 >
Date:10:23, 14 January 2008
Author:midom
Status:old
Tags:
Comment:
* 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...
Modified paths:
  • /trunk/phase3/includes/OutputPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialPage.php (modified) (history)
  • /trunk/phase3/includes/SpecialRandompage.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/OutputPage.php
@@ -592,23 +592,7 @@
593593 }
594594 $fname = 'OutputPage::output';
595595 wfProfileIn( $fname );
596 - $sk = $wgUser->getSkin();
597596
598 - if ( $wgUseAjax ) {
599 - $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
600 -
601 - wfRunHooks( 'AjaxAddScript', array( &$this ) );
602 -
603 - if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) {
604 - $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
605 - $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
606 - }
607 -
608 - if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
609 - $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
610 - }
611 - }
612 -
613597 if ( '' != $this->mRedirect ) {
614598 if( substr( $this->mRedirect, 0, 4 ) != 'http' ) {
615599 # Standards require redirect URLs to be absolute
@@ -691,6 +675,25 @@
692676 $wgRequest->response()->header( 'HTTP/1.1 ' . $this->mStatusCode . ' ' . $statusMessage[$this->mStatusCode] );
693677 }
694678
 679+ $sk = $wgUser->getSkin();
 680+
 681+ if ( $wgUseAjax ) {
 682+ $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajax.js?$wgStyleVersion\"></script>\n" );
 683+
 684+ wfRunHooks( 'AjaxAddScript', array( &$this ) );
 685+
 686+ if( $wgAjaxSearch && $wgUser->getBoolOption( 'ajaxsearch' ) ) {
 687+ $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxsearch.js?$wgStyleVersion\"></script>\n" );
 688+ $this->addScript( "<script type=\"{$wgJsMimeType}\">hookEvent(\"load\", sajax_onload);</script>\n" );
 689+ }
 690+
 691+ if( $wgAjaxWatch && $wgUser->isLoggedIn() ) {
 692+ $this->addScript( "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/ajaxwatch.js?$wgStyleVersion\"></script>\n" );
 693+ }
 694+ }
 695+
 696+
 697+
695698 # Buffer output; final headers may depend on later processing
696699 ob_start();
697700
Index: trunk/phase3/includes/Title.php
@@ -1370,8 +1370,12 @@
13711371 * @todo fold these checks into userCan()
13721372 */
13731373 public function userCanRead() {
1374 - global $wgUser;
1375 -
 1374+ global $wgUser, $wgGroupPermissions;
 1375+
 1376+ # Shortcut for public wikis, allows skipping quite a bit of code path
 1377+ if ($wgGroupPermissions['*']['read'])
 1378+ return true;
 1379+
13761380 $result = null;
13771381 wfRunHooks( 'userCan', array( &$this, &$wgUser, 'read', &$result ) );
13781382 if ( $result !== null ) {
Index: trunk/phase3/includes/SpecialPage.php
@@ -89,7 +89,7 @@
9090 'Newimages' => array( 'IncludableSpecialPage', 'Newimages' ),
9191 'Listusers' => array( 'SpecialPage', 'Listusers' ),
9292 'Statistics' => array( 'SpecialPage', 'Statistics' ),
93 - 'Randompage' => array( 'SpecialPage', 'Randompage' ),
 93+ 'Randompage' => 'Randompage',
9494 'Lonelypages' => array( 'SpecialPage', 'Lonelypages' ),
9595 'Uncategorizedpages' => array( 'SpecialPage', 'Uncategorizedpages' ),
9696 'Uncategorizedcategories' => array( 'SpecialPage', 'Uncategorizedcategories' ),
@@ -408,7 +408,6 @@
409409 $par = $bits[1];
410410 }
411411 $page = SpecialPage::getPageByAlias( $name );
412 -
413412 # Nonexistent?
414413 if ( !$page ) {
415414 if ( !$including ) {
Index: trunk/phase3/includes/SpecialRandompage.php
@@ -9,40 +9,29 @@
1010 */
1111
1212 /**
13 - * Main execution point
14 - * @param $par Namespace to select the page from
15 - */
16 -function wfSpecialRandompage( $par = null ) {
17 - global $wgOut, $wgContLang;
18 -
19 - $rnd = new RandomPage();
20 - $rnd->setNamespace( $wgContLang->getNsIndex( $par ) );
21 - $rnd->setRedirect( false );
22 -
23 - $title = $rnd->getRandomTitle();
24 -
25 - if( is_null( $title ) ) {
26 - $wgOut->addWikiText( wfMsg( 'randompage-nopages' ) );
27 - return;
28 - }
29 -
30 - $wgOut->reportTime();
31 - $wgOut->redirect( $title->getFullUrl() );
32 -}
33 -
34 -
35 -/**
3613 * Special page to direct the user to a random page
3714 *
3815 * @addtogroup SpecialPage
3916 */
40 -class RandomPage {
 17+class RandomPage extends SpecialPage {
4118 private $namespace = NS_MAIN; // namespace to select pages from
4219 private $redirect = false; // select redirects instead of normal pages?
4320
4421 public function getNamespace ( ) {
4522 return $this->namespace;
4623 }
 24+
 25+ function getTitle($par=null) {
 26+ return SpecialPage::getTitleFor("Randompage");
 27+ }
 28+
 29+ function getLocalName() {
 30+ return SpecialPage::getLocalNameFor("Randompage");
 31+ }
 32+
 33+ public function setHeaders() {}
 34+ public function outputHeader() {}
 35+
4736 public function setNamespace ( $ns ) {
4837 if( $ns < NS_MAIN ) $ns = NS_MAIN;
4938 $this->namespace = $ns;
@@ -53,7 +42,25 @@
5443 public function setRedirect ( $redirect ) {
5544 $this->redirect = $redirect;
5645 }
 46+
 47+ public function execute( $par = null ) {
 48+ global $wgOut, $wgContLang;
5749
 50+ if ($par)
 51+ $this->setNamespace( $wgContLang->getNsIndex( $par ) );
 52+ $this->setRedirect( false );
 53+
 54+ $title = $this->getRandomTitle();
 55+
 56+ if( is_null( $title ) ) {
 57+ $wgOut->addWikiText( wfMsg( 'randompage-nopages' ) );
 58+ return;
 59+ }
 60+
 61+ $wgOut->redirect( $title->getFullUrl() );
 62+ }
 63+
 64+
5865 /**
5966 * Choose a random title.
6067 * @return Title object (or null if nothing to choose from)

Follow-up revisions

RevisionCommit summaryAuthorDate
r29736Cleanup for Special:Randompage and Special: Randomredirect after r29725 - htt......midom12:50, 14 January 2008

Status & tagging log