Resolves improperly named XML ids on the namespace tabs, as well as fixes up some...
authorTrevor Parscal <tparscal@users.mediawiki.org>
Mon, 6 Jul 2009 22:43:04 +0000 (22:43 +0000)
committerTrevor Parscal <tparscal@users.mediawiki.org>
Mon, 6 Jul 2009 22:43:04 +0000 (22:43 +0000)
includes/Title.php
skins/Vector.php

index 762adc5..b18b28a 100644 (file)
@@ -3521,40 +3521,29 @@ class Title {
         * Generate strings used for xml 'id' names in monobook tabs
         * @return \type{\string} XML 'id' name
         */
-       public function getNamespaceKey() {
-               global $wgContLang;
-               switch ($this->getNamespace()) {
-                       case NS_MAIN:
-                       case NS_TALK:
-                               return 'nstab-main';
-                       case NS_USER:
-                       case NS_USER_TALK:
-                               return 'nstab-user';
-                       case NS_MEDIA:
-                               return 'nstab-media';
-                       case NS_SPECIAL:
-                               return 'nstab-special';
-                       case NS_PROJECT:
-                       case NS_PROJECT_TALK:
-                               return 'nstab-project';
-                       case NS_FILE:
-                       case NS_FILE_TALK:
-                               return 'nstab-image';
-                       case NS_MEDIAWIKI:
-                       case NS_MEDIAWIKI_TALK:
-                               return 'nstab-mediawiki';
-                       case NS_TEMPLATE:
-                       case NS_TEMPLATE_TALK:
-                               return 'nstab-template';
-                       case NS_HELP:
-                       case NS_HELP_TALK:
-                               return 'nstab-help';
-                       case NS_CATEGORY:
-                       case NS_CATEGORY_TALK:
-                               return 'nstab-category';
-                       default:
-                               return 'nstab-' . $wgContLang->lc( $this->getSubjectNsText() );
+       public function getNamespaceKey( $prepend = 'nstab-' ) {
+               global $wgContLang, $wgCanonicalNamespaceNames;
+               // Gets the subject namespace if this title
+               $namespace = MWNamespace::getSubject( $this->getNamespace() );
+               // Checks if cononical namespace name exists for namespace
+               if ( isset( $wgCanonicalNamespaceNames[$namespace] ) ) {
+                       // Uses canonical namespace name
+                       $namespaceKey = $wgCanonicalNamespaceNames[$namespace];
+               } else {
+                       // Uses text of namespace
+                       $namespaceKey = $this->getSubjectNsText();
+               }
+               // Makes namespace key lowercase
+               $namespaceKey = $wgContLang->lc( $namespaceKey );
+               // Uses main
+               if ( $namespaceKey == '' ) {
+                       $namespaceKey = 'main';
+               }
+               // Changes file to image for backwards compatibility
+               if ( $namespaceKey == 'file' ) {
+                       $namespaceKey = 'image';
                }
+               return $prepend . $namespaceKey;
        }
 
        /**
index c910c99..d410c36 100644 (file)
@@ -79,11 +79,8 @@ class SkinVector extends SkinTemplate {
                        $isTalk = $this->mTitle->isTalkPage();
 
                        // Generates XML IDs from namespace names
-                       $subjectId = $wgContLang->lc($wgCanonicalNamespaceNames[MWNamespace::getSubject($this->mTitle->getNamespace())]);
+                       $subjectId = $this->mTitle->getNamespaceKey( '' );
                        
-                       if ( $subjectId == '' ) {
-                               $subjectId = 'main';
-                       }
                        if ( $subjectId == 'main' ) {
                                $talkId = 'talk';
                        } else {
@@ -95,9 +92,11 @@ class SkinVector extends SkinTemplate {
                        $links['namespaces'][$subjectId] = $this->tabAction(
                                $subjectPage, 'vector-namespace-' . $subjectId, !$isTalk, '', true
                        );
+                       $links['namespaces'][$subjectId]['context'] = 'subject';
                        $links['namespaces'][$talkId] = $this->tabAction(
                                $talkPage, 'vector-namespace-talk', $isTalk, '', true
                        );
+                       $links['namespaces'][$talkId]['context'] = 'talk';
                        
                        // Adds view view link
                        if ( $this->mTitle->exists() ) {
@@ -374,8 +373,12 @@ class VectorTemplate extends QuickTemplate {
                $nav = $this->skin->buildNavigationUrls();
                foreach ( $nav as $section => $links ) {
                        foreach ( $links as $key => $link ) {
+                               $insert = '';
+                               if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
+                                       $insert = 'nstab-';
+                               }
                                $nav[$section][$key]['attributes'] =
-                                       ' id="' . Sanitizer::escapeId( "ca-$key" ) . '"';
+                                       ' id="' . Sanitizer::escapeId( "ca-{$insert}{$key}" ) . '"';
                                if ( $nav[$section][$key]['class'] ) {
                                        $nav[$section][$key]['attributes'] .=
                                                ' class="' . htmlspecialchars( $link['class'] ) . '"';
@@ -390,10 +393,10 @@ class VectorTemplate extends QuickTemplate {
                                        in_array( $key, array( 'edit', 'watch', 'unwatch' ) )
                                ) {
                                        $nav[$section][$key]['key'] =
-                                               $this->skin->tooltip( "ca-$key" );
+                                               $this->skin->tooltip( "ca-{$insert}{$key}" );
                                } else {
                                        $nav[$section][$key]['key'] =
-                                               $this->skin->tooltipAndAccesskey( "ca-$key" );
+                                               $this->skin->tooltipAndAccesskey( "ca-{$insert}{$key}" );
                                }
                        }
                }