本文整理汇总了PHP中Parser::extractTagsAndParams方法的典型用法代码示例。如果您正苦于以下问题:PHP Parser::extractTagsAndParams方法的具体用法?PHP Parser::extractTagsAndParams怎么用?PHP Parser::extractTagsAndParams使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Parser
的用法示例。
在下文中一共展示了Parser::extractTagsAndParams方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: renderRandom
function renderRandom($input, $argv, $parser)
{
$count = intval($argv['count']);
$result = '';
$format = '%ITEM%';
$items = array();
$elements = array('item', 'format');
$text = Parser::extractTagsAndParams($elements, $input, $matches);
foreach ($matches as $marker => $data) {
list($element, $content, $params, $tag) = $data;
if ($element === 'item') {
$content = trim($content, " \t");
$content = trim($content, "\n");
$items[] = str_replace('%ITEM%', $content, $format);
} else {
if ($element === 'format') {
if (!empty($content) && preg_match('/%ITEM%/', $content) != 0) {
$format = str_replace('«', '<', $content);
$format = str_replace('»', '>', $format);
$format = trim($format, " \t");
$format = trim($format, "\n");
$format = str_replace('\\n', "\n", $format);
}
}
}
}
$entries = count($items);
if ($entries == 0) {
return '';
}
if ($count <= 0) {
$count = 1;
} else {
if ($count > $entries) {
$count = $entries;
}
}
$keys = array_rand($items, $count);
if (is_array($keys)) {
foreach ($keys as $key) {
$result .= $parser->recursiveTagParse($items[$key]);
}
} else {
$result = $parser->recursiveTagParse($items[$keys]);
}
$parser->disableCache();
return $result;
}
示例2: build
public function build()
{
global $wgContLang;
$dc = MwRdf::Vocabulary('dc');
$dcterms = MwRdf::Vocabulary('dcterms');
$rdfs = MwRdf::Vocabulary('rdfs');
$model = MwRdf::Model();
$tr = $this->Agent->titleResource();
$article = $this->Agent->getArticle();
$text = $article->getContent(true);
$parser = new Parser();
$parser->mOptions = new ParserOptions();
$parser->mTitle = $this;
$parser->initialiseVariables();
$parser->clearState();
$tags = array('nowiki');
$m = array();
$text = $parser->extractTagsAndParams($tags, $text, $m);
# XXX: maybe it would actually be better to do this at another
# stage after the parser has already identified interwiki and
# lang links
# Find prefixed links
preg_match_all("/\\[\\[([^|\\]]+:[^|\\]]+)(\\|.*)?\\]\\]/", $text, $m);
if (!isset($m[0])) {
return $model;
}
// nothing found so nevermind
foreach ($m[1] as $linktext) {
$iwlink = Title::newFromText($linktext);
if (isset($iwlink)) {
$pfx = $iwlink->getInterwiki();
if (strlen($pfx) > 0) {
$iwlinkmf = MwRdf::ModelingAgent($iwlink);
$iwr = $iwlinkmf->titleResource();
# XXX: Wikitravel uses some 4+ prefixes for sister site links
if ($wgContLang->getLanguageName($pfx) && strlen($pfx) < 4) {
$model->addStatement(MwRdf::Statement($tr, $dcterms->hasVersion, $iwr));
$model->addStatement(MwRdf::Statement($iwr, $dc->language, MwRdf::Language($pfx)));
} else {
# XXX: Express the "sister site" relationship better
$model->addStatement(MwRdf::Statement($tr, $rdfs->seeAlso, $iwr));
}
}
}
}
return $model;
}
示例3: articleSaveGeo
/**
* Hook function called every time a page is saved
* Use the ArticleSaveComplete instead of ArticleSave since the ID is
* not available upon ArticleSave for new articles
*/
function articleSaveGeo($article, $user, $text)
{
$id = $article->getID();
$g = new GisDatabase();
$g->delete_position($id);
$tag = 'geo';
$gis_content = array();
// !JF1
$text = Parser::extractTagsAndParams(array($tag), $text, $gis_content);
foreach ($gis_content as $marker => $tagresult) {
$tagname = $tagresult[0];
$content = $tagresult[1];
$params = $tagresult[2];
$full = $tagresult[3];
if ($tagname != 'geo') {
continue;
}
$p = new GeoParam($content);
$attr = $p->get_attr();
$g->add_position($id, $p->latdeg_min, $p->londeg_min, $p->latdeg_max, $p->londeg_max, $attr['globe'], $attr['type'], $attr['arg:type']);
}
return true;
}
示例4: parse
/**
* Convert wikitext to HTML
* Do not call this function recursively.
*
* @param string $text Text we want to parse
* @param Title &$title A title object
* @param array $options
* @param boolean $linestart
* @param boolean $clearState
* @param int $revid number to pass in {{REVISIONID}}
* @return ParserOutput a ParserOutput
*/
public function parse($text, &$title, $options, $linestart = true, $clearState = true, $revid = null)
{
/**
* First pass--just handle <nowiki> sections, pass the rest off
* to internalParse() which does all the real work.
*/
global $wgUseTidy, $wgAlwaysUseTidy, $wgContLang;
$fname = 'Parser::parse-' . wfGetCaller();
wfProfileIn(__METHOD__);
wfProfileIn($fname);
if ($clearState) {
$this->clearState();
}
$this->mOptions = $options;
$this->setTitle($title);
$oldRevisionId = $this->mRevisionId;
$oldRevisionTimestamp = $this->mRevisionTimestamp;
if ($revid !== null) {
$this->mRevisionId = $revid;
$this->mRevisionTimestamp = null;
}
$this->setOutputType(self::OT_HTML);
wfRunHooks('ParserBeforeStrip', array(&$this, &$text, &$this->mStripState));
# No more strip!
wfRunHooks('ParserAfterStrip', array(&$this, &$text, &$this->mStripState));
$text = $this->internalParse($text);
$text = $this->mStripState->unstripGeneral($text);
# Clean up special characters, only run once, next-to-last before doBlockLevels
$fixtags = array('/(.) (?=\\?|:|;|!|%|\\302\\273)/' => '\\1 \\2', '/(\\302\\253) /' => '\\1 ');
$text = preg_replace(array_keys($fixtags), array_values($fixtags), $text);
# only once and last
$text = $this->doBlockLevels($text, $linestart);
$this->replaceLinkHolders($text);
# the position of the parserConvert() call should not be changed. it
# assumes that the links are all replaced and the only thing left
# is the <nowiki> mark.
# Side-effects: this calls $this->mOutput->setTitleText()
$text = $wgContLang->parserConvert($text, $this);
$text = $this->mStripState->unstripNoWiki($text);
wfRunHooks('ParserBeforeTidy', array(&$this, &$text));
//!JF Move to its own function
$uniq_prefix = $this->mUniqPrefix;
$matches = array();
$elements = array_keys($this->mTransparentTagHooks);
$text = Parser::extractTagsAndParams($elements, $text, $matches, $uniq_prefix);
foreach ($matches as $marker => $data) {
list($element, $content, $params, $tag) = $data;
$tagName = strtolower($element);
if (isset($this->mTransparentTagHooks[$tagName])) {
$output = call_user_func_array($this->mTransparentTagHooks[$tagName], array($content, $params, $this));
} else {
$output = $tag;
}
$this->mStripState->general->setPair($marker, $output);
}
$text = $this->mStripState->unstripGeneral($text);
$text = Sanitizer::normalizeCharReferences($text);
if ($wgUseTidy and $this->mOptions->mTidy or $wgAlwaysUseTidy) {
$text = Parser::tidy($text);
} else {
# attempt to sanitize at least some nesting problems
# (bug #2702 and quite a few others)
$tidyregs = array('/(<([bi])>)(<([bi])>)?([^<]*)(<\\/?a[^<]*>)([^<]*)(<\\/\\4>)?(<\\/\\2>)/' => '\\1\\3\\5\\8\\9\\6\\1\\3\\7\\8\\9', '/(<a[^>]+>)([^<]*)(<a[^>]+>[^<]*)<\\/a>(.*)<\\/a>/' => '\\1\\2</a>\\3</a>\\1\\4</a>', '/(<([aib]) [^>]+>)([^<]*)(<div([^>]*)>)(.*)(<\\/div>)([^<]*)(<\\/\\2>)/' => '\\1\\3<div\\5>\\6</div>\\8\\9', '/<([bi])><\\/\\1>/' => '');
$text = preg_replace(array_keys($tidyregs), array_values($tidyregs), $text);
}
wfRunHooks('ParserAfterTidy', array(&$this, &$text));
# Information on include size limits, for the benefit of users who try to skirt them
if ($this->mOptions->getEnableLimitReport()) {
$max = $this->mOptions->getMaxIncludeSize();
$limitReport = "NewPP limit report\n" . "Preprocessor node count: {$this->mPPNodeCount}/{$this->mOptions->mMaxPPNodeCount}\n" . "Post-expand include size: {$this->mIncludeSizes['post-expand']}/{$max} bytes\n" . "Template argument size: {$this->mIncludeSizes['arg']}/{$max} bytes\n";
wfRunHooks('ParserLimitReport', array($this, &$limitReport));
$text .= "\n<!-- \n{$limitReport}-->\n";
}
$this->mOutput->setText($text);
$this->mRevisionId = $oldRevisionId;
$this->mRevisionTimestamp = $oldRevisionTimestamp;
wfProfileOut($fname);
wfProfileOut(__METHOD__);
return $this->mOutput;
}
示例5: strip
/**
* Strips and renders nowiki, pre, math, hiero
* If $render is set, performs necessary rendering operations on plugins
* Returns the text, and fills an array with data needed in unstrip()
*
* @param StripState $state
*
* @param bool $stripcomments when set, HTML comments <!-- like this -->
* will be stripped in addition to other tags. This is important
* for section editing, where these comments cause confusion when
* counting the sections in the wikisource
*
* @param array dontstrip contains tags which should not be stripped;
* used to prevent stipping of <gallery> when saving (fixes bug 2700)
*
* @private
*/
function strip($text, $state, $stripcomments = false, $dontstrip = array())
{
global $wgContLang, $wgUseTeX, $wgScriptPath, $wgVersion, $wgHooks, $wgExtensionFunctions;
wfProfileIn(__METHOD__);
$render = $this->mOutputType == OT_HTML;
$uniq_prefix = $this->mUniqPrefix;
$commentState = new ReplacementArray();
$nowikiItems = array();
$generalItems = array();
$elements = array_merge(array('nowiki', 'gallery', 'math'), array_keys($this->mTagHooks));
if (isset($wgHooks['ParserFirstCallInit']) && in_array('efSyntaxHighlight_GeSHiSetup', $wgHooks['ParserFirstCallInit']) || isset($wgExtensionFunctions) && in_array('efSyntaxHighlight_GeSHiSetup', $wgExtensionFunctions)) {
$elements = array_merge($elements, array('source'));
}
if (isset($wgHooks['ParserFirstCallInit']) && in_array('wfCite', $wgHooks['ParserFirstCallInit']) || isset($wgExtensionFunctions) && in_array('wfCite', $wgExtensionFunctions)) {
$elements = array_merge($elements, array('ref', 'references'));
}
global $wgRawHtml;
if ($wgRawHtml) {
$elements[] = 'html';
}
# Removing $dontstrip tags from $elements list (currently only 'gallery', fixing bug 2700)
foreach ($elements as $k => $v) {
if (!in_array($v, $dontstrip)) {
continue;
}
unset($elements[$k]);
}
$elements = array_unique($elements);
$matches = array();
if (version_compare("1.12", $wgVersion, ">")) {
$text = Parser::extractTagsAndParams($elements, $text, $matches, $uniq_prefix);
} else {
$text = self::extractTagsAndParams($elements, $text, $matches, $uniq_prefix);
}
foreach ($matches as $marker => $data) {
list($element, $content, $params, $tag) = $data;
if ($render) {
$tagName = strtolower($element);
wfProfileIn(__METHOD__ . "-render-{$tagName}");
switch ($tagName) {
case '!--':
// Comment
if (substr($tag, -3) == '-->') {
$output = $tag;
} else {
// Unclosed comment in input.
// Close it so later stripping can remove it
$output = "{$tag}-->";
}
break;
case 'references':
$output = $this->fck_wikiTag('references', $content, $params);
break;
case 'ref':
$output = $this->fck_wikiTag('ref', $content, $params);
break;
case 'source':
$output = $this->fck_wikiTag('source', $content, $params);
break;
case 'html':
if ($wgRawHtml) {
$output = $this->fck_wikiTag('html', $content, $params);
}
break;
case 'nowiki':
$output = $this->fck_wikiTag('nowiki', $content, $params);
// required by FCKeditor
break;
case 'math':
if ($wgUseTeX) {
//normal render
$output = $wgContLang->armourMath(MathRenderer::renderMath($content));
} else {
// show fakeimage
$output = '<img _fckfakelement="true" class="FCK__MWMath" _fck_mw_math="' . $content . '" src="' . $wgScriptPath . '/skins/common/images/button_math.png" />';
}
break;
case 'gallery':
$output = $this->fck_wikiTag('gallery', $content, $params);
// required by FCKeditor
//$output = $this->renderImageGallery( $content, $params );
break;
default:
//.........这里部分代码省略.........
示例6: sanitizeWikiText
static function sanitizeWikiText($text, $parser = null)
{
if (!$parser) {
$parser = $GLOBALS['wgParser'];
}
$elements = array_keys($parser->mTagHooks);
$uniq_prefix = "NR-UNIQ";
$matches = array();
$text = Parser::extractTagsAndParams($elements, $text, $matches, $uniq_prefix);
foreach ($matches as $marker => $data) {
list($element, $content, $params, $tag) = $data;
$tagName = strtolower($element);
$output = '';
if ($tagName == '!--') {
$output = $tag;
}
//keep comments for now, may be stripped later
#print "* $marker => " . htmlspecialchars($output) . "<br />\n";
$text = str_replace($marker, $output, $text);
}
return $text;
}
示例7: strip
/**
* Strips and renders nowiki, pre, math, hiero
* If $render is set, performs necessary rendering operations on plugins
* Returns the text, and fills an array with data needed in unstrip()
* If the $state is already a valid strip state, it adds to the state
*
* @param bool $stripcomments when set, HTML comments <!-- like this -->
* will be stripped in addition to other tags. This is important
* for section editing, where these comments cause confusion when
* counting the sections in the wikisource
*
* @param array dontstrip contains tags which should not be stripped;
* used to prevent stipping of <gallery> when saving (fixes bug 2700)
*
* @private
*/
function strip($text, &$state, $stripcomments = false, $dontstrip = array())
{
wfProfileIn(__METHOD__);
$render = $this->mOutputType == OT_HTML;
$uniq_prefix = $this->mUniqPrefix;
$commentState = array();
$elements = array_merge(array('nowiki', 'gallery'), array_keys($this->mTagHooks));
global $wgRawHtml;
if ($wgRawHtml) {
$elements[] = 'html';
}
if ($this->mOptions->getUseTeX()) {
$elements[] = 'math';
}
# Removing $dontstrip tags from $elements list (currently only 'gallery', fixing bug 2700)
foreach ($elements as $k => $v) {
if (!in_array($v, $dontstrip)) {
continue;
}
unset($elements[$k]);
}
$matches = array();
$text = Parser::extractTagsAndParams($elements, $text, $matches, $uniq_prefix);
foreach ($matches as $marker => $data) {
list($element, $content, $params, $tag) = $data;
if ($render) {
$tagName = strtolower($element);
wfProfileIn(__METHOD__ . "-render-{$tagName}");
switch ($tagName) {
case '!--':
// Comment
if (substr($tag, -3) == '-->') {
$output = $tag;
} else {
// Unclosed comment in input.
// Close it so later stripping can remove it
$output = "{$tag}-->";
}
break;
case 'html':
if ($wgRawHtml) {
$output = $content;
break;
}
// Shouldn't happen otherwise. :)
// Shouldn't happen otherwise. :)
case 'nowiki':
$output = wfEscapeHTMLTagsOnly($content);
break;
case 'math':
$output = MathRenderer::renderMath($content);
break;
case 'gallery':
$output = $this->renderImageGallery($content, $params);
break;
default:
if (isset($this->mTagHooks[$tagName])) {
$output = call_user_func_array($this->mTagHooks[$tagName], array($content, $params, $this));
} else {
throw new MWException("Invalid call hook {$element}");
}
}
wfProfileOut(__METHOD__ . "-render-{$tagName}");
} else {
// Just stripping tags; keep the source
$output = $tag;
}
// Unstrip the output, because unstrip() is no longer recursive so
// it won't do it itself
$output = $this->unstrip($output, $state);
if (!$stripcomments && $element == '!--') {
$commentState[$marker] = $output;
} elseif ($element == 'html' || $element == 'nowiki') {
$state['nowiki'][$marker] = $output;
} else {
$state['general'][$marker] = $output;
}
}
# Unstrip comments unless explicitly told otherwise.
# (The comments are always stripped prior to this point, so as to
# not invoke any extension tags / parser hooks contained within
# a comment.)
if (!$stripcomments) {
// Put them all back and forget them
//.........这里部分代码省略.........
示例8: recentImagesParserHook
/**
* nifty "parser hook" for <recentimages> tag
* @return string tag body
*/
public static function recentImagesParserHook(Parser $parser, $text, $strip_state)
{
global $wgRTEParserEnabled;
if (!empty($wgRTEParserEnabled)) {
return true;
}
$tags = array();
$text = $parser->extractTagsAndParams(array('recentimages'), $text, $tags);
foreach ($tags as $uniqId => $tagData) {
if ($tagData[0] == 'recentimages') {
$args = self::extractArgs($tagData[2]);
// preserve all <gallery> tag params
unset($tagData[2]['size']);
unset($tagData[2]['ns']);
$galleryTagParams = '';
foreach ($tagData[2] as $paramKey => $paramValue) {
$galleryTagParams .= $paramKey . '="' . $paramValue . '" ';
}
$tagBody = "<gallery {$galleryTagParams}>\n";
foreach (DataProvider::GetRecentlyUploadedImages($args['limit']) as $image) {
$tagBody .= $image['name'] . "\n";
}
$tagBody .= "</gallery>\n";
$text = str_replace($uniqId, $tagBody, $text);
} else {
// small hack to restore everything accidentally replaced UNIQ marker (e.g. <!-- --> tag)
$text = str_replace($uniqId, $tagData[3], $text);
}
}
return true;
}
示例9: execute
function execute($par)
{
global $wgOut;
include "Parse_Entries.php";
#Don't want to output standard Wiki stuff, just want blank page.
$wgOut->disable();
# If just Special:BibtexExport , explain what it is and die.
if ($par == "") {
echo "<h3>You haven't specified which wiki page you would like the BibTeX from.</h3>";
echo "<div style=\"width:33em\">";
echo "To grab the BibTeX between the <bibtex> and </bibtex> tags ";
echo "in an article, simply visit Special:BibtexExport/Article_Name.";
echo "<p>";
echo "To narrow it down you can append a query to the URL. For example, if you ";
echo "wanted to get the bibtex for all the Haystack publications by David Huynh ";
echo "in the year 2005, simply visit: <p>";
echo "<a href=\"http://simile.mit.edu/exhibited-wiki/Special:BibtexExport/Haystack?field:author=David%20Huynh&field:year=2005\">";
echo "http://simile.mit.edu/exhibited-wiki/Special:BibtexExport/Haystack?field:author=David%20Huynh&field:year=2005</a>";
echo "</div>";
die;
}
# Grab the article associated with the text past Special:BibtexExport.
# e.g. Special:BibtexExport/Some_Article will grab all the data in the
# Some_Article page.
$title = Title::newFromURL($par);
$article = new Article($title);
$article->loadContent();
$text = $article->getContent();
# Try to get just the stuff in <bibtex> </bibtex> tags.
$bibtexmatches = array();
$anything = Parser::extractTagsAndParams(array('bibtex'), $text, $bibtexmatches);
# info stored in $bibtexmatches array, but key is randomly generated, so must
# iterate through the *one* element in the array.
# that in turn is an array, with the second key being the content
foreach ($bibtexmatches as $match) {
$bibtex = $match[1];
}
# If there's a query string (e.g. Special:BibtexExport/Article?author=name)
# we have more work to do. Otherwise, we're done.
if (!$_SERVER['QUERY_STRING']) {
echo "{$bibtex}";
} else {
#Parse Bibtex
$parse = new PARSEENTRIES();
$parse->loadBibtexString($bibtex);
$parse->extractEntries();
list($preamble, $strings, $entries, $undefinedStrings) = $parse->returnArrays();
#filter by queries of form, e.g., ?field:author=Charles%20Darwin
$queries = explode("&", $_SERVER['QUERY_STRING']);
foreach ($queries as $query) {
$survivingentries = array();
list($attr, $val) = explode("=", $query);
$val = rawurldecode($val);
$explodedattr = explode(":", $attr);
if ($explodedattr[0] == "field") {
# filter by some field
$filterby = $explodedattr[1];
#Now we know what to filter by, let's go through the bibtex.
foreach ($entries as $entry) {
if ($filterby == "author") {
$authorarray = explode(" and ", $entry['author']);
if (in_array($val, $authorarray)) {
$survivingentries[] = $entry;
}
} elseif ($entry[$filterby] == $val) {
$survivingentries[] = $entry;
}
}
}
unset($entries);
$entries = $survivingentries;
unset($survivingentries);
}
#Surviving entries should now be in $entries.
echo self::parsedEntriesToBibtex($entries);
}
exit;
}
示例10: axShowCurrentPage
public static function axShowCurrentPage($articleId, $namespace, $offset, $skin)
{
global $wgParser;
wfProfileIn(__METHOD__);
$result = "";
$offset = intval($offset);
if ($offset >= 0) {
$oTitle = Title::newFromID($articleId);
if (!empty($oTitle) && $oTitle instanceof Title) {
self::$oTitle = $oTitle;
$oRevision = Revision::newFromTitle($oTitle);
$sText = $oRevision->getText();
$id = Parser::extractTagsAndParams(array(BLOGTPL_TAG), $oRevision->getText(), $matches, md5(BLOGTPL_TAG . $articleId . $namespace . $offset));
if (!empty($matches)) {
list($sKey, $aValues) = each($matches);
list(, $input, $params, ) = $matches[$sKey];
$input = trim($input);
if (!empty($input) && !empty($params)) {
$aTags = array();
$count = 0;
/* try to find count */
if (preg_match_all(BLOGS_XML_REGEX, $input, $aTags)) {
if (!empty($aTags) && !empty($aTags[1])) {
if (in_array('count', array_values($aTags[1]))) {
foreach ($aTags[1] as $id => $key) {
if ($key == 'count') {
$count = intval($aTags[2][$id]);
break;
}
}
}
}
}
if (!empty($params) && array_key_exists('count', $params)) {
$count = intval($params['count']);
}
if (empty($count)) {
$count = intval(self::$aBlogParams['count']['default']);
}
$offset = $count * $offset;
/* set new value of offset */
$params['offset'] = $offset;
/* run parser */
$result = self::parseTag($input, $params, $wgParser);
}
}
} else {
wfDebugLog(__METHOD__, "Invalid parameters - {$articleId}, {$namespace}, {$offset} \n");
}
}
wfProfileOut(__METHOD__);
if (is_array($result)) {
return $result[0];
}
return $result;
}
示例11: parseText
/**
* Parses a text for protect-tags and stores the texts in member-fields.
* The resulting array are mContent, mParams and mSections.
* @param is_encrypted Boolean value, that indicates, if the parsed text
* is encrypted at all (dafault is true).
*/
public function parseText($is_encrypted = true)
{
$this->mContent = array();
$this->mParams = array();
$this->mElements = array(PROTECT_TAG);
$this->mParsedText = Parser::extractTagsAndParams($this->mElements, $this->mText, $this->mContent);
// Strip out anything except <protect> (i.e. <!-- --> comments)
foreach ($this->mContent as $key => $content) {
if (strtolower($content[0]) === PROTECT_TAG) {
continue;
}
// Put back text by replacing random key with original text
$this->mParsedText = str_replace($key, $content[3], $this->mParsedText);
// Remove content for replaced $key from $this->mContent
unset($this->mContent[$key]);
}
// decrypt all tags that are stored encrypted
foreach ($this->mContent as $key => $content) {
$dec = false;
if ($is_encrypted === true) {
$dec = $this->DecryptContent($key, $content[1]);
}
if ($dec !== false && $dec !== "") {
$this->mContent[$key][1] = $dec;
}
}
}