/** * @covers WikiExporter::pageByTitle */ public function testPageByTitle() { global $wgContLang; $pageTitle = 'UTPage'; $exporter = new WikiExporter($this->db, WikiExporter::FULL); $title = Title::newFromText($pageTitle); $sink = new DumpStringOutput(); $exporter->setOutputSink($sink); $exporter->openStream(); $exporter->pageByTitle($title); $exporter->closeStream(); // This throws error if invalid xml output $xmlObject = simplexml_load_string($sink); /** * Check namespaces match xml */ $xmlNamespaces = (array) $xmlObject->siteinfo->namespaces->namespace; $xmlNamespaces = str_replace(' ', '_', $xmlNamespaces); unset($xmlNamespaces['@attributes']); foreach ($xmlNamespaces as &$namespaceObject) { if (is_object($namespaceObject)) { $namespaceObject = ''; } } $actualNamespaces = (array) $wgContLang->getNamespaces(); $actualNamespaces = array_values($actualNamespaces); $this->assertEquals($actualNamespaces, $xmlNamespaces); // Check xml page title correct $xmlTitle = (array) $xmlObject->page->title; $this->assertEquals($pageTitle, $xmlTitle[0]); // Check xml page text is not empty $text = (array) $xmlObject->page->revision->text; $this->assertNotEquals('', $text[0]); }
/** * @param ApiPageSet $pageSet Pages to be exported * @param ApiResult $result Result to output to */ private function doExport($pageSet, $result) { $exportTitles = []; $titles = $pageSet->getGoodTitles(); if (count($titles)) { $user = $this->getUser(); /** @var $title Title */ foreach ($titles as $title) { if ($title->userCan('read', $user)) { $exportTitles[] = $title; } } } $exporter = new WikiExporter($this->getDB()); $sink = new DumpStringOutput(); $exporter->setOutputSink($sink); $exporter->openStream(); foreach ($exportTitles as $title) { $exporter->pageByTitle($title); } $exporter->closeStream(); // Don't check the size of exported stuff // It's not continuable, so it would cause more // problems than it'd solve if ($this->mParams['exportnowrap']) { $result->reset(); // Raw formatter will handle this $result->addValue(null, 'text', $sink, ApiResult::NO_SIZE_CHECK); $result->addValue(null, 'mime', 'text/xml', ApiResult::NO_SIZE_CHECK); } else { $result->addValue('query', 'export', $sink, ApiResult::NO_SIZE_CHECK); $result->addValue('query', ApiResult::META_BC_SUBELEMENTS, ['export']); } }