From 991f79858740fd389f943cd58e9553c2dd6df2d0 Mon Sep 17 00:00:00 2001 From: Antoine Musso Date: Tue, 11 Jan 2005 18:18:16 +0000 Subject: [PATCH] * Remove some hardcoded 0 instead of NS_MAIN * Note in define.php that people should NOT change the integer values for NS_* constants --- includes/Article.php | 2 +- includes/Database.php | 5 +++-- includes/Defines.php | 2 ++ includes/Linker.php | 2 +- includes/Skin.php | 4 ++-- includes/SpecialAllpages.php | 8 ++++---- includes/SpecialAncientpages.php | 2 +- includes/SpecialBrokenRedirects.php | 2 +- includes/SpecialLonelypages.php | 2 +- includes/SpecialMaintenance.php | 4 ++-- includes/SpecialNewpages.php | 2 +- includes/SpecialPopularpages.php | 2 +- includes/SpecialRandompage.php | 2 +- includes/SpecialShortpages.php | 2 +- includes/SpecialValidate.php | 6 +++--- includes/Title.php | 4 +++- 16 files changed, 28 insertions(+), 23 deletions(-) diff --git a/includes/Article.php b/includes/Article.php index 6099e3de85..56055cc2c5 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -2231,7 +2231,7 @@ function wfArticleIsStub( $articleID ) { array( 'LENGTH(old_text) AS len', 'page_namespace', 'page_is_redirect' ), array( 'page_id' => $articleID, "page.page_latest=text.old_id" ), $fname ) ; - if ( $s == false OR $s->page_is_redirect OR $s->page_namespace != 0 ) { + if ( $s == false OR $s->page_is_redirect OR $s->page_namespace != NS_MAIN ) { return false; } $size = $s->len; diff --git a/includes/Database.php b/includes/Database.php index 68dad7332f..0deaf93944 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -652,8 +652,9 @@ class Database { * $conds: a condition map, terms are ANDed together. * Items with numeric keys are taken to be literal conditions * Takes an array of selected variables, and a condition map, which is ANDed - * e.g. selectRow( "page", array( "page_id" ), array( "page_namespace" => 0, "page_title" => "Astronomy" ) ) - * would return an object where $obj->page_id is the ID of the Astronomy article + * e.g: selectRow( "page", array( "page_id" ), array( "page_namespace" => + * NS_MAIN, "page_title" => "Astronomy" ) ) would return an object where + * $obj- >page_id is the ID of the Astronomy article * * @todo migrate documentation to phpdocumentor format */ diff --git a/includes/Defines.php b/includes/Defines.php index f5b7e9f71b..c52b2deed1 100644 --- a/includes/Defines.php +++ b/includes/Defines.php @@ -26,6 +26,8 @@ define('NS_SPECIAL', -1); * * Number 100 and beyond are reserved for custom namespaces; * DO NOT assign standard namespaces at 100 or beyond. + * DO NOT Change integer values as they are most probably hardcoded everywhere + * see bug #696 which talked about that. */ define('NS_MAIN', 0); define('NS_TALK', 1); diff --git a/includes/Linker.php b/includes/Linker.php index 72770ab425..b671a04004 100644 --- a/includes/Linker.php +++ b/includes/Linker.php @@ -223,7 +223,7 @@ class Linker { 'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ; if ( $s !== false ) { $size = $s->x; - if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) { + if ( $s->cur_is_redirect OR $s->cur_namespace != NS_MAIN ) { $size = $threshold*2 ; # Really big } } else { diff --git a/includes/Skin.php b/includes/Skin.php index 30d013b5a8..14bb1903db 100644 --- a/includes/Skin.php +++ b/includes/Skin.php @@ -1092,7 +1092,7 @@ class Skin extends Linker { if ( 0 == count( $a ) ) { if ( !$wgUseNewInterlanguage ) return ''; $ns = $wgContLang->getNsIndex ( $wgTitle->getNamespace () ) ; - if ( $ns != 0 AND $ns != 1 ) return '' ; + if ( $ns != NS_MAIN AND $ns != NS_TALK ) return '' ; $pn = 'Intl' ; $x = 'mode=addlink&xt='.$wgTitle->getDBkey() ; return $this->makeKnownLink( $wgContLang->specialPage( $pn ), @@ -1266,7 +1266,7 @@ class Skin extends Linker { } # this can be passed the NS number as defined in Language.php - /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=0 ) { + /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) { $title = Title::makeTitleSafe( $namespace, $name ); $this->checkTitle($title, $name); return $title->getLocalURL( $urlaction ); diff --git a/includes/SpecialAllpages.php b/includes/SpecialAllpages.php index e657842f15..e21392af24 100644 --- a/includes/SpecialAllpages.php +++ b/includes/SpecialAllpages.php @@ -30,7 +30,7 @@ function wfSpecialAllpages( $par=NULL ) { } } -function namespaceForm ( $namespace = 0, $from = '' ) { +function namespaceForm ( $namespace = NS_MAIN, $from = '' ) { global $wgContLang, $wgScript; $t = Title::makeTitle( NS_SPECIAL, "Allpages" ); @@ -57,7 +57,7 @@ function namespaceForm ( $namespace = 0, $from = '' ) { return $out; } -function indexShowToplevel ( $namespace = 0 ) { +function indexShowToplevel ( $namespace = NS_MAIN ) { global $wgOut, $indexMaxperpage, $toplevelMaxperpage, $wgContLang, $wgRequest, $wgUser; $sk = $wgUser->getSkin(); $fname = "indexShowToplevel"; @@ -158,7 +158,7 @@ function indexShowToplevel ( $namespace = 0 ) { $wgOut->addHtml( $out2 . $out ); } -function indexShowline( $inpoint, $outpoint, $namespace = 0 ) { +function indexShowline( $inpoint, $outpoint, $namespace = NS_MAIN ) { global $wgOut, $wgLang, $wgUser; $sk = $wgUser->getSkin(); $dbr =& wfGetDB( DB_SLAVE ); @@ -177,7 +177,7 @@ function indexShowline( $inpoint, $outpoint, $namespace = 0 ) { return ''.$out.''; } -function indexShowChunk( $from, $namespace = 0 ) { +function indexShowChunk( $from, $namespace = NS_MAIN ) { global $wgOut, $wgUser, $indexMaxperpage, $wgContLang; $sk = $wgUser->getSkin(); $maxPlusOne = $indexMaxperpage + 1; diff --git a/includes/SpecialAncientpages.php b/includes/SpecialAncientpages.php index c847e1ead8..253c917487 100644 --- a/includes/SpecialAncientpages.php +++ b/includes/SpecialAncientpages.php @@ -38,7 +38,7 @@ class AncientPagesPage extends QueryPage { page_title as title, rev_timestamp as value FROM $page, $revision - WHERE page_namespace=0 AND page_is_redirect=0 + WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0 AND page_latest=rev_id"; } diff --git a/includes/SpecialBrokenRedirects.php b/includes/SpecialBrokenRedirects.php index 9c48cb4d3a..743e450feb 100644 --- a/includes/SpecialBrokenRedirects.php +++ b/includes/SpecialBrokenRedirects.php @@ -34,7 +34,7 @@ class BrokenRedirectsPage extends PageQueryPage { extract( $dbr->tableNames( 'page', 'brokenlinks' ) ); $sql = "SELECT bl_to,page_title FROM $brokenlinks,$page " . - "WHERE page_is_redirect=1 AND page_namespace=0 AND bl_from=page_id "; + 'WHERE page_is_redirect=1 AND page_namespace='.NS_MAIN.' AND bl_from=page_id '; return $sql; } diff --git a/includes/SpecialLonelypages.php b/includes/SpecialLonelypages.php index 86e0b8dbb4..6f0f73f7c5 100644 --- a/includes/SpecialLonelypages.php +++ b/includes/SpecialLonelypages.php @@ -36,7 +36,7 @@ class LonelyPagesPage extends PageQueryPage { return "SELECT 'Lonelypages' as type, page_namespace AS namespace, page_title AS title, page_title AS value " . "FROM $page LEFT JOIN $links ON page_id=l_to ". - "WHERE l_to IS NULL AND page_namespace=0 AND page_is_redirect=0"; + 'WHERE l_to IS NULL AND page_namespace='.NS_MAIN.' AND page_is_redirect=0'; } } diff --git a/includes/SpecialMaintenance.php b/includes/SpecialMaintenance.php index abd88a184d..265b706424 100644 --- a/includes/SpecialMaintenance.php +++ b/includes/SpecialMaintenance.php @@ -218,7 +218,7 @@ function wfSpecialMispeelings () { $y = $x ; $x = preg_replace( '/^(\S+).*$/', '$1', $x ); $sql = "SELECT DISTINCT cur_title FROM $cur,$searchindex WHERE cur_id=si_page AND ". - "cur_namespace=0 AND cur_is_redirect=0 AND " . + "cur_namespace=".NS_MAIN." AND cur_is_redirect=0 AND " . "(MATCH(si_text) AGAINST ('" . $dbr->strencode( $wgContLang->stripForSearch( $x ) ) . "'))" ; $res = $dbr->query( $sql, $fname ); while ( $obj = $dbr->fetchObject ( $res ) ) { @@ -268,7 +268,7 @@ function wfSpecialMissingLanguageLinks() { $cur = $dbr->tableName( 'cur' ); $sql = "SELECT cur_title FROM $cur " . - "WHERE cur_namespace=0 AND cur_is_redirect=0 " . + "WHERE cur_namespace=".NS_MAIN." AND cur_is_redirect=0 " . "AND cur_title NOT LIKE '%/%' AND cur_text NOT LIKE '%[[" . wfStrencode( $thelang ) . ":%' " . "LIMIT {$offset}, {$limit}"; diff --git a/includes/SpecialNewpages.php b/includes/SpecialNewpages.php index 9367a5ee4e..a8935ec811 100644 --- a/includes/SpecialNewpages.php +++ b/includes/SpecialNewpages.php @@ -51,7 +51,7 @@ class NewPagesPage extends QueryPage { old_text as text FROM $recentchanges,$page,$text WHERE rc_cur_id=page_id AND rc_new=1 - AND rc_namespace=0 AND page_is_redirect=0 + AND rc_namespace=".NS_MAIN." AND page_is_redirect=0 AND page_latest=old_id"; } diff --git a/includes/SpecialPopularpages.php b/includes/SpecialPopularpages.php index 32349963bb..4e1a0881eb 100644 --- a/includes/SpecialPopularpages.php +++ b/includes/SpecialPopularpages.php @@ -37,7 +37,7 @@ class PopularPagesPage extends QueryPage { page_title as title, page_counter as value FROM $page - WHERE page_namespace=0 AND page_is_redirect=0"; + WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0"; } function formatResult( $skin, $result ) { diff --git a/includes/SpecialRandompage.php b/includes/SpecialRandompage.php index 9a9326c9e4..7cd7ff0f9a 100644 --- a/includes/SpecialRandompage.php +++ b/includes/SpecialRandompage.php @@ -34,7 +34,7 @@ function wfSpecialRandompage() { } $sqlget = "SELECT page_id,page_title FROM $page $use_index - WHERE page_namespace=0 AND page_is_redirect=0 $extra + WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0 $extra AND page_random>$randstr ORDER BY page_random LIMIT 1"; diff --git a/includes/SpecialShortpages.php b/includes/SpecialShortpages.php index 1467a44ea3..f99642831d 100644 --- a/includes/SpecialShortpages.php +++ b/includes/SpecialShortpages.php @@ -42,7 +42,7 @@ class ShortPagesPage extends QueryPage { page_title as title, LENGTH(old_text) AS value FROM $page, $text - WHERE page_namespace=0 AND page_is_redirect=0 + WHERE page_namespace=".NS_MAIN." AND page_is_redirect=0 AND page_latest=old_id"; } diff --git a/includes/SpecialValidate.php b/includes/SpecialValidate.php index aaaac55c41..b1b16f7a2a 100644 --- a/includes/SpecialValidate.php +++ b/includes/SpecialValidate.php @@ -33,7 +33,7 @@ class Validation { function find_this_version( $article_title , &$article_time , &$id , &$tab ) { $id = ""; $tab = ""; - $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=0 AND cur_title='" . wfStrencode( $article_title ) . "'"; + $sql = "SELECT cur_id,cur_timestamp FROM cur WHERE cur_namespace=".NS_MAIN." AND cur_title='" . wfStrencode( $article_title ) . "'"; $res = wfQuery( $sql, DB_READ ); if( $s = wfFetchObject( $res ) ) { if ( $article_time == "" ) { @@ -47,7 +47,7 @@ class Validation { } if ( $id == "" ) { - $sql = "SELECT old_id FROM old WHERE old_namespace=0 AND old_title='" . wfStrencode( $article_title ) . + $sql = "SELECT old_id FROM old WHERE old_namespace=".NS_MAIN." AND old_title='" . wfStrencode( $article_title ) . "' AND old_timestamp='" . wfStrencode( $article_time ) . "'"; $res = wfQuery( $sql, DB_READ ); if( $s = wfFetchObject( $res ) ) { @@ -103,7 +103,7 @@ class Validation { if( !isset( $val[$article_time] ) ) { if( $article_time == "" ) { $res = wfQuery( "select cur_timestamp FROM cur WHERE cur_title='" . - wfStrencode( $article_title ) . "' AND cur_namespace=0", DB_READ ); + wfStrencode( $article_title ) . "' AND cur_namespace=".NS_MAIN, DB_READ ); if( $s = wfFetchObject( $res ) ) { $article_time = $s->cur_timestamp; } diff --git a/includes/Title.php b/includes/Title.php index e9d723d5d0..462afbba1b 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -55,7 +55,9 @@ class Title { $this->mNamespace = 0; $this->mRestrictionsLoaded = false; $this->mRestrictions = array(); - $this->mDefaultNamespace = 0; + # Dont change the following, NS_MAIN is hardcoded in several place + # See bug #696 + $this->mDefaultNamespace = NS_MAIN; } /** -- 2.20.1