/**
  * @dataProvider basicProvider
  */
 public function testBasic($title, $ns, ForeignTitle $foreignTitle)
 {
     $factory = new NaiveForeignTitleFactory();
     $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());
     $this->assertEquals(str_replace(' ', '_', $title), $foreignTitle->getFullText());
 }
 /**
  * @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());
 }
 /**
  * Determines which local title best corresponds to the given foreign title.
  * If such a title can't be found or would be locally invalid, null is
  * returned.
  *
  * @param ForeignTitle $foreignTitle The ForeignTitle to convert
  * @return Title|null
  */
 public function createTitleFromForeignTitle(ForeignTitle $foreignTitle)
 {
     global $wgContLang;
     if ($foreignTitle->isNamespaceIdKnown()) {
         $foreignNs = $foreignTitle->getNamespaceId();
         // For built-in namespaces (0 <= ID < 100), we try to find a local NS with
         // the same namespace ID
         if ($foreignNs < 100 && MWNamespace::exists($foreignNs)) {
             return Title::makeTitleSafe($foreignNs, $foreignTitle->getText());
         }
     }
     // Do we have a local namespace by the same name as the foreign
     // namespace?
     $targetNs = $wgContLang->getNsIndex($foreignTitle->getNamespaceName());
     if ($targetNs !== false) {
         return Title::makeTitleSafe($targetNs, $foreignTitle->getText());
     }
     // Otherwise, just fall back to main namespace
     return Title::makeTitleSafe(0, $foreignTitle->getFullText());
 }
Exemplo n.º 4
0
 /**
  * @dataProvider fullTextProvider
  */
 public function testFullText(ForeignTitle $title, $fullText)
 {
     $this->assertEquals($fullText, $title->getFullText());
 }
 /**
  * @param Title $title
  * @param ForeignTitle $foreignTitle
  * @param int $revisionCount
  * @param int $successCount
  * @param array $pageInfo
  * @return void
  */
 function reportPage($title, $foreignTitle, $revisionCount, $successCount, $pageInfo)
 {
     $args = func_get_args();
     call_user_func_array($this->mOriginalPageOutCallback, $args);
     if ($title === null) {
         # Invalid or non-importable title; a notice is already displayed
         return;
     }
     $this->mPageCount++;
     if ($successCount > 0) {
         $this->getOutput()->addHTML("<li>" . Linker::linkKnown($title) . " " . $this->msg('import-revision-count')->numParams($successCount)->escaped() . "</li>\n");
         if ($this->mIsUpload) {
             $detail = $this->msg('import-logentry-upload-detail')->numParams($successCount)->inContentLanguage()->text();
             if ($this->reason) {
                 $detail .= $this->msg('colon-separator')->inContentLanguage()->text() . $this->reason;
             }
             $action = 'upload';
         } else {
             $interwiki = '[[:' . $this->mInterwiki . ':' . $foreignTitle->getFullText() . ']]';
             $detail = $this->msg('import-logentry-interwiki-detail')->numParams($successCount)->params($interwiki)->inContentLanguage()->text();
             if ($this->reason) {
                 $detail .= $this->msg('colon-separator')->inContentLanguage()->text() . $this->reason;
             }
             $action = 'interwiki';
         }
         $logEntry = new ManualLogEntry('import', $action);
         $logEntry->setTarget($title);
         $logEntry->setComment($detail);
         $logEntry->setPerformer($this->getUser());
         $logid = $logEntry->insert();
         $logEntry->publish($logid);
         $comment = $detail;
         // quick
         $dbw = wfGetDB(DB_MASTER);
         $latest = $title->getLatestRevID();
         $nullRevision = Revision::newNullRevision($dbw, $title->getArticleID(), $comment, true, $this->getUser());
         if (!is_null($nullRevision)) {
             $nullRevision->insertOn($dbw);
             $page = WikiPage::factory($title);
             # Update page record
             $page->updateRevisionOn($dbw, $nullRevision);
             Hooks::run('NewRevisionFromEditComplete', array($page, $nullRevision, $latest, $this->getUser()));
         }
     } else {
         $this->getOutput()->addHTML("<li>" . Linker::linkKnown($title) . " " . $this->msg('import-nonewrevisions')->escaped() . "</li>\n");
     }
 }
 /**
  * Determines which local title best corresponds to the given foreign title.
  * If such a title can't be found or would be locally invalid, null is
  * returned.
  *
  * @param ForeignTitle $foreignTitle The ForeignTitle to convert
  * @return Title|null
  */
 public function createTitleFromForeignTitle(ForeignTitle $foreignTitle)
 {
     return Title::newFromText($this->rootPage->getPrefixedDBkey() . '/' . $foreignTitle->getFullText());
 }
 /**
  * Determines which local title best corresponds to the given foreign title.
  * If such a title can't be found or would be locally invalid, null is
  * returned.
  *
  * @param ForeignTitle $foreignTitle The ForeignTitle to convert
  * @return Title|null
  */
 public function createTitleFromForeignTitle(ForeignTitle $foreignTitle)
 {
     return Title::makeTitleSafe($this->ns, $foreignTitle->getText());
 }