Merge "(bug 37195) Doc fix. $from and $until are arrays since 1.17."
[lhc/web/wiklou.git] / skins / CologneBlue.php
index 8c97a3c..56c6b08 100644 (file)
@@ -71,8 +71,6 @@ class CologneBlueTemplate extends BaseTemplate {
        /**
         * Language/charset variant links for classic-style skins
         * @return string
-        *
-        * @fixed
         */
        function variantLinks() {
                $s = array();
@@ -86,7 +84,6 @@ class CologneBlueTemplate extends BaseTemplate {
                return $this->getSkin()->getLanguage()->pipeList( $s );
        }
 
-       // @fixed
        function otherLanguages() {
                global $wgHideInterlanguageLinks;
                if ( $wgHideInterlanguageLinks ) {
@@ -110,7 +107,6 @@ class CologneBlueTemplate extends BaseTemplate {
                        . $this->getSkin()->getLanguage()->pipeList( $s );
        }
 
-       // @fixed
        function pageTitleLinks() {
                $s = array();
                $footlinks = $this->getFooterLinks();
@@ -122,226 +118,79 @@ class CologneBlueTemplate extends BaseTemplate {
                return $this->getSkin()->getLanguage()->pipeList( $s );
        }
 
-       function bottomLinks() {
-               $sep = wfMessage( 'pipe-separator' )->escaped() . "\n";
-
-               $s = '';
-               if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
-                       $element[] = '<strong>' . $this->editThisPage() . '</strong>';
-
-                       if ( $this->getSkin()->getUser()->isLoggedIn() ) {
-                               $element[] = $this->watchThisPage();
-                       }
-
-                       $element[] = $this->talkLink();
-                       $element[] = $this->historyLink();
-                       $element[] = $this->whatLinksHere();
-                       $element[] = $this->watchPageLinksLink();
-
-                       $title = $this->getSkin()->getTitle();
-
-                       if (
-                               $title->getNamespace() == NS_USER ||
-                               $title->getNamespace() == NS_USER_TALK
-                       ) {
-                               $id = User::idFromName( $title->getText() );
-                               $ip = User::isIP( $title->getText() );
-
-                               # Both anons and non-anons have contributions list
-                               if ( $id || $ip ) {
-                                       $element[] = $this->userContribsLink();
-                               }
-
-                               if ( $this->getSkin()->showEmailUser( $id ) ) {
-                                       $element[] = $this->emailUserLink();
-                               }
-                       }
-
-                       $s = implode( $element, $sep );
-
-                       if ( $title->getArticleID() ) {
-                               $s .= "\n<br />";
-
-                               // Delete/protect/move links for privileged users
-                               if ( $this->getSkin()->getUser()->isAllowed( 'delete' ) ) {
-                                       $s .= $this->deleteThisPage();
-                               }
-
-                               if ( $this->getSkin()->getUser()->isAllowed( 'protect' ) ) {
-                                       $s .= $sep . $this->protectThisPage();
-                               }
-
-                               if ( $this->getSkin()->getUser()->isAllowed( 'move' ) ) {
-                                       $s .= $sep . $this->moveThisPage();
-                               }
-                       }
-
-                       $s .= "<br />\n" . $this->otherLanguages();
+       /**
+        * Used in bottomLinks() to eliminate repetitive code.
+        *
+        * @param $key string Key to be passed to makeListItem()
+        * @param $navlink array Navlink suitable for processNavlinkForDocument()
+        * @param $message string Key of the message to use in place of standard text
+        *
+        * @return string
+        */
+       function processBottomLink( $key, $navlink, $message=null ) {
+               if ( !$navlink ) {
+                       // Empty navlinks might be passed.
+                       return null;
                }
 
-               return $s;
-       }
-
-       function editThisPage() {
-               if ( !$this->getSkin()->getOutput()->isArticleRelated() ) {
-                       $s = wfMessage( 'protectedpage' )->text();
-               } else {
-                       $title = $this->getSkin()->getTitle();
-                       if ( $title->quickUserCan( 'edit' ) && $title->exists() ) {
-                               $t = wfMessage( 'editthispage' )->text();
-                       } elseif ( $title->quickUserCan( 'create' ) && !$title->exists() ) {
-                               $t = wfMessage( 'create-this-page' )->text();
-                       } else {
-                               $t = wfMessage( 'viewsource' )->text();
-                       }
-
-                       $s = Linker::linkKnown(
-                               $title,
-                               $t,
-                               array(),
-                               $this->getSkin()->editUrlOptions()
-                       );
+               if ( $message ) {
+                       $navlink['text'] = wfMessage( $message )->escaped();
                }
 
-               return $s;
+               return $this->makeListItem( $key, $this->processNavlinkForDocument( $navlink ), array( 'tag' => 'span' ) );
        }
 
-       function deleteThisPage() {
-               $diff = $this->getSkin()->getRequest()->getVal( 'diff' );
-               $title = $this->getSkin()->getTitle();
-
-               if ( $title->getArticleID() && ( !$diff ) && $this->getSkin()->getUser()->isAllowed( 'delete' ) ) {
-                       $t = wfMessage( 'deletethispage' )->text();
+       function bottomLinks() {
+               $toolbox = $this->getToolbox();
+               $content_nav = $this->data['content_navigation'];
 
-                       $s = Linker::linkKnown(
-                               $title,
-                               $t,
-                               array(),
-                               array( 'action' => 'delete' )
-                       );
-               } else {
-                       $s = '';
-               }
+               $lines = array();
 
-               return $s;
-       }
+               if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
+                       // First row. Regular actions.
+                       $element = array();
 
-       function protectThisPage() {
-               $diff = $this->getSkin()->getRequest()->getVal( 'diff' );
-               $title = $this->getSkin()->getTitle();
+                       $editLinkMessage = $this->getSkin()->getTitle()->exists() ? 'editthispage' : 'create-this-page';
+                       $element[] = $this->processBottomLink( 'edit', $content_nav['views']['edit'], $editLinkMessage );
+                       $element[] = $this->processBottomLink( 'viewsource', $content_nav['views']['viewsource'], 'viewsource' );
 
-               if ( $title->getArticleID() && ( ! $diff ) && $this->getSkin()->getUser()->isAllowed( 'protect' ) ) {
-                       if ( $title->isProtected() ) {
-                               $text = wfMessage( 'unprotectthispage' )->text();
-                               $query = array( 'action' => 'unprotect' );
-                       } else {
-                               $text = wfMessage( 'protectthispage' )->text();
-                               $query = array( 'action' => 'protect' );
-                       }
+                       $element[] = $this->processBottomLink( 'watch', $content_nav['actions']['watch'], 'watchthispage' );
+                       $element[] = $this->processBottomLink( 'unwatch', $content_nav['actions']['unwatch'], 'unwatchthispage' );
 
-                       $s = Linker::linkKnown(
-                               $title,
-                               $text,
-                               array(),
-                               $query
-                       );
-               } else {
-                       $s = '';
-               }
+                       $element[] = $this->talkLink();
 
-               return $s;
-       }
+                       $element[] = $this->processBottomLink( 'history', $content_nav['views']['history'], 'history' );
+                       $element[] = $this->processBottomLink( 'info', $toolbox['info'] );
+                       $element[] = $this->processBottomLink( 'whatlinkshere', $toolbox['whatlinkshere'] );
+                       $element[] = $this->processBottomLink( 'recentchangeslinked', $toolbox['recentchangeslinked'] );
 
-       function watchThisPage() {
-               // Cache
-               $title = $this->getSkin()->getTitle();
+                       $element[] = $this->processBottomLink( 'contributions', $toolbox['contributions'] );
+                       $element[] = $this->processBottomLink( 'emailuser', $toolbox['emailuser'] );
 
-               if ( $this->getSkin()->getOutput()->isArticleRelated() ) {
-                       if ( $this->getSkin()->getUser()->isWatched( $title ) ) {
-                               $text = wfMessage( 'unwatchthispage' )->text();
-                               $query = array(
-                                       'action' => 'unwatch',
-                                       'token' => UnwatchAction::getUnwatchToken( $title, $this->getSkin()->getUser() ),
-                               );
-                               $id = 'mw-unwatch-link';
-                       } else {
-                               $text = wfMessage( 'watchthispage' )->text();
-                               $query = array(
-                                       'action' => 'watch',
-                                       'token' => WatchAction::getWatchToken( $title, $this->getSkin()->getUser() ),
-                               );
-                               $id = 'mw-watch-link';
-                       }
+                       $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
 
-                       $s = Linker::linkKnown(
-                               $title,
-                               $text,
-                               array( 'id' => $id ),
-                               $query
-                       );
-               } else {
-                       $s = wfMessage( 'notanarticle' )->text();
-               }
 
-               return $s;
-       }
+                       // Second row. Privileged actions.
+                       $element = array();
 
-       function moveThisPage() {
-               if ( $this->getSkin()->getTitle()->quickUserCan( 'move' ) ) {
-                       return Linker::linkKnown(
-                               SpecialPage::getTitleFor( 'Movepage' ),
-                               wfMessage( 'movethispage' )->text(),
-                               array(),
-                               array( 'target' => $this->getSkin()->getTitle()->getPrefixedDBkey() )
-                       );
-               } else {
-                       // no message if page is protected - would be redundant
-                       return '';
-               }
-       }
+                       $element[] = $this->processBottomLink( 'delete', $content_nav['actions']['delete'], 'deletethispage' );
+                       $element[] = $this->processBottomLink( 'undelete', $content_nav['actions']['undelete'], 'undeletethispage' );
 
-       function historyLink() {
-               return Linker::link(
-                       $this->getSkin()->getTitle(),
-                       wfMessage( 'history' )->escaped(),
-                       array( 'rel' => 'archives' ),
-                       array( 'action' => 'history' )
-               );
-       }
+                       $element[] = $this->processBottomLink( 'protect', $content_nav['actions']['protect'], 'protectthispage' );
+                       $element[] = $this->processBottomLink( 'unprotect', $content_nav['actions']['unprotect'], 'unprotectthispage' );
 
-       function whatLinksHere() {
-               return Linker::linkKnown(
-                       SpecialPage::getTitleFor( 'Whatlinkshere', $this->getSkin()->getTitle()->getPrefixedDBkey() ),
-                       wfMessage( 'whatlinkshere' )->escaped()
-               );
-       }
+                       $element[] = $this->processBottomLink( 'move', $content_nav['actions']['move'], 'movethispage' );
 
-       function userContribsLink() {
-               return Linker::linkKnown(
-                       SpecialPage::getTitleFor( 'Contributions', $this->getSkin()->getTitle()->getDBkey() ),
-                       wfMessage( 'contributions' )->escaped()
-               );
-       }
+                       $lines[] = $this->getSkin()->getLanguage()->pipeList( array_filter( $element ) );
 
-       function emailUserLink() {
-               return Linker::linkKnown(
-                       SpecialPage::getTitleFor( 'Emailuser', $this->getSkin()->getTitle()->getDBkey() ),
-                       wfMessage( 'emailuser' )->escaped()
-               );
-       }
 
-       function watchPageLinksLink() {
-               if ( !$this->getSkin()->getOutput()->isArticleRelated() ) {
-                       return wfMessage( 'parentheses', wfMessage( 'notanarticle' )->text() )->escaped();
-               } else {
-                       return Linker::linkKnown(
-                               SpecialPage::getTitleFor( 'Recentchangeslinked', $this->getSkin()->getTitle()->getPrefixedDBkey() ),
-                               wfMessage( 'recentchangeslinked-toolbox' )->escaped()
-                       );
+                       // Third row. Language links.
+                       $lines[] = $this->otherLanguages();
                }
+
+               return implode( array_filter( $lines ), "<br />\n" ) . "<br />\n";
        }
 
-       // @fixed
        function talkLink() {
                $title = $this->getSkin()->getTitle();
 
@@ -385,10 +234,7 @@ class CologneBlueTemplate extends BaseTemplate {
 
                // 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' ) );
+               return $this->processBottomLink( $message,  $namespacesLinks[$key], $message );
        }
 
        /**
@@ -418,25 +264,19 @@ class CologneBlueTemplate extends BaseTemplate {
 
        /**
         * @return string
-        *
-        * @fixed
         */
        function beforeContent() {
                ob_start();
 ?>
 <div id="content">
        <div id="topbar">
-               <p id="sitetitle">
+               <p id="sitetitle" role="banner">
                        <a href="<?php echo htmlspecialchars( $this->data['nav_urls']['mainpage']['href'] ) ?>">
                                <?php echo wfMessage( 'sitetitle' )->escaped() ?>
                        </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>
-               </div>
-               <div id="linkcollection">
+               <div id="linkcollection" role="navigation">
                        <div id="langlinks"><?php echo str_replace( '<br />', '', $this->otherLanguages() ) ?></div>
                        <?php echo $this->getSkin()->getCategories() ?>
                        <div id="titlelinks"><?php echo $this->pageTitleLinks() ?></div>
@@ -445,11 +285,14 @@ class CologneBlueTemplate extends BaseTemplate {
                        <?php } ?>
                </div>
        </div>
-       <div id="article">
+       <div id="article" role="main">
                <?php if ( $this->getSkin()->getSiteNotice() ) { ?>
                <div id="siteNotice"><?php echo $this->getSkin()->getSiteNotice() ?></div>
                <?php } ?>
-               <h1 id="firstHeading"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
+               <h1 id="firstHeading" lang="<?php
+                       $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageLanguage()->getCode();
+                       $this->html( 'pageLanguage' );
+               ?>"><span dir="auto"><?php echo $this->data['title'] ?></span></h1>
                <?php if ( $this->translator->translate( 'tagline' ) ) { ?>
                <p class="tagline"><?php echo htmlspecialchars( $this->translator->translate( 'tagline' ) ) ?></p>
                <?php } ?>
@@ -468,14 +311,12 @@ class CologneBlueTemplate extends BaseTemplate {
 
        /**
         * @return string
-        *
-        * @fixed
         */
        function afterContent() {
                ob_start();
 ?>
        </div>
-       <div id='footer'>
+       <div id="footer" role="contentinfo">
 <?php
                // Page-related links
                echo $this->bottomLinks();
@@ -499,7 +340,14 @@ class CologneBlueTemplate extends BaseTemplate {
 ?>
        </div>
 </div>
-<?php echo $this->quickBar() ?>
+<div id="mw-navigation">
+       <h2><?php echo wfMessage( 'navigation-heading' )->escaped() ?></h2>
+       <div id="toplinks" role="navigation">
+               <p id="syslinks"><?php echo $this->sysLinks() ?></p>
+               <p id="variantlinks"><?php echo $this->variantLinks() ?></p>
+       </div>
+       <?php echo $this->quickBar() ?>
+</div>
 <?php
                $s = ob_get_contents();
                ob_end_clean();
@@ -509,8 +357,6 @@ class CologneBlueTemplate extends BaseTemplate {
 
        /**
         * @return string
-        *
-        * @fixed
         */
        function sysLinks() {
                $s = array(
@@ -544,8 +390,6 @@ class CologneBlueTemplate extends BaseTemplate {
         *
         * @param $bar sidebar data
         * @return array modified sidebar data
-        *
-        * @fixed
         */
        function sidebarAdditions( $bar ) {
                // "This page" and "Edit" menus
@@ -577,9 +421,10 @@ class CologneBlueTemplate extends BaseTemplate {
                        $qbmyoptions[$key] = null;
                }
 
-               $bar['qbedit'] = $qbedit;
-               $bar['qbpageoptions'] = $qbpageoptions;
-               $bar['qbmyoptions'] = $qbmyoptions;
+               // Use the closest reasonable name
+               $bar['cactions'] = $qbedit;
+               $bar['pageoptions'] = $qbpageoptions; // this is a non-standard portlet name, but nothing fits
+               $bar['personal'] = $qbmyoptions;
 
                return $bar;
        }
@@ -589,8 +434,6 @@ class CologneBlueTemplate extends BaseTemplate {
         * @access private
         *
         * @return string
-        *
-        * @fixed
         */
        function quickBar() {
                // Massage the sidebar. We want to:
@@ -626,12 +469,9 @@ class CologneBlueTemplate extends BaseTemplate {
                $bar = array();
                foreach ( $orig_bar as $heading => $data ) {
                        if ( $heading == 'SEARCH' ) {
-                               $bar['qbfind'] = $this->searchForm( 'sidebar' );
+                               $bar['search'] = $this->searchForm( 'sidebar' );
                        } elseif ( $heading == 'TOOLBOX' ) {
-                               $bar['toolbox'] = $this->getToolbox();
-                       } elseif ( $heading == 'navigation' ) {
-                               // Use the navigation heading from standard sidebar as the "browse" section
-                               $bar['qbbrowse'] = $data;
+                               $bar['tb'] = $this->getToolbox();
                        } else {
                                $bar[$heading] = $data;
                        }
@@ -639,12 +479,22 @@ class CologneBlueTemplate extends BaseTemplate {
 
 
                // Output the sidebar
+               // CologneBlue uses custom messages for some portlets, but we should keep the ids for consistency
+               $idToMessage = array(
+                       'search' => 'qbfind',
+                       'navigation' => 'qbbrowse',
+                       'tb' => 'toolbox',
+                       'cactions' => 'qbedit',
+                       'personal' => 'qbmyoptions',
+                       'pageoptions' => 'qbpageoptions',
+               );
+
                $s = "<div id='quickbar'>\n";
 
                foreach ( $bar as $heading => $data ) {
-                       $headingMsg = wfMessage( $heading );
-                       $headingHTML = "<h6>" . ( $headingMsg->exists() ? $headingMsg->escaped() : htmlspecialchars( $heading ) ) . "</h6>";
                        $portletId = Sanitizer::escapeId( "p-$heading" );
+                       $headingMsg = wfMessage( $idToMessage[$heading] ? $idToMessage[$heading] : $heading );
+                       $headingHTML = "<h3>" . ( $headingMsg->exists() ? $headingMsg->escaped() : htmlspecialchars( $heading ) ) . "</h3>";
                        $listHTML = "";
 
                        if ( is_array( $data ) ) {
@@ -664,7 +514,8 @@ class CologneBlueTemplate extends BaseTemplate {
                        }
 
                        if ( $listHTML ) {
-                               $s .= "<div class=\"portlet\" id=\"$portletId\">\n$headingHTML\n$listHTML\n</div>\n";
+                               $role = ( $heading == 'search' ) ? 'search' : 'navigation';
+                               $s .= "<div class=\"portlet\" id=\"$portletId\" role=\"$role\">\n$headingHTML\n$listHTML\n</div>\n";
                        }
                }
 
@@ -675,8 +526,6 @@ class CologneBlueTemplate extends BaseTemplate {
        /**
         * @param $label string
         * @return string
-        *
-        * @fixed
         */
        function searchForm( $which ) {
                global $wgUseTwoButtonsSearchForm;