public function execute() { $stripProtocols = (bool) $this->getOption('strip-protocols', false); $forceProtocol = $this->getOption('force-protocol', null); $url = $this->getOption('load-from', 'https://meta.wikimedia.org/w/api.php'); $scriptPath = $this->getOption('script-path', '/w/$1'); $articlePath = $this->getOption('article-path', '/wiki/$1'); $expandGroup = !$this->getOption('no-expand-group', false); $siteGroup = $this->getOption('site-group'); $wikiId = $this->getOption('wiki'); if ($stripProtocols && is_string($forceProtocol)) { $this->error("You can't use both strip-protocols and force-protocol", 1); } $protocol = true; if ($stripProtocols) { $protocol = false; } elseif (is_string($forceProtocol)) { $protocol = $forceProtocol; } // @todo make it configurable, such as from a config file. $validGroups = array('wikipedia', 'wikivoyage', 'wikiquote', 'wiktionary', 'wikibooks', 'wikisource', 'wikiversity', 'wikinews'); try { $json = $this->getSiteMatrixData($url); $siteMatrixParser = new SiteMatrixParser($scriptPath, $articlePath, $protocol, $expandGroup); $sites = $siteMatrixParser->sitesFromJson($json); $store = SiteSQLStore::newInstance(); $sitesBuilder = new SitesBuilder($store, $validGroups); $sitesBuilder->buildStore($sites, $siteGroup, $wikiId); } catch (MWException $e) { $this->output($e->getMessage()); } $this->output("done.\n"); }
/** * @dataProvider sitesFromJsonProvider */ public function testSitesFromJson($scriptPath, $articlePath, $protocol, $expected) { $json = $this->getSiteMatrixJson(); $siteMatrixParser = new SiteMatrixParser($scriptPath, $articlePath, $protocol); $sites = $siteMatrixParser->sitesFromJson($json); ksort($expected); ksort($sites); $this->assertEquals($expected, $sites); }