Index: trunk/phase3/includes/Title.php |
— | — | @@ -337,7 +337,10 @@ |
338 | 338 | public static function nameOf( $id ) { |
339 | 339 | $dbr = wfGetDB( DB_SLAVE ); |
340 | 340 | |
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__ ); |
342 | 345 | if ( $s === false ) { return NULL; } |
343 | 346 | |
344 | 347 | $n = self::makeName( $s->page_namespace, $s->page_title ); |
— | — | @@ -1285,7 +1288,8 @@ |
1286 | 1289 | |
1287 | 1290 | $dbr = wfGetDB( DB_SLAVE ); |
1288 | 1291 | $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__ ); |
1290 | 1294 | |
1291 | 1295 | if ($row = $dbr->fetchRow( $res )) { |
1292 | 1296 | return $row; |
— | — | @@ -1355,7 +1359,8 @@ |
1356 | 1360 | $dbw = wfGetDB( DB_MASTER ); |
1357 | 1361 | |
1358 | 1362 | $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__ ); |
1360 | 1365 | } |
1361 | 1366 | |
1362 | 1367 | /** |
— | — | @@ -1392,8 +1397,7 @@ |
1393 | 1398 | * @return \type{\bool} TRUE or FALSE |
1394 | 1399 | */ |
1395 | 1400 | public function isMovable() { |
1396 | | - return MWNamespace::isMovable( $this->getNamespace() ) |
1397 | | - && $this->getInterwiki() == ''; |
| 1401 | + return MWNamespace::isMovable( $this->getNamespace() ) && $this->getInterwiki() == ''; |
1398 | 1402 | } |
1399 | 1403 | |
1400 | 1404 | /** |
— | — | @@ -1871,6 +1875,9 @@ |
1872 | 1876 | * @return \type{\int} the ID |
1873 | 1877 | */ |
1874 | 1878 | public function getArticleID( $flags = 0 ) { |
| 1879 | + if( $this->getNamespace() < 0 ) { |
| 1880 | + return $this->mArticleID = 0; |
| 1881 | + } |
1875 | 1882 | $linkCache = LinkCache::singleton(); |
1876 | 1883 | if( $flags & GAID_FOR_UPDATE ) { |
1877 | 1884 | $oldUpdate = $linkCache->forUpdate( true ); |
— | — | @@ -1894,10 +1901,9 @@ |
1895 | 1902 | public function isRedirect( $flags = 0 ) { |
1896 | 1903 | if( !is_null($this->mRedirect) ) |
1897 | 1904 | 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; |
1902 | 1908 | } |
1903 | 1909 | $linkCache = LinkCache::singleton(); |
1904 | 1910 | $this->mRedirect = (bool)$linkCache->getGoodLinkFieldObj( $this, 'redirect' ); |
— | — | @@ -1914,10 +1920,9 @@ |
1915 | 1921 | public function getLength( $flags = 0 ) { |
1916 | 1922 | if( $this->mLength != -1 ) |
1917 | 1923 | 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; |
1922 | 1927 | } |
1923 | 1928 | $linkCache = LinkCache::singleton(); |
1924 | 1929 | $this->mLength = intval( $linkCache->getGoodLinkFieldObj( $this, 'length' ) ); |
— | — | @@ -1935,9 +1940,7 @@ |
1936 | 1941 | return $this->mLatestID; |
1937 | 1942 | |
1938 | 1943 | $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__ ); |
1942 | 1945 | return $this->mLatestID; |
1943 | 1946 | } |
1944 | 1947 | |
— | — | @@ -1967,26 +1970,19 @@ |
1968 | 1971 | */ |
1969 | 1972 | public function invalidateCache() { |
1970 | 1973 | global $wgUseFileCache; |
1971 | | - |
1972 | | - if ( wfReadOnly() ) { |
| 1974 | + if( wfReadOnly() ) { |
1973 | 1975 | return; |
1974 | 1976 | } |
1975 | | - |
1976 | 1977 | $dbw = wfGetDB( DB_MASTER ); |
1977 | 1978 | $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__ |
1984 | 1982 | ); |
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() ); |
1989 | 1986 | } |
1990 | | - |
1991 | 1987 | return $success; |
1992 | 1988 | } |
1993 | 1989 | |
— | — | @@ -2838,24 +2834,19 @@ |
2839 | 2835 | * Checks if this page is just a one-rev redirect. |
2840 | 2836 | * Adds lock, so don't use just for light purposes. |
2841 | 2837 | * |
2842 | | - * @param $curId \type{int} page ID, optional |
2843 | 2838 | * @return \type{\bool} TRUE or FALSE |
2844 | 2839 | */ |
2845 | | - public function isSingleRevRedirect( $curId = 0 ) { |
| 2840 | + public function isSingleRevRedirect() { |
2846 | 2841 | $dbw = wfGetDB( DB_MASTER ); |
2847 | | - $curId = $curId ? $curId : $this->getArticleId(); |
2848 | | - # Nothing here? |
2849 | | - if( !$curId ) { |
2850 | | - return true; |
2851 | | - } |
2852 | 2842 | # Is it a redirect? |
2853 | 2843 | $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(), |
2856 | 2846 | __METHOD__, |
2857 | 2847 | 'FOR UPDATE' |
2858 | 2848 | ); |
2859 | 2849 | # Cache some fields we may want |
| 2850 | + $this->mArticleID = $row ? intval($row->page_id) : 0; |
2860 | 2851 | $this->mRedirect = $row ? (bool)$row->page_is_redirect : false; |
2861 | 2852 | $this->mLatestID = $row ? intval($row->page_latest) : false; |
2862 | 2853 | if( !$this->mRedirect ) { |
— | — | @@ -2926,8 +2917,7 @@ |
2927 | 2918 | * @return \type{\bool} TRUE or FALSE |
2928 | 2919 | */ |
2929 | 2920 | public function isWatchable() { |
2930 | | - return !$this->isExternal() |
2931 | | - && MWNamespace::isWatchable( $this->getNamespace() ); |
| 2921 | + return !$this->isExternal() && MWNamespace::isWatchable( $this->getNamespace() ); |
2932 | 2922 | } |
2933 | 2923 | |
2934 | 2924 | /** |
— | — | @@ -3155,12 +3145,7 @@ |
3156 | 3146 | */ |
3157 | 3147 | public function getTouched( $db = NULL ) { |
3158 | 3148 | $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__ ); |
3165 | 3150 | return $touched; |
3166 | 3151 | } |
3167 | 3152 | |