Platonides <Platonides <at> gmail.com> writes:
You are not expected to use recursiveTagParse() not being called by the Parser. You are initializing the parser by hand.
Try instead using $wgParser->parse()
Thank you! Switching to parse() worked. I had to instantiate a new parser rather than using $wgParser, since I got the "UNIQ...QINU" error in my "real" code when I used $wgParser.
I'm copying my simple working test code to the bottom of this message in case anybody else is trying to get something similar working. It can be invoked with wikitext of the form:
{{#testQuery:[[Category:Author]] |searchlabel= |format=table }}
Thanks,
Cindy
<?php
/** * To activate the functionality of this extension include the following * in your LocalSettings.php file: * include_once("$IP/extensions/TestQuery/TestQuery.php"); */
if( !defined( 'MEDIAWIKI' ) ) die( "This is an extension to the MediaWiki package and cannot be run standalone." );
# credits $wgExtensionCredits['parserhook'][] = array ( 'name' => 'TestQuery', 'version' => '1.0', 'author' => "Cindy Cicalese", 'description' => "Bug test" );
$wgUseAjax = true; $wgAjaxExportList[] = 'testQueryPopulateDiv';
$wgHooks['LanguageGetMagic'][] = 'wfExtensionTestQuery_Magic'; $wgHooks['ParserFirstCallInit'][] = 'efTestQueryParserFunction_Setup';
function efTestQueryParserFunction_Setup (& $parser) { $parser->setFunctionHook('testQuery', 'testQuery'); return true; }
function wfExtensionTestQuery_Magic(& $magicWords, $langCode) { $magicWords['testQuery'] = array (0, 'testQuery'); return true; }
function testQuery($parser, $query) { $params = func_get_args(); array_shift($params); // first is $parser; strip it array_shift($params); // second is query string; strip it $testQuery = new TestQuery(); $output = $testQuery->firstVisit($parser, $query, $params); $parser->disableCache(); return array($parser->insertStripItem($output, $parser->mStripState), 'noparse' => false); }
function testQueryPopulateDiv($query, $paramString, $title, $offset, $limit) { $params = explode("|", $paramString); $testQuery = new TestQuery(); $output = $testQuery->populateDiv($query, $params, $title, $offset, $limit); return $output; }
class TestQuery {
function firstVisit($parser, $query, $params) { $js = <<<EOT <script type="text/javascript"> function buttonClicked() { var query = document.forms['TestQuery'].Query.value; var params = document.forms['TestQuery'].Params.value; var title = document.forms['TestQuery'].Title.value; var offset = document.forms['TestQuery'].Offset.value; var limit = document.forms['TestQuery'].Limit.value; offset = parseInt(offset) + parseInt(limit); document.forms['TestQuery'].Offset.value = offset; var div = document.getElementById('TestDiv'); sajax_do_call('testQueryPopulateDiv', [query, params, title, offset, limit], div); } </script> EOT; $parser->mOutput->addHeadItem($js); $title = $parser->getTitle()->getText(); $output = $this->buildForm($query, $params, $title); $result = $this->getData($query, $params, $title, 0, 5); $output .= $this->buildDiv($result); return $output; }
function populateDiv($query, $params, $title, $offset, $limit) { return $this->getData($query, $params, $title, $offset, $limit); }
private function buildForm($query, $params, $title) { $paramString = implode("|", $params); $out = <<<EOT <center> <button type='button' id='TestButton' onClick="buttonClicked()">Test Button </button> <form id='TestQuery' method='post' action=''> <input type='hidden' name='Query' value='$query'> <input type='hidden' name='Params' value='$paramString'> <input type='hidden' name='Title' value='$title'> <input type='hidden' name='Offset' value='0'> <input type='hidden' name='Limit' value='5'> </form> </center><br> EOT; return $out; }
private function getData($query, $params, $title, $offset, $limit) { $params['offset'] = $offset; $params['limit'] = $limit; $result = $this->doSMWAsk($query, $params); $parser = new Parser; $output = $parser->parse($result, Title::newFromText($title), new ParserOptions); return $output->getText(); }
private function doSMWAsk($query, $rawParams) { SMWQueryProcessor::processFunctionParams($rawParams, $qs, $params, $printouts); $output = SMWQueryProcessor::getResultFromQueryString($query, $params, $printouts, SMW_OUTPUT_WIKI); return $output; }
private function buildDiv($result) { $output = "<div id='TestDiv' display='block'>"; $output .= $result; $output .= "</div>"; return $output; } }