* @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 !== '' ) {
* @return string $title->getText()
*/
public function getText( LinkTarget $title ) {
- return $this->formatTitle( false, $title->getText(), '' );
+ return $title->getText();
}
/**
/**
* 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
*
* @return string
*/
public function getText() {
- return str_replace( '_', ' ', $this->getDBkey() );
+ return str_replace( '_', ' ', $this->dbkey );
}
/**
+++ /dev/null
-<?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
- }
-}
--- /dev/null
+<?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
+ }
+}