本文整理汇总了PHP中MagicWord类的典型用法代码示例。如果您正苦于以下问题:PHP MagicWord类的具体用法?PHP MagicWord怎么用?PHP MagicWord使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MagicWord类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: MagicNoNumberedHeadingsParserBeforeInternalParse
function MagicNoNumberedHeadingsParserBeforeInternalParse($parser, $text, $stripState)
{
if (MagicWord::get('MAG_NONUMBEREDHEADINGS')->matchAndRemove($text)) {
$parser->mOptions->mNumberHeadings = FALSE;
}
return true;
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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());
}
示例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" );
}
示例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;
}
示例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;
}
示例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';
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}