/**
     * Generates the XML description of all terms in the data source that match 
     * the input policy.
     * @param string $dataSourceSpec
     * 		The XML structure from getSourceSpecification, filled with the data 
     * 		the user entered.
     * @param string $importSet
     * 		One of the <importSet>-elements from the XML structure from 
     * 		getImportSets() or empty.
     * @param string $inputPolicy
     * 		The XML structure of the input policy. It contains the specification
     * 		of the terms to import and their properties.
     * @param string $conflictPolicy
     * 		The XML structure of the conflict policy. It defines if existing articles
     * 		are overwritten or not.
     *  
     * @param boolean $createTermList
     * 		If <true>, the XML structure for <getTermList> is created otherwise
     * 		the one for <getTerms>
     * 
     * @return string
     *		An XML structure that contains all requested terms.
     * 		If the operation fails, an error message is returned.
     * 		Example:
     * 		<?xml version="1.0"?>
     *		<ReturnValue xmlns="http://www.ontoprise.de/smwplus#">
     *		    <value>false</value>
     *		    <message>The specified data source does not exist.</message>
     * 		</ReturnValue>
     *  
     */
    private function createTerms($dataSourceSpec, $importSet, $inputPolicy, $conflictPolicy, $createTermList)
    {
        $wiki = $this->getSourceWikiFromSpec($dataSourceSpec);
        if (!array_key_exists($wiki, $this->mWikiAPIs)) {
            echo "Unknown wiki: {$wiki}\n";
            return '<?xml version="1.0"?>
					<ReturnValue xmlns="http://www.ontoprise.de/smwplus#">
						<value>false</value>
						<message>The specified data source "' . $wiki . '" does not exist.</message>
					</ReturnValue>';
        }
        $iai = new IAIArticleImporter($this->mWikiAPIs[$wiki]);
        $importSets = $this->parseImportSets($importSet);
        $policy = $this->parseInputPolicy($inputPolicy);
        $terms = '';
        // Find the terms in the source wiki closest to the requested terms
        $ipTerms = $policy['terms'];
        foreach ($ipTerms as $k => $term) {
            if (empty($term)) {
                continue;
            }
            // check if the term is available in the source wiki
            $term = trim($term);
            $ns = 0;
            $t = Title::newFromText($term);
            if ($t) {
                $ns = $t->getNamespace();
                $term = $t->getText();
            }
            $matches = $iai->getArticles($term, $ns, 1);
            $ipTerms[$k] = $matches[0];
        }
        if ($createTermList) {
            foreach ($ipTerms as $t) {
                $terms .= "<articleName>" . $t . "</articleName>\n";
            }
        } else {
            // Conflict policy
            $overwrite = true;
            preg_match('/<overwriteExistingTerms.*?>(.*?)<\\/overwriteExistingTerms>/i', $conflictPolicy, $overwriteMatch);
            if (count($overwriteMatch) == 2) {
                $overwrite = $overwriteMatch[1] == 'true';
                echo "\nSkip existing articles: " . ($overwrite ? "false\n" : "true\n");
            }
            echo "Importing from wiki: {$wiki}\n";
            echo "Articles to import: \n";
            foreach ($ipTerms as $t) {
                echo "{$t}\n";
            }
            echo "\n";
            $importArticles = true;
            $importTemplates = true;
            $importImages = true;
            echo "Import sets: ";
            if (!empty($importSets)) {
                if (!in_array('Articles', $importSets)) {
                    $importArticles = false;
                }
                if (!in_array('Templates', $importSets)) {
                    $importTemplates = false;
                }
                if (!in_array('Images', $importSets)) {
                    $importImages = false;
                }
            }
            if ($importArticles) {
                echo "Articles, ";
            }
            if ($importTemplates) {
                echo "Templates, ";
            }
            if ($importImages) {
                echo "Images ";
            }
            echo "\n";
            try {
                $iai->startReport();
                if ($importArticles) {
                    $iai->importArticles($ipTerms, $importTemplates, $importImages, !$overwrite);
                } else {
                    if ($importTemplates) {
                        $iai->importTemplates($ipTerms);
                    }
                    if ($importImages) {
                        $iai->importImagesForArticle($ipTerms);
                    }
                }
                if (!empty($images)) {
                    $iai->importImages($images, true);
                }
            } catch (Exception $e) {
                echo "Caught an exception: \n" . $e->getMessage();
                return '<?xml version="1.0"?>
						<ReturnValue xmlns="http://www.ontoprise.de/smwplus#">
							<value>false</value>
							<message>Caught an exception: ' . $e->getMessage() . '</message>
						</ReturnValue>';
            }
            $report = $iai->createReport(true);
            echo "Saved report for articles in: {$report}\n";
            $terms .= "<term>\n";
            $terms .= "<articleName>{$report}_TIF</articleName>\n";
            $terms .= "<linkToReport>{$report}</linkToReport>\n";
            $terms .= "</term>\n";
        }
        return '<?xml version="1.0"?>' . "\n" . '<terms xmlns="http://www.ontoprise.de/smwplus#">' . "\n" . $terms . '</terms>' . "\n";
    }
示例#2
0
    echo "\nThe following images were specified:\n";
    foreach ($images as $i) {
        echo $i . "\n";
    }
    die;
}
/**
 * Do the import
 */
$ai = new IAIArticleImporter($wikiApi);
$articleImp = "";
$imageImp = "";
try {
    $ai->startReport();
    if (!empty($articles)) {
        $ai->importArticles($articles, $importTemplates, $importImages, $skipExisting);
    }
    if (!empty($images)) {
        $ai->importImages($images, true);
    }
} catch (Exception $e) {
    echo "Caught an exception: \n" . $e->getMessage();
}
$report = $ai->createReport(true);
echo "Saved report for articles in: {$report}\n";
die;
/**
 * Returns an array of template names that are missing as listed by Special:WantedTemplates
 *
 * @return array(string)
 * 		Array of template names