API: Set robots noindex,nofollow on HTML output
authorBrad Jorsch <bjorsch@wikimedia.org>
Thu, 25 Oct 2018 13:31:31 +0000 (09:31 -0400)
committerBrad Jorsch <bjorsch@wikimedia.org>
Thu, 25 Oct 2018 13:37:30 +0000 (09:37 -0400)
There's probably not much benefit in search engines indexing the API
auto-generated help or various random "format=jsonfm" outputs.

On Wikimedia wikis we already have a robots.txt entry denying indexing
of everything under /w/, which includes api.php.

Bug: T207818
Change-Id: I196d401eeb5fcf49844265df41ad3cce83ffdcdf

includes/api/ApiFormatBase.php
includes/api/ApiHelp.php

index 234fcfd..9d69145 100644 (file)
@@ -252,6 +252,7 @@ abstract class ApiFormatBase extends ApiBase {
                        $out = new OutputPage( $context );
                        $context->setOutput( $out );
 
+                       $out->setRobotPolicy( 'noindex,nofollow' );
                        $out->addModuleStyles( 'mediawiki.apipretty' );
                        $out->setPageTitle( $context->msg( 'api-format-title' ) );
 
index 72509c2..84fcbef 100644 (file)
@@ -44,6 +44,7 @@ class ApiHelp extends ApiBase {
                $context->setLanguage( $this->getMain()->getLanguage() );
                $context->setTitle( SpecialPage::getTitleFor( 'ApiHelp' ) );
                $out = new OutputPage( $context );
+               $out->setRobotPolicy( 'noindex,nofollow' );
                $out->setCopyrightUrl( 'https://www.mediawiki.org/wiki/Special:MyLanguage/Copyright' );
                $context->setOutput( $out );