HTMLTitleTextField: Support 'relative' config option
[lhc/web/wiklou.git] / includes / OutputPage.php
index 7322404..a551fe1 100644 (file)
@@ -2282,7 +2282,6 @@ class OutputPage extends ContextSource {
                if ( $this->mArticleBodyOnly ) {
                        echo $this->mBodytext;
                } else {
-
                        $sk = $this->getSkin();
                        // add skin specific modules
                        $modules = $sk->getDefaultModules();
@@ -3434,19 +3433,19 @@ class OutputPage extends ContextSource {
                        $lang = $this->getTitle()->getPageLanguage();
                        if ( $lang->hasVariants() ) {
                                $variants = $lang->getVariants();
-                               foreach ( $variants as $_v ) {
-                                       $tags["variant-$_v"] = Html::element( 'link', array(
+                               foreach ( $variants as $variant ) {
+                                       $tags["variant-$variant"] = Html::element( 'link', array(
                                                'rel' => 'alternate',
-                                               'hreflang' => wfBCP47( $_v ),
-                                               'href' => $this->getTitle()->getLocalURL( array( 'variant' => $_v ) ) )
+                                               'hreflang' => wfBCP47( $variant ),
+                                               'href' => $this->getTitle()->getLocalURL( array( 'variant' => $variant ) ) )
                                        );
                                }
+                               # x-default link per https://support.google.com/webmasters/answer/189077?hl=en
+                               $tags["variant-x-default"] = Html::element( 'link', array(
+                                       'rel' => 'alternate',
+                                       'hreflang' => 'x-default',
+                                       'href' => $this->getTitle()->getLocalURL() ) );
                        }
-                       # x-default link per https://support.google.com/webmasters/answer/189077?hl=en
-                       $tags["variant-x-default"] = Html::element( 'link', array(
-                               'rel' => 'alternate',
-                               'hreflang' => 'x-default',
-                               'href' => $this->getTitle()->getLocalURL() ) );
                }
 
                # Copyright
@@ -3525,8 +3524,25 @@ class OutputPage extends ContextSource {
                        if ( $canonicalUrl !== false ) {
                                $canonicalUrl = wfExpandUrl( $canonicalUrl, PROTO_CANONICAL );
                        } else {
-                               $reqUrl = $this->getRequest()->getRequestURL();
-                               $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL );
+                               if ( $this->isArticleRelated() ) {
+                                       // This affects all requests where "setArticleRelated" is true. This is
+                                       // typically all requests that show content (query title, curid, oldid, diff),
+                                       // and all wikipage actions (edit, delete, purge, info, history etc.).
+                                       // It does not apply to File pages and Special pages.
+                                       // 'history' and 'info' actions address page metadata rather than the page
+                                       // content itself, so they may not be canonicalized to the view page url.
+                                       // TODO: this ought to be better encapsulated in the Action class.
+                                       $action = Action::getActionName( $this->getContext() );
+                                       if ( in_array( $action, array( 'history', 'info' ) ) ) {
+                                               $query = "action={$action}";
+                                       } else {
+                                               $query = '';
+                                       }
+                                       $canonicalUrl = $this->getTitle()->getCanonicalURL( $query );
+                               } else {
+                                       $reqUrl = $this->getRequest()->getRequestURL();
+                                       $canonicalUrl = wfExpandUrl( $reqUrl, PROTO_CANONICAL );
+                               }
                        }
                }
                if ( $canonicalUrl !== false ) {
@@ -3936,13 +3952,21 @@ class OutputPage extends ContextSource {
         * @since 1.25
         */
        public function enableOOUI() {
-               OOUI\Theme::setSingleton( new OOUI\MediaWikiTheme() );
+               $themes = ExtensionRegistry::getInstance()->getAttribute( 'SkinOOUIThemes' );
+               // Make keys (skin names) lowercase for case-insensitive matching.
+               $themes = array_change_key_case( $themes, CASE_LOWER );
+               $skinName = strtolower( $this->getSkin()->getSkinName() );
+               $theme = isset( $themes[ $skinName ] ) ? $themes[ $skinName ] : 'MediaWiki';
+               // For example, 'OOUI\MediaWikiTheme'.
+               $themeClass = "OOUI\\{$theme}Theme";
+               OOUI\Theme::setSingleton( new $themeClass() );
                OOUI\Element::setDefaultDir( $this->getLanguage()->getDir() );
                $this->addModuleStyles( array(
                        'oojs-ui.styles',
                        'oojs-ui.styles.icons',
                        'oojs-ui.styles.indicators',
                        'oojs-ui.styles.textures',
+                       'mediawiki.widgets.styles',
                ) );
        }
 }