protected function runConsole($params)
 {
     global $wgParser;
     $options = new ParserOptions();
     $wgParser->startExternalParse($params['title'], $options, Parser::OT_HTML, true);
     $engine = Scribunto::getParserEngine($wgParser);
     try {
         $result = $engine->runConsole($params);
     } catch (ScribuntoException $e) {
         $trace = $e->getScriptTraceHtml();
         $message = $e->getMessage();
         $html = Html::element('p', array(), $message);
         if ($trace !== false) {
             $html .= Html::element('p', array(), $this->msg('scribunto-common-backtrace')->inContentLanguage()->text()) . $trace;
         }
         return array('type' => 'error', 'html' => $html, 'message' => $message, 'messagename' => $e->getMessageName());
     }
     return array('type' => 'normal', 'print' => strval($result['print']), 'return' => strval($result['return']));
 }
 /**
  * Function executed by use of {{#infoboxbuilder:}} parser function.
  * It gets the code from InfoboxBuilder.lua and creates new module object
  * from it. The module is then invoked and the result is returned.
  * @param  Parser  $parser Parser object
  * @param  PPFrame $frame  PPFrame object
  * @param  array   $args   Array of arguments passed from $frame object
  * @return string          A string returned by InfoboxBuilder.lua
  */
 public static function parserFunctionHook(\Parser $parser, $frame, $args)
 {
     wfProfileIn(__METHOD__);
     try {
         /**
          * Add the registered SCSS with the default theme
          */
         $parser->getOutput()->addModuleStyles('ext.wikia.InfoboxBuilder');
         $engine = \Scribunto::getParserEngine($parser);
         unset($args[0]);
         $childFrame = $frame->newChild($args, $parser->getTitle(), 1);
         $moduleText = file_get_contents(__DIR__ . '/includes/lua/InfoboxBuilder.lua');
         $module = new \Scribunto_LuaModule($engine, $moduleText, 'InfoboxBuilder');
         $result = $module->invoke('builder', $childFrame);
         $result = \UtfNormal::cleanUp(strval($result));
         wfProfileOut(__METHOD__);
         return $result;
     } catch (\ScribuntoException $e) {
         $trace = $e->getScriptTraceHtml(array('msgOptions' => array('content')));
         $html = \Html::element('p', array(), $e->getMessage());
         if ($trace !== false) {
             $html .= \Html::element('p', array(), wfMessage('scribunto-common-backtrace')->inContentLanguage()->text()) . $trace;
         }
         $out = $parser->getOutput();
         if (!isset($out->scribunto_errors)) {
             $out->addOutputHook('ScribuntoError');
             $out->scribunto_errors = array();
             $parser->addTrackingCategory('scribunto-common-error-category');
         }
         $out->scribunto_errors[] = $html;
         $id = 'mw-scribunto-error-' . (count($out->scribunto_errors) - 1);
         $parserError = wfMessage('scribunto-parser-error')->inContentLanguage()->text() . $parser->insertStripItem('<!--' . htmlspecialchars($e->getMessage()) . '-->');
         wfProfileOut(__METHOD__);
         // #iferror-compatible error element
         return "<strong class=\"error\"><span class=\"scribunto-error\" id=\"{$id}\">" . $parserError . "</span></strong>";
     }
 }
Example #3
0
 /**
  * Adds report of number of evaluations by the single wikitext page.
  *
  * @param $parser Parser
  * @param $report
  * @return bool
  */
 public static function reportLimits($parser, &$report)
 {
     if (Scribunto::isParserEnginePresent($parser)) {
         $engine = Scribunto::getParserEngine($parser);
         $report .= $engine->getLimitReport();
     }
     return true;
 }
Example #4
0
 /**
  * Adds report of number of evaluations by the single wikitext page.
  *
  * @param Parser $parser
  * @param ParserOutput $output
  * @return bool
  */
 public static function reportLimitData(Parser $parser, ParserOutput $output)
 {
     // Unhook the deprecated hook, since the new one exists.
     global $wgHooks;
     unset($wgHooks['ParserLimitReport']['scribunto']);
     if (Scribunto::isParserEnginePresent($parser)) {
         $engine = Scribunto::getParserEngine($parser);
         $engine->reportLimitData($output);
     }
     return true;
 }