public function execute()
 {
     $params = $this->extractRequestParams();
     $titles = explode('|', $params['titles']);
     $templateHelper = new TemplatePageHelper();
     $templatePages = [];
     foreach ($titles as $title) {
         $templateHelper->setTemplateByName($title);
         $articleId = $templateHelper->getTitle()->getArticleId();
         if ($articleId > 0) {
             $templatePages[$articleId] = ['title' => $title, 'params' => $templateHelper->getTemplateParams()];
         }
     }
     $this->getResult()->setIndexedTagName($templatePages, 'pages');
     $this->getResult()->addValue(null, 'pages', $templatePages);
 }
Example #2
0
 /**
  * Get info about given wikitext with double brackets syntax (templates, magic words, parser functions)
  */
 public static function resolveDoubleBrackets()
 {
     global $wgRequest, $wgTitle, $wgRDBData;
     $templateHelper = new TemplatePageHelper();
     $wikitext = $wgRequest->getVal('wikitext', '');
     $html = $templateHelper->getHtml($wikitext, $wgTitle);
     // 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']) {
                 $templateHelper->setTemplateByTitle($wgRDBData['title']);
                 $out['availableParams'] = $templateHelper->getTemplateParams();
             }
             // Get key and value for each argument
             for ($argIndex = 0; $argIndex < $wgRDBData['args']->node->length; $argIndex++) {
                 $argNode = new PPNode_DOM($wgRDBData['args']->node->item($argIndex));
                 $argParts = $argNode->splitArg();
                 $key = !empty($argParts['index']) ? $argParts['index'] : $argParts['name']->node->textContent;
                 $valueNodes = $argParts['value']->getChildren();
                 $value = "";
                 // Loop through all children and concatenate their contents, parsing tags if necessary
                 for ($valueIndex = 0; $valueIndex < $valueNodes->node->length; $valueIndex++) {
                     $valueNode = new PPNode_DOM($valueNodes->node->item($valueIndex));
                     // Parse extension tags (BugId:43779)
                     if ($valueNode->node->nodeName == 'ext') {
                         $extParts = $valueNode->splitExt();
                         // Name and attr are required parameters, the others are optional.
                         $value .= "<" . $extParts['name']->node->textContent . $extParts['attr']->node->textContent . ">";
                         if (isset($extParts['inner'])) {
                             $value .= $extParts['inner']->node->textContent;
                         }
                         if (isset($extParts['close'])) {
                             $value .= $extParts['close']->node->textContent;
                         }
                         // Just use text content
                     } else {
                         $value .= $valueNode->node->textContent;
                     }
                     $out['passedParams'][trim($key)] = trim($value);
                 }
             }
         }
         $out['type'] = $wgRDBData['type'];
         $out['html'] = $html;
     }
     return $out;
 }