Fix rel="copyright" for ApiHelp
authorRicordisamoa <ricordisamoa@openmailbox.org>
Mon, 8 Jun 2015 13:39:06 +0000 (15:39 +0200)
committerRicordisamoa <ricordisamoa@openmailbox.org>
Fri, 12 Jun 2015 23:53:40 +0000 (01:53 +0200)
Bug: T94038
Bug: T93995
Change-Id: I06e9bb6797c4e4ee00e5d72eda1e273800b2c7f4

includes/OutputPage.php
includes/api/ApiHelp.php

index a8fc01d..3b9da40 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.
         *
@@ -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 ) {
index a81ae3f..f6d124f 100644 (file)
@@ -45,6 +45,7 @@ class ApiHelp extends ApiBase {
                $context->setLanguage( $this->getMain()->getLanguage() );
                $context->setTitle( SpecialPage::getTitleFor( 'ApiHelp' ) );
                $out = new OutputPage( $context );
+               $out->setCopyrightUrl( 'https://www.mediawiki.org/wiki/Special:MyLanguage/Copyright' );
                $context->setOutput( $out );
 
                self::getHelp( $context, $modules, $params );