当前位置: 首页>>代码示例>>PHP>>正文


PHP ParserOptions::newFromContext方法代码示例

本文整理汇总了PHP中ParserOptions::newFromContext方法的典型用法代码示例。如果您正苦于以下问题:PHP ParserOptions::newFromContext方法的具体用法?PHP ParserOptions::newFromContext怎么用?PHP ParserOptions::newFromContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ParserOptions的用法示例。


在下文中一共展示了ParserOptions::newFromContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getJsonFormatForArticle

 /**
  * @param \Article $article
  * @return JsonFormatNode
  */
 public function getJsonFormatForArticle(\Article $article)
 {
     $measurement = \Wikia\Measurements\Time::start([__CLASS__, __METHOD__]);
     $html = $article->getPage()->getParserOutput(\ParserOptions::newFromContext($this->requestContext))->getText();
     $measurement->stop();
     return $this->htmlParser->parse($html);
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:11,代码来源:JsonFormatService.php

示例2: index

 public function index()
 {
     $title = Title::newFromText('Version', NS_SPECIAL);
     $popts = ParserOptions::newFromContext(RequestContext::getMain());
     $this->wg->Title = $title;
     $this->specialPage->setHeaders();
     $softwareListPrepped = array();
     foreach ($this->version->getSoftwareList() as $key => $val) {
         $softwareListPrepped[$this->wg->Parser->parse($key, $title, $popts)->getText()] = $this->wg->Parser->parse($val, $title, $popts)->getText();
     }
     $this->setVal('copyRightAndAuthorList', $this->wg->Parser->parse($this->version->getCopyrightAndAuthorList(), $title, $popts)->getText());
     $this->setVal('softwareInformation', $this->wg->Parser->parse($this->version->softwareInformation(), $title, $popts)->getText());
     $this->setVal('extensionCredit', $this->wg->Parser->parse($this->version->getExtensionCredits(), $title, $popts)->getText());
     $this->setVal('ip', str_replace('--', ' - ', htmlspecialchars($this->getContext()->getRequest()->getIP())));
     $this->setVal('wikiaCodeMessage', wfMessage('wikia-version-code')->escaped());
     $this->setVal('wikiaCodeVersion', $this->version->getWikiaCodeVersion());
     $this->setVal('wikiaConfigMessage', wfMessage('wikia-version-config')->escaped());
     $this->setVal('wikiaConfigVersion', $this->version->getWikiaConfigVersion());
     $this->setVal('versionLicenseMessage', wfMessage('version-license')->escaped());
     $this->setVal('versionLicenseInfoMessage', wfMessage('version-license-info')->parse());
     $this->setVal('versionSoftwareMessage', wfMessage('version-software')->escaped());
     $this->setVal('versionSoftwareProductMessage', wfMessage('version-software-product')->escaped());
     $this->setVal('versionSoftwareVersionMessage', wfMessage('version-software-version')->escaped());
     $this->setVal('versionSoftwareList', $softwareListPrepped);
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:25,代码来源:WikiaSpecialVersionController.class.php

示例3: execute

 public function execute()
 {
     // Cache may vary on $wgUser because ParserOptions gets data from it
     $this->getMain()->setCacheMode('anon-public-user-private');
     // Get parameters
     $params = $this->extractRequestParams();
     // Create title for parser
     $title_obj = Title::newFromText($params['title']);
     if (!$title_obj) {
         $this->dieUsageMsg(array('invalidtitle', $params['title']));
     }
     $result = $this->getResult();
     // Parse text
     global $wgParser;
     $options = ParserOptions::newFromContext($this->getContext());
     if ($params['includecomments']) {
         $options->setRemoveComments(false);
     }
     if ($params['generatexml']) {
         $wgParser->startExternalParse($title_obj, $options, OT_PREPROCESS);
         $dom = $wgParser->preprocessToDom($params['text']);
         if (is_callable(array($dom, 'saveXML'))) {
             $xml = $dom->saveXML();
         } else {
             $xml = $dom->__toString();
         }
         $xml_result = array();
         $result->setContent($xml_result, $xml);
         $result->addValue(null, 'parsetree', $xml_result);
     }
     $retval = $wgParser->preprocess($params['text'], $title_obj, $options);
     // Return result
     $retval_array = array();
     $result->setContent($retval_array, $retval);
     $result->addValue(null, $this->getModuleName(), $retval_array);
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:36,代码来源:ApiExpandTemplates.php

示例4: parserOptions

 /**
  * Get/set the ParserOptions object to use for wikitext parsing
  *
  * @param ParserOptions|null $options Either the ParserOption to use or null to only get the
  *   current ParserOption object
  * @return ParserOptions
  */
 public function parserOptions($options = null)
 {
     if ($options !== null && !empty($options->isBogus)) {
         // Someone is trying to set a bogus pre-$wgUser PO. Check if it has
         // been changed somehow, and keep it if so.
         $anonPO = ParserOptions::newFromAnon();
         $anonPO->setEditSection(false);
         if (!$options->matches($anonPO)) {
             wfLogWarning(__METHOD__ . ': Setting a changed bogus ParserOptions: ' . wfGetAllCallers(5));
             $options->isBogus = false;
         }
     }
     if (!$this->mParserOptions) {
         if (!$this->getContext()->getUser()->isSafeToLoad()) {
             // $wgUser isn't unstubbable yet, so don't try to get a
             // ParserOptions for it. And don't cache this ParserOptions
             // either.
             $po = ParserOptions::newFromAnon();
             $po->setEditSection(false);
             $po->isBogus = true;
             if ($options !== null) {
                 $this->mParserOptions = empty($options->isBogus) ? $options : null;
             }
             return $po;
         }
         $this->mParserOptions = ParserOptions::newFromContext($this->getContext());
         $this->mParserOptions->setEditSection(false);
     }
     if ($options !== null && !empty($options->isBogus)) {
         // They're trying to restore the bogus pre-$wgUser PO. Do the right
         // thing.
         return wfSetVar($this->mParserOptions, null, true);
     } else {
         return wfSetVar($this->mParserOptions, $options);
     }
 }
开发者ID:OrBin,项目名称:mediawiki,代码行数:43,代码来源:OutputPage.php

示例5: testParserTest

 /**
  * @group medium
  * @dataProvider parserTestProvider
  * @param string $desc
  * @param string $input
  * @param string $result
  * @param array $opts
  * @param array $config
  */
 public function testParserTest($desc, $input, $result, $opts, $config)
 {
     if ($this->regex != '' && !preg_match('/' . $this->regex . '/', $desc)) {
         $this->assertTrue(true);
         // XXX: don't flood output with "test made no assertions"
         // $this->markTestSkipped( 'Filtered out by the user' );
         return;
     }
     if (!$this->isWikitextNS(NS_MAIN)) {
         // parser tests frequently assume that the main namespace contains wikitext.
         // @todo When setting up pages, force the content model. Only skip if
         //        $wgtContentModelUseDB is false.
         $this->markTestSkipped("Main namespace does not support wikitext," . "skipping parser test: {$desc}");
     }
     wfDebug("Running parser test: {$desc}\n");
     $opts = $this->parseOptions($opts);
     $context = $this->setupGlobals($opts, $config);
     $user = $context->getUser();
     $options = ParserOptions::newFromContext($context);
     if (isset($opts['title'])) {
         $titleText = $opts['title'];
     } else {
         $titleText = 'Parser test';
     }
     $local = isset($opts['local']);
     $preprocessor = isset($opts['preprocessor']) ? $opts['preprocessor'] : null;
     $parser = $this->getParser($preprocessor);
     $title = Title::newFromText($titleText);
     # Parser test requiring math. Make sure texvc is executable
     # or just skip such tests.
     if (isset($opts['math']) || isset($opts['texvc'])) {
         global $wgTexvc;
         if (!isset($wgTexvc)) {
             $this->markTestSkipped("SKIPPED: \$wgTexvc is not set");
         } elseif (!is_executable($wgTexvc)) {
             $this->markTestSkipped("SKIPPED: texvc binary does not exist" . " or is not executable.\n" . "Current configuration is:\n\$wgTexvc = '{$wgTexvc}'");
         }
     }
     if (isset($opts['djvu'])) {
         if (!$this->djVuSupport->isEnabled()) {
             $this->markTestSkipped("SKIPPED: djvu binaries do not exist or are not executable.\n");
         }
     }
     if (isset($opts['tidy'])) {
         if (!$this->tidySupport->isEnabled()) {
             $this->markTestSkipped("SKIPPED: tidy extension is not installed.\n");
         } else {
             $options->setTidy(true);
         }
     }
     if (isset($opts['pst'])) {
         $out = $parser->preSaveTransform($input, $title, $user, $options);
     } elseif (isset($opts['msg'])) {
         $out = $parser->transformMsg($input, $options, $title);
     } elseif (isset($opts['section'])) {
         $section = $opts['section'];
         $out = $parser->getSection($input, $section);
     } elseif (isset($opts['replace'])) {
         $section = $opts['replace'][0];
         $replace = $opts['replace'][1];
         $out = $parser->replaceSection($input, $section, $replace);
     } elseif (isset($opts['comment'])) {
         $out = Linker::formatComment($input, $title, $local);
     } elseif (isset($opts['preload'])) {
         $out = $parser->getPreloadText($input, $title, $options);
     } else {
         $output = $parser->parse($input, $title, $options, true, true, 1337);
         $output->setTOCEnabled(!isset($opts['notoc']));
         $out = $output->getText();
         if (isset($opts['tidy'])) {
             $out = preg_replace('/\\s+$/', '', $out);
         }
         if (isset($opts['showtitle'])) {
             if ($output->getTitleText()) {
                 $title = $output->getTitleText();
             }
             $out = "{$title}\n{$out}";
         }
         if (isset($opts['showindicators'])) {
             $indicators = '';
             foreach ($output->getIndicators() as $id => $content) {
                 $indicators .= "{$id}={$content}\n";
             }
             $out = $indicators . $out;
         }
         if (isset($opts['ill'])) {
             $out = implode(' ', $output->getLanguageLinks());
         } elseif (isset($opts['cat'])) {
             $outputPage = $context->getOutput();
             $outputPage->addCategoryLinks($output->getCategories());
             $cats = $outputPage->getCategoryLinks();
//.........这里部分代码省略.........
开发者ID:huatuoorg,项目名称:mediawiki,代码行数:101,代码来源:NewParserTest.php

示例6: parseValue

 /**
  * Wrapper around OutputPage::parseInline
  *
  * @param $value String Wikitext to parse
  * @param $lang Language
  *
  * @since 1.3
  *
  * @return String parsed wikitext
  */
 private function parseValue($value, Language $lang)
 {
     global $wgParser;
     wfProfileIn(__METHOD__);
     $parserOptions = ParserOptions::newFromContext($this->context);
     $parserOptions->setEditSection(false);
     $parserOptions->setInterfaceMessage(true);
     $parserOptions->setUserLang($lang);
     $parserOptions->setTargetLanguage($lang);
     $output = $wgParser->parse($value, $this->getTitle(), $parserOptions);
     $parsed = $output->getText();
     // Strip out the surrounding <p> tags
     $m = array();
     if (preg_match('/^<p>(.*)\\n?<\\/p>\\n?/sU', $parsed, $m)) {
         $parsed = $m[1];
     }
     $this->updateTemplates($output);
     wfProfileOut(__METHOD__);
     return $parsed;
 }
开发者ID:DanielDobre,项目名称:fossology,代码行数:30,代码来源:UploadWizardCampaign.php

示例7: execute

 public function execute()
 {
     // The data is hot but user-dependent, like page views, so we set vary cookies
     $this->getMain()->setCacheMode('anon-public-user-private');
     // Get parameters
     $params = $this->extractRequestParams();
     $text = $params['text'];
     $title = $params['title'];
     $page = $params['page'];
     $pageid = $params['pageid'];
     $oldid = $params['oldid'];
     if (!is_null($page) && (!is_null($text) || $title != 'API')) {
         $this->dieUsage('The page parameter cannot be used together with the text and title parameters', 'params');
     }
     $prop = array_flip($params['prop']);
     if (isset($params['section'])) {
         $this->section = $params['section'];
     } else {
         $this->section = false;
     }
     // The parser needs $wgTitle to be set, apparently the
     // $title parameter in Parser::parse isn't enough *sigh*
     // TODO: Does this still need $wgTitle?
     global $wgParser, $wgTitle, $wgLang;
     // Currently unnecessary, code to act as a safeguard against any change in current behaviour of uselang breaks
     $oldLang = null;
     if (isset($params['uselang']) && $params['uselang'] != $wgLang->getCode()) {
         $oldLang = $wgLang;
         // Backup wgLang
         $wgLang = Language::factory($params['uselang']);
     }
     $popts = ParserOptions::newFromContext($this->getContext());
     $popts->setTidy(true);
     $popts->enableLimitReport(!$params['disablepp']);
     $redirValues = null;
     // Return result
     $result = $this->getResult();
     if (!is_null($oldid) || !is_null($pageid) || !is_null($page)) {
         if (!is_null($oldid)) {
             // Don't use the parser cache
             $rev = Revision::newFromID($oldid);
             if (!$rev) {
                 $this->dieUsage("There is no revision ID {$oldid}", 'missingrev');
             }
             if (!$rev->userCan(Revision::DELETED_TEXT, $this->getUser())) {
                 $this->dieUsage("You don't have permission to view deleted revisions", 'permissiondenied');
             }
             $titleObj = $rev->getTitle();
             $wgTitle = $titleObj;
             // If for some reason the "oldid" is actually the current revision, it may be cached
             if ($titleObj->getLatestRevID() === intval($oldid)) {
                 // May get from/save to parser cache
                 $p_result = $this->getParsedSectionOrText($titleObj, $popts, $pageid, isset($prop['wikitext']));
             } else {
                 // This is an old revision, so get the text differently
                 $this->text = $rev->getText(Revision::FOR_THIS_USER, $this->getUser());
                 if ($this->section !== false) {
                     $this->text = $this->getSectionText($this->text, 'r' . $rev->getId());
                 }
                 // Should we save old revision parses to the parser cache?
                 $p_result = $wgParser->parse($this->text, $titleObj, $popts);
             }
         } else {
             // Not $oldid, but $pageid or $page
             if ($params['redirects']) {
                 $reqParams = array('action' => 'query', 'redirects' => '');
                 if (!is_null($pageid)) {
                     $reqParams['pageids'] = $pageid;
                 } else {
                     // $page
                     $reqParams['titles'] = $page;
                 }
                 $req = new FauxRequest($reqParams);
                 $main = new ApiMain($req);
                 $main->execute();
                 $data = $main->getResultData();
                 $redirValues = isset($data['query']['redirects']) ? $data['query']['redirects'] : array();
                 $to = $page;
                 foreach ((array) $redirValues as $r) {
                     $to = $r['to'];
                 }
                 $titleObj = Title::newFromText($to);
             } else {
                 if (!is_null($pageid)) {
                     $reqParams['pageids'] = $pageid;
                     $titleObj = Title::newFromID($pageid);
                 } else {
                     // $page
                     $to = $page;
                     $titleObj = Title::newFromText($to);
                 }
             }
             if (!is_null($pageid)) {
                 if (!$titleObj) {
                     // Still throw nosuchpageid error if pageid was provided
                     $this->dieUsageMsg(array('nosuchpageid', $pageid));
                 }
             } elseif (!$titleObj || !$titleObj->exists()) {
                 $this->dieUsage("The page you specified doesn't exist", 'missingtitle');
             }
//.........这里部分代码省略.........
开发者ID:laiello,项目名称:media-wiki-law,代码行数:101,代码来源:ApiParse.php

示例8: makeParserOptions

 /**
  * Get parser options suitable for rendering the primary article wikitext
  *
  * @param IContextSource|User|string $context One of the following:
  *        - IContextSource: Use the User and the Language of the provided
  *          context
  *        - User: Use the provided User object and $wgLang for the language,
  *          so use an IContextSource object if possible.
  *        - 'canonical': Canonical options (anonymous user with default
  *          preferences and content language).
  * @return ParserOptions
  */
 public function makeParserOptions($context)
 {
     global $wgContLang;
     if ($context instanceof IContextSource) {
         $options = ParserOptions::newFromContext($context);
     } elseif ($context instanceof User) {
         // settings per user (even anons)
         $options = ParserOptions::newFromUser($context);
     } else {
         // canonical settings
         $options = ParserOptions::newFromUserAndLang(new User(), $wgContLang);
     }
     if ($this->getTitle()->isConversionTable()) {
         $options->disableContentConversion();
     }
     $options->enableLimitReport();
     // show inclusion/loop reports
     $options->setTidy(true);
     // fix bad HTML
     return $options;
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:33,代码来源:WikiPage.php

示例9: execute

 public function execute()
 {
     // Cache may vary on $wgUser because ParserOptions gets data from it
     $this->getMain()->setCacheMode('anon-public-user-private');
     // Get parameters
     $params = $this->extractRequestParams();
     $this->requireMaxOneParameter($params, 'prop', 'generatexml');
     if ($params['prop'] === null) {
         $this->logFeatureUsage('action=expandtemplates&!prop');
         $this->setWarning('Because no values have been specified for the prop parameter, a ' . 'legacy format has been used for the output. This format is deprecated, and in ' . 'the future, a default value will be set for the prop parameter, causing the new' . 'format to always be used.');
         $prop = array();
     } else {
         $prop = array_flip($params['prop']);
     }
     // Get title and revision ID for parser
     $revid = $params['revid'];
     if ($revid !== null) {
         $rev = Revision::newFromId($revid);
         if (!$rev) {
             $this->dieUsage("There is no revision ID {$revid}", 'missingrev');
         }
         $title_obj = $rev->getTitle();
     } else {
         $title_obj = Title::newFromText($params['title']);
         if (!$title_obj || $title_obj->isExternal()) {
             $this->dieUsageMsg(array('invalidtitle', $params['title']));
         }
     }
     $result = $this->getResult();
     // Parse text
     global $wgParser;
     $options = ParserOptions::newFromContext($this->getContext());
     if ($params['includecomments']) {
         $options->setRemoveComments(false);
     }
     $retval = array();
     if (isset($prop['parsetree']) || $params['generatexml']) {
         $wgParser->startExternalParse($title_obj, $options, Parser::OT_PREPROCESS);
         $dom = $wgParser->preprocessToDom($params['text']);
         if (is_callable(array($dom, 'saveXML'))) {
             $xml = $dom->saveXML();
         } else {
             $xml = $dom->__toString();
         }
         if (isset($prop['parsetree'])) {
             unset($prop['parsetree']);
             $retval['parsetree'] = $xml;
         } else {
             // the old way
             $result->addValue(null, 'parsetree', $xml);
             $result->addValue(null, ApiResult::META_BC_SUBELEMENTS, array('parsetree'));
         }
     }
     // if they didn't want any output except (probably) the parse tree,
     // then don't bother actually fully expanding it
     if ($prop || $params['prop'] === null) {
         $wgParser->startExternalParse($title_obj, $options, Parser::OT_PREPROCESS);
         $frame = $wgParser->getPreprocessor()->newFrame();
         $wikitext = $wgParser->preprocess($params['text'], $title_obj, $options, $revid, $frame);
         if ($params['prop'] === null) {
             // the old way
             ApiResult::setContentValue($retval, 'wikitext', $wikitext);
         } else {
             $p_output = $wgParser->getOutput();
             if (isset($prop['categories'])) {
                 $categories = $p_output->getCategories();
                 if ($categories) {
                     $categories_result = array();
                     foreach ($categories as $category => $sortkey) {
                         $entry = array();
                         $entry['sortkey'] = $sortkey;
                         ApiResult::setContentValue($entry, 'category', $category);
                         $categories_result[] = $entry;
                     }
                     ApiResult::setIndexedTagName($categories_result, 'category');
                     $retval['categories'] = $categories_result;
                 }
             }
             if (isset($prop['properties'])) {
                 $properties = $p_output->getProperties();
                 if ($properties) {
                     ApiResult::setArrayType($properties, 'BCkvp', 'name');
                     ApiResult::setIndexedTagName($properties, 'property');
                     $retval['properties'] = $properties;
                 }
             }
             if (isset($prop['volatile'])) {
                 $retval['volatile'] = $frame->isVolatile();
             }
             if (isset($prop['ttl']) && $frame->getTTL() !== null) {
                 $retval['ttl'] = $frame->getTTL();
             }
             if (isset($prop['wikitext'])) {
                 $retval['wikitext'] = $wikitext;
             }
             if (isset($prop['modules'])) {
                 $retval['modules'] = array_values(array_unique($p_output->getModules()));
                 $retval['modulescripts'] = array_values(array_unique($p_output->getModuleScripts()));
                 $retval['modulestyles'] = array_values(array_unique($p_output->getModuleStyles()));
             }
//.........这里部分代码省略.........
开发者ID:huatuoorg,项目名称:mediawiki,代码行数:101,代码来源:ApiExpandTemplates.php

示例10: extractRowInfo

 private function extractRowInfo($row)
 {
     $revision = new Revision($row);
     $title = $revision->getTitle();
     $vals = array();
     if ($this->fld_ids) {
         $vals['revid'] = intval($revision->getId());
         // $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
         if (!is_null($revision->getParentId())) {
             $vals['parentid'] = intval($revision->getParentId());
         }
     }
     if ($this->fld_flags && $revision->isMinor()) {
         $vals['minor'] = '';
     }
     if ($this->fld_user || $this->fld_userid) {
         if ($revision->isDeleted(Revision::DELETED_USER)) {
             $vals['userhidden'] = '';
         } else {
             if ($this->fld_user) {
                 $vals['user'] = $revision->getUserText();
             }
             $userid = $revision->getUser();
             if (!$userid) {
                 $vals['anon'] = '';
             }
             if ($this->fld_userid) {
                 $vals['userid'] = $userid;
             }
         }
     }
     if ($this->fld_timestamp) {
         $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $revision->getTimestamp());
     }
     if ($this->fld_size) {
         if (!is_null($revision->getSize())) {
             $vals['size'] = intval($revision->getSize());
         } else {
             $vals['size'] = 0;
         }
     }
     if ($this->fld_sha1) {
         if ($revision->getSha1() != '') {
             $vals['sha1'] = wfBaseConvert($revision->getSha1(), 36, 16, 40);
         } else {
             $vals['sha1'] = '';
         }
     }
     if ($this->fld_comment || $this->fld_parsedcomment) {
         if ($revision->isDeleted(Revision::DELETED_COMMENT)) {
             $vals['commenthidden'] = '';
         } else {
             $comment = $revision->getComment();
             if ($this->fld_comment) {
                 $vals['comment'] = $comment;
             }
             if ($this->fld_parsedcomment) {
                 $vals['parsedcomment'] = Linker::formatComment($comment, $title);
             }
         }
     }
     if ($this->fld_tags) {
         if ($row->ts_tags) {
             $tags = explode(',', $row->ts_tags);
             $this->getResult()->setIndexedTagName($tags, 'tag');
             $vals['tags'] = $tags;
         } else {
             $vals['tags'] = array();
         }
     }
     if (!is_null($this->token)) {
         $tokenFunctions = $this->getTokenFunctions();
         foreach ($this->token as $t) {
             $val = call_user_func($tokenFunctions[$t], $title->getArticleID(), $title, $revision);
             if ($val === false) {
                 $this->setWarning("Action '{$t}' is not allowed for the current user");
             } else {
                 $vals[$t . 'token'] = $val;
             }
         }
     }
     $text = null;
     global $wgParser;
     if ($this->fld_content || !is_null($this->difftotext)) {
         $text = $revision->getText();
         // Expand templates after getting section content because
         // template-added sections don't count and Parser::preprocess()
         // will have less input
         if ($this->section !== false) {
             $text = $wgParser->getSection($text, $this->section, false);
             if ($text === false) {
                 $this->dieUsage("There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection');
             }
         }
     }
     if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
         if ($this->generateXML) {
             $wgParser->startExternalParse($title, ParserOptions::newFromContext($this->getContext()), OT_PREPROCESS);
             $dom = $wgParser->preprocessToDom($text);
             if (is_callable(array($dom, 'saveXML'))) {
//.........这里部分代码省略.........
开发者ID:seedbank,项目名称:old-repo,代码行数:101,代码来源:ApiQueryRevisions.php

示例11: getRawText

 /**
  * Get the text that should be returned, or false if the page or revision
  * was not found.
  *
  * @return String|Bool
  */
 public function getRawText()
 {
     global $wgParser;
     # No longer used
     if ($this->mGen) {
         return '';
     }
     $text = false;
     $title = $this->getTitle();
     $request = $this->getRequest();
     // If it's a MediaWiki message we can just hit the message cache
     if ($request->getBool('usemsgcache') && $title->getNamespace() == NS_MEDIAWIKI) {
         // The first "true" is to use the database, the second is to use the content langue
         // and the last one is to specify the message key already contains the language in it ("/de", etc.)
         $text = MessageCache::singleton()->get($title->getDBkey(), true, true, true);
         // If the message doesn't exist, return a blank
         if ($text === false) {
             $text = '';
         }
     } else {
         // Get it from the DB
         $rev = Revision::newFromTitle($title, $this->getOldId());
         if ($rev) {
             $lastmod = wfTimestamp(TS_RFC2822, $rev->getTimestamp());
             $request->response()->header("Last-modified: {$lastmod}");
             // Public-only due to cache headers
             $content = $rev->getContent();
             if ($content === null) {
                 // revision not found (or suppressed)
                 $text = false;
             } elseif (!$content instanceof TextContent) {
                 // non-text content
                 wfHttpError(415, "Unsupported Media Type", "The requested page uses the content model `" . $content->getModel() . "` which is not supported via this interface.");
                 die;
             } else {
                 // want a section?
                 $section = $request->getIntOrNull('section');
                 if ($section !== null) {
                     $content = $content->getSection($section);
                 }
                 if ($content === null || $content === false) {
                     // section not found (or section not supported, e.g. for JS and CSS)
                     $text = false;
                 } else {
                     $text = $content->getNativeData();
                 }
             }
         }
     }
     if ($text !== false && $text !== '' && $request->getVal('templates') === 'expand') {
         $text = $wgParser->preprocess($text, $title, ParserOptions::newFromContext($this->getContext()));
     }
     return $text;
 }
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:60,代码来源:RawAction.php

示例12: runTest

 /**
  * Run a given wikitext input through a freshly-constructed wiki parser,
  * and compare the output against the expected results.
  * Prints status and explanatory messages to stdout.
  *
  * staticSetup() and setupWikiData() must be called before this function
  * is entered.
  *
  * @param array $test The test parameters:
  *  - test: The test name
  *  - desc: The subtest description
  *  - input: Wikitext to try rendering
  *  - options: Array of test options
  *  - config: Overrides for global variables, one per line
  *
  * @return ParserTestResult or false if skipped
  */
 public function runTest($test)
 {
     wfDebug(__METHOD__ . ": running {$test['desc']}");
     $opts = $this->parseOptions($test['options']);
     $teardownGuard = $this->perTestSetup($test);
     $context = RequestContext::getMain();
     $user = $context->getUser();
     $options = ParserOptions::newFromContext($context);
     if (isset($opts['tidy'])) {
         if (!$this->tidySupport->isEnabled()) {
             $this->recorder->skipped($test, 'tidy extension is not installed');
             return false;
         } else {
             $options->setTidy(true);
         }
     }
     if (isset($opts['title'])) {
         $titleText = $opts['title'];
     } else {
         $titleText = 'Parser test';
     }
     $local = isset($opts['local']);
     $preprocessor = isset($opts['preprocessor']) ? $opts['preprocessor'] : null;
     $parser = $this->getParser($preprocessor);
     $title = Title::newFromText($titleText);
     if (isset($opts['pst'])) {
         $out = $parser->preSaveTransform($test['input'], $title, $user, $options);
     } elseif (isset($opts['msg'])) {
         $out = $parser->transformMsg($test['input'], $options, $title);
     } elseif (isset($opts['section'])) {
         $section = $opts['section'];
         $out = $parser->getSection($test['input'], $section);
     } elseif (isset($opts['replace'])) {
         $section = $opts['replace'][0];
         $replace = $opts['replace'][1];
         $out = $parser->replaceSection($test['input'], $section, $replace);
     } elseif (isset($opts['comment'])) {
         $out = Linker::formatComment($test['input'], $title, $local);
     } elseif (isset($opts['preload'])) {
         $out = $parser->getPreloadText($test['input'], $title, $options);
     } else {
         $output = $parser->parse($test['input'], $title, $options, true, true, 1337);
         $output->setTOCEnabled(!isset($opts['notoc']));
         $out = $output->getText();
         if (isset($opts['tidy'])) {
             $out = preg_replace('/\\s+$/', '', $out);
         }
         if (isset($opts['showtitle'])) {
             if ($output->getTitleText()) {
                 $title = $output->getTitleText();
             }
             $out = "{$title}\n{$out}";
         }
         if (isset($opts['showindicators'])) {
             $indicators = '';
             foreach ($output->getIndicators() as $id => $content) {
                 $indicators .= "{$id}={$content}\n";
             }
             $out = $indicators . $out;
         }
         if (isset($opts['ill'])) {
             $out = implode(' ', $output->getLanguageLinks());
         } elseif (isset($opts['cat'])) {
             $out = '';
             foreach ($output->getCategories() as $name => $sortkey) {
                 if ($out !== '') {
                     $out .= "\n";
                 }
                 $out .= "cat={$name} sort={$sortkey}";
             }
         }
     }
     ScopedCallback::consume($teardownGuard);
     $expected = $test['result'];
     if (count($this->normalizationFunctions)) {
         $expected = ParserTestResultNormalizer::normalize($test['expected'], $this->normalizationFunctions);
         $out = ParserTestResultNormalizer::normalize($out, $this->normalizationFunctions);
     }
     $testResult = new ParserTestResult($test, $expected, $out);
     return $testResult;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:98,代码来源:ParserTestRunner.php

示例13: getRawText

 /**
  * Get the text that should be returned, or false if the page or revision
  * was not found.
  *
  * @return String|Bool
  */
 public function getRawText()
 {
     global $wgParser;
     # No longer used
     if ($this->mGen) {
         return '';
     }
     $text = false;
     $title = $this->getTitle();
     $request = $this->getRequest();
     // If it's a MediaWiki message we can just hit the message cache
     if ($request->getBool('usemsgcache') && $title->getNamespace() == NS_MEDIAWIKI) {
         $key = $title->getDBkey();
         $msg = wfMessage($key)->inContentLanguage();
         # If the message doesn't exist, return a blank
         $text = !$msg->exists() ? '' : $msg->plain();
     } else {
         // Get it from the DB
         $rev = Revision::newFromTitle($title, $this->getOldId());
         if ($rev) {
             $lastmod = wfTimestamp(TS_RFC2822, $rev->getTimestamp());
             $request->response()->header("Last-modified: {$lastmod}");
             // Public-only due to cache headers
             $text = $rev->getText();
             $section = $request->getIntOrNull('section');
             if ($section !== null) {
                 $text = $wgParser->getSection($text, $section);
             }
         }
     }
     if ($text !== false && $text !== '' && $request->getVal('templates') === 'expand') {
         $text = $wgParser->preprocess($text, $title, ParserOptions::newFromContext($this->getContext()));
     }
     return $text;
 }
开发者ID:laiello,项目名称:media-wiki-law,代码行数:41,代码来源:RawAction.php

示例14: profilePreferences

 /**
  * @param $user User
  * @param $context IContextSource
  * @param $defaultPreferences
  * @return void
  */
 static function profilePreferences($user, IContextSource $context, &$defaultPreferences)
 {
     global $wgAuth, $wgContLang, $wgParser, $wgCookieExpiration, $wgLanguageCode, $wgDisableTitleConversion, $wgDisableLangConversion, $wgMaxSigChars, $wgEnableEmail, $wgEmailConfirmToEdit, $wgEnableUserEmail, $wgEmailAuthentication, $wgEnotifWatchlist, $wgEnotifUserTalk, $wgEnotifRevealEditorAddress;
     ## User info #####################################
     // Information panel
     $defaultPreferences['username'] = array('type' => 'info', 'label-message' => 'username', 'default' => $user->getName(), 'section' => 'personal/info');
     $defaultPreferences['userid'] = array('type' => 'info', 'label-message' => 'uid', 'default' => $user->getId(), 'section' => 'personal/info');
     # Get groups to which the user belongs
     $userEffectiveGroups = $user->getEffectiveGroups();
     $userGroups = $userMembers = array();
     foreach ($userEffectiveGroups as $ueg) {
         if ($ueg == '*') {
             // Skip the default * group, seems useless here
             continue;
         }
         $groupName = User::getGroupName($ueg);
         $userGroups[] = User::makeGroupLinkHTML($ueg, $groupName);
         $memberName = User::getGroupMember($ueg, $user->getName());
         $userMembers[] = User::makeGroupLinkHTML($ueg, $memberName);
     }
     asort($userGroups);
     asort($userMembers);
     $lang = $context->getLanguage();
     $defaultPreferences['usergroups'] = array('type' => 'info', 'label' => $context->msg('prefs-memberingroups')->numParams(count($userGroups))->parse(), 'default' => $context->msg('prefs-memberingroups-type', $lang->commaList($userGroups), $lang->commaList($userMembers))->plain(), 'raw' => true, 'section' => 'personal/info');
     $defaultPreferences['editcount'] = array('type' => 'info', 'label-message' => 'prefs-edits', 'default' => $lang->formatNum($user->getEditCount()), 'section' => 'personal/info');
     if ($user->getRegistration()) {
         $displayUser = $context->getUser();
         $userRegistration = $user->getRegistration();
         $defaultPreferences['registrationdate'] = array('type' => 'info', 'label-message' => 'prefs-registration', 'default' => $context->msg('prefs-registration-date-time', $lang->userTimeAndDate($userRegistration, $displayUser), $lang->userDate($userRegistration, $displayUser), $lang->userTime($userRegistration, $displayUser))->parse(), 'section' => 'personal/info');
     }
     // Actually changeable stuff
     $defaultPreferences['realname'] = array('type' => $wgAuth->allowPropChange('realname') ? 'text' : 'info', 'default' => $user->getRealName(), 'section' => 'personal/info', 'label-message' => 'yourrealname', 'help-message' => 'prefs-help-realname');
     $defaultPreferences['gender'] = array('type' => 'select', 'section' => 'personal/info', 'options' => array($context->msg('gender-male')->text() => 'male', $context->msg('gender-female')->text() => 'female', $context->msg('gender-unknown')->text() => 'unknown'), 'label-message' => 'yourgender', 'help-message' => 'prefs-help-gender');
     if ($wgAuth->allowPasswordChange()) {
         $link = Linker::link(SpecialPage::getTitleFor('ChangePassword'), $context->msg('prefs-resetpass')->escaped(), array(), array('returnto' => SpecialPage::getTitleFor('Preferences')));
         $defaultPreferences['password'] = array('type' => 'info', 'raw' => true, 'default' => $link, 'label-message' => 'yourpassword', 'section' => 'personal/info');
     }
     if ($wgCookieExpiration > 0) {
         $defaultPreferences['rememberpassword'] = array('type' => 'toggle', 'label' => $context->msg('tog-rememberpassword')->numParams(ceil($wgCookieExpiration / (3600 * 24)))->text(), 'section' => 'personal/info');
     }
     // Language
     $languages = Language::getLanguageNames(false);
     if (!array_key_exists($wgLanguageCode, $languages)) {
         $languages[$wgLanguageCode] = $wgLanguageCode;
     }
     ksort($languages);
     $options = array();
     foreach ($languages as $code => $name) {
         $display = wfBCP47($code) . ' - ' . $name;
         $options[$display] = $code;
     }
     $defaultPreferences['language'] = array('type' => 'select', 'section' => 'personal/i18n', 'options' => $options, 'label-message' => 'yourlanguage');
     /* see if there are multiple language variants to choose from*/
     $variantArray = array();
     if (!$wgDisableLangConversion) {
         $variants = $wgContLang->getVariants();
         foreach ($variants as $v) {
             $v = str_replace('_', '-', strtolower($v));
             $variantArray[$v] = $wgContLang->getVariantname($v, false);
         }
         $options = array();
         foreach ($variantArray as $code => $name) {
             $display = wfBCP47($code) . ' - ' . $name;
             $options[$display] = $code;
         }
         if (count($variantArray) > 1) {
             $defaultPreferences['variant'] = array('label-message' => 'yourvariant', 'type' => 'select', 'options' => $options, 'section' => 'personal/i18n', 'help-message' => 'prefs-help-variant');
         }
     }
     if (count($variantArray) > 1 && !$wgDisableLangConversion && !$wgDisableTitleConversion) {
         $defaultPreferences['noconvertlink'] = array('type' => 'toggle', 'section' => 'personal/i18n', 'label-message' => 'tog-noconvertlink');
     }
     // show a preview of the old signature first
     $oldsigWikiText = $wgParser->preSaveTransform("~~~", $context->getTitle(), $user, ParserOptions::newFromContext($context));
     $oldsigHTML = $context->getOutput()->parseInline($oldsigWikiText, true, true);
     $defaultPreferences['oldsig'] = array('type' => 'info', 'raw' => true, 'label-message' => 'tog-oldsig', 'default' => $oldsigHTML, 'section' => 'personal/signature');
     $defaultPreferences['nickname'] = array('type' => $wgAuth->allowPropChange('nickname') ? 'text' : 'info', 'maxlength' => $wgMaxSigChars, 'label-message' => 'yournick', 'validation-callback' => array('Preferences', 'validateSignature'), 'section' => 'personal/signature', 'filter-callback' => array('Preferences', 'cleanSignature'));
     $defaultPreferences['fancysig'] = array('type' => 'toggle', 'label-message' => 'tog-fancysig', 'help-message' => 'prefs-help-signature', 'section' => 'personal/signature');
     ## Email stuff
     if ($wgEnableEmail) {
         $helpMessages[] = $wgEmailConfirmToEdit ? 'prefs-help-email-required' : 'prefs-help-email';
         if ($wgEnableUserEmail) {
             // additional messages when users can send email to each other
             $helpMessages[] = 'prefs-help-email-others';
         }
         $link = Linker::link(SpecialPage::getTitleFor('ChangeEmail'), $context->msg($user->getEmail() ? 'prefs-changeemail' : 'prefs-setemail')->escaped(), array(), array('returnto' => SpecialPage::getTitleFor('Preferences')));
         $emailAddress = $user->getEmail() ? htmlspecialchars($user->getEmail()) : '';
         if ($wgAuth->allowPropChange('emailaddress')) {
             $emailAddress .= $emailAddress == '' ? $link : " ({$link})";
         }
         $defaultPreferences['emailaddress'] = array('type' => 'info', 'raw' => true, 'default' => $emailAddress, 'label-message' => 'youremail', 'section' => 'personal/email', 'help-messages' => $helpMessages);
         $disableEmailPrefs = false;
         if ($wgEmailAuthentication) {
             if ($user->getEmail()) {
//.........这里部分代码省略.........
开发者ID:laiello,项目名称:media-wiki-law,代码行数:101,代码来源:Preferences.php

示例15: parseText

 public function parseText($rawText)
 {
     global $wgEnableParserCache;
     $this->mRawtext = self::removeMetadataTag($rawText);
     $wgEnableParserCache = false;
     $parser = ParserPool::get();
     $parser->ac_metadata = [];
     // VOLDEV-68: Remove broken section edit links
     $opts = ParserOptions::newFromContext(RequestContext::getMain());
     $opts->setEditSection(false);
     $head = $parser->parse($rawText, $this->mTitle, $opts);
     $this->mText = wfFixMalformedHTML($head->getText());
     $this->mHeadItems = $head->getHeadItems();
     if (isset($parser->ac_metadata)) {
         $this->mMetadata = $parser->ac_metadata;
     } else {
         $this->mMetadata = [];
     }
     ParserPool::release($parser);
     return $this->mText;
 }
开发者ID:Tjorriemorrie,项目名称:app,代码行数:21,代码来源:ArticleComment.class.php


注:本文中的ParserOptions::newFromContext方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。