r43462 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43461‎ | r43462 | r43463 >
Date:22:20, 13 November 2008
Author:aaron
Status:old
Tags:
Comment:
Various code/style/performance tweaks
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -337,7 +337,10 @@
338338 public static function nameOf( $id ) {
339339 $dbr = wfGetDB( DB_SLAVE );
340340
341 - $s = $dbr->selectRow( 'page', array( 'page_namespace','page_title' ), array( 'page_id' => $id ), __METHOD__ );
 341+ $s = $dbr->selectRow( 'page',
 342+ array( 'page_namespace','page_title' ),
 343+ array( 'page_id' => $id ),
 344+ __METHOD__ );
342345 if ( $s === false ) { return NULL; }
343346
344347 $n = self::makeName( $s->page_namespace, $s->page_title );
@@ -1285,7 +1288,8 @@
12861289
12871290 $dbr = wfGetDB( DB_SLAVE );
12881291 $res = $dbr->select( 'protected_titles', '*',
1289 - array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()) );
 1292+ array( 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ),
 1293+ __METHOD__ );
12901294
12911295 if ($row = $dbr->fetchRow( $res )) {
12921296 return $row;
@@ -1355,7 +1359,8 @@
13561360 $dbw = wfGetDB( DB_MASTER );
13571361
13581362 $dbw->delete( 'protected_titles',
1359 - array ('pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey()), __METHOD__ );
 1363+ array( 'pt_namespace' => $this->getNamespace(), 'pt_title' => $this->getDBkey() ),
 1364+ __METHOD__ );
13601365 }
13611366
13621367 /**
@@ -1392,8 +1397,7 @@
13931398 * @return \type{\bool} TRUE or FALSE
13941399 */
13951400 public function isMovable() {
1396 - return MWNamespace::isMovable( $this->getNamespace() )
1397 - && $this->getInterwiki() == '';
 1401+ return MWNamespace::isMovable( $this->getNamespace() ) && $this->getInterwiki() == '';
13981402 }
13991403
14001404 /**
@@ -1871,6 +1875,9 @@
18721876 * @return \type{\int} the ID
18731877 */
18741878 public function getArticleID( $flags = 0 ) {
 1879+ if( $this->getNamespace() < 0 ) {
 1880+ return $this->mArticleID = 0;
 1881+ }
18751882 $linkCache = LinkCache::singleton();
18761883 if( $flags & GAID_FOR_UPDATE ) {
18771884 $oldUpdate = $linkCache->forUpdate( true );
@@ -1894,10 +1901,9 @@
18951902 public function isRedirect( $flags = 0 ) {
18961903 if( !is_null($this->mRedirect) )
18971904 return $this->mRedirect;
1898 - # Zero for special pages.
1899 - # Also, calling getArticleID() loads the field from cache!
1900 - if( !$this->getArticleID($flags) || $this->getNamespace() == NS_SPECIAL ) {
1901 - return false;
 1905+ # Calling getArticleID() loads the field from cache as needed
 1906+ if( !$this->getArticleID($flags) ) {
 1907+ return $this->mRedirect = false;
19021908 }
19031909 $linkCache = LinkCache::singleton();
19041910 $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' );
@@ -1914,10 +1920,9 @@
19151921 public function getLength( $flags = 0 ) {
19161922 if( $this->mLength != -1 )
19171923 return $this->mLength;
1918 - # Zero for special pages.
1919 - # Also, calling getArticleID() loads the field from cache!
1920 - if( !$this->getArticleID($flags) || $this->getNamespace() == NS_SPECIAL ) {
1921 - return 0;
 1924+ # Calling getArticleID() loads the field from cache as needed
 1925+ if( !$this->getArticleID($flags) ) {
 1926+ return $this->mLength = 0;
19221927 }
19231928 $linkCache = LinkCache::singleton();
19241929 $this->mLength = intval( $linkCache->getGoodLinkFieldObj( $this, 'length' ) );
@@ -1935,9 +1940,7 @@
19361941 return $this->mLatestID;
19371942
19381943 $db = ($flags & GAID_FOR_UPDATE) ? wfGetDB(DB_MASTER) : wfGetDB(DB_SLAVE);
1939 - $this->mLatestID = $db->selectField( 'page', 'page_latest',
1940 - array( 'page_namespace' => $this->getNamespace(), 'page_title' => $this->getDBKey() ),
1941 - __METHOD__ );
 1944+ $this->mLatestID = $db->selectField( 'page', 'page_latest', $this->pageCond(), __METHOD__ );
19421945 return $this->mLatestID;
19431946 }
19441947
@@ -1967,26 +1970,19 @@
19681971 */
19691972 public function invalidateCache() {
19701973 global $wgUseFileCache;
1971 -
1972 - if ( wfReadOnly() ) {
 1974+ if( wfReadOnly() ) {
19731975 return;
19741976 }
1975 -
19761977 $dbw = wfGetDB( DB_MASTER );
19771978 $success = $dbw->update( 'page',
1978 - array( /* SET */
1979 - 'page_touched' => $dbw->timestamp()
1980 - ), array( /* WHERE */
1981 - 'page_namespace' => $this->getNamespace() ,
1982 - 'page_title' => $this->getDBkey()
1983 - ), 'Title::invalidateCache'
 1979+ array( 'page_touched' => $dbw->timestamp() ),
 1980+ $this->pageCond(),
 1981+ __METHOD__
19841982 );
1985 -
1986 - if ($wgUseFileCache) {
1987 - $cache = new HTMLFileCache($this);
1988 - @unlink($cache->fileCacheName());
 1983+ if( $wgUseFileCache) {
 1984+ $cache = new HTMLFileCache( $this );
 1985+ @unlink( $cache->fileCacheName() );
19891986 }
1990 -
19911987 return $success;
19921988 }
19931989
@@ -2838,24 +2834,19 @@
28392835 * Checks if this page is just a one-rev redirect.
28402836 * Adds lock, so don't use just for light purposes.
28412837 *
2842 - * @param $curId \type{int} page ID, optional
28432838 * @return \type{\bool} TRUE or FALSE
28442839 */
2845 - public function isSingleRevRedirect( $curId = 0 ) {
 2840+ public function isSingleRevRedirect() {
28462841 $dbw = wfGetDB( DB_MASTER );
2847 - $curId = $curId ? $curId : $this->getArticleId();
2848 - # Nothing here?
2849 - if( !$curId ) {
2850 - return true;
2851 - }
28522842 # Is it a redirect?
28532843 $row = $dbw->selectRow( 'page',
2854 - array( 'page_is_redirect', 'page_latest' ),
2855 - array( 'page_id' => $curId ),
 2844+ array( 'page_is_redirect', 'page_latest', 'page_id' ),
 2845+ $this->pageCond(),
28562846 __METHOD__,
28572847 'FOR UPDATE'
28582848 );
28592849 # Cache some fields we may want
 2850+ $this->mArticleID = $row ? intval($row->page_id) : 0;
28602851 $this->mRedirect = $row ? (bool)$row->page_is_redirect : false;
28612852 $this->mLatestID = $row ? intval($row->page_latest) : false;
28622853 if( !$this->mRedirect ) {
@@ -2926,8 +2917,7 @@
29272918 * @return \type{\bool} TRUE or FALSE
29282919 */
29292920 public function isWatchable() {
2930 - return !$this->isExternal()
2931 - && MWNamespace::isWatchable( $this->getNamespace() );
 2921+ return !$this->isExternal() && MWNamespace::isWatchable( $this->getNamespace() );
29322922 }
29332923
29342924 /**
@@ -3155,12 +3145,7 @@
31563146 */
31573147 public function getTouched( $db = NULL ) {
31583148 $db = isset($db) ? $db : wfGetDB( DB_SLAVE );
3159 - $touched = $db->selectField( 'page', 'page_touched',
3160 - array(
3161 - 'page_namespace' => $this->getNamespace(),
3162 - 'page_title' => $this->getDBkey()
3163 - ), __METHOD__
3164 - );
 3149+ $touched = $db->selectField( 'page', 'page_touched', $this->pageCond(), __METHOD__ );
31653150 return $touched;
31663151 }
31673152

Status & tagging log