Remove WikiReference::getHostname.
authordaniel <daniel.kinzler@wikimedia.de>
Fri, 11 Sep 2015 17:34:54 +0000 (19:34 +0200)
committerOri.livneh <ori@wikimedia.org>
Mon, 14 Sep 2015 18:41:13 +0000 (18:41 +0000)
getHostname() was broken and seems to be unused.

Change-Id: I8d44a6907ad395ea12deebf404831c06e07ed401

includes/WikiMap.php
tests/phpunit/includes/WikiReferenceTest.php

index a01f1b6..027ff72 100644 (file)
@@ -148,20 +148,6 @@ class WikiReference {
                $this->mServer = $server === null ? $canonicalServer : $server;
        }
 
-       /**
-        * @return string
-        * @throws MWException
-        */
-       public function getHostname() {
-               $prefixes = array( 'http://', 'https://' );
-               foreach ( $prefixes as $prefix ) {
-                       if ( substr( $this->mCanonicalServer, 0, strlen( $prefix ) ) ) {
-                               return substr( $this->mCanonicalServer, strlen( $prefix ) );
-                       }
-               }
-               throw new MWException( "Invalid hostname for wiki {$this->mMinor}.{$this->mMajor}" );
-       }
-
        /**
         * Get the URL in a way to be displayed to the user
         * More or less Wikimedia specific
@@ -169,13 +155,12 @@ class WikiReference {
         * @return string
         */
        public function getDisplayName() {
-               $url = $this->getUrl( '' );
-               $parsed = wfParseUrl( $url );
+               $parsed = wfParseUrl( $this->mCanonicalServer );
                if ( $parsed ) {
                        return $parsed['host'];
                } else {
-                       // Invalid URL. There's no sane thing to do here, so just return it
-                       return $url;
+                       // Invalid server spec. There's no sane thing to do here, so just return the canonical server name in full
+                       return $this->mCanonicalServer;
                }
        }
 
index ce9fc66..4fe2e85 100644 (file)
@@ -6,30 +6,13 @@
 
 class WikiReferenceTest extends PHPUnit_Framework_TestCase {
 
-       public function provideGetHostname() {
-               return array(
-                       'http' => array( 'foo.bar', 'http://foo.bar' ),
-                       'https' => array( 'foo.bar', 'https://foo.bar' ),
-               );
-       }
-
-       /**
-        * @dataProvider provideGetHostname
-        */
-       public function testGetHostname( $expected, $canonicalServer ) {
-               $this->markTestSkipped( 'The implementation is patently broken.' );
-
-               $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, '/wiki/$1' );
-               $this->assertEquals( $expected, $reference->getHostname() );
-       }
-
        public function provideGetDisplayName() {
                return array(
                        'http' => array( 'foo.bar', 'http://foo.bar' ),
                        'https' => array( 'foo.bar', 'http://foo.bar' ),
 
                        // apparently, this is the expected behavior
-                       'invalid' => array( 'purple kittens/wiki/', 'purple kittens' ),
+                       'invalid' => array( 'purple kittens', 'purple kittens' ),
                );
        }
 
@@ -67,6 +50,7 @@ class WikiReferenceTest extends PHPUnit_Framework_TestCase {
 
        /**
         * @dataProvider provideGetCanonicalUrl
+        * @note getUrl is an alias for getCanonicalUrl
         */
        public function testGetUrl( $expected, $canonicalServer, $server, $path, $page, $fragmentId ) {
                $reference = new WikiReference( 'wiki', 'xx', $canonicalServer, $path, $server );