function testErrorMessage()
 {
     $m = DataTransclusionHandler::errorMessage('datatransclusion-test-wikitext', false);
     $this->assertEquals('<span class="error datatransclusion-test-wikitext">some <span class="test">html</span> and \'\'markup\'\'.</span>', $m);
     $m = DataTransclusionHandler::errorMessage('datatransclusion-test-evil-html', false);
     $this->assertEquals('<span class="error datatransclusion-test-evil-html">some <object>evil</object> html.</span>', $m);
     $m = DataTransclusionHandler::errorMessage('datatransclusion-test-nowiki', false);
     $this->assertEquals('<span class="error datatransclusion-test-nowiki">some <nowiki>{{nowiki}}</nowiki> code.</span>', $m);
     $m = DataTransclusionHandler::errorMessage('datatransclusion-test-wikitext', true);
     $this->assertEquals('<span class="error datatransclusion-test-wikitext">some <span class="test">html</span> and <i>markup</i>.</span>', $m);
     $m = DataTransclusionHandler::errorMessage('datatransclusion-test-evil-html', true);
     $this->assertEquals('<span class="error datatransclusion-test-evil-html">some &lt;object&gt;evil&lt;/object&gt; html.</span>', $m);
     $m = DataTransclusionHandler::errorMessage('datatransclusion-test-nowiki', true);
     $this->assertEquals('<span class="error datatransclusion-test-nowiki">some {{nowiki}} code.</span>', $m);
 }
 /**
  * Fetches a records and renders it, according to the given array of parameters.
  * Common implementation for parser tag and parser function.
  */
 static function handleRecordTransclusion($template, $argv, $parser, $asHTML, $templateText = null)
 {
     // find out which data source to use...
     if (empty($argv['source'])) {
         if (empty($argv[1])) {
             wfDebugLog('DataTransclusion', "no source specified\n");
             return DataTransclusionHandler::errorMessage('datatransclusion-missing-source', $asHTML);
         } else {
             $sourceName = $argv[1];
         }
     } else {
         $sourceName = $argv['source'];
     }
     $source = DataTransclusionHandler::getDataSource($sourceName);
     if (empty($source)) {
         wfDebugLog('DataTransclusion', "unknown source: {$sourceName}\n");
         return DataTransclusionHandler::errorMessage('datatransclusion-unknown-source', $asHTML, $sourceName);
     }
     // find out how to render the record
     if (!empty($argv['template'])) {
         $template = $argv['template'];
     } elseif ($template === null || $template === false) {
         if (empty($argv[0])) {
             wfDebugLog('DataTransclusion', "missing 'template' argument\n");
             return DataTransclusionHandler::errorMessage('datatransclusion-missing-argument-template', $asHTML);
         } else {
             $template = $argv[0];
         }
     }
     // find key
     $by = false;
     $key = false;
     $keyFields = $source->getKeyFields();
     foreach ($keyFields as $k) {
         if (isset($argv[$k])) {
             $by = $k;
             $key = $argv[$k];
             break;
             //XXX: could keep running and complain about multiple keys
         }
     }
     if (!$by) {
         global $wgContLang;
         wfDebugLog('DataTransclusion', "no key specified\n");
         return DataTransclusionHandler::errorMessage('datatransclusion-missing-key', $asHTML, $sourceName, $wgContLang->commaList($keyFields), count($keyFields));
     }
     // collect options
     $options = array();
     $optionNames = $source->getOptionNames();
     if ($optionNames) {
         foreach ($optionNames as $n) {
             if (isset($argv[$n])) {
                 $options[$n] = $argv[$n];
             }
         }
     }
     // load the record
     $record = $source->fetchRecord($by, $key, $options);
     if (empty($record)) {
         wfDebugLog('DataTransclusion', "no record found matching {$by}={$key} in {$sourceName}\n");
         return DataTransclusionHandler::errorMessage('datatransclusion-record-not-found', $asHTML, $sourceName, $by, $key);
     }
     // render the record into wiki text
     if ($template === "#dump") {
         $t = null;
     } else {
         $t = Title::newFromText($template, NS_TEMPLATE);
         if (empty($t)) {
             wfDebugLog('DataTransclusion', "illegal template name: {$template}\n");
             return DataTransclusionHandler::errorMessage('datatransclusion-bad-template-name', $asHTML, $template);
         }
     }
     $handler = new DataTransclusionHandler($parser, $source, $t, $templateText);
     $record = $handler->normalizeRecord($record, $argv);
     $text = $handler->render($record);
     if ($text === false) {
         wfDebugLog('DataTransclusion', "template not found: {$template}\n");
         return DataTransclusionHandler::errorMessage('datatransclusion-unknown-template', $asHTML, $template);
     }
     // set parser output expiry
     $expire = $source->getCacheDuration();
     if ($expire !== false && $expire !== null) {
         $parser->getOutput()->updateCacheExpiry($expire);
         // NOTE: this works only since r67185 //TESTME (how?)
     }
     if ($asHTML && $parser) {
         // render into HTML if desired
         $html = $parser->recursiveTagParse($text);
         return $html;
     } else {
         return $text;
     }
 }