From 8115df20ab0de32947f8049acded66f6114aefcd Mon Sep 17 00:00:00 2001 From: Brion Vibber Date: Tue, 22 Nov 2011 19:33:53 +0000 Subject: [PATCH] * (bug 32376) XML export tweak to use canonical user namespaces instead of gendered ones for now The gendered namespaces aren't listed in the namespaces list, and just adding them as-is may break reader implementations. Using the canonical form should have little effect on most activity while keeping things working. Should resolve Lucene search problems (bug 31697) related to the Lucene search indexer not understanding the gendered namespace names. After fix and reindex, the canonical forms should get returned and automatically transformed back into appropriate gendered forms in the search view. [per IRC discussion check-up with Ariel about this bug and the patches on bug 30513 which cover related namespacey issues] --- includes/Export.php | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/includes/Export.php b/includes/Export.php index dec604e5cd..d3ee9879d7 100644 --- a/includes/Export.php +++ b/includes/Export.php @@ -476,14 +476,14 @@ class XmlDumpWriter { function openPage( $row ) { $out = " \n"; $title = Title::makeTitle( $row->page_namespace, $row->page_title ); - $out .= ' ' . Xml::elementClean( 'title', array(), $title->getPrefixedText() ) . "\n"; + $out .= ' ' . Xml::elementClean( 'title', array(), self::canonicalTitle( $title ) ) . "\n"; $out .= ' ' . Xml::element( 'ns', array(), strval( $row->page_namespace) ) . "\n"; $out .= ' ' . Xml::element( 'id', array(), strval( $row->page_id ) ) . "\n"; if ( $row->page_is_redirect ) { $page = WikiPage::factory( $title ); $redirect = $page->getRedirectTarget(); if ( $redirect instanceOf Title && $redirect->isValidRedirectTarget() ) { - $out .= ' ' . Xml::element( 'redirect', array( 'title' => $redirect->getPrefixedText() ) ) . "\n"; + $out .= ' ' . Xml::element( 'redirect', array( 'title' => self::canonicalTitle( $redirect ) ) ) . "\n"; } } if ( $row->page_restrictions != '' ) { @@ -595,7 +595,7 @@ class XmlDumpWriter { $out .= " " . Xml::element( 'text', array( 'deleted' => 'deleted' ) ) . "\n"; } else { $title = Title::makeTitle( $row->log_namespace, $row->log_title ); - $out .= " " . Xml::elementClean( 'logtitle', null, $title->getPrefixedText() ) . "\n"; + $out .= " " . Xml::elementClean( 'logtitle', null, self::canonicalTitle( $title ) ) . "\n"; $out .= " " . Xml::elementClean( 'params', array( 'xml:space' => 'preserve' ), strval( $row->log_params ) ) . "\n"; @@ -677,6 +677,29 @@ class XmlDumpWriter { " \n"; } + /** + * Return prefixed text form of title, but using the content language's + * canonical namespace. This skips any special-casing such as gendered + * user namespaces -- which while useful, are not yet listed in the + * XML data so are unsafe in export. + * + * @param Title $title + * @return string + */ + public static function canonicalTitle( Title $title ) { + if ( $title->getInterwiki() ) { + return $title->getPrefixedText(); + } + + global $wgContLang; + $prefix = $wgContLang->getNsText( $title->getNamespace() ); + + if ($prefix !== '') { + $prefix .= ':'; + } + + return $prefix . $title->getText(); + } } -- 2.20.1