Merge "CologneBlue rewrite: fix talkLink() to use generic nav links"
[lhc/web/wiklou.git] / skins / CologneBlue.php
index 17487f4..32aa902 100644 (file)
@@ -43,7 +43,7 @@ class SkinCologneBlue extends SkinTemplate {
                $out->addModuleStyles( 'mediawiki.legacy.oldshared' );
                $out->addModuleStyles( 'skins.cologneblue' );
        }
-       
+
        /**
         * Override langlink formatting behavior not to uppercase the language names.
         * See otherLanguages() in CologneBlueTemplate.
@@ -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,8 +65,8 @@ class CologneBlueTemplate extends BaseTemplate {
                $this->html( 'dataAfterContent' );
                $this->printTrail();
                echo "\n</body></html>";
+               wfRestoreWarnings();
        }
-       
 
        /**
         * Language/charset variant links for classic-style skins
@@ -83,7 +85,7 @@ class CologneBlueTemplate extends BaseTemplate {
 
                return $this->getSkin()->getLanguage()->pipeList( $s );
        }
-       
+
        // @fixed
        function otherLanguages() {
                global $wgHideInterlanguageLinks;
@@ -112,11 +114,11 @@ class CologneBlueTemplate extends BaseTemplate {
        function pageTitleLinks() {
                $s = array();
                $footlinks = $this->getFooterLinks();
-               
+
                foreach ( $footlinks['places'] as $item ) {
                        $s[] = $this->data[$item];
                }
-               
+
                return $this->getSkin()->getLanguage()->pipeList( $s );
        }
 
@@ -339,61 +341,84 @@ 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;
        }
-       
+
        /**
         * @return string
-        * 
+        *
         * @fixed
         */
        function beforeContent() {
@@ -407,7 +432,6 @@ class CologneBlueTemplate extends BaseTemplate {
                        </a>
                </p>
                <p id="sitesub"><?php echo wfMessage( 'sitesubtitle' )->escaped() ?></p>
-               
                <div id="toplinks">
                        <p id="syslinks"><?php echo $this->sysLinks() ?></p>
                        <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
@@ -438,13 +462,13 @@ class CologneBlueTemplate extends BaseTemplate {
 <?php
                $s = ob_get_contents();
                ob_end_clean();
-               
+
                return $s;
        }
 
        /**
         * @return string
-        * 
+        *
         * @fixed
         */
        function afterContent() {
@@ -456,7 +480,7 @@ class CologneBlueTemplate extends BaseTemplate {
                // Page-related links
                echo $this->bottomLinks();
                echo "\n<br />";
-               
+
                // Footer and second searchbox
                echo $this->getSkin()->getLanguage()->pipeList( array(
                        $this->getSkin()->mainPageLink(),
@@ -464,7 +488,7 @@ class CologneBlueTemplate extends BaseTemplate {
                        $this->searchForm( 'footer' )
                ) );
                echo "\n<br />";
-               
+
                // Standard footer info
                $footlinks = $this->getFooterLinks();
                if ( $footlinks['info'] ) {
@@ -485,7 +509,7 @@ class CologneBlueTemplate extends BaseTemplate {
 
        /**
         * @return string
-        * 
+        *
         * @fixed
         */
        function sysLinks() {
@@ -515,13 +539,10 @@ class CologneBlueTemplate extends BaseTemplate {
                return $this->getSkin()->getLanguage()->pipeList( $s );
        }
 
-
-
-       
        /**
         * @param $heading string
         * @return string
-        * 
+        *
         * @fixed
         */
        function menuHead( $heading ) {
@@ -533,35 +554,35 @@ class CologneBlueTemplate extends BaseTemplate {
         * @access private
         *
         * @return string
-        * 
+        *
         * @fixed
         */
        function quickBar(){
                $s = "\n<div id='quickbar'>";
 
                $sep = "<br />\n";
-               
+
                $plain_bar = $this->data['sidebar'];
                $bar = array();
-               
+
                // Massage the sidebar
                // We want to place SEARCH at the beginning and a lot of stuff before TOOLBOX (or at the end, if it's missing)
                $additions_done = false;
                while ( !$additions_done ) {
                        $bar = array(); // Empty it out
-                       
+
                        // Always display search on top
                        $bar['SEARCH'] = true;
-                               
+
                        foreach ( $plain_bar as $heading => $links ) {
                                if ( $heading == 'TOOLBOX' ) {
                                        if( $links !== NULL ) {
                                                // If this is not a toolbox prosthetic we inserted outselves, fill it out
                                                $plain_bar['TOOLBOX'] = $this->getToolbox();
                                        }
-                                       
+
                                        // And insert the stuff
-                                       
+
                                        // "This page" and "Edit" menus
                                        // We need to do some massaging here... we reuse all of the items, except for $...['views']['view'],
                                        // as $...['namespaces']['main'] and $...['namespaces']['talk'] together serve the same purpose.
@@ -586,36 +607,36 @@ class CologneBlueTemplate extends BaseTemplate {
                                        );
                                        $bar['qbedit'] = $qbedit;
                                        $bar['qbpageoptions'] = $qbpageoptions;
-                                       
+
                                        // 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;
                                }
-                               
+
                                // Re-insert current heading, unless it's SEARCH
                                if ( $heading != 'SEARCH' ) {
                                        $bar[$heading] = $plain_bar[$heading];
                                }
                        }
-                       
+
                        // If TOOLBOX is missing, $additions_done is still false
                        if ( !$additions_done ) {
                                $plain_bar['TOOLBOX'] = false;
                        }
                }
-               
+
                foreach ( $bar as $heading => $links ) {
                        if ( $heading == 'SEARCH' ) {
                                $s .= $this->menuHead( wfMessage( 'qbfind' )->text() );
                                $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';
@@ -623,11 +644,11 @@ class CologneBlueTemplate extends BaseTemplate {
                                        if ( $heading == 'TOOLBOX' ) {
                                                $heading = 'toolbox';
                                        }
-                                       
+
                                        $headingMsg = wfMessage( $heading );
                                        $any_link = false;
                                        $t = $this->menuHead( $headingMsg->exists() ? $headingMsg->text() : $heading );
-                                       
+
                                        foreach ( $links as $key => $link ) {
                                                // Can be empty due to rampant sidebar massaging we're doing above
                                                if ( $link ) {
@@ -635,10 +656,13 @@ class CologneBlueTemplate extends BaseTemplate {
                                                        $t .= $this->makeListItem( $key, $link, array( 'tag' => 'span' ) ) . $sep;
                                                }
                                        }
-                                       
+
                                        if ( $any_link ) {
                                                $s .= $t;
                                        }
+                               } else {
+                                       // $links can be a HTML string
+                                       $s .= $links;
                                }
                        }
                }
@@ -650,7 +674,7 @@ class CologneBlueTemplate extends BaseTemplate {
        /**
         * @param $label string
         * @return string
-        * 
+        *
         * @fixed
         */
        function searchForm( $which ) {