From d5d5ab110870ef9216183880447f2da2f708fc14 Mon Sep 17 00:00:00 2001 From: Trevor Parscal Date: Mon, 6 Jul 2009 22:43:04 +0000 Subject: [PATCH] Resolves improperly named XML ids on the namespace tabs, as well as fixes up some nastyness in the Title object --- includes/Title.php | 55 +++++++++++++++++++--------------------------- skins/Vector.php | 17 ++++++++------ 2 files changed, 32 insertions(+), 40 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index 762adc5e19..b18b28a804 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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; } /** diff --git a/skins/Vector.php b/skins/Vector.php index c910c993e0..d410c36d30 100644 --- a/skins/Vector.php +++ b/skins/Vector.php @@ -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}" ); } } } -- 2.20.1