本文整理汇总了PHP中MagicWord类的典型用法代码示例。如果您正苦于以下问题:PHP MagicWord类的具体用法?PHP MagicWord怎么用?PHP MagicWord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MagicWord类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: MagicNoNumberedHeadingsParserBeforeInternalParse
function MagicNoNumberedHeadingsParserBeforeInternalParse($parser, $text, $stripState)
{
if (MagicWord::get('MAG_NONUMBEREDHEADINGS')->matchAndRemove($text)) {
$parser->mOptions->mNumberHeadings = FALSE;
}
return true;
}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:7,代码来源:MagicNoNumberedHeadings.php
示例2: onParserBeforeInternalParse
/**
*
* Process the MagicWords
*
* @param Parser $parser
* @param string $text
* @param StripState $stripState
* @return boolean
*/
function onParserBeforeInternalParse(&$parser, &$text, &$stripState)
{
$config = \PageAttachment\Configuration\StaticConfiguration::getInstance();
$pageAttachmentDefinedMagicWord = false;
$allowAttachments = false;
$magicWord1 = \MagicWord::get(self::MagicWord_NOATTACHMENTS);
if ($magicWord1->matchAndRemove($text)) {
$pageAttachmentDefinedMagicWord = true;
$allowAttachments = false;
}
$magicWord2 = \MagicWord::get(self::MagicWord_ALLOWATTACHMENTS);
if ($magicWord2->matchAndRemove($text)) {
$pageAttachmentDefinedMagicWord = true;
$allowAttachments = true;
}
if ($pageAttachmentDefinedMagicWord == true) {
if ($allowAttachments == true) {
if ($config->isAllowAttachmentsUsingMagicWord()) {
$parser->mOutput->addHeadItem('<script> pageAttachment__ALLOW_ATTACHMENTS__ = true; </script>');
}
} else {
if ($config->isDisallowAttachmentsUsingMagicWord()) {
$parser->mOutput->addHeadItem('<script> pageAttachment__ALLOW_ATTACHMENTS__ = false; </script>');
}
}
}
return true;
}
开发者ID:mediawiki-extensions,项目名称:mediawiki-page-attachment,代码行数:37,代码来源:MagicWordHandler.php
示例3: onInternalParseBeforeLinks
/**
* Hook entry for removing the magic words from displayed text
*/
public static function onInternalParseBeforeLinks(&$parser, &$text, &$strip_state)
{
global $wgRTEParserEnabled;
if (empty($wgRTEParserEnabled)) {
MagicWord::get('CATEXHIBITION_DISABLED')->matchAndRemove($text);
}
return true;
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:11,代码来源:CategoryExhibitionHelper.class.php
示例4: PSINoTocNumParserBeforeInternalParse
function PSINoTocNumParserBeforeInternalParse($parser, $text, $stripState)
{
if (MagicWord::get(MAG_NOTOCNUM)->matchAndRemove($text)) {
global $wgOut;
$wgOut->addScript('
<style type="text/css"><!-- .tocnumber {display:none;} --></style>
');
}
return true;
}
开发者ID:Jobava,项目名称:diacritice-meta-repo,代码行数:10,代码来源:PSINoTocNum.php
示例5: setUp
protected function setUp()
{
parent::setUp();
$contLang = Language::factory('en');
$this->setMwGlobals(array('wgShowDBErrorBacktrace' => true, 'wgLanguageCode' => 'en', 'wgContLang' => $contLang, 'wgLang' => Language::factory('en'), 'wgMemc' => new EmptyBagOStuff(), 'wgAlwaysUseTidy' => false, 'wgCleanSignatures' => true));
$this->options = ParserOptions::newFromUserAndLang(new User(), $contLang);
$this->options->setTemplateCallback(array(__CLASS__, 'statelessFetchTemplate'));
$this->parser = new Parser();
MagicWord::clearCache();
}
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:10,代码来源:ExtraParserTest.php
示例6: testMakeRedirectContent
/**
* @dataProvider provideMakeRedirectContent
* @param Title|string $title Title object or string for Title::newFromText()
* @param string $expected Serialized form of the content object built
* @covers WikitextContentHandler::makeRedirectContent
*/
public function testMakeRedirectContent($title, $expected)
{
global $wgContLang;
$wgContLang->resetNamespaces();
MagicWord::clearCache();
if (is_string($title)) {
$title = Title::newFromText($title);
}
$content = $this->handler->makeRedirectContent($title);
$this->assertEquals($expected, $content->serialize());
}
开发者ID:paladox,项目名称:mediawiki,代码行数:17,代码来源:WikitextContentHandlerTest.php
示例7: execute
public function execute() {
$this->batchsize = $this->getOption( 'batchsize', 50 );
$variableIDs = MagicWord::getVariableIDs();
foreach ( $variableIDs as $id ) {
$magic = MagicWord::get( $id );
foreach ( $magic->getSynonyms() as $synonym ) {
$this->processSynonym( $synonym );
}
}
$this->output( "All done\n" );
}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:11,代码来源:cleanupBug31576.php
示例8: run
function run()
{
if (!$this->redirTitle) {
$this->setLastError('Invalid title');
return false;
}
$targetRev = Revision::newFromTitle($this->title);
if (!$targetRev) {
wfDebug(__METHOD__ . ": target redirect already deleted, ignoring\n");
return true;
}
$text = $targetRev->getText();
$currentDest = Title::newFromRedirect($text);
if (!$currentDest || !$currentDest->equals($this->redirTitle)) {
wfDebug(__METHOD__ . ": Redirect has changed since the job was queued\n");
return true;
}
# Check for a suppression tag (used e.g. in periodically archived discussions)
$mw = MagicWord::get('staticredirect');
if ($mw->match($text)) {
wfDebug(__METHOD__ . ": skipping: suppressed with __STATICREDIRECT__\n");
return true;
}
# Find the current final destination
$newTitle = self::getFinalDestination($this->redirTitle);
if (!$newTitle) {
wfDebug(__METHOD__ . ": skipping: single redirect, circular redirect or invalid redirect destination\n");
return true;
}
if ($newTitle->equals($this->redirTitle)) {
# The redirect is already right, no need to change it
# This can happen if the page was moved back (say after vandalism)
wfDebug(__METHOD__ . ": skipping, already good\n");
}
# Preserve fragment (bug 14904)
$newTitle = Title::makeTitle($newTitle->getNamespace(), $newTitle->getDBkey(), $currentDest->getFragment());
# Fix the text
# Remember that redirect pages can have categories, templates, etc.,
# so the regex has to be fairly general
$newText = preg_replace('/ \\[ \\[ [^\\]]* \\] \\] /x', '[[' . $newTitle->getFullText() . ']]', $text, 1);
if ($newText === $text) {
$this->setLastError('Text unchanged???');
return false;
}
# Save it
global $wgUser;
$oldUser = $wgUser;
$wgUser = $this->getUser();
$article = new Article($this->title);
$reason = wfMsgForContent('double-redirect-fixed-' . $this->reason, $this->redirTitle->getPrefixedText(), $newTitle->getPrefixedText());
$article->doEdit($newText, $reason, EDIT_UPDATE | EDIT_SUPPRESS_RC);
$wgUser = $oldUser;
return true;
}
开发者ID:ui-libraries,项目名称:TIRW,代码行数:54,代码来源:DoubleRedirectJob.php
示例9: onInternalParseBeforeLinks
/**
* Entry for removing the magic words from displayed text
*/
public static function onInternalParseBeforeLinks(&$parser, &$text, &$strip_state)
{
wfProfileIn(__METHOD__);
if (empty(F::app()->wg->RTEParserEnabled)) {
$oMagicWord = MagicWord::get('RELATEDVIDEOS_POSITION');
$text = $oMagicWord->replace('<span data-placeholder="RelatedVideosModule"></span>', $text, 1);
$text = $oMagicWord->replace('', $text);
}
wfProfileOut(__METHOD__);
return true;
}
开发者ID:schwarer2006,项目名称:wikia,代码行数:14,代码来源:RelatedVideos.hooks.php
示例10: init
/**
* Static initializer.
*/
public static function init() {
$iExQuoteMW = MagicWord::get( 'wc_initial_exterior_quote' );
$fExQuoteMW = MagicWord::get( 'wc_final_exterior_quote' );
$iInQuoteMW = MagicWord::get( 'wc_initial_interior_quote' );
$fInQuoteMW = MagicWord::get( 'wc_final_interior_quote' );
$iExQuotes = implode( $iExQuoteMW->getSynonyms() );
$fExQuotes = implode( $fExQuoteMW->getSynonyms() );
$iInQuotes = implode( $iInQuoteMW->getSynonyms() );
$fInQuotes = implode( $fInQuoteMW->getSynonyms() );
self::$patternExternal = '/(^|[\p{Ps}\p{Zs}\p{Pd}\p{Pi}\'])[' . $iExQuotes . '](.*?)[' . $fExQuotes . ']($|[\p{Pe}\p{Zs}\.,;:?!\p{Pd}\p{Pf}\'])/usS';
self::$patternInternal = '/(^|[\p{Ps}\p{Zs}\p{Pd}\p{Pi}"])[' . $iInQuotes . '](.*?)[' . $fInQuotes . ']($|[\p{Pe}\p{Zs}\.,;:?!\p{Pd}\p{Pf}"])/usS';
}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:15,代码来源:WCTitle.php
示例11: setUp
protected function setUp()
{
parent::setUp();
$contLang = Language::factory('en');
$this->setMwGlobals(['wgShowDBErrorBacktrace' => true, 'wgCleanSignatures' => true]);
$this->setUserLang('en');
$this->setContentLang($contLang);
// FIXME: This test should pass without setting global content language
$this->options = ParserOptions::newFromUserAndLang(new User(), $contLang);
$this->options->setTemplateCallback([__CLASS__, 'statelessFetchTemplate']);
$this->parser = new Parser();
MagicWord::clearCache();
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:13,代码来源:ExtraParserTest.php
示例12: stripMagicWords
/**
* Remove relevant SMW magic words from the given text and return
* an array of the names of all discovered magic words. Moreover,
* store this array in the current parser output, using the variable
* mSMWMagicWords.
*/
public static function stripMagicWords(&$text, Parser $parser)
{
$words = array();
$mw = MagicWord::get('SMW_NOFACTBOX');
if ($mw->matchAndRemove($text)) {
$words[] = 'SMW_NOFACTBOX';
}
$mw = MagicWord::get('SMW_SHOWFACTBOX');
if ($mw->matchAndRemove($text)) {
$words[] = 'SMW_SHOWFACTBOX';
}
$output = $parser->getOutput();
$output->mSMWMagicWords = $words;
return $words;
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:21,代码来源:SMW_ParseData.php
示例13: setUp
function setUp()
{
global $wgMemc;
global $wgContLang;
global $wgShowDBErrorBacktrace;
global $wgLanguageCode;
global $wgAlwaysUseTidy;
$wgShowDBErrorBacktrace = true;
$wgLanguageCode = 'en';
$wgContLang = new Language('en');
$wgMemc = new EmptyBagOStuff();
$wgAlwaysUseTidy = false;
$this->options = new ParserOptions();
$this->options->setTemplateCallback(array(__CLASS__, 'statelessFetchTemplate'));
$this->parser = new Parser();
MagicWord::clearCache();
}
开发者ID:Jobava,项目名称:diacritice-meta-repo,代码行数:17,代码来源:ExtraParserTest.php
示例14: onArticleFromTitle
/**
* @param Title $title
* @param WikiPage $article
* @return bool
*/
public function onArticleFromTitle(Title &$title, &$article)
{
if ($title->exists() && $title->getNamespace() != NS_FILE && $title->getNamespace() != NS_CATEGORY) {
$key = $this->generateCacheKey($title->getArticleId());
$this->switches = $this->app->wg->memc->get($key);
if (empty($this->switches)) {
$article = F::build('Article', array($title));
$this->switches = array();
foreach ($this->magicWords as $wordID) {
$magicWord = MagicWord::get($wordID);
$this->switches[$wordID] = 0 < $magicWord->match($article->getRawText());
}
$this->app->wg->memc->set($key, $this->switches, self::CACHE_DURATION);
}
$this->process();
}
return true;
}
开发者ID:schwarer2006,项目名称:wikia,代码行数:23,代码来源:LandingPagesParser.class.php
示例15: makeRedirectContent
/**
* Returns a WikitextContent object representing a redirect to the given destination page.
*
* @param Title $destination The page to redirect to.
* @param string $text Text to include in the redirect, if possible.
*
* @return Content
*
* @see ContentHandler::makeRedirectContent
*/
public function makeRedirectContent(Title $destination, $text = '')
{
$optionalColon = '';
if ($destination->getNamespace() == NS_CATEGORY) {
$optionalColon = ':';
} else {
$iw = $destination->getInterwiki();
if ($iw && Language::fetchLanguageName($iw, null, 'mw')) {
$optionalColon = ':';
}
}
$mwRedir = MagicWord::get('redirect');
$redirectText = $mwRedir->getSynonym(0) . ' [[' . $optionalColon . $destination->getFullText() . ']]';
if ($text != '') {
$redirectText .= "\n" . $text;
}
return new WikitextContent($redirectText);
}
开发者ID:Tarendai,项目名称:spring-website,代码行数:28,代码来源:WikitextContentHandler.php
示例16: onArticleFromTitle
/**
* @param Title $title
* @param WikiPage $article
* @return bool
*/
public static function onArticleFromTitle(Title &$title, &$article)
{
global $wgLandingPagesAsContentMagicWords;
$app = F::app();
if ($title->exists() && $title->getNamespace() != NS_FILE && $title->getNamespace() != NS_CATEGORY) {
$key = self::generateCacheKey($title->getArticleId());
self::$switches = $app->wg->memc->get($key);
if (empty(self::$switches)) {
$article = new Article($title);
self::$switches = array();
$magicWords = array_keys($wgLandingPagesAsContentMagicWords);
foreach ($magicWords as $wordID) {
$magicWord = MagicWord::get($wordID);
self::$switches[$wordID] = 0 < $magicWord->match($article->getRawText());
}
$app->wg->memc->set($key, self::$switches, self::CACHE_DURATION);
}
self::process();
}
return true;
}
开发者ID:Tjorriemorrie,项目名称:app,代码行数:26,代码来源:LandingPagesParser.class.php
示例17: switchHook
function switchHook(&$parser)
{
$args = func_get_args();
array_shift($args);
$value = trim(array_shift($args));
$found = false;
$parts = null;
$default = null;
foreach ($args as $arg) {
$parts = array_map('trim', explode('=', $arg, 2));
if (count($parts) == 2) {
if ($found || $parts[0] == $value) {
return $parts[1];
} else {
$mwDefault =& MagicWord::get('default');
if ($mwDefault->matchStartAndRemove($parts[0])) {
$default = $parts[1];
}
# else wrong case, continue
}
} elseif (count($parts) == 1) {
# Multiple input, single output
# If the value matches, set a flag and continue
if ($parts[0] == $value) {
$found = true;
}
}
# else RAM corruption due to cosmic ray?
}
# Default case
# Check if the last item had no = sign, thus specifying the default case
if (count($parts) == 1) {
return $parts[0];
} elseif (!is_null($default)) {
return $default;
} else {
return '';
}
}
开发者ID:clrh,项目名称:mediawiki,代码行数:39,代码来源:ParserFunctions.php
示例18: getDoubleUnderscoreRegex
static function getDoubleUnderscoreRegex() {
if ( WOMMagicWordParser::$mwa === null ) {
WOMMagicWordParser::$mwa = MagicWord::getDoubleUnderscoreArray();
foreach ( WOMMagicWordParser::$mwa->names as $name ) {
$magic = MagicWord::get( $name );
$case = intval( $magic->isCaseSensitive() );
foreach ( $magic->getSynonyms() as $i => $syn ) {
$group = '(' . preg_quote( $syn, '/' ) . ')';
if ( WOMMagicWordParser::$underscores[$case] === '' ) {
WOMMagicWordParser::$underscores[$case] = $group;
} else {
WOMMagicWordParser::$underscores[$case] .= '|' . $group;
}
}
}
if ( WOMMagicWordParser::$underscores[0] !== '' ) {
WOMMagicWordParser::$underscores[0] = "/^(" . WOMMagicWordParser::$underscores[0] . ")/i";
}
if ( WOMMagicWordParser::$underscores[1] !== '' ) {
WOMMagicWordParser::$underscores[1] = "/^(" . WOMMagicWordParser::$underscores[1] . ")/";
}
}
return WOMMagicWordParser::$underscores;
}
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:24,代码来源:WOMMagicWordParser.php
示例19: efSharedHelpRemoveMagicWord
function efSharedHelpRemoveMagicWord(&$parser, &$text, &$strip_state)
{
$found = MagicWord::get('MAG_NOSHAREDHELP')->matchAndRemove($text);
if ($found) {
$text .= NOSHAREDHELP_MARKER;
}
return true;
}
开发者ID:schwarer2006,项目名称:wikia,代码行数:8,代码来源:SharedHelp.php
示例20: setFunctionHook
/**
* Create a function, e.g. {{sum:1|2|3}}
* The callback function should have the form:
* function myParserFunction( &$parser, $arg1, $arg2, $arg3 ) { ... }
*
* Or with SFH_OBJECT_ARGS:
* function myParserFunction( $parser, $frame, $args ) { ... }
*
* The callback may either return the text result of the function, or an array with the text
* in element 0, and a number of flags in the other elements. The names of the flags are
* specified in the keys. Valid flags are:
* found The text returned is valid, stop processing the template. This
* is on by default.
* nowiki Wiki markup in the return value should be escaped
* isHTML The returned text is HTML, armour it against wikitext transformation
*
* @param string $id The magic word ID
* @param mixed $callback The callback function (and object) to use
* @param int $flags A combination of the following flags:
* SFH_NO_HASH No leading hash, i.e. {{plural:...}} instead of {{#if:...}}
*
* SFH_OBJECT_ARGS Pass the template arguments as PPNode objects instead of text. This
* allows for conditional expansion of the parse tree, allowing you to eliminate dead
* branches and thus speed up parsing. It is also possible to analyse the parse tree of
* the arguments, and to control the way they are expanded.
*
* The $frame parameter is a PPFrame. This can be used to produce expanded text from the
* arguments, for instance:
* $text = isset( $args[0] ) ? $frame->expand( $args[0] ) : '';
*
* For technical reasons, $args[0] is pre-expanded and will be a string. This may change in
* future versions. Please call $frame->expand() on it anyway so that your code keeps
* working if/when this is changed.
*
* If you want whitespace to be trimmed from $args, you need to do it yourself, post-
* expansion.
*
* Please read the documentation in includes/parser/Preprocessor.php for more information
* about the methods available in PPFrame and PPNode.
*
* @throws MWException
* @return string|callback The old callback function for this name, if any
*/
public function setFunctionHook($id, $callback, $flags = 0)
{
global $wgContLang;
$oldVal = isset($this->mFunctionHooks[$id]) ? $this->mFunctionHooks[$id][0] : null;
$this->mFunctionHooks[$id] = array($callback, $flags);
# Add to function cache
$mw = MagicWord::get($id);
if (!$mw) {
throw new MWException(__METHOD__ . '() expecting a magic word identifier.');
}
$synonyms = $mw->getSynonyms();
$sensitive = intval($mw->isCaseSensitive());
foreach ($synonyms as $syn) {
# Case
if (!$sensitive) {
$syn = $wgContLang->lc($syn);
}
# Add leading hash
if (!($flags & SFH_NO_HASH)) {
$syn = '#' . $syn;
}
# Remove trailing colon
if (substr($syn, -1, 1) === ':') {
$syn = substr($syn, 0, -1);
}
$this->mFunctionSynonyms[$sensitive][$syn] = $id;
}
return $oldVal;
}
开发者ID:Tarendai,项目名称:spring-website,代码行数:72,代码来源:Parser.php
注:本文中的MagicWord类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论