Beispiel #1
0
 /**
  * @param string $wikiID
  * @return WikiReference|null WikiReference object or null if the wiki was not found
  */
 private static function getWikiWikiReferenceFromSites($wikiID)
 {
     static $siteStore = null;
     if (!$siteStore) {
         // Replace once T114471 got fixed and don't do the caching here.
         $siteStore = SiteSQLStore::newInstance();
     }
     $site = $siteStore->getSite($wikiID);
     if (!$site instanceof MediaWikiSite) {
         // Abort if not a MediaWikiSite, as this is about Wikis
         return null;
     }
     $urlParts = wfParseUrl($site->getPageUrl());
     if ($urlParts === false || !isset($urlParts['path']) || !isset($urlParts['host'])) {
         // We can't create a meaningful WikiReference without URLs
         return null;
     }
     // XXX: Check whether path contains a $1?
     $path = $urlParts['path'];
     if (isset($urlParts['query'])) {
         $path .= '?' . $urlParts['query'];
     }
     $canonicalServer = isset($urlParts['scheme']) ? $urlParts['scheme'] : 'http';
     $canonicalServer .= '://' . $urlParts['host'];
     return new WikiReference($canonicalServer, $path);
 }
 /**
  * Do the import.
  */
 public function execute()
 {
     $file = $this->getArg(0);
     $importer = new SiteImporter(SiteSQLStore::newInstance());
     $importer->setExceptionCallback(array($this, 'reportException'));
     $importer->importFromFile($file);
     $this->output("Done.\n");
 }
Beispiel #3
0
 /**
  * Do the actual work. All child classes will need to implement this
  */
 public function execute()
 {
     $file = $this->getArg(0);
     if ($file === 'php://output' || $file === 'php://stdout') {
         $this->mQuiet = true;
     }
     $handle = fopen($file, 'w');
     if (!$handle) {
         $this->error("Failed to open {$file} for writing.\n", 1);
     }
     $exporter = new SiteExporter($handle);
     $sites = SiteSQLStore::newInstance()->getSites('recache');
     $exporter->exportSites($sites);
     fclose($handle);
     $this->output("Exported sites to " . realpath($file) . ".\n");
 }
 /**
  * @covers SiteSQLStore::newInstance
  */
 public function testNewInstance()
 {
     $siteStore = SiteSQLStore::newInstance();
     $this->assertInstanceOf('SiteSQLStore', $siteStore);
 }
Beispiel #5
0
 public function testClear()
 {
     $store = SiteSQLStore::newInstance();
     $this->assertTrue($store->clear());
     $site = $store->getSite('enwiki');
     $this->assertNull($site);
     $sites = $store->getSites();
     $this->assertEquals(0, $sites->count());
 }
 /**
  * Inserts sites into the database for the unit tests that need them.
  *
  * @since 0.1
  */
 public static function insertIntoDb()
 {
     $sitesTable = SiteSQLStore::newInstance();
     $sitesTable->clear();
     $sitesTable->saveSites(TestSites::getSites());
 }