(bug 36780) Improve display of IPv6 addresses
authorcsteipp <csteipp@wikimedia.org>
Tue, 22 May 2012 23:30:07 +0000 (23:30 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Mon, 26 Nov 2012 23:00:33 +0000 (23:00 +0000)
Also add partial tests for Linker::userLink()

Change-Id: I680a59bb0ec3ca1d85ed12b0debb3446c73a3aab

includes/Linker.php
tests/phpunit/includes/LinkerTest.php [new file with mode: 0644]

index e5db232..12edcc8 100644 (file)
@@ -1075,6 +1075,9 @@ class Linker {
        public static function userLink( $userId, $userName, $altUserName = false ) {
                if ( $userId == 0 ) {
                        $page = SpecialPage::getTitleFor( 'Contributions', $userName );
+                       if ( $altUserName === false ) {
+                               $altUserName = IP::prettifyIP( $userName );
+                       }
                } else {
                        $page = Title::makeTitle( NS_USER, $userName );
                }
diff --git a/tests/phpunit/includes/LinkerTest.php b/tests/phpunit/includes/LinkerTest.php
new file mode 100644 (file)
index 0000000..4799dc0
--- /dev/null
@@ -0,0 +1,70 @@
+<?php
+
+class LinkerTest extends MediaWikiTestCase {
+
+       /**
+        * @dataProvider provideCasesForUserLink
+        * @cover Linker::userLink
+        */
+       function testUserLink( $expected, $userId, $userName, $altUserName = false, $msg='' ) {
+               $this->setMwGlobals( array(
+                       'wgArticlePath' => '/wiki/$1',
+               ) );
+
+               $this->assertEquals( $expected,
+                       Linker::userLink( $userId, $userName, $altUserName, $msg )
+               );
+       }
+
+       function provideCasesForUserLink() {
+               # Format:
+               # - expected
+               # - userid
+               # - username
+               # - optional altUserName
+               # - optional message
+               return array(
+
+                       ### ANONYMOUS USER ########################################
+                       array(
+                               '<a href="/wiki/Special:Contributions/JohnDoe" title="Special:Contributions/JohnDoe" class="mw-userlink">JohnDoe</a>',
+                               0, 'JohnDoe', false,
+                       ),
+                       array(
+                               '<a href="/wiki/Special:Contributions/::1" title="Special:Contributions/::1" class="mw-userlink">::1</a>',
+                               0, '::1', false,
+                               'Anonymous with pretty IPv6'
+                       ),
+                       array(
+                               '<a href="/wiki/Special:Contributions/0:0:0:0:0:0:0:1" title="Special:Contributions/0:0:0:0:0:0:0:1" class="mw-userlink">::1</a>',
+                               0, '0:0:0:0:0:0:0:1', false,
+                               'Anonymous with almost pretty IPv6'
+                       ),
+                       array(
+                               '<a href="/wiki/Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" title="Special:Contributions/0000:0000:0000:0000:0000:0000:0000:0001" class="mw-userlink">::1</a>',
+                               0, '0000:0000:0000:0000:0000:0000:0000:0001', false,
+                               'Anonymous with full IPv6'
+                       ),
+                       array(
+                               '<a href="/wiki/Special:Contributions/::1" title="Special:Contributions/::1" class="mw-userlink">AlternativeUsername</a>',
+                               0, '::1', 'AlternativeUsername',
+                               'Anonymous with pretty IPv6 and an alternative username'
+                       ),
+
+                       # IPV4
+                       array(
+                               '<a href="/wiki/Special:Contributions/127.0.0.1" title="Special:Contributions/127.0.0.1" class="mw-userlink">127.0.0.1</a>',
+                               0, '127.0.0.1', false,
+                               'Anonymous with IPv4'
+                       ),
+                       array(
+                               '<a href="/wiki/Special:Contributions/127.0.0.1" title="Special:Contributions/127.0.0.1" class="mw-userlink">AlternativeUsername</a>',
+                               0, '127.0.0.1', 'AlternativeUsername',
+                               'Anonymous with IPv4 and an alternative username'
+                       ),
+
+                       ### Regular user ##########################################
+                       # TODO!
+               );
+       }
+}