Merge "Use Title::makeName in Special:Export to simplify code"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Sat, 18 Aug 2018 04:10:00 +0000 (04:10 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Sat, 18 Aug 2018 04:10:00 +0000 (04:10 +0000)
includes/title/MediaWikiTitleCodec.php
includes/title/TitleFormatter.php
includes/title/TitleValue.php
tests/phpunit/includes/api/PrefixUniquenessTest.php [deleted file]
tests/phpunit/structure/ApiPrefixUniquenessTest.php [new file with mode: 0644]

index a00ef1e..15f8ff0 100644 (file)
@@ -112,18 +112,16 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
         * @return string
         */
        public function formatTitle( $namespace, $text, $fragment = '', $interwiki = '' ) {
-               if ( $namespace !== false ) {
+               if ( $namespace !== 0 && $namespace !== false ) {
                        // Try to get a namespace name, but fallback
-                       // to empty string if it doesn't exist
+                       // to empty string if it doesn't exist. And
+                       // assume that ns 0 is the empty string.
                        try {
                                $nsName = $this->getNamespaceName( $namespace, $text );
                        } catch ( InvalidArgumentException $e ) {
                                $nsName = '';
                        }
-
-                       if ( $namespace !== 0 ) {
-                               $text = $nsName . ':' . $text;
-                       }
+                       $text = $nsName . ':' . $text;
                }
 
                if ( $fragment !== '' ) {
@@ -176,7 +174,7 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
         * @return string $title->getText()
         */
        public function getText( LinkTarget $title ) {
-               return $this->formatTitle( false, $title->getText(), '' );
+               return $title->getText();
        }
 
        /**
index 4551d75..8859066 100644 (file)
@@ -50,7 +50,7 @@ interface TitleFormatter {
        /**
         * Returns the title text formatted for display, without namespace of fragment.
         *
-        * @note Only minimal normalization is applied. Consider using TitleValue::getText() directly.
+        * @note Consider using LinkTarget::getText() directly, it's identical.
         *
         * @param LinkTarget $title The title to format
         *
index 18e578d..43a399a 100644 (file)
@@ -158,7 +158,7 @@ class TitleValue implements LinkTarget {
         * @return string
         */
        public function getText() {
-               return str_replace( '_', ' ', $this->getDBkey() );
+               return str_replace( '_', ' ', $this->dbkey );
        }
 
        /**
diff --git a/tests/phpunit/includes/api/PrefixUniquenessTest.php b/tests/phpunit/includes/api/PrefixUniquenessTest.php
deleted file mode 100644 (file)
index d125a7d..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-<?php
-
-/**
- * Checks that all API query modules, core and extensions, have unique prefixes.
- *
- * @group API
- */
-class PrefixUniquenessTest extends MediaWikiTestCase {
-
-       public function testPrefixes() {
-               $main = new ApiMain( new FauxRequest() );
-               $query = new ApiQuery( $main, 'foo', 'bar' );
-               $moduleManager = $query->getModuleManager();
-
-               $modules = $moduleManager->getNames();
-               $prefixes = [];
-
-               foreach ( $modules as $name ) {
-                       $module = $moduleManager->getModule( $name );
-                       $class = get_class( $module );
-
-                       $prefix = $module->getModulePrefix();
-                       if ( $prefix !== '' && isset( $prefixes[$prefix] ) ) {
-                               $this->fail( "Module prefix '{$prefix}' is shared between {$class} and {$prefixes[$prefix]}" );
-                       }
-                       $prefixes[$module->getModulePrefix()] = $class;
-               }
-               $this->assertTrue( true ); // dummy call to make this test non-incomplete
-       }
-}
diff --git a/tests/phpunit/structure/ApiPrefixUniquenessTest.php b/tests/phpunit/structure/ApiPrefixUniquenessTest.php
new file mode 100644 (file)
index 0000000..4f95fbb
--- /dev/null
@@ -0,0 +1,49 @@
+<?php
+
+/**
+ * Checks that all API query modules, core and extensions, have unique prefixes.
+ *
+ * @group API
+ * @coversNothing
+ */
+class ApiPrefixUniquenessTest extends MediaWikiTestCase {
+
+       public function testPrefixes() {
+               $main = new ApiMain( new FauxRequest() );
+               $query = new ApiQuery( $main, 'foo' );
+               $moduleManager = $query->getModuleManager();
+
+               $modules = $moduleManager->getNames();
+               $prefixes = [];
+
+               foreach ( $modules as $name ) {
+                       $module = $moduleManager->getModule( $name );
+                       $class = get_class( $module );
+
+                       $prefix = $module->getModulePrefix();
+                       if ( $prefix === '' /* HACK: T196962 */ || $prefix === 'wbeu' ) {
+                               continue;
+                       }
+
+                       if ( isset( $prefixes[$prefix] ) ) {
+                               $this->fail(
+                                       "Module prefix '{$prefix}' is shared between {$class} and {$prefixes[$prefix]}"
+                               );
+                       }
+                       $prefixes[$module->getModulePrefix()] = $class;
+
+                       if ( $module instanceof ApiQueryGeneratorBase ) {
+                               // namespace with 'g', a generator can share a prefix with a module
+                               $prefix = 'g' . $prefix;
+                               if ( isset( $prefixes[$prefix] ) ) {
+                                       $this->fail(
+                                               "Module prefix '{$prefix}' is shared between {$class} and {$prefixes[$prefix]}" .
+                                                       " (as a generator)"
+                                       );
+                               }
+                               $prefixes[$module->getModulePrefix()] = $class;
+                       }
+               }
+               $this->assertTrue( true ); // dummy call to make this test non-incomplete
+       }
+}