Merge "CologneBlue rewrite: fix talkLink() to use generic nav links"
[lhc/web/wiklou.git] / skins / CologneBlue.php
index d99f427..32aa902 100644 (file)
@@ -55,6 +55,8 @@ class SkinCologneBlue extends SkinTemplate {
 
 class CologneBlueTemplate extends BaseTemplate {
        function execute() {
+               // Suppress warnings to prevent notices about missing indexes in $this->data
+               wfSuppressWarnings();
                $this->html( 'headelement' );
                echo $this->beforeContent();
                $this->html( 'bodytext' );
@@ -63,6 +65,7 @@ class CologneBlueTemplate extends BaseTemplate {
                $this->html( 'dataAfterContent' );
                $this->printTrail();
                echo "\n</body></html>";
+               wfRestoreWarnings();
        }
 
        /**
@@ -338,56 +341,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;
        }
 
        /**
@@ -585,7 +611,7 @@ class CologneBlueTemplate extends BaseTemplate {
                                        // Personal tools ("My pages")
                                        $bar['qbmyoptions'] = $this->getPersonalTools();
                                        foreach ( array ( 'logout', 'createaccount', 'login', 'anonlogin' ) as $key ) {
-                                               $bar['qbmyoptions'][$key] = false;
+                                               $bar['qbmyoptions'][$key] = null;
                                        }
 
                                        $additions_done = true;
@@ -609,8 +635,8 @@ class CologneBlueTemplate extends BaseTemplate {
                                $s .= $this->searchForm( 'sidebar' );
                        } elseif ( $heading == 'LANGUAGES' ) {
                                // discard these; we display languages below page content
-                       } else {
-                               if ( $links ) {
+                       } elseif ( $links ) {
+                               if ( is_array( $links ) ) {
                                        // Use the navigation heading from standard sidebar as the "browse" section
                                        if ( $heading == 'navigation' ) {
                                                $heading = 'qbbrowse';
@@ -634,6 +660,9 @@ class CologneBlueTemplate extends BaseTemplate {
                                        if ( $any_link ) {
                                                $s .= $t;
                                        }
+                               } else {
+                                       // $links can be a HTML string
+                                       $s .= $links;
                                }
                        }
                }