}
}
- /**
- * Convert namespace.
- * @param $title String: the title included namespace
- * @return Array of string
- * @private
- */
- function convertNamespace( $title, $variant ) {
- $splittitle = explode( ':', $title, 2 );
- if ( count( $splittitle ) < 2 ) {
- return $title;
- }
- if ( isset( $this->mNamespaceTables[$variant][$splittitle[0]] ) ) {
- $splittitle[0] = $this->mNamespaceTables[$variant][$splittitle[0]];
- }
- $ret = implode( ':', $splittitle );
- return $ret;
- }
-
/**
* Convert text to different variants of a language. The automatic
* conversion is done in autoConvert(). Here we parse the text
return $this->recursiveConvertTopLevel( $text, $variant );
}
+ /**
+ * Convert a Title object to a readable string in the preferred variant
+ */
+ public function convertTitle( $title ) {
+ $variant = $this->getPreferredVariant();
+ if ( $title->getNamespace() === NS_MAIN ) {
+ $text = '';
+ } else {
+ $text = $title->getNsText();
+ if ( isset( $this->mNamespaceTables[$variant][$text] ) ) {
+ $text = $this->mNamespaceTables[$variant][$text];
+ }
+ $text .= ':';
+ }
+ $text .= $title->getText();
+ $text = $this->autoConvert( $text, $variant );
+ return $text;
+ }
+
protected function recursiveConvertTopLevel( $text, $variant, $depth = 0 ) {
$startPos = 0;
$out = '';