/** * @dataProvider basicProvider */ public function testBasic($title, $ns, ForeignTitle $foreignTitle) { $foreignNamespaces = array(0 => '', 1 => 'Talk', 100 => 'Portal', 9000 => 'Bogus'); $factory = new NamespaceAwareForeignTitleFactory($foreignNamespaces); $testTitle = $factory->createForeignTitle($title, $ns); $this->assertEquals($testTitle->isNamespaceIdKnown(), $foreignTitle->isNamespaceIdKnown()); if ($testTitle->isNamespaceIdKnown() && $foreignTitle->isNamespaceIdKnown()) { $this->assertEquals($testTitle->getNamespaceId(), $foreignTitle->getNamespaceId()); } $this->assertEquals($testTitle->getNamespaceName(), $foreignTitle->getNamespaceName()); $this->assertEquals($testTitle->getText(), $foreignTitle->getText()); }
/** * @param string $text * @param string|null $ns * @return array|bool */ private function processTitle($text, $ns = null) { if (is_null($this->foreignNamespaces)) { $foreignTitleFactory = new NaiveForeignTitleFactory(); } else { $foreignTitleFactory = new NamespaceAwareForeignTitleFactory($this->foreignNamespaces); } $foreignTitle = $foreignTitleFactory->createForeignTitle($text, intval($ns)); $title = $this->importTitleFactory->createTitleFromForeignTitle($foreignTitle); $commandLineMode = $this->config->get('CommandLineMode'); if (is_null($title)) { # Invalid page title? Ignore the page $this->notice('import-error-invalid', $foreignTitle->getFullText()); return false; } elseif ($title->isExternal()) { $this->notice('import-error-interwiki', $title->getPrefixedText()); return false; } elseif (!$title->canExist()) { $this->notice('import-error-special', $title->getPrefixedText()); return false; } elseif (!$title->userCan('edit') && !$commandLineMode) { # Do not import if the importing wiki user cannot edit this page $this->notice('import-error-edit', $title->getPrefixedText()); return false; } elseif (!$title->exists() && !$title->userCan('create') && !$commandLineMode) { # Do not import if the importing wiki user cannot create this page $this->notice('import-error-create', $title->getPrefixedText()); return false; } return array($title, $foreignTitle); }