Merge "Provide direction hinting in the personal toolbar"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 1 Mar 2014 16:59:15 +0000 (16:59 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 1 Mar 2014 16:59:15 +0000 (16:59 +0000)
1  2 
includes/SkinTemplate.php

@@@ -130,65 -130,39 +130,65 @@@ class SkinTemplate extends Skin 
         */
        public function getLanguages() {
                global $wgHideInterlanguageLinks;
 -              $out = $this->getOutput();
 +              if ( $wgHideInterlanguageLinks ) {
 +                      return array();
 +              }
  
 -              # Language links
 -              $language_urls = array();
 -
 -              if ( !$wgHideInterlanguageLinks ) {
 -                      foreach ( $out->getLanguageLinks() as $languageLinkText ) {
 -                              $languageLinkParts = explode( ':', $languageLinkText, 2 );
 -                              $class = 'interwiki-' . $languageLinkParts[0];
 -                              unset( $languageLinkParts );
 -                              $languageLinkTitle = Title::newFromText( $languageLinkText );
 -                              if ( $languageLinkTitle ) {
 -                                      $ilInterwikiCode = $languageLinkTitle->getInterwiki();
 -                                      $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
 -
 -                                      if ( strval( $ilLangName ) === '' ) {
 -                                              $ilLangName = $languageLinkText;
 -                                      } else {
 -                                              $ilLangName = $this->formatLanguageName( $ilLangName );
 -                                      }
 +              $userLang = $this->getLanguage();
 +              $languageLinks = array();
  
 -                                      $language_urls[] = array(
 -                                              'href' => $languageLinkTitle->getFullURL(),
 -                                              'text' => $ilLangName,
 -                                              'title' => $languageLinkTitle->getText(),
 -                                              'class' => $class,
 -                                              'lang' => wfBCP47( $ilInterwikiCode ),
 -                                              'hreflang' => wfBCP47( $ilInterwikiCode ),
 -                                      );
 +              foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
 +                      $languageLinkParts = explode( ':', $languageLinkText, 2 );
 +                      $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
 +                      unset( $languageLinkParts );
 +
 +                      $languageLinkTitle = Title::newFromText( $languageLinkText );
 +                      if ( $languageLinkTitle ) {
 +                              $ilInterwikiCode = $languageLinkTitle->getInterwiki();
 +                              $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
 +
 +                              if ( strval( $ilLangName ) === '' ) {
 +                                      $ilLangName = $languageLinkText;
 +                              } else {
 +                                      $ilLangName = $this->formatLanguageName( $ilLangName );
 +                              }
 +
 +                              // CLDR extension or similar is required to localize the language name;
 +                              // otherwise we'll end up with the autonym again.
 +                              $ilLangLocalName = Language::fetchLanguageName(
 +                                      $ilInterwikiCode,
 +                                      $userLang->getCode()
 +                              );
 +
 +                              $languageLinkTitleText = $languageLinkTitle->getText();
 +                              if ( $languageLinkTitleText === '' ) {
 +                                      $ilTitle = wfMessage(
 +                                              'interlanguage-link-title-langonly',
 +                                              $ilLangLocalName
 +                                      )->text();
 +                              } else {
 +                                      $ilTitle = wfMessage(
 +                                              'interlanguage-link-title',
 +                                              $languageLinkTitleText,
 +                                              $ilLangLocalName
 +                                      )->text();
                                }
 +
 +                              $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
 +                              $languageLink = array(
 +                                      'href' => $languageLinkTitle->getFullURL(),
 +                                      'text' => $ilLangName,
 +                                      'title' => $ilTitle,
 +                                      'class' => $class,
 +                                      'lang' => $ilInterwikiCodeBCP47,
 +                                      'hreflang' => $ilInterwikiCodeBCP47,
 +                              );
 +                              wfRunHooks( 'SkinTemplateGetLanguageLink', array( &$languageLink, $languageLinkTitle, $this->getTitle() ) );
 +                              $languageLinks[] = $languageLink;
                        }
                }
 -              return $language_urls;
 +
 +              return $languageLinks;
        }
  
        protected function setupTemplateForOutput() {
         * @param $out OutputPage
         */
        function outputPage( OutputPage $out = null ) {
 -              global $wgContLang;
 -              global $wgScript, $wgStylePath;
 -              global $wgMimeType, $wgJsMimeType;
 -              global $wgXhtmlNamespaces, $wgHtml5Version;
 -              global $wgDisableCounters, $wgSitename, $wgLogo;
 -              global $wgMaxCredits, $wgShowCreditsIfMax;
 -              global $wgPageShowWatchingUsers;
 -              global $wgArticlePath, $wgScriptPath, $wgServer;
 -
                wfProfileIn( __METHOD__ );
                Profiler::instance()->setTemplated( true );
  
                }
  
                $out = $this->getOutput();
 -              $request = $this->getRequest();
 -              $user = $this->getUser();
 -              $title = $this->getTitle();
  
                wfProfileIn( __METHOD__ . '-init' );
                $this->initPage( $out );
                wfProfileOut( __METHOD__ . '-init' );
 +              $tpl = $this->prepareQuickTemplate( $out );
 +              // execute template
 +              wfProfileIn( __METHOD__ . '-execute' );
 +              $res = $tpl->execute();
 +              wfProfileOut( __METHOD__ . '-execute' );
 +
 +              // result may be an error
 +              $this->printOrError( $res );
 +
 +              if ( $oldContext ) {
 +                      $this->setContext( $oldContext );
 +              }
 +
 +              wfProfileOut( __METHOD__ );
 +      }
 +
 +      /**
 +       * initialize various variables and generate the template
 +       *
 +       * @since 1.23
 +       * @return QuickTemplate the template to be executed by outputPage
 +       */
 +      protected function prepareQuickTemplate() {
 +              global $wgContLang, $wgScript, $wgStylePath,
 +                      $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
 +                      $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
 +                      $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
 +                      $wgScriptPath, $wgServer;
  
 +              wfProfileIn( __METHOD__ );
 +
 +              $title = $this->getTitle();
 +              $request = $this->getRequest();
 +              $out = $this->getOutput();
                $tpl = $this->setupTemplateForOutput();
  
                wfProfileIn( __METHOD__ . '-stuff-head' );
                        $feeds = array();
                        foreach ( $out->getSyndicationLinks() as $format => $link ) {
                                $feeds[$format] = array(
 +                                      // Messages: feed-atom, feed-rss
                                        'text' => $this->msg( "feed-$format" )->text(),
                                        'href' => $link
                                );
                $tpl->set( 'dataAfterContent', $this->afterContentHook() );
                wfProfileOut( __METHOD__ . '-stuff5' );
  
 -              // execute template
 -              wfProfileIn( __METHOD__ . '-execute' );
 -              $res = $tpl->execute();
 -              wfProfileOut( __METHOD__ . '-execute' );
 -
 -              // result may be an error
 -              $this->printOrError( $res );
 -
 -              if ( $oldContext ) {
 -                      $this->setContext( $oldContext );
 -              }
                wfProfileOut( __METHOD__ );
 +              return $tpl;
        }
  
        /**
         * @return array
         */
        protected function buildPersonalUrls() {
 -              global $wgSecureLogin;
 -
                $title = $this->getTitle();
                $request = $this->getRequest();
                $pageurl = $title->getLocalURL();
                        }
                }
  
 -              if ( $wgSecureLogin && $request->detectProtocol() === 'https' ) {
 -                      $a['wpStickHTTPS'] = true;
 -              }
 -
                $returnto = wfArrayToCgi( $a );
                if ( $this->loggedin ) {
                        $personal_urls['userpage'] = array(
                                'active' => $active
                        );
                        $personal_urls['logout'] = array(
 -                              'text' => $this->msg( 'userlogout' )->text(),
 +                              'text' => $this->msg( 'pt-userlogout' )->text(),
                                'href' => self::makeSpecialUrl( 'Userlogout',
                                        // userlogout link must always contain an & character, otherwise we might not be able
                                        // to detect a buggy precaching proxy (bug 17790)
                        $useCombinedLoginLink = $this->useCombinedLoginLink();
                        $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
                                ? 'nav-login-createaccount'
 -                              : 'login';
 +                              : 'pt-login';
                        $is_signup = $request->getText( 'type' ) == 'signup';
  
 -                      # anonlogin & login are the same
 -                      $proto = $wgSecureLogin ? PROTO_HTTPS : null;
 -
 -                      $login_id = $this->showIPinHeader() ? 'anonlogin' : 'login';
                        $login_url = array(
                                'text' => $this->msg( $loginlink )->text(),
 -                              'href' => self::makeSpecialUrl( 'Userlogin', $returnto, $proto ),
 +                              'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
                                'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup ),
 -                              'class' => $wgSecureLogin ? 'link-https' : ''
                        );
                        $createaccount_url = array(
 -                              'text' => $this->msg( 'createaccount' )->text(),
 -                              'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup", $proto ),
 +                              'text' => $this->msg( 'pt-createaccount' )->text(),
 +                              'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
                                'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
 -                              'class' => $wgSecureLogin ? 'link-https' : ''
                        );
  
                        if ( $this->showIPinHeader() ) {
                                $personal_urls['createaccount'] = $createaccount_url;
                        }
  
 -                      $personal_urls[$login_id] = $login_url;
 +                      $personal_urls['login'] = $login_url;
                }
  
 -              wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
 +              wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
                wfProfileOut( __METHOD__ );
                return $personal_urls;
        }
                                        }
                                }
  
 -                              if ( $title->getNamespace() !== NS_MEDIAWIKI && $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() ) {
 +                              if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
 +                                      MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
 +                              ) {
                                        $mode = $title->isProtected() ? 'unprotect' : 'protect';
                                        $content_navigation['actions'][$mode] = array(
                                                'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
                                );
                        }
  
 -                      $sur = new UserrightsPage;
 -                      $sur->setContext( $this->getContext() );
 -                      if ( $sur->userCanExecute( $this->getUser() ) ) {
 -                              $nav_urls['userrights'] = array(
 -                                      'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
 -                              );
 +                      if ( !$user->isAnon() ) {
 +                              $sur = new UserrightsPage;
 +                              $sur->setContext( $this->getContext() );
 +                              if ( $sur->userCanExecute( $this->getUser() ) ) {
 +                                      $nav_urls['userrights'] = array(
 +                                              'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
 +                                      );
 +                              }
                        }
                }
  
        function getNameSpaceKey() {
                return $this->getTitle()->getNamespaceKey();
        }
 -
 -      public function commonPrintStylesheet() {
 -              return false;
 -      }
  }
  
  /**
@@@ -1404,6 -1378,15 +1404,6 @@@ abstract class QuickTemplate 
                echo htmlspecialchars( $this->data[$str] );
        }
  
 -      /**
 -       * @private
 -       * @deprecated since 1.21; use Xml::encodeJsVar() or Xml::encodeJsCall() instead
 -       */
 -      function jstext( $str ) {
 -              wfDeprecated( __METHOD__, '1.21' );
 -              echo Xml::escapeJsString( $this->data[$str] );
 -      }
 -
        /**
         * @private
         */
        public function getSkin() {
                return $this->data['skin'];
        }
 +
 +      /**
 +       * Fetch the output of a QuickTemplate and return it
 +       *
 +       * @since 1.23
 +       * @return String
 +       */
 +      public function getHTML() {
 +              ob_start();
 +              $this->execute();
 +              $html = ob_get_contents();
 +              ob_end_clean();
 +              return $html;
 +      }
  }
  
  /**
@@@ -1596,7 -1565,7 +1596,7 @@@ abstract class BaseTemplate extends Qui
                        if ( isset( $plink['active'] ) ) {
                                $ptool['active'] = $plink['active'];
                        }
-                       foreach ( array( 'href', 'class', 'text' ) as $k ) {
+                       foreach ( array( 'href', 'class', 'text', 'dir' ) as $k ) {
                                if ( isset( $plink[$k] ) ) {
                                        $ptool['links'][0][$k] = $plink[$k];
                                }
         * on the link) is present it will be used to generate a tooltip and
         * accesskey for the link.
         *
 +       * The keys "context" and "primary" are ignored; these keys are used
 +       * internally by skins and are not supposed to be included in the HTML
 +       * output.
 +       *
         * If you don't want an accesskey, set $item['tooltiponly'] = true;
         *
         * @param array $options can be used to affect the output of a link.
  
                if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
                        $attrs = $item;
 -                      foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) {
 +                      foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
                                unset( $attrs[$k] );
                        }
  
         * body and html tags.
         */
        function printTrail() { ?>
 +<?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() ); ?>
  <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
  <?php $this->html( 'reporttime' ) ?>
 -<?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() );
 +<?php
        }
  
  }