By the way, the code to get converted titles and namespaces
has been cleaned up.
Change-Id: Ifcbd56c989d83b9d32dfa99e0b2f06d01e17a2bd
if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
continue;
}
if ( $nsId < NS_MAIN || in_array( $nsId, $params['exclude'] ) ) {
continue;
}
+ if ( $nsId === NS_MAIN ) {
// For other namespaces use use the namespace prefix as label, but for
// main we don't use "" but the user message descripting it (e.g. "(Main)" or "(Article)")
$nsName = wfMessage( 'blanknamespace' )->text();
// For other namespaces use use the namespace prefix as label, but for
// main we don't use "" but the user message descripting it (e.g. "(Main)" or "(Article)")
$nsName = wfMessage( 'blanknamespace' )->text();
+ } elseif ( is_int( $nsId ) ) {
+ $nsName = $wgContLang->convertNamespace( $nsId );
}
$optionsHtml[] = Html::element(
'option', array(
}
$optionsHtml[] = Html::element(
'option', array(
function convert( $t ) { return $t; }
function convertTo( $text, $variant ) { return $text; }
function convertTitle( $t ) { return $t->getPrefixedText(); }
function convert( $t ) { return $t; }
function convertTo( $text, $variant ) { return $text; }
function convertTitle( $t ) { return $t->getPrefixedText(); }
+ function convertNamespace( $ns ) { return $this->mLang->getFormattedNsText( $ns ); }
function getVariants() { return array( $this->mLang->getCode() ); }
function getPreferredVariant() { return $this->mLang->getCode(); }
function getDefaultVariant() { return $this->mLang->getCode(); }
function getVariants() { return array( $this->mLang->getCode() ); }
function getPreferredVariant() { return $this->mLang->getCode(); }
function getDefaultVariant() { return $this->mLang->getCode(); }
return $this->mConverter->convertTitle( $title );
}
return $this->mConverter->convertTitle( $title );
}
+ /**
+ * Convert a namespace index to a string in the preferred variant
+ *
+ * @param $ns int
+ * @return string
+ */
+ public function convertNamespace( $ns ) {
+ return $this->mConverter->convertNamespace( $ns );
+ }
+
/**
* Check if this is a language with variants
*
/**
* Check if this is a language with variants
*
public function convertTitle( $title ) {
$variant = $this->getPreferredVariant();
$index = $title->getNamespace();
public function convertTitle( $title ) {
$variant = $this->getPreferredVariant();
$index = $title->getNamespace();
- if ( $index === NS_MAIN ) {
+ if ( $index !== NS_MAIN ) {
+ $text = $this->convertNamespace( $index ) . ':';
+ } else {
+ }
+ $text .= $this->translate( $title->getText(), $variant );
+ return $text;
+ }
+
+ /**
+ * Get the namespace display name in the preferred variant.
+ *
+ * @param $index int namespace id
+ * @return String: namespace name for display
+ */
+ public function convertNamespace( $index ) {
+ $variant = $this->getPreferredVariant();
+ if ( $index === NS_MAIN ) {
+ return '';
- // first let's check if a message has given us a converted name
+ // First check if a message gives a converted name in the target variant.
+ $nsConvMsg = wfMessage( 'conversion-ns' . $index )->inLanguage( $variant );
+ if ( $nsConvMsg->exists() ) {
+ return $nsConvMsg->plain();
+ }
+ // Then check if a message gives a converted name in content language
+ // which needs extra translation to the target variant.
$nsConvMsg = wfMessage( 'conversion-ns' . $index )->inContentLanguage();
if ( $nsConvMsg->exists() ) {
$nsConvMsg = wfMessage( 'conversion-ns' . $index )->inContentLanguage();
if ( $nsConvMsg->exists() ) {
- $text = $nsConvMsg->plain();
- } else {
- // the message does not exist, try retrieve it from the current
- // variant's namespace names.
- $langObj = $this->mLangObj->factory( $variant );
- $text = $langObj->getFormattedNsText( $index );
+ return $this->translate( $nsConvMsg->plain(), $variant );
+ // No message exists, retrieve it from the target variant's namespace names.
+ $langObj = $this->mLangObj->factory( $variant );
+ return $langObj->getFormattedNsText( $index );
- $text .= $title->getText();
- $text = $this->translate( $text, $variant );
- return $text;