Exemplo n.º 1
0
 /**
  * Get info about given wikitext with double brackets syntax (templates, magic words, parser functions)
  */
 public static function resolveDoubleBrackets()
 {
     global $wgRequest, $wgTitle, $wgRDBEnabled, $wgRDBData, $wgParser;
     // initialization of required objects and settings
     $wgParser->getstriplist();
     //we need to create (unstub) this object, because of in_array($tagName, $stripList) in parser
     $parser = new Parser();
     //$parser->mDefaultStripList = $parser->mStripList = array();
     $parser->mTagHooks =& $wgParser->mTagHooks;
     $parser->mStripList =& $wgParser->mStripList;
     $parserOptions = new ParserOptions();
     $parserOptions->setEditSection(false);
     // parsing wikitext in RDB (resolve double backets) mode
     $wgRDBEnabled = true;
     $wikitext = $wgRequest->getVal('wikitext', '');
     $html = $parser->parse($wikitext, $wgTitle, $parserOptions)->getText();
     // processing data from RDB mode
     if (!is_array($wgRDBData) || !isset($wgRDBData['type']) || $wgRDBData['type'] == 'error') {
         $out = array('type' => 'unknown');
     } else {
         if ($wgRDBData['type'] == 'tpl') {
             $out = array();
             $out['title'] = $wgRDBData['title']->getPrefixedDBkey();
             $out['exists'] = $wgRDBData['title']->exists() ? true : false;
             if ($out['exists']) {
                 $out['availableParams'] = RTE::getTemplateParams($wgRDBData['title'], $parser);
             }
             for ($i = 0; $i < $wgRDBData['args']->node->length; $i++) {
                 $arg = new PPNode_DOM($wgRDBData['args']->node->item($i));
                 $argSplited = $arg->splitArg();
                 $key = !empty($argSplited['index']) ? $argSplited['index'] : $argSplited['name']->node->textContent;
                 $value = $argSplited['value']->node->textContent;
                 $out['passedParams'][trim($key)] = trim($value);
             }
         }
         $out['type'] = $wgRDBData['type'];
         $out['html'] = $html;
     }
     return $out;
 }