From cc1fbbe002b8e293434d9010554d7aeaffa573be Mon Sep 17 00:00:00 2001 From: Magnus Manske Date: Tue, 20 Apr 2004 21:30:59 +0000 Subject: [PATCH] Category namespaces --- includes/Namespace.php | 6 +++++- includes/Parser.php | 25 +++++++++++-------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/includes/Namespace.php b/includes/Namespace.php index 996f5231a2..a989e908ae 100644 --- a/includes/Namespace.php +++ b/includes/Namespace.php @@ -58,6 +58,7 @@ class Namespace { function getWikipedia() { return NS_WP; } function getImage() { return NS_IMAGE; } function getMedia() { return NS_MEDIA; } + function getCategory() { return NS_CATEGORY; } function isMovable( $index ) { @@ -69,7 +70,10 @@ class Namespace { function isTalk( $index ) { - if ( NS_TALK == $index || NS_USER_TALK == $index || NS_WP_TALK == $index || NS_IMAGE_TALK == $index || NS_MEDIAWIKI_TALK == $index || NS_TEMPLATE_TALK == $index || NS_HELP_TALK == $index ) { + if ( NS_TALK == $index || NS_USER_TALK == $index || NS_WP_TALK + == $index || NS_IMAGE_TALK == $index || NS_MEDIAWIKI_TALK == $index || + NS_TEMPLATE_TALK == $index || NS_HELP_TALK == $index || + NS_CATEGORY_TALK ) { return true; } return false; diff --git a/includes/Parser.php b/includes/Parser.php index 7b978654bc..27bdaaf6cc 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -261,24 +261,19 @@ class Parser global $wgLang , $wgUser ; if ( !$this->mOptions->getUseCategoryMagic() ) return ; $id = $this->mTitle->getArticleID() ; - $cat = $wgLang->ucfirst ( wfMsg ( "category" ) ) ; + if ( $this->mTitle->getNamespace() != Namespace::getCategory() ) return "" ; $ti = $this->mTitle->getText() ; - $ti = explode ( ":" , $ti , 2 ) ; - if ( $cat != $ti[0] ) return "" ; $r = "
\n"; $articles = array() ; $parents = array () ; $children = array() ; - -# $sk =& $this->mGetSkin(); $sk =& $wgUser->getSkin() ; $data = array () ; - $cns = 14 ; - $sql1 = "SELECT DISTINCT cur_title,cur_namespace FROM cur,links WHERE cur_namespace={$cns} l_to={$id} AND l_from=cur_id"; - $sql2 = "SELECT DISTINCT cur_title,cur_namespace FROM cur,brokenlinks cur_namespace={$cns} WHERE bl_to={$id} AND bl_from=cur_id" ; + $sql1 = "SELECT DISTINCT cur_title,cur_namespace FROM cur,links WHERE l_to={$id} AND l_from=cur_id"; + $sql2 = "SELECT DISTINCT cur_title,cur_namespace FROM cur,brokenlinks WHERE bl_to={$id} AND bl_from=cur_id" ; $res = wfQuery ( $sql1, DB_READ ) ; while ( $x = wfFetchObject ( $res ) ) $data[] = $x ; @@ -286,7 +281,6 @@ class Parser $res = wfQuery ( $sql2, DB_READ ) ; while ( $x = wfFetchObject ( $res ) ) $data[] = $x ; - foreach ( $data AS $x ) { $t = $wgLang->getNsText ( $x->cur_namespace ) ; @@ -314,7 +308,7 @@ class Parser if ( count ( $articles ) > 0 ) { asort ( $articles ) ; - $h = wfMsg( "category_header", $ti[1] ); + $h = wfMsg( "category_header", $ti ); $r .= "

{$h}

\n" ; $r .= implode ( ", " , $articles ) ; } @@ -485,7 +479,10 @@ class Parser $sk =& $this->mOptions->getSkin(); $text = $sk->transformContent( $text ); - $text .= $this->categoryMagic () ; + if ( !isset ( $this->categoryMagicDone ) ) { + $text .= $this->categoryMagic () ; + $this->categoryMagicDone = true ; + } wfProfileOut( $fname ); return $text; @@ -830,7 +827,7 @@ class Parser if ( !$image ) { $image = Namespace::getImage(); } if ( !$special ) { $special = Namespace::getSpecial(); } if ( !$media ) { $media = Namespace::getMedia(); } - if ( !$category ) { $category = wfMsg ( "category" ) ; } + if ( !$category ) { $category = Namespace::getCategory(); ; } $nottalk = !Namespace::isTalk( $this->mTitle->getNamespace() ); @@ -893,9 +890,9 @@ class Parser $wgLinkCache->addImageLinkObj( $nt ); return $s; } - if ( $ns == 14 ) { + if ( $ns == $category ) { $t = $nt->getText() ; - $nnt = Title::newFromText ( $category.":".$t ) ; + $nnt = Title::newFromText ( Namespace::getCanonicalName($category).":".$t ) ; $t = $sk->makeLinkObj( $nnt, $t, "", "" , $prefix ); $this->mOutput->mCategoryLinks[] = $t ; $s .= $prefix . $trail ; -- 2.20.1