Esempio n. 1
0
/**
 * 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;
}
Esempio n. 2
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;
 }
Esempio n. 3
0
 /**
  * Add content from plain text
  * @since 1.17
  * @param &$bar array
  * @param $text string
  */
 function addToSidebarPlain(&$bar, $text)
 {
     $lines = explode("\n", $text);
     $wikiBar = array();
     # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
     $heading = '';
     foreach ($lines as $line) {
         if (strpos($line, '*') !== 0) {
             continue;
         }
         if (strpos($line, '**') !== 0) {
             $heading = trim($line, '* ');
             if (!array_key_exists($heading, $bar)) {
                 $bar[$heading] = array();
             }
         } else {
             $line = trim($line, '* ');
             if (strpos($line, '|') !== false) {
                 // sanity check
                 $line = array_map('trim', explode('|', $line, 2));
                 $link = wfMsgForContent($line[0]);
                 if ($link == '-') {
                     continue;
                 }
                 $text = wfMsgExt($line[1], 'parsemag');
                 if (wfEmptyMsg($line[1], $text)) {
                     $text = $line[1];
                 }
                 if (wfEmptyMsg($line[0], $link)) {
                     $link = $line[0];
                 }
                 if (preg_match('/^(?:' . wfUrlProtocols() . ')/', $link)) {
                     $href = $link;
                 } else {
                     $title = Title::newFromText($link);
                     if ($title) {
                         $title = $title->fixSpecialName();
                         $href = $title->getLocalURL();
                     } else {
                         $href = 'INVALID-TITLE';
                     }
                 }
                 $bar[$heading][] = array('text' => $text, 'href' => $href, 'id' => 'n-' . strtr($line[1], ' ', '-'), 'active' => false);
             } else {
                 if (substr($line, 0, 2) == '{{' && substr($line, -2) == '}}') {
                     global $wgParser, $wgTitle;
                     $line = substr($line, 2, strlen($line) - 4);
                     $options = new ParserOptions();
                     $options->setEditSection(false);
                     $options->setInterfaceMessage(true);
                     $wikiBar[$heading] = $wgParser->parse(wfMsgForContentNoTrans($line), $wgTitle, $options)->getText();
                 } else {
                     continue;
                 }
             }
         }
     }
     if (count($wikiBar) > 0) {
         $bar = array_merge($bar, $wikiBar);
     }
     return $bar;
 }