*/
public function formatTitle( $namespace, $text, $fragment = '', $interwiki = '' ) {
if ( $namespace !== false ) {
- $namespace = $this->getNamespaceName( $namespace, $text );
+ // Try to get a namespace name, but fallback
+ // to empty string if it doesn't exist
+ try {
+ $nsName = $this->getNamespaceName( $namespace, $text );
+ } catch ( InvalidArgumentException $e ) {
+ $nsName = '';
+ }
- if ( $namespace !== '' ) {
- $text = $namespace . ':' . $text;
+ if ( $namespace !== 0 ) {
+ $text = $nsName . ':' . $text;
}
}
);
}
+ /**
+ * @since 1.27
+ * @see TitleFormatter::getPrefixedDBkey()
+ * @param LinkTarget $target
+ * @return string
+ */
+ public function getPrefixedDBkey( LinkTarget $target ) {
+ $key = '';
+ if ( $target->isExternal() ) {
+ $key .= $target->getInterwiki() . ':';
+ }
+ // Try to get a namespace name, but fallback
+ // to empty string if it doesn't exist
+ try {
+ $nsName = $this->getNamespaceName(
+ $target->getNamespace(),
+ $target->getText()
+ );
+ } catch ( InvalidArgumentException $e ) {
+ $nsName = '';
+ }
+
+ if ( $target->getNamespace() !== 0 ) {
+ $key .= $nsName . ':';
+ }
+
+ $key .= $target->getText();
+
+ return strtr( $key, ' ', '_' );
+ }
+
/**
* @see TitleFormatter::getText()
*