From: Alexandre Emsenhuber Date: Fri, 11 Jan 2013 10:30:21 +0000 (+0100) Subject: Make Block::newFromTarget() work again when passing only a vague target X-Git-Tag: 1.31.0-rc.0~21058^2 X-Git-Url: https://git.cyclocoop.org/%27.WWW_URL.%27admin/?a=commitdiff_plain;h=323480faaa2c76db8470165db5638c419bde45d4;p=lhc%2Fweb%2Fwiklou.git Make Block::newFromTarget() work again when passing only a vague target 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 --- diff --git a/includes/Article.php b/includes/Article.php index 2c59fe750e..8eb58a957f 100644 --- a/includes/Article.php +++ b/includes/Article.php @@ -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' + ); } } diff --git a/includes/Block.php b/includes/Block.php index afacc43aa2..b4c577cc88 100644 --- a/includes/Block.php +++ b/includes/Block.php @@ -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 );