Make Block::newFromTarget() work again when passing only a vague target
authorAlexandre Emsenhuber <ialex.wiki@gmail.com>
Fri, 11 Jan 2013 10:30:21 +0000 (11:30 +0100)
committerAlexandre Emsenhuber <ialex.wiki@gmail.com>
Fri, 11 Jan 2013 10:30:21 +0000 (11:30 +0100)
Since SVN r106354 (85ee2d2d), when passing null or an invalid block target
to Block::newFromTarget(), it was never returning any block, even if the
vague target would have matched one.

This broke two features of core MediaWiki:
- Excluding user and user talk pages of blocked users from being indexed,
  the feature that actually caused bug 33101 and the revision mentionned above
- Blocking of account creation when both the user and its IP address are blocked,
  but of only the IP address blocks prevents account creation (bug 13611)
And maybe some others in extensions, I didn't check that.

This changes reverts part of r106354 to make Block::newFromTarget() work again
in that case and changed Article::getRobotPolicy() to pass the user to be checked
as vague target only when it's an IP address and as specific target otherwise.

Change-Id: Ie7e16e0bae8c4326d16cca237877693f7b474a01

includes/Article.php
includes/Block.php

index 2c59fe7..8eb58a9 100644 (file)
@@ -864,15 +864,21 @@ class Article extends Page {
 
                $ns = $this->getTitle()->getNamespace();
 
-               if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
-                       # Don't index user and user talk pages for blocked users (bug 11443)
-                       if ( !$this->getTitle()->isSubpage() ) {
-                               if ( Block::newFromTarget( null, $this->getTitle()->getText() ) instanceof Block ) {
-                                       return array(
-                                               'index'  => 'noindex',
-                                               'follow' => 'nofollow'
-                                       );
-                               }
+               # Don't index user and user talk pages for blocked users (bug 11443)
+               if ( ( $ns == NS_USER || $ns == NS_USER_TALK ) && !$this->getTitle()->isSubpage() ) {
+                       $specificTarget = null;
+                       $vagueTarget = null;
+                       $titleText = $this->getTitle()->getText();
+                       if ( IP::isValid( $titleText ) ) {
+                               $vagueTarget = $titleText;
+                       } else {
+                               $specificTarget = $titleText;
+                       }
+                       if ( Block::newFromTarget( $specificTarget, $vagueTarget ) instanceof Block ) {
+                               return array(
+                                       'index'  => 'noindex',
+                                       'follow' => 'nofollow'
+                               );
                        }
                }
 
index afacc43..b4c577c 100644 (file)
@@ -1057,7 +1057,7 @@ class Block {
                        # passed by some callers (bug 29116)
                        return null;
 
-               } elseif( in_array( $type, array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE ) ) ) {
+               } elseif( in_array( $type, array( Block::TYPE_USER, Block::TYPE_IP, Block::TYPE_RANGE, null ) ) ) {
                        $block = new Block();
                        $block->fromMaster( $fromMaster );