From 8cfa62d8376bdcde687dad1837f08bac6f82f09e Mon Sep 17 00:00:00 2001 From: Thalia Date: Thu, 27 Jun 2019 19:24:52 +0100 Subject: [PATCH] Bidi isolate user names in block error paramters This fixes parameters returned by AbstractBlock::getBlockErrorParams, but not those from ApiBlockInfoTrait. Change-Id: I122017808766de1e9a9035f2f39a7b08607e56c1 --- includes/block/AbstractBlock.php | 12 ++++++----- .../Permissions/PermissionManagerTest.php | 20 +++++++++---------- .../phpunit/includes/TitlePermissionTest.php | 20 +++++++++---------- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/includes/block/AbstractBlock.php b/includes/block/AbstractBlock.php index 0357f8d29d..d24a2a5773 100644 --- a/includes/block/AbstractBlock.php +++ b/includes/block/AbstractBlock.php @@ -513,10 +513,13 @@ abstract class AbstractBlock { * @return array */ public function getBlockErrorParams( IContextSource $context ) { + $lang = $context->getLanguage(); + $blocker = $this->getBlocker(); if ( $blocker instanceof User ) { // local user $blockerUserpage = $blocker->getUserPage(); - $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerUserpage->getText()}]]"; + $blockerText = $lang->embedBidi( $blockerUserpage->getText() ); + $link = "[[{$blockerUserpage->getPrefixedText()}|{$blockerText}]]"; } else { // foreign user $link = $blocker; } @@ -528,19 +531,18 @@ abstract class AbstractBlock { /* $ip returns who *is* being blocked, $intended contains who was meant to be blocked. * This could be a username, an IP range, or a single IP. */ - $intended = $this->getTarget(); - $lang = $context->getLanguage(); + $intended = (string)$this->getTarget(); return [ $link, $reason, $context->getRequest()->getIP(), - $this->getByName(), + $lang->embedBidi( $this->getByName() ), // TODO: SystemBlock replaces this with the system block type. Clean up // error params so that this is not necessary. $this->getId(), $lang->formatExpiry( $this->getExpiry() ), - (string)$intended, + $lang->embedBidi( $intended ), $lang->userTimeAndDate( $this->getTimestamp(), $context->getUser() ), ]; } diff --git a/tests/phpunit/includes/Permissions/PermissionManagerTest.php b/tests/phpunit/includes/Permissions/PermissionManagerTest.php index 88a3f43f0e..3da73c148e 100644 --- a/tests/phpunit/includes/Permissions/PermissionManagerTest.php +++ b/tests/phpunit/includes/Permissions/PermissionManagerTest.php @@ -1105,8 +1105,8 @@ class PermissionManagerTest extends MediaWikiLangTestCase { ] ); $this->user->mBlock->mTimestamp = 0; $this->assertEquals( [ [ 'autoblockedtext', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', null, 'infinite', '127.0.8.1', + "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1', + "\u{202A}Useruser\u{202C}", null, 'infinite', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ] ], MediaWikiServices::getInstance()->getPermissionManager()->getPermissionErrors( 'move-target', $this->user, $this->title ) ); @@ -1130,8 +1130,8 @@ class PermissionManagerTest extends MediaWikiLangTestCase { 'expiry' => 10, ] ); $this->assertEquals( [ [ 'blockedtext', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1', + "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1', + "\u{202A}Useruser\u{202C}", null, '23:00, 31 December 1969', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ], MediaWikiServices::getInstance()->getPermissionManager() ->getPermissionErrors( 'move-target', $this->user, $this->title ) ); @@ -1150,8 +1150,8 @@ class PermissionManagerTest extends MediaWikiLangTestCase { ] ); $errors = [ [ 'systemblockedtext', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', 'test', 'infinite', '127.0.8.1', + "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1', + "\u{202A}Useruser\u{202C}", 'test', 'infinite', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ]; $this->assertEquals( $errors, @@ -1208,8 +1208,8 @@ class PermissionManagerTest extends MediaWikiLangTestCase { ] ); $errors = [ [ 'blockedtext-partial', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1', + "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1', + "\u{202A}Useruser\u{202C}", null, '23:00, 31 December 1969', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ]; $this->assertEquals( $errors, @@ -1282,8 +1282,8 @@ class PermissionManagerTest extends MediaWikiLangTestCase { ] ); $errors = [ [ 'blockedtext', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', null, 'infinite', '127.0.8.1', + "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1', + "\u{202A}Useruser\u{202C}", null, 'infinite', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ]; $this->assertEquals( $errors, diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index 150e2ed14a..e6cf8c8b89 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -948,8 +948,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase { ] ); $this->user->mBlock->setTimestamp( 0 ); $this->assertEquals( [ [ 'autoblockedtext', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', null, 'infinite', '127.0.8.1', + "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1', + "\u{202A}Useruser\u{202C}", null, 'infinite', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ] ], $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); @@ -970,8 +970,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase { 'expiry' => 10, ] ); $this->assertEquals( [ [ 'blockedtext', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1', + "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1', + "\u{202A}Useruser\u{202C}", null, '23:00, 31 December 1969', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ], $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this ) @@ -988,8 +988,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase { ] ); $errors = [ [ 'systemblockedtext', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', 'test', 'infinite', '127.0.8.1', + "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1', + "\u{202A}Useruser\u{202C}", 'test', 'infinite', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ]; $this->assertEquals( $errors, @@ -1034,8 +1034,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase { ] ); $errors = [ [ 'blockedtext-partial', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1', + "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1', + "\u{202A}Useruser\u{202C}", null, '23:00, 31 December 1969', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ]; $this->assertEquals( $errors, @@ -1102,8 +1102,8 @@ class TitlePermissionTest extends MediaWikiLangTestCase { ] ); $errors = [ [ 'blockedtext', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', null, 'infinite', '127.0.8.1', + "[[User:Useruser|\u{202A}Useruser\u{202C}]]", 'no reason given', '127.0.0.1', + "\u{202A}Useruser\u{202C}", null, 'infinite', '127.0.8.1', $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ] ]; $this->assertEquals( $errors, -- 2.20.1