From 4329cd87f75a5d71ddd2ef3b3d90bf13e0185716 Mon Sep 17 00:00:00 2001 From: MatmaRex Date: Fri, 5 Oct 2012 20:13:15 +0200 Subject: [PATCH] CologneBlue rewrite: fix talkLink() to use generic nav links * introduce processNavlinkForDocument() for repeated links * remove wfFindFile() check for NS_FILE namespace: Linker::link() already checks this * redo the way the message for the link is selected * comment everything Change-Id: Ibeb0a1bfa1f34b9fdd9f6e5f082d6973d1ba09b9 --- skins/CologneBlue.php | 107 +++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 42 deletions(-) diff --git a/skins/CologneBlue.php b/skins/CologneBlue.php index 473ee2b441..f7f08ec2d9 100644 --- a/skins/CologneBlue.php +++ b/skins/CologneBlue.php @@ -339,56 +339,79 @@ class CologneBlueTemplate extends BaseTemplate { } } + // @fixed function talkLink() { $title = $this->getSkin()->getTitle(); - if ( NS_SPECIAL == $title->getNamespace() ) { - # No discussion links for special pages - return ''; + + if ( $title->getNamespace() == NS_SPECIAL ) { + // No discussion links for special pages + return ""; } - $linkOptions = array(); - - if ( $title->isTalkPage() ) { - $link = $title->getSubjectPage(); - switch( $link->getNamespace() ) { - case NS_MAIN: - $text = wfMessage( 'articlepage' ); - break; - case NS_USER: - $text = wfMessage( 'userpage' ); - break; - case NS_PROJECT: - $text = wfMessage( 'projectpage' ); - break; - case NS_FILE: - $text = wfMessage( 'imagepage' ); - # Make link known if image exists, even if the desc. page doesn't. - if ( wfFindFile( $link ) ) - $linkOptions[] = 'known'; - break; - case NS_MEDIAWIKI: - $text = wfMessage( 'mediawikipage' ); - break; - case NS_TEMPLATE: - $text = wfMessage( 'templatepage' ); - break; - case NS_HELP: - $text = wfMessage( 'viewhelppage' ); - break; - case NS_CATEGORY: - $text = wfMessage( 'categorypage' ); - break; - default: - $text = wfMessage( 'articlepage' ); - } + $companionTitle = $title->isTalkPage() ? $title->getSubjectPage() : $title->getTalkPage(); + $companionNamespace = $companionTitle->getNamespace(); + + // TODO these messages appear to only be used by CologneBlue and legacy skins, + // kill and replace with something more sensibly named? + $nsToMessage = array( + NS_MAIN => 'articlepage', + NS_USER => 'userpage', + NS_PROJECT => 'projectpage', + NS_FILE => 'imagepage', + NS_MEDIAWIKI => 'mediawikipage', + NS_TEMPLATE => 'templatepage', + NS_HELP => 'viewhelppage', + NS_CATEGORY => 'categorypage', + NS_FILE => 'imagepage', + ); + + // Find out the message to use for link text. Use either the array above or, + // for non-talk pages, a generic "discuss this" message. + // Default is the same as for main namespace. + if ( isset( $nsToMessage[$companionNamespace] ) ) { + $message = $nsToMessage[$companionNamespace]; } else { - $link = $title->getTalkPage(); - $text = wfMessage( 'talkpage' ); + $message = $companionTitle->isTalkPage() ? 'talkpage' : 'articlepage'; } - $s = Linker::link( $link, $text->text(), array(), array(), $linkOptions ); + // Obviously this can't be reasonable and just return the key for talk namespace, only for content ones. + // Thus we have to mangle it in exactly the same way SkinTemplate does. (bug 40805) + $key = $companionTitle->getNamespaceKey( '' ); + if ( $companionTitle->isTalkPage() ) { + $key = ( $key == 'main' ? 'talk' : $key . "_talk" ); + } - return $s; + // Use the regular navigational link, but replace its text. Everything else stays unmodified. + $namespacesLinks = $this->data['content_navigation']['namespaces']; + $link = $this->processNavlinkForDocument( $namespacesLinks[ $key ] ); + $link['text'] = wfMessage( $message )->text(); + + return $this->makeListItem( $message, $link, array( 'tag' => 'span' ) ); + } + + /** + * Takes a navigational link generated by SkinTemplate in whichever way + * and mangles attributes unsuitable for repeated use. In particular, this modifies the ids + * and removes the accesskeys. This is necessary to be able to use the same navlink twice, + * e.g. in sidebar and in footer. + * + * @param $navlink array Navigational link generated by SkinTemplate + * @param $idPrefix mixed Prefix to add to id of this navlink. If false, id is removed entirely. Default is 'cb-'. + */ + function processNavlinkForDocument( $navlink, $idPrefix='cb-' ) { + if ( $navlink['id'] ) { + $navlink['single-id'] = $navlink['id']; // to allow for tooltip generation + $navlink['tooltiponly'] = true; // but no accesskeys + + // mangle or remove the id + if ( $idPrefix === false ) { + unset( $navlink['id'] ); + } else { + $navlink['id'] = $idPrefix . $navlink['id']; + } + } + + return $navlink; } /** -- 2.20.1