Apply default robot policy for non-existing user pages
authorumherirrender <umherirrender_de.wp@web.de>
Fri, 24 May 2013 14:17:12 +0000 (16:17 +0200)
committerMarius Hoch <hoo@online.de>
Fri, 24 May 2013 16:12:34 +0000 (18:12 +0200)
MediaWiki is sending HTTP 200 for every user page, this can result in
search engine indexing user pages with block hint. This is not happen,
when the page exists (even it is empty), so applying the default robot
policy also for non-existing user pages to avoid this.

Change-Id: Ia62b977b3488d6b002c7b129d9308b7887e4f42d

includes/Article.php

index a0d4438..dc57911 100644 (file)
@@ -855,11 +855,11 @@ class Article implements Page {
        /**
         * Get the robot policy to be used for the current view
         * @param string $action the action= GET parameter
-        * @param $pOutput ParserOutput
+        * @param $pOutput ParserOutput|null
         * @return Array the policy that should be set
         * TODO: actions other than 'view'
         */
-       public function getRobotPolicy( $action, $pOutput ) {
+       public function getRobotPolicy( $action, $pOutput = null ) {
                global $wgArticleRobotPolicies, $wgNamespaceRobotPolicies, $wgDefaultRobotPolicy;
 
                $ns = $this->getTitle()->getNamespace();
@@ -1142,6 +1142,13 @@ class Article implements Page {
                        $this->getContext()->getRequest()->response()->header( "HTTP/1.1 404 Not Found" );
                }
 
+               if ( $validUserPage ) {
+                       // Also apply the robot policy for nonexisting user pages (as those aren't served as 404)
+                       $policy = $this->getRobotPolicy( 'view' );
+                       $outputPage->setIndexPolicy( $policy['index'] );
+                       $outputPage->setFollowPolicy( $policy['follow'] );
+               }
+
                $hookResult = wfRunHooks( 'BeforeDisplayNoArticleText', array( $this ) );
 
                if ( ! $hookResult ) {