public function setUp()
 {
     $this->parser = new Parser();
     $title = Title::newFromText('test');
     $options = new ParserOptions();
     $this->parser->startExternalParse($title, $options, 'text', true);
     parent::setUp();
 }
 function setUp()
 {
     parent::setUp();
     $parser = new Parser();
     $options = new ParserOptions();
     $options->setTemplateCallback(array($this, 'templateCallback'));
     $parser->startExternalParse(Title::newMainPage(), $options, Parser::OT_HTML, true);
     try {
         $engine = new Scribunto_LuaSandboxEngine(array('parser' => $parser) + $this->sandboxOpts);
         $engine->setTitle($parser->getTitle());
         $engine->getInterpreter();
         $this->engines['LuaSandbox'] = $engine;
     } catch (Scribunto_LuaInterpreterNotFoundError $e) {
         $this->markTestSkipped("LuaSandbox interpreter not available");
         return;
     }
     try {
         $engine = new Scribunto_LuaStandaloneEngine(array('parser' => $parser) + $this->standaloneOpts);
         $engine->setTitle($parser->getTitle());
         $engine->getInterpreter();
         $this->engines['LuaStandalone'] = $engine;
     } catch (Scribunto_LuaInterpreterNotFoundError $e) {
         $this->markTestSkipped("LuaStandalone interpreter not available");
         return;
     }
 }
 protected function setUpParser()
 {
     $parser = new Parser();
     $options = new ParserOptions();
     $title = Title::newFromText('Test');
     $parser->Options($options);
     $parser->startExternalParse($title, $options, 'text', true);
     return $parser;
 }
 private function makeEngine($class, $opts)
 {
     $parser = new Parser();
     $options = new ParserOptions();
     $options->setTemplateCallback(array($this, 'templateCallback'));
     $parser->startExternalParse(Title::newMainPage(), $options, Parser::OT_HTML, true);
     $engine = new $class(array('parser' => $parser) + $opts);
     $parser->scribunto_engine = $engine;
     $engine->setTitle($parser->getTitle());
     $engine->getInterpreter();
     return $engine;
 }
 public function execute()
 {
     $text = $this->getParameter("text");
     $title = $this->getParameter("title");
     $arguments = $this->getFrameArguments();
     if ($arguments === null) {
         $this->getResult()->setWarning("Arguments json format incorect or empty");
     }
     $parser = new Parser();
     $parser->startExternalParse(Title::newFromText($title), new ParserOptions(), 'text', true);
     $frame = $parser->getPreprocessor()->newCustomFrame($arguments);
     try {
         $output = PortableInfoboxParserTagController::getInstance()->render($text, $parser, $frame);
         $this->getResult()->addValue(null, $this->getModuleName(), ['text' => ['*' => $output]]);
     } catch (\Wikia\PortableInfobox\Parser\Nodes\UnimplementedNodeException $e) {
         $this->dieUsage(wfMessage('unimplemented-infobox-tag', [$e->getMessage()])->escaped(), "notimplemented");
     } catch (\Wikia\PortableInfobox\Parser\XmlMarkupParseErrorException $e) {
         $this->dieUsage(wfMessage('xml-parse-error')->text(), "badxml");
     }
 }
 function execute($params)
 {
     global $wgRequest, $wgOut, $wgUser;
     global $wgContLang, $wgProxyKey, $wgParser;
     $article = $wgRequest->getText('article', $params);
     $map = $wgRequest->getText('map', $params);
     $wgOut->disable();
     header("Cache-Control: no-cache, must-revalidate");
     header("Content-type: application/vnd.google-earth.kml+xml");
     header('Content-Disposition: attachment; filename="' . $article . '.kml"');
     $title = Title::newFromText($article);
     if ($title) {
         $revision = Revision::newFromTitle($title);
         $mapOptions = GoogleMaps::getMapSettings($title, array('icons' => 'http://maps.google.com/mapfiles/kml/pal4/{label}.png', 'icon' => 'icon57'));
         $exporter = new GoogleMapsKmlExporter($wgContLang, str_replace('{label}', $mapOptions['icon'], $mapOptions['icons']));
         $popts = ParserOptions::newFromUser($wgUser);
         $popts->setEditSection(false);
         $wgParser->startExternalParse($this->getTitle(), $popts, OT_WIKI, true);
         $localParser = new Parser();
         $localParser->startExternalParse($this->getTitle(), $popts, OT_WIKI, true);
         if (preg_match_all("/<googlemap( .*?|)>(.*?)<\\/googlemap>/s", $revision->getText(), $matches)) {
             $exporter->addFileHeader();
             for ($i = 0; $i < count($matches[2]); $i++) {
                 $attrs = Sanitizer::decodeTagAttributes($matches[1][$i]);
                 $mapOptions['version'] = isset($attrs['version']) ? $attrs['version'] : "0";
                 $exporter->addHeader(isset($attrs['title']) ? $attrs['title'] : "Map #" . ($i + 1));
                 GoogleMaps::renderContent($matches[2][$i], $wgParser, $localParser, $exporter, $mapOptions);
                 $exporter->addTrailer();
             }
             $exporter->addFileTrailer();
             echo $exporter->render();
         } else {
             echo "No maps in {$article}!";
         }
     } else {
         echo "No article found by the name of {$article}";
     }
 }
Exemple #7
0
 /**
  * Returns message in the requested format after parsing wikitext to html
  * This is meant to be equivalent to wfMsgExt() with parse, parsemag and
  * escape as available options but using the DPL local parser instead of
  * the global one (bugfix).
  */
 function msgExt($key, $options)
 {
     $args = func_get_args();
     array_shift($args);
     array_shift($args);
     if (!is_array($options)) {
         $options = array($options);
     }
     $string = wfMsgNoTrans($key);
     $string = wfMsgReplaceArgs($string, $args);
     if (in_array('parse', $options)) {
         $this->mParserOptions->setInterfaceMessage(true);
         $string = $this->mParser->recursiveTagParse($string);
         $this->mParserOptions->setInterfaceMessage(false);
         // $string = $parserOutput->getText();
     } elseif (in_array('parsemag', $options)) {
         $parser = new Parser();
         $parserOptions = new ParserOptions();
         $parserOptions->setInterfaceMessage(true);
         $parser->startExternalParse($this->mParserTitle, $parserOptions, OT_MSG);
         $string = $parser->transformMsg($string, $parserOptions);
     }
     if (in_array('escape', $options)) {
         $string = htmlspecialchars($string);
     }
     return $string;
 }
 function getEngine()
 {
     if (!$this->engine) {
         $parser = new Parser();
         $options = new ParserOptions();
         $options->setTemplateCallback(array($this, 'templateCallback'));
         $parser->startExternalParse(Title::newMainPage(), $options, Parser::OT_HTML, true);
         $class = "Scribunto_{$this->engineName}Engine";
         $this->engine = new $class(self::$engineConfigurations[$this->engineName] + array('parser' => $parser));
         $this->engine->setTitle($parser->getTitle());
     }
     return $this->engine;
 }
/**
 * Returns message in the requested format
 * @param string $key Key of the message
 * @param array $options Processing rules:
 *  <i>parse<i>: parses wikitext to html
 *  <i>parseinline<i>: parses wikitext to html and removes the surrounding p's added by parser or tidy
 *  <i>escape<i>: filters message trough htmlspecialchars
 *  <i>replaceafter<i>: parameters are substituted after parsing or escaping
 */
function wfMsgExt($key, $options)
{
    global $wgOut, $wgMsgParserOptions, $wgParser;
    $args = func_get_args();
    array_shift($args);
    array_shift($args);
    if (!is_array($options)) {
        $options = array($options);
    }
    $string = wfMsgGetKey($key, true, false, false);
    if (!in_array('replaceafter', $options)) {
        $string = wfMsgReplaceArgs($string, $args);
    }
    if (in_array('parse', $options)) {
        $string = $wgOut->parse($string, true, true);
    } elseif (in_array('parseinline', $options)) {
        $string = $wgOut->parse($string, true, true);
        $m = array();
        if (preg_match("~^<p>(.*)\n?</p>\$~", $string, $m)) {
            $string = $m[1];
        }
    } elseif (in_array('parsemag', $options)) {
        global $wgTitle;
        $parser = new Parser();
        $parserOptions = new ParserOptions();
        $parserOptions->setInterfaceMessage(true);
        $parser->startExternalParse($wgTitle, $parserOptions, OT_MSG);
        $string = $parser->transformMsg($string, $parserOptions);
    }
    if (in_array('escape', $options)) {
        $string = htmlspecialchars($string);
    }
    if (in_array('replaceafter', $options)) {
        $string = wfMsgReplaceArgs($string, $args);
    }
    return $string;
}
 /**
  *
  */
 function prepareAction()
 {
     // get options from the request, but keep the explicitly set options
     global $wgVersion;
     if (version_compare($wgVersion, '1.20', '>=')) {
         $data = $this->getRequest()->getValues();
     } else {
         // TODO: remove else branch when raising supported version to MW 1.20, getValues() was buggy before
         $data = $_POST + $_GET;
     }
     $this->mOptions = SFUtils::array_merge_recursive_distinct($data, $this->mOptions);
     global $wgParser;
     if ($wgParser === null) {
         $wgParser = new Parser();
     }
     $wgParser->startExternalParse(null, ParserOptions::newFromUser($this->getUser()), Parser::OT_WIKI);
     // MW uses the parameter 'title' instead of 'target' when submitting
     // data for formedit action => use that
     if (!array_key_exists('target', $this->mOptions) && array_key_exists('title', $this->mOptions)) {
         $this->mOptions['target'] = $this->mOptions['title'];
         unset($this->mOptions['title']);
     }
     // if the 'query' parameter was used, unpack the param string
     if (array_key_exists('query', $this->mOptions)) {
         $this->addOptionsFromString($this->mOptions['query']);
         unset($this->mOptions['query']);
     }
     // if an action is explicitly set in the form data, use that
     if (array_key_exists('wpSave', $this->mOptions)) {
         // set action to 'save' if requested
         $this->mAction = self::ACTION_SAVE;
         unset($this->mOptions['wpSave']);
     } else {
         if (array_key_exists('wpPreview', $this->mOptions)) {
             // set action to 'preview' if requested
             $this->mAction = self::ACTION_PREVIEW;
             unset($this->mOptions['wpPreview']);
         } else {
             if (array_key_exists('wpDiff', $this->mOptions)) {
                 // set action to 'preview' if requested
                 $this->mAction = self::ACTION_DIFF;
                 unset($this->mOptions['wpDiff']);
             } else {
                 if (array_key_exists('action', $this->mOptions)) {
                     switch ($this->mOptions['action']) {
                         case 'sfautoedit':
                             $this->mAction = self::ACTION_SAVE;
                             break;
                         case 'preview':
                             $this->mAction = self::ACTION_PREVIEW;
                             break;
                         default:
                             $this->mAction = self::ACTION_FORMEDIT;
                     }
                 } else {
                     // set default action
                     $this->mAction = self::ACTION_FORMEDIT;
                 }
             }
         }
     }
     $hookQuery = null;
     // ensure 'form' key exists
     if (array_key_exists('form', $this->mOptions)) {
         $hookQuery = $this->mOptions['form'];
     } else {
         $this->mOptions['form'] = '';
     }
     // ensure 'target' key exists
     if (array_key_exists('target', $this->mOptions)) {
         if ($hookQuery !== null) {
             $hookQuery .= '/' . $this->mOptions['target'];
         }
     } else {
         $this->mOptions['target'] = '';
     }
     // Normalize form and target names
     $form = Title::newFromText($this->mOptions['form']);
     if ($form !== null) {
         $this->mOptions['form'] = $form->getPrefixedText();
     }
     $target = Title::newFromText($this->mOptions['target']);
     if ($target !== null) {
         $this->mOptions['target'] = $target->getPrefixedText();
     }
     Hooks::run('sfSetTargetName', array(&$this->mOptions['target'], $hookQuery));
     // set html return status. If all goes well, this will not be changed
     $this->mStatus = 200;
 }