X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Ftitle%2FNamespaceAwareForeignTitleFactory.php;h=4d24cb850ca15a51b1a53e94efc319431bfbdb0f;hp=bf97e2cdf24dc96c470d9349ad2bf7374ee3432b;hb=ef8bc825c6614a1687c7593d4beb0ebe24a1ada4;hpb=03e2a132d290ddc28464fc91f3465a566f54aa50 diff --git a/includes/title/NamespaceAwareForeignTitleFactory.php b/includes/title/NamespaceAwareForeignTitleFactory.php index bf97e2cdf2..4d24cb850c 100644 --- a/includes/title/NamespaceAwareForeignTitleFactory.php +++ b/includes/title/NamespaceAwareForeignTitleFactory.php @@ -52,7 +52,7 @@ class NamespaceAwareForeignTitleFactory implements ForeignTitleFactory { public function __construct( $foreignNamespaces ) { $this->foreignNamespaces = $foreignNamespaces; if ( !is_null( $foreignNamespaces ) ) { - $this->foreignNamespacesFlipped = array(); + $this->foreignNamespacesFlipped = []; foreach ( $foreignNamespaces as $id => $name ) { $newKey = self::normalizeNamespaceName( $name ); $this->foreignNamespacesFlipped[$newKey] = $id; @@ -115,15 +115,23 @@ class NamespaceAwareForeignTitleFactory implements ForeignTitleFactory { protected function parseTitleWithNs( $title, $ns ) { $pieces = explode( ':', $title, 2 ); + // Is $title of the form Namespace:Title (true), or just Title (false)? + $titleIncludesNamespace = ( $ns != '0' && count( $pieces ) === 2 ); + if ( isset( $this->foreignNamespaces[$ns] ) ) { $namespaceName = $this->foreignNamespaces[$ns]; } else { - $namespaceName = $ns == '0' ? '' : $pieces[0]; + // If the foreign wiki is misconfigured, XML dumps can contain a page with + // a non-zero namespace ID, but whose title doesn't contain a colon + // (T114115). In those cases, output a made-up namespace name to avoid + // collisions. The ImportTitleFactory might replace this with something + // more appropriate. + $namespaceName = $titleIncludesNamespace ? $pieces[0] : "Ns$ns"; } // We assume that the portion of the page title before the colon is the - // namespace name, except in the case of namespace 0 - if ( $ns != '0' ) { + // namespace name, except in the case of namespace 0. + if ( $titleIncludesNamespace ) { $pageName = $pieces[1]; } else { $pageName = $title;