/**
 * This function is called, when a <ImportSettings>-tag for a Term Import
 * has been found in an article.
 *
 */
function termImportParserHook($input, $args, $parser)
{
    require_once "SMW_TermImportDefinitionValidator.php";
    $attr = "";
    foreach ($args as $k => $v) {
        $attr .= " " . $k . '="' . $v . '"';
    }
    $completeImportSettings = "<ImportSettings{$attr}>" . $input . "</ImportSettings>\n";
    $messages = "";
    $tiDV = new SMWTermImportDefinitionValidator($completeImportSettings);
    if (!$tiDV->isValidXML()) {
        $messages .= "\n* Invalid XML";
    } else {
        if (!$tiDV->isValidModuleConfiguration()) {
            $messages .= "\n* Invalid ModuleConfiguration.";
        }
        if (!$tiDV->isValidDataSource()) {
            $messages .= "\n* Invalid data source definition.";
        }
        if (!$tiDV->isValidConflictPolicy()) {
            $messages .= "\n* Invalid conflict policy.";
        }
        if (!$tiDV->isValidMappingPolicy()) {
            $messages .= "\n* Invalid mapping policy.";
        }
        if (!$tiDV->isValidImportSet()) {
            $messages .= "\n* Invalid import set.";
        }
        if (!$tiDV->isValidInputPolicy()) {
            $messages .= "\n* Invalid Input Policy.";
        }
        if (!$tiDV->isValidUpdatePolicy()) {
            $messages .= "\n* Invalid update policy.";
        }
    }
    if (strlen($messages) > 0) {
        $messages = '<h4><span class="mw-headline">The Term Import Definition is erronious</span></h4>' . $messages;
    } else {
        global $wgArticlePath;
        if (strpos($wgArticlePath, "?") > 0) {
            $url = Title::makeTitleSafe(NS_SPECIAL, "TermImport")->getFullURL() . "&tiname=" . $parser->getTitle()->getText();
        } else {
            $url = Title::makeTitleSafe(NS_SPECIAL, "TermImport")->getFullURL() . "?tiname=" . $parser->getTitle()->getText();
        }
        $messages = '<h4><a href="' . $url . '">Click here to edit the Term Import definition in the GUI</a></h4>';
    }
    $completeImportSettings = '<h4><span class="mw-headline">Term Import definition</span></h4>' . '<pre>' . trim(htmlspecialchars($completeImportSettings)) . '</pre>';
    return $completeImportSettings . $messages;
}