Merge "Update Special:ChangePassword to use HTMLForm"
[lhc/web/wiklou.git] / includes / SkinTemplate.php
index 414312a..18e36ba 100644 (file)
@@ -130,51 +130,63 @@ class SkinTemplate extends Skin {
         */
        public function getLanguages() {
                global $wgHideInterlanguageLinks;
-               $out = $this->getOutput();
+               if ( $wgHideInterlanguageLinks ) {
+                       return array();
+               }
+
                $userLang = $this->getLanguage();
+               $languageLinks = array();
 
-               # Language links
-               $language_urls = array();
-
-               if ( !$wgHideInterlanguageLinks ) {
-                       foreach ( $out->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 );
-                                       }
+               foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
+                       $languageLinkParts = explode( ':', $languageLinkText, 2 );
+                       $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
+                       unset( $languageLinkParts );
 
-                                       // 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() );
+                       $languageLinkTitle = Title::newFromText( $languageLinkText );
+                       if ( $languageLinkTitle ) {
+                               $ilInterwikiCode = $languageLinkTitle->getInterwiki();
+                               $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
 
-                                       if ( $languageLinkTitle->getText() === '' ) {
-                                               $ilTitle = wfMessage( 'interlanguage-link-title-langonly', $ilLangLocalName )->text();
-                                       } else {
-                                               $ilTitle = wfMessage( 'interlanguage-link-title', $languageLinkTitle->getText(),
-                                                       $ilLangLocalName )->text();
-                                       }
+                               if ( strval( $ilLangName ) === '' ) {
+                                       $ilLangName = $languageLinkText;
+                               } else {
+                                       $ilLangName = $this->formatLanguageName( $ilLangName );
+                               }
 
-                                       $language_urls[] = array(
-                                               'href' => $languageLinkTitle->getFullURL(),
-                                               'text' => $ilLangName,
-                                               'title' => $ilTitle,
-                                               'class' => $class,
-                                               'lang' => wfBCP47( $ilInterwikiCode ),
-                                               'hreflang' => wfBCP47( $ilInterwikiCode ),
-                                       );
+                               // 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 );
+                               $languageLinks[] = array(
+                                       'href' => $languageLinkTitle->getFullURL(),
+                                       'text' => $ilLangName,
+                                       'title' => $ilTitle,
+                                       'class' => $class,
+                                       'lang' => $ilInterwikiCodeBCP47,
+                                       'hreflang' => $ilInterwikiCodeBCP47,
+                               );
                        }
                }
-               return $language_urls;
+
+               return $languageLinks;
        }
 
        protected function setupTemplateForOutput() {
@@ -235,7 +247,6 @@ class SkinTemplate extends Skin {
                }
 
                $out = $this->getOutput();
-               $user = $this->getUser();
 
                wfProfileIn( __METHOD__ . '-init' );
                $this->initPage( $out );
@@ -260,10 +271,9 @@ class SkinTemplate extends Skin {
         * initialize various variables and generate the template
         *
         * @since 1.23
-        * @param $out OutputPage
         * @return QuickTemplate the template to be executed by outputPage
         */
-       protected function prepareQuickTemplate( OutputPage $out = null ) {
+       protected function prepareQuickTemplate() {
                global $wgContLang, $wgScript, $wgStylePath,
                        $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
                        $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
@@ -274,6 +284,7 @@ class SkinTemplate extends Skin {
 
                $title = $this->getTitle();
                $request = $this->getRequest();
+               $out = $this->getOutput();
                $tpl = $this->setupTemplateForOutput();
 
                wfProfileIn( __METHOD__ . '-stuff-head' );
@@ -1027,7 +1038,9 @@ class SkinTemplate extends Skin {
                                        }
                                }
 
-                               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,
@@ -1390,15 +1403,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
         */