Merge "mediawiki.jqueryMsg: Declare dependency on user.options"
[lhc/web/wiklou.git] / includes / OutputPage.php
index fd55379..0ed847e 100644 (file)
@@ -304,6 +304,11 @@ class OutputPage extends ContextSource {
         */
        private $mEnableSectionEditLinks = true;
 
+       /**
+        * @var string|null The URL to send in a <link> element with rel=copyright
+        */
+       private $copyrightUrl;
+
        /**
         * Constructor for OutputPage. This should not be called directly.
         * Instead a new RequestContext should be created and it will implicitly create
@@ -340,6 +345,18 @@ class OutputPage extends ContextSource {
                return $this->mRedirect;
        }
 
+       /**
+        * Set the copyright URL to send with the output.
+        * Empty string to omit, null to reset.
+        *
+        * @since 1.26
+        *
+        * @param string|null $url
+        */
+       public function setCopyrightUrl( $url ) {
+               $this->copyrightUrl = $url;
+       }
+
        /**
         * Set the HTTP status code to send with the output.
         *
@@ -600,7 +617,8 @@ class OutputPage extends ContextSource {
                        $module = $resourceLoader->getModule( $val );
 
                        if ( $module instanceof ResourceLoaderModule && $module->isPositionDefault() ) {
-                               $warning = __METHOD__ . ': style module should define its position explicitly: ' . $val . ' ' . get_class( $module );
+                               $warning = __METHOD__ . ': style module should define its position explicitly: ' .
+                                       $val . ' ' . get_class( $module );
                                wfDebugLog( 'resourceloader', $warning );
                                wfLogWarning( $warning );
                        }
@@ -2264,7 +2282,6 @@ class OutputPage extends ContextSource {
                if ( $this->mArticleBodyOnly ) {
                        echo $this->mBodytext;
                } else {
-
                        $sk = $this->getSkin();
                        // add skin specific modules
                        $modules = $sk->getDefaultModules();
@@ -3432,17 +3449,21 @@ class OutputPage extends ContextSource {
                }
 
                # Copyright
-               $copyright = '';
-               if ( $config->get( 'RightsPage' ) ) {
-                       $copy = Title::newFromText( $config->get( 'RightsPage' ) );
+               if ( $this->copyrightUrl !== null ) {
+                       $copyright = $this->copyrightUrl;
+               } else {
+                       $copyright = '';
+                       if ( $config->get( 'RightsPage' ) ) {
+                               $copy = Title::newFromText( $config->get( 'RightsPage' ) );
 
-                       if ( $copy ) {
-                               $copyright = $copy->getLocalURL();
+                               if ( $copy ) {
+                                       $copyright = $copy->getLocalURL();
+                               }
                        }
-               }
 
-               if ( !$copyright && $config->get( 'RightsUrl' ) ) {
-                       $copyright = $config->get( 'RightsUrl' );
+                       if ( !$copyright && $config->get( 'RightsUrl' ) ) {
+                               $copyright = $config->get( 'RightsUrl' );
+                       }
                }
 
                if ( $copyright ) {
@@ -3503,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 ) {