public static function renderCollection($input, array $args, Parser $parser, PPFrame $frame) { $string_array = array(); $parsed_input = $parser->recursiveTagParse($input, $frame); if (Collection::startsWith($parsed_input, "Coll") === true) { $results = Collection::getResults($parsed_input); $string_array[] = '{| class="wikitable"'; $string_array[] = "! "; foreach ($results['langs'] as $lang) { $string_array[] = "!" . $lang; } $string_array[] = "|-"; foreach (array_keys($results['data']) as $pagename) { $string_array[] = "|[[" . $pagename . " |Edit]]"; foreach ($results['langs'] as $lang) { if (isset($results['data'][$pagename][$lang])) { $string_array[] = "|" . implode("<br/>", $results['data'][$pagename][$lang]); } else { $string_array[] = "|"; } } $string_array[] = "|-"; } $string_array[] = "|}"; return $parser->recursiveTagParse(implode("\n\n", $string_array), $frame); } else { return $parser->recursiveTagParse("No results", $frame); } }
/** * Transforms from wikitext string to HTML. * Require a value. * * @param string|boolean $value A string or boolean <i>true</i> * @return string * @throws UserError When value is not a signed integer. */ protected function parse($value) { if (!$this->parser instanceof \Parser) { throw new \MWException('Parser must be set using setParser()'); } if ($value === true) { // parameter specified without value Tools::ThrowUserError(wfMessage('wfmk-value-required', $this->getName())); } return $this->parser->recursiveTagParse($value); }
/** * Parses the <spoiler> tag. * * @access public * @param string User input between <spoiler> * @param array Array of arguments from the opening spoiler tag. * @param object Mediawiki Parser Object * @param object PPFrame object * @return string HTML */ public static function parseSpoilerTag($input, array $args, Parser $parser, PPFrame $frame) { $out = $parser->getOutput(); $out->addModules('ext.spoilers'); $renderedInput = $parser->recursiveTagParse($input); $output = "<div class='spoilers'>\n\t\t\t\t\t\t<div class='spoilers-button-container'>\n\t\t\t\t\t\t\t<span class='spoilers-button'>\n\t\t\t\t\t\t\t\t<span class='spoilers-show'>" . ($args['show'] ? htmlentities($args['show'], ENT_QUOTES) : wfMessage('spoilers_show_default')->text()) . "</span>\n\t\t\t\t\t\t\t\t<span class='spoilers-hide' style='display:none;'>" . ($args['hide'] ? htmlentities($args['hide'], ENT_QUOTES) : wfMessage('spoilers_hide_default')->text()) . "</span>\n\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class='spoilers-body' style='display:none;'>{$renderedInput}</div>\n\t\t\t\t\t</div>"; return $output; }
/** * Renderer for <emblem> parser tag hook * * @param $input * @param $args Array * @param $parser Parser * @param $frame */ public static function render($input, $args, Parser $parser, PPFrame $frame) { $output = $parser->getOutput(); if (!isset($output->articleEmblems)) { $output->articleEmblems = array(); } $output->articleEmblems[] = $parser->recursiveTagParse($input, $frame); return ''; }
/** * @static * @param $contents * @param $attributes * @param Parser $parser * @return string */ public static function hideContent($contents, $attributes, $parser) { $app = F::app(); if ($app->checkSkin($app->wg->MobileSkins)) { return ''; } else { return $parser->recursiveTagParse($contents); } }
/** * Utility function to parse wikitext without having to care * about handling a tag extension or parser function. * * @since 0.4.4 * * @param string $text The wikitext to be parsed * * @return string the parsed output */ protected function parseWikitext($text) { // Parse the wikitext to HTML. if ($this->isFunction()) { return $this->parser->parse(text, $this->parser->mTitle, $this->parser->mOptions, true, false)->getText(); } else { return $this->parser->recursiveTagParse($text, $this->frame); } }
public static function renderModuleContainerTag($content, array $attributes, Parser $parser, PPFrame $frame) { if (!empty($attributes['content-title'])) { $title = Title::newFromText($attributes['content-title']); if ($title->exists()) { $article = Article::newFromTitle($title, RequestContext::getMain()); $attributes['content'] = $parser->recursiveTagParse($article->getContent()); } } return F::app()->renderView('Njord', 'modula', $attributes); }
/** * Return an error message based on an error ID * * @param string $key Message name for the error * @param string $param Parameter to pass to the message * @param string $parse Whether to parse the message ('parse') or not ('noparse') * @return string XHTML or wikitext ready for output */ function error($key, $param = null, $parse = 'parse') { # We rely on the fact that PHP is okay with passing unused argu- # ments to functions. If $1 is not used in the message, wfMessage will # just ignore the extra parameter. $ret = '<strong class="error mw-ext-cite-error">' . wfMessage('cite_error', wfMessage($key, $param)->inContentLanguage()->plain())->inContentLanguage()->plain() . '</strong>'; if ($parse == 'parse') { $ret = $this->mParser->recursiveTagParse($ret); } return $ret; }
/** * Parse a given fragment and fix up Tidy's trail of blood on * it... * * @param string $in The text to parse * @return string The parsed text */ function parse($in) { if (method_exists($this->mParser, 'recursiveTagParse')) { // New fast method return $this->mParser->recursiveTagParse($in); } else { // Old method $ret = $this->mParser->parse($in, $this->mParser->mTitle, $this->mParser->mOptions, false, false); $text = $ret->getText(); return $this->fixTidy($text); } }
/** * Embeds video of the chosen service * @param Parser $parser Instance of running Parser. * @param String $service Which online service has the video. * @param String $id Identifier of the chosen service * @param String $width Width of video (optional) * @param String $desc description to show (optional, unused) * @param String $align alignment of the video (optional, unused) * @return String Encoded representation of input params (to be processed later) */ public static function parserFunction_ev($parser, $service = null, $id = null, $width = null, $align = null, $desc = null) { global $wgScriptPath; # Initialize things once if (!EmbedVideo::$initialized) { EmbedVideo::VerifyWidthMinAndMax(); # Add system messages wfLoadExtensionMessages('embedvideo'); $parser->disableCache(); EmbedVideo::$initialized = true; } # Get the name of the host if ($service === null || $id === null) { return EmbedVideo::errMissingParams($service, $id); } $service = trim($service); $id = trim($id); $desc = $parser->recursiveTagParse($desc); $entry = EmbedVideo::getServiceEntry($service); if (!$entry) { return EmbedVideo::errBadService($service); } if (!EmbedVideo::sanitizeWidth($entry, $width)) { return EmbedVideo::errBadWidth($width); } $height = EmbedVideo::getHeight($entry, $width); $hasalign = $align !== null; if ($hasalign) { $desc = EmbedVideo::getDescriptionMarkup($desc); } # If the service has an ID pattern specified, verify the id number if (!EmbedVideo::verifyID($entry, $id)) { return EmbedVideo::errBadID($service, $id); } # if the service has it's own custom extern declaration, use that instead if (array_key_exists('extern', $entry) && ($clause = $entry['extern']) != null) { $clause = wfMsgReplaceArgs($clause, array($wgScriptPath, $id, $width, $height)); if ($hasalign) { $clause = EmbedVideo::generateAlignExternClause($clause, $align, $desc, $width, $height); } return array($clause, 'noparse' => true, 'isHTML' => true); } # Build URL and output embedded flash object $url = wfMsgReplaceArgs($entry['url'], array($id, $width, $height)); $clause = ""; if ($hasalign) { $clause = EmbedVideo::generateAlignClause($url, $width, $height, $align, $desc); } else { $clause = EmbedVideo::generateNormalClause($url, $width, $height); } return array($clause, 'noparse' => true, 'isHTML' => true); }
/** * This function is the callback that the ParserFirstCallInit hook assigns * to the parser whenever a supported FBML tag is encountered (like <fb:like-box>). * Function createParserHook($tag) creates an anonymous (lambda-style) * function that simply redirects to parserHook(), filling in the missing * $tag argument with the $tag provided to createParserHook. */ public static function parserHook($tag, $text, $args, Parser $parser) { if ($tag == 'fb:like-box' && isset($args['profileid'])) { $args['profile_id'] = $args['profileid']; unset($args['profileid']); } // add custom attribute to look for in DOM. We use this to determine // if the Facebook SDK should be loaded. $args['data-type'] = 'xfbml-tag'; // Allow other tags by default $attrs = self::implodeAttrs($args); return "<{$tag}{$attrs}>" . $parser->recursiveTagParse($text) . "</{$tag}>"; }
/** * @param $tab * @param Parser $parser * @return string */ function buildTab($tab, $parser) { if (trim($tab) == '') { return ''; } $arr = explode("=", $tab); $tabName = array_shift($arr); // Wikia Change Start @author aquilax $tabName = trim($tabName); // Wikia Change End $tabBody = $parser->recursiveTagParse(implode("=", $arr)); $tab = '<div class="tabbertab" title="' . htmlspecialchars($tabName) . '">' . '<p>' . $tabBody . '</p>' . '</div>'; return $tab; }
/** * Build individual tab. * * @access private * @param string Tab information * @param object Mediawiki Parser Object * @return string HTML */ private static function buildTab($tab = '', Parser $parser) { $tab = trim($tab); if (empty($tab)) { return $tab; } $args = explode('=', $tab); $tabName = array_shift($args); $tabBody = $parser->recursiveTagParse(implode('=', $args)); $tab = ' <div class="tabbertab" title="' . htmlspecialchars($tabName) . '"> <p>' . $tabBody . '</p> </div>'; return $tab; }
/** * @param $input * @param $argv * @param Parser $parser * @return mixed|string */ function renderChosen($input, $argv, $parser) { # Prevent caching #$parser->disableCache(); global $wgParserCacheExpireTime; $wgParserCacheExpireTime = 60; wfDebug("soft disable Cache (choose)\n"); # Parse the options and calculate total weight $len = preg_match_all("/<option(?:(?:\\s[^>]*?)?\\sweight=[\"']?([^\\s>]+))?" . "(?:\\s[^>]*)?>([\\s\\S]*?)<\\/option>/", $input, $out); $r = 0; for ($i = 0; $i < $len; $i++) { if (strlen($out[1][$i]) == 0) { $out[1][$i] = 1; } else { $out[1][$i] = intval($out[1][$i]); } $r += $out[1][$i]; } # Choose an option at random if ($r <= 0) { return ""; } $r = mt_rand(1, $r); for ($i = 0; $i < $len; $i++) { $r -= $out[1][$i]; if ($r <= 0) { $input = $out[2][$i]; break; } } # If running new parser, take the easy way out if (defined('Parser::VERSION') && version_compare(Parser::VERSION, '1.6.1', '>')) { return $parser->recursiveTagParse($input); } # Otherwise, create new parser to handle rendering $localParser = new Parser(); # Initialize defaults, then copy info from parent parser $localParser->clearState(); $localParser->mTagHooks = $parser->mTagHooks; $localParser->mTemplates = $parser->mTemplates; $localParser->mTemplatePath = $parser->mTemplatePath; $localParser->mFunctionHooks = $parser->mFunctionHooks; $localParser->mFunctionSynonyms = $parser->mFunctionSynonyms; # Render the chosen option $output = $localParser->parse($input, $parser->mTitle, $parser->mOptions, false, false); return $output->getText(); }
public function renderTag($input, $params, Parser $parser, PPFrame $frame) { //$this->frame = $frame; global $wgRTEParserEnabled, $wgHTTPProxy, $wgFogbugzAPIConfig, $wgCaptchaDirectory, $wgCaptchaDirectoryLevels, $wgStylePath; if (!isset($params['id'])) { return ''; } $output = Xml::openElement('span', array('class' => 'fogbugz_tck', 'data-id' => $parser->recursiveTagParse($params['id'], $frame))); //$output .= $input; $output .= Xml::openElement('img', array('src' => $wgStylePath . '/common/images/ajax.gif')); $output .= Xml::closeElement('span'); $data = array('wikitext' => RTEData::get('wikitext', self::$mWikitextIdx), 'placeholder' => 1); //$dataIdx = RTEData::put('data', $data); //$output = RTEData::addIdxToTag($dataIdx, $output); $output .= F::build('JSSnippets')->addToStack(array('/extensions/wikia/FogbugzTag/js/FogbugzTag.js')); return $output; }
function wfSampleSetProp($input, array $args, Parser $parser, PPFrame $frame) { $parsed = $parser->recursiveTagParse($input, $frame); // Since this can span different parses, we need to take account of // the fact recursiveTagParse only half parses the text. or strip tags // (UNIQ's) will be exposed. (Alternative would be to just call // $parser->replaceLinkHolders() and $parser->mStripState->unstripBoth() // right here right now. $serialized = serialize($parser->serializeHalfParsedText($parsed)); $parser->getOutput()->setProperty('SimpleSetPropExtension', $serialized); // Note if other pages change based on a property, you should see $wgPagePropLinkInvalidations // to automatically invalidate dependant page. In this example that would be pages that // use <getprop page="something>. However that would require adding a linking table // (since none of the standard ones work for this example) which is a bit beyond the // scope of this simple example. return ''; }
static function renderToolProperty($input, array $args, Parser $parser, PPFrame $frame) { $parser->disableCache(); $id = $args['id']; $property = $args['property']; $format = array_key_exists('format', $args) ? $args['format'] : null; $function = array_key_exists('function', $args) ? $args['function'] : null; $parsedId = $parser->recursiveTagParse($id, $frame); if (is_numeric($parsedId) && !array_key_exists($parsedId, self::$resources)) { $lnf = new LNF(); self::$resources[$parsedId] = $lnf->getResource($parsedId); } if (array_key_exists($parsedId, self::$resources)) { $res = self::$resources[$parsedId]; } if ($res == null) { return $property; } if ($property == "ToolEngineers") { if (is_array($res->ToolEngineers)) { $html = "<ul>"; foreach ($res->ToolEngineers as $item) { $html .= '<li><a href="mailto:' . $item->Email[0] . '">' . $item->DisplayName . '</li>'; } $html .= "</ul>"; return $html; } else { $result = self::getPropertyValue($res, "ToolEngineers"); } } else { $result = self::getPropertyValue($res, $property); } if ($function != null) { $result = self::$function($result); } if ($format == null) { return $result; } else { return sprintf($format, $result); } }
/** * Creates a HTML link that will open in a new browser window or tab. * * @param Parser $parser Parser being used * @param string $target literal URI or a MediaWiki link for linked resource * @param string $label link text * @return string HTML */ function efParserCreateLink($parser, $target, $label = null) { // sanitise the input and set defaults if (is_null($label)) { $label = $target; $label = htmlspecialchars($label, ENT_NOQUOTES, 'UTF-8'); } else { $label = preg_replace("/\\b({$parser->mUrlProtocols})/", "\$1 ", $label); // Hack to not parse external links by breaking them $label = $parser->recursiveTagParse($label); $label = preg_replace("/\\b({$parser->mUrlProtocols}) /", "\$1", $label); // Put them back together } $attributes = array('target' => '_blank'); // WARNING: the order of the statements below does matter! // // Also, the Parser::insertStripItem is used to render the HTML inline. // See: http://www.mediawiki.org/wiki/Manual:Parser_functions#Parser_interface // Process (or rule out) external targets (literal URIs) if (preg_match($parser->mExtLinkBracketedRegex, "[{$target}]")) { return $parser->insertStripItem(Linker::makeExternalLink($target, $label, false, '', $attributes), $parser->mStripState); } // The target is not a literal URI. Create a Title object. $oTitle = Title::newFromText($target); // Title::newFromText may occasionally return null, which means something is really wrong with the $target. if (is_null($oTitle)) { return $parser->insertStripItem(wfMsg('newwindowlinks-invalid-target'), $parser->mStripState); } // Process (or rule out) existing local articles. if ($oTitle->exists()) { return $parser->insertStripItem(Linker::link($oTitle, $label, $attributes), $parser->mStripState); } // Process (or rule out) interwiki links. if (true !== $oTitle->isLocal()) { return $parser->insertStripItem(Linker::makeExternalLink($oTitle->getFullURL(), $label, false, '', $attributes), $parser->mStripState); } // Only non existing local articles remain. return $parser->insertStripItem(Linker::link($oTitle, $label, $attributes), $parser->mStripState); }
/** * @param string $input * @param Array $args * @param Parser $parser * @return string */ function TimelineConstruct($input, $args, &$parser) { $lines = explode("\n", $input); foreach ($lines as $line) { $line_array = explode("|", $line); //invalid line if (count($line_array) < 2) { continue; } $time = strtotime($line_array[0]); //invalid date if (!$time) { continue; } //the data might have | in it, so lets combine the rest of the array unset($line_array[0]); $data = implode("|", $line_array); $events[] = array("time" => $time, "month_name" => date("F", $time), "month" => date("n", $time), "year" => date("Y", $time), "day" => date("j", $time), "data" => $parser->recursiveTagParse($data)); } usort($events, "TimelineSort"); $output = TimelineRender($events); return $output; }
/** * Parse the text into proper poem format * @param string $in The text inside the poem tag * @param array $param * @param Parser $parser * @param boolean $frame * @return string */ public static function renderPoem($in, $param = array(), $parser = null, $frame = false) { // using newlines in the text will cause the parser to add <p> tags, // which may not be desired in some cases $newline = isset($param['compact']) ? '' : "\n"; $tag = $parser->insertStripItem("<br />", $parser->mStripState); // replace colons with indented spans $text = preg_replace_callback('/^(:+)(.+)$/m', array('Poem', 'indentVerse'), $in); // replace newlines with <br /> tags unless they are at the beginning or end // of the poem $text = preg_replace(array("/^\n/", "/\n\$/D", "/\n/"), array("", "", "{$tag}\n"), $text); // replace spaces at the beginning of a line with non-breaking spaces $text = preg_replace_callback('/^( +)/m', array('Poem', 'replaceSpaces'), $text); $text = $parser->recursiveTagParse($text, $frame); $attribs = Sanitizer::validateTagAttributes($param, 'div'); // Wrap output in a <div> with "poem" class. if (isset($attribs['class'])) { $attribs['class'] = 'poem ' . $attribs['class']; } else { $attribs['class'] = 'poem'; } return Html::rawElement('div', $attribs, $newline . trim($text) . $newline); }
/** * The callback function for converting the input text to HTML output * * @param string $input * @param array $argv * @param Parser $parser * @return string */ function renderSpoiler($input, $argv, $parser) { # $argv is an array containing any arguments passed to the # extension like <example argument="foo" bar>.. # Put this on the sandbox page: (works in MediaWiki 1.5.5) # <example argument="foo" argument2="bar">Testing text **example** in between the new tags</example> $outputObj = $parser->recursiveTagParse($input); $spoilerId = wfMakeSpoilerId(); // quick hack to get rid of 'undefined index' notices... foreach (array('collapsed', 'contentstyle', 'footwarningtext', 'headwarningtext', 'linkstyle', 'linktext', 'spoilerstyle', 'warningstyle') as $a) { if (!isset($argv[$a])) { $argv[$a] = ''; } } $output = "<span onClick=\"toggleObjectVisibility('" . $spoilerId . "'); return false;\" style=\"" . ($argv["linkstyle"] == '' ? "cursor:pointer; background-color:#ffdddd; color:#000000; font-weight:bold; padding:4px 4px 2px 4px; border:solid red 1px; line-height: 24px;" : $argv["linkstyle"]) . "\">"; $output .= ($argv["linktext"] == '' ? wfMsg('spoiler-showhide-label') : $argv["linktext"]) . "</span>"; $output .= "<div id=\"" . $spoilerId . "\" style=\"visibility:visible; position:relative; " . ($argv["spoilerstyle"] == '' ? "" : $argv["spoilerstyle"]) . "\">"; if (!in_array("hidewarning", array_values($argv))) { $output .= "<div style=\"" . ($argv["warningstyle"] == '' ? "border-top: 2px red solid; border-bottom: 2px red solid; padding:3px; line-height: 22px;" : $argv["warningstyle"]) . "\">"; $output .= $argv["headwarningtext"] == '' ? wfMsg('spoiler-warning') : $argv["headwarningtext"]; $output .= "</div>"; } $output .= "<div id=\"" . $spoilerId . "_content\" style=\"" . ($argv["contentstyle"] == '' ? "padding-top:4px; padding-bottom:4px;" : $argv["contentstyle"]) . "\">" . $outputObj . "</div>"; if (!in_array("hidewarning", array_values($argv))) { $output .= "<div style=\"" . ($argv["warningstyle"] == '' ? "border-top: 2px red solid; border-bottom: 2px red solid; padding:3px; line-height: 22px;" : $argv["warningstyle"]) . "\">"; $output .= $argv["footwarningtext"] == '' ? wfMsg('spoiler-endshere') : $argv["footwarningtext"]; $output .= "</div>"; } $output .= "</div>"; if ($argv["collapsed"] != "false") { $output .= "<script type=\"text/javascript\" language=\"JavaScript\">"; $output .= "toggleObjectVisibility('" . $spoilerId . "');"; $output .= "</script>"; } return $output; }
public static function noMathJaxTag($text, array $args, Parser $parser, PPFrame $frame) { $output = $parser->recursiveTagParse($text, $frame); return '<span class="tex2jax_ignore">' . $output . '</span>'; }
/** * Processes params (assumed valid) and sets them as class properties * @param Array $params Array of pre-validated params * @param Parser $parser If passed, the parser will be used to recursively parse all params * @return Array An array of processed params */ protected static function processParams($params, $parser = null) { //correct params for compatibility with "HTML Meta and Title" extension foreach (self::$convert_params as $from => $to) { if (isset($params[$from])) { $params[$to] = $params[$from]; unset($params[$from]); } } $processed = array(); //ensure only valid parameter names are processed foreach (self::$valid_params as $p) { if (isset($params[$p])) { //if the parser has been passed and the param is parsable parse it, else simply assign it $processed[$p] = $parser && in_array($p, self::$parse_params) ? $parser->recursiveTagParse($params[$p]) : $params[$p]; } } //set the processed values as class properties foreach ($processed as $k => $v) { if ($k === 'title') { self::$title = $v; } else { if ($k === 'title_mode' && in_array($v, self::$valid_title_modes)) { self::$title_mode = $v; } else { if ($k === 'title_separator') { self::$title_separator = ' ' . $v . ' '; } else { if (isset(self::$tag_types[$k]) && self::$tag_types[$k] === 'meta') { self::$meta[$k] = $v; } else { if (isset(self::$tag_types[$k]) && self::$tag_types[$k] === 'property') { self::$property[$k] = $v; } } } } } } return $processed; }
static private function expandSpeakers($raw, $speakers, Parser $parser, PPFrame $frame){ if ($speakers != null){ foreach($speakers as $key => $value){ $raw = preg_replace('/<\s*'.$key.'\s*>/', $value, $raw); } } return $parser->recursiveTagParse($raw, $frame); }
/** * Default parser tag renderer */ public static function jsonTagRender($input, array $args, Parser $parser, PPFrame $frame) { global $wgJsonData; $wgJsonData = new JsonData($frame->title); $json = $input; $goodschema = true; try { $schematext = $wgJsonData->getSchemaText(); } catch (JsonDataException $e) { $schematext = $wgJsonData->readJsonFromPredefined('openschema'); wfDebug(__METHOD__ . ": " . htmlspecialchars($e->getMessage()) . "\n"); $goodschema = false; } $schematitletext = $wgJsonData->getSchemaTitleText(); if ($goodschema && !is_null($schematitletext)) { // Register dependency in templatelinks, using technique (and a // little code) from http://www.mediawiki.org/wiki/Manual:Tag_extensions $schematitle = Title::newFromText($schematitletext); $schemarev = Revision::newFromTitle($schematitle); $schemaid = $schemarev ? $schemarev->getPage() : 0; $parser->mOutput->addTemplate($schematitle, $schemaid, $schemarev ? $schemarev->getId() : 0); } $data = json_decode($json, true); $schema = json_decode($schematext, true); $rootjson = new JsonTreeRef($data); $rootjson->attachSchema($schema); $markup = JsonDataMarkup::getMarkup($rootjson, 0); return $parser->recursiveTagParse($markup, $frame); }
/** * Wrapper function parse, call the other functions * @param string $text the content * @return string the parsed output */ function parse( $text ) { wfProfileIn( __METHOD__ ); $output = $this->parser->recursiveTagParse( $text ); wfProfileOut( __METHOD__ ); return $output; }
/** * Takes a line and parse it into title, titleLink, alt & caption parameters * @todo Make arguments to paremeters parsing less ugly & more flexible, with widgetsFramework for example. * * @param string $line * @param Parser $parser * @return array title, titleLink, alt, caption */ private static function parseLine($line, $parser, $frame) { $explosion = explode('|', $line); $parameters = array(); $parameters['title'] = null; $parameters['titleLink'] = null; #Title to link to $parameters['alt'] = ''; #html alternative text $parameters['caption'] = ''; #html caption #arguments are parsed by position... :,-( #first arg is file title $titleText = array_shift($explosion); if (is_null($titleText)) { # Empty line or something went wrong return false; } if (strpos($titleText, '%') !== false) { #fix possible url encoding of title $titleText = rawurldecode($titleText); } $title = Title::newFromText($titleText, NS_FILE); if (is_null($title)) { # Bogus title. Ignore these so we don't bomb out later. return false; } else { $parameters['title'] = $title; } #second arg could be link $titleLinkText = count($explosion) > 0 ? self::identifyByName('link', $explosion[0]) : false; if ($titleLinkText === false) { #title link is not set } else { if ($titleLinkText === true || $titleLinkText == '') { #title link is set to empty (no linking) } else { #title link is set $titleLink = Title::newFromText($titleLinkText); if (!is_null($titleLink) && $titleLink->isKnown()) { #isKnown, register to the output for the link table $parser->getOutput()->addLink($titleLink); $parameters['titleLink'] = $titleLink; } } array_shift($explosion); } #third arg could be alt $altText = count($explosion) > 0 ? self::identifyByname('alt', $explosion[0]) : false; if ($altText === false) { #alt is not set } else { $parameters['alt'] = htmlspecialchars($altText); array_shift($explosion); } #the rest is the caption, we can reconstruct the WikiText broken by explode('|'). $captionText = implode('|', $explosion); $parameters['caption'] = $parser->recursiveTagParse($captionText, $frame); return $parameters; }
/** * Generates the output for a <libravatar/> tag during parsing. * * @param string $content Content of the tag * (between opening and closing tag) * @param array $params Array of tag parameters. * @param Parser $parser MediaWiki parser object * @param PPFrame_DOM $frame Context data with e.g. template variables * * @return string HTML representation of the libravatar tag. * * @throws MWException In case Services_Libravatar is not available */ function mwLibravatarTagParse($content, $params, $parser, $frame) { include_once 'Services/Libravatar.php'; if (!class_exists('Services_Libravatar')) { throw new MWException('Libravatar: Services_Libravatar not available'); } $sla = new Services_Libravatar(); $sla->detectHttps(); $extra = ''; try { // email attribute if (isset($params['email'])) { //all fine } else { if ($content != '') { $params['email'] = trim($content); } else { throw new InvalidArgumentException('email attribute missing'); } } $params['email'] = $parser->recursiveTagParse($params['email'], $frame); // size attribute if (isset($params['size'])) { $params['size'] = (int) $params['size']; } else { if (isset($GLOBALS['wgLibravatarSize'])) { $params['size'] = (int) $GLOBALS['wgLibravatarSize']; } } $params['size'] = $parser->recursiveTagParse($params['size'], $frame); $sla->setSize($params['size']); $extra .= sprintf(' width="%d" height="%d"', $params['size'], $params['size']); // default attribute if (isset($params['default'])) { // ok } else { if (isset($GLOBALS['wgLibravatarDefault'])) { $params['default'] = $GLOBALS['wgLibravatarDefault']; } } if (isset($params['default'])) { $params['default'] = $parser->recursiveTagParse($params['default'], $frame); $sla->setDefault($params['default']); } // algorithm attribute if (isset($params['algorithm'])) { // ok } else { if (isset($GLOBALS['wgLibravatarAlgorithm'])) { $params['algorithm'] = $GLOBALS['wgLibravatarAlgorithm']; } } if (isset($params['algorithm'])) { $params['algorithm'] = $parser->recursiveTagParse($params['algorithm'], $frame); $sla->setAlgorithm($params['algorithm']); } } catch (Exception $e) { return sprintf('<span style="color:red">%s</span>', 'Libravatar error: ' . htmlspecialchars($e->getMessage())); } if (isset($params['title'])) { $extra .= sprintf(' title="%s"', htmlspecialchars($parser->recursiveTagParse($params['title'], $frame))); } if (isset($params['style'])) { $extra .= sprintf(' style="%s"', htmlspecialchars($parser->recursiveTagParse($params['style'], $frame))); } return sprintf('<img src="%s" alt="%s" width="%s"%s/>', htmlspecialchars($sla->getUrl($params['email'])), htmlspecialchars('Avatar of ' . str_replace(array('@', '.'), array(' at ', ' dot '), $params['email'])), htmlspecialchars($params['size']), $extra); }
/** * Set the description. * * @access private * @param string Description * @param object Mediawiki Parser object * @return void */ private static function setDescription($description, \Parser $parser) { self::$description = !$description ? false : $parser->recursiveTagParse($description); }
/** * Embeds video of the chosen service * @param Parser $parser Instance of running Parser. * @param String $service Which online service has the video. * @param String $id Identifier of the chosen service * @param String $width Width of video (optional) * @param String $desc description to show (optional) * @param String $align alignment of the video (optional) * @return String Encoded representation of input params (to be processed later) */ public static function parserFunction_ev($parser, $service = null, $id = null, $width = null, $align = null, $desc = null) { global $wgScriptPath; // Initialize things once if (!self::$initialized) { self::VerifyWidthMinAndMax(); self::$initialized = true; } // Get the name of the host if ($service === null || $id === null) { return self::errMissingParams($service, $id); } $service = trim($service); $id = trim($id); $desc = $parser->recursiveTagParse($desc); $entry = self::getServiceEntry($service); if (!$entry) { return self::errBadService($service); } if (!self::sanitizeWidth($entry, $width)) { return self::errBadWidth($width); } $height = self::getHeight($entry, $width); $hasalign = $align !== null || $align == 'auto'; if ($hasalign) { $align = trim($align); if (!self::validateAlignment($align)) { return self::errBadAlignment($align); } $desc = self::getDescriptionMarkup($desc); } // If the service has an ID pattern specified, verify the id number if (!self::verifyID($entry, $id)) { return self::errBadID($service, $id); } $url = null; // If service is Yandex -> use own parser if ($service == 'yandex' || $service == 'yandexvideo') { $url = self::getYandex($id); $url = htmlspecialchars_decode($url); } // if the service has it's own custom extern declaration, use that instead if (array_key_exists('extern', $entry) && ($clause = $entry['extern']) != NULL) { if ($service == 'screen9') { $clause = self::parseScreen9Id($id, $width, $height); if ($clause == null) { return self::errBadScreen9Id(); } } else { $clause = wfMsgReplaceArgs($clause, array($wgScriptPath, $id, $width, $height, $url)); } if ($hasalign) { $clause = self::generateAlignExternClause($clause, $align, $desc, $width, $height); } return array($clause, 'noparse' => true, 'isHTML' => true); } // Build URL and output embedded flash object $url = wfMsgReplaceArgs($entry['url'], array($id, $width, $height)); $clause = ""; // If service is RuTube -> use own parser if ($service == 'rutube') { $url = self::getRuTube($id); } if ($hasalign) { $clause = self::generateAlignClause($url, $width, $height, $align, $desc); } else { $clause = self::generateNormalClause($url, $width, $height); } return array($clause, 'noparse' => true, 'isHTML' => true); }