本文整理汇总了PHP中ParserOptions::newFromUser方法的典型用法代码示例。如果您正苦于以下问题:PHP ParserOptions::newFromUser方法的具体用法?PHP ParserOptions::newFromUser怎么用?PHP ParserOptions::newFromUser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParserOptions
的用法示例。
在下文中一共展示了ParserOptions::newFromUser方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLongNumericLinesDontKillTheParser
/**
* @see Bug 8689
* @covers Parser::parse
*/
public function testLongNumericLinesDontKillTheParser()
{
$longLine = '1.' . str_repeat('1234567890', 100000) . "\n";
$title = Title::newFromText('Unit test');
$options = ParserOptions::newFromUser(new User());
$this->assertEquals("<p>{$longLine}</p>", $this->parser->parse($longLine, $title, $options)->getText());
}
示例2: getMessagesFormatted
function getMessagesFormatted($severity = self::MESSAGE_WARNING, $header = null)
{
global $wgTitle, $wgUser;
$ret = '';
foreach ($this->mMessages as $message) {
if ($message[1] <= $severity) {
$ret .= '* ' . $message[0] . "\n";
}
}
if ($ret != '') {
if (!$this->mParser) {
$parser = new Parser();
}
if ($header == null) {
$header = '';
} elseif ($header != '') {
$header = Html::rawElement('div', array('class' => 'heading'), $header);
}
$ret = Html::rawElement('div', array('class' => 'messages'), $header . "\n" . $ret);
$ret = $parser->parse($ret, $wgTitle, ParserOptions::newFromUser($wgUser));
} else {
$ret = null;
}
return $ret;
}
示例3: initialise
function initialise(&$memCached, $useDB, $expiry, $memcPrefix)
{
$fname = 'MessageCache::initialise';
wfProfileIn($fname);
$this->mUseCache = !is_null($memCached);
$this->mMemc =& $memCached;
$this->mDisable = !$useDB;
$this->mExpiry = $expiry;
$this->mDisableTransform = false;
$this->mMemcKey = $memcPrefix . ':messages';
$this->mKeys = false;
# initialised on demand
$this->mInitialised = true;
wfProfileIn($fname . '-parseropt');
$this->mParserOptions = ParserOptions::newFromUser($u = NULL);
wfProfileOut($fname . '-parseropt');
wfProfileIn($fname . '-parser');
$this->mParser = new Parser();
wfProfileOut($fname . '-parser');
# When we first get asked for a message,
# then we'll fill up the cache. If we
# can return a cache hit, this saves
# some extra milliseconds
$this->mDeferred = true;
wfProfileOut($fname);
}
示例4: genParserOptions
function genParserOptions()
{
global $wgUser;
$this->mParserOptions = ParserOptions::newFromUser($wgUser);
$this->mParserOptions->setDateFormat(MW_DATE_DEFAULT);
$this->mParserOptions->setEditSection(false);
}
示例5: sandboxParse
function sandboxParse($wikiText){
global $wgUser;
$myParser = new Parser();
$myParserOptions = ParserOptions::newFromUser( $wgUser );
$result = $myParser->parse($wikiText, $this->getTitle(), $myParserOptions);
return $result->getText();
}
示例6: renderFlags
/**
* Parses the wrapped wikitext and returns an HTML block of code with rendered flags.
* @param array $templateCalls
* @param $pageId
* @return ParserOutput
*/
public function renderFlags(array $templateCalls, $pageId)
{
global $wgUser;
$wikitext = $this->wrapAllFlags($templateCalls);
$title = \Title::newFromID($pageId);
return \ParserPool::parse($wikitext, $title, \ParserOptions::newFromUser($wgUser));
}
示例7: checkOptions
public function checkOptions()
{
if ($this->hasOption('save-failed')) {
$this->saveFailed = $this->getOption('save-failed');
}
$this->stripParametersEnabled = $this->hasOption('strip-parameters');
$this->showParsedOutput = $this->hasOption('show-parsed-output');
$this->showDiff = $this->hasOption('show-diff');
if ($this->showDiff) {
$bin = $this->getOption('diff-bin', getenv('DIFF'));
if ($bin != '') {
global $wgDiff;
$wgDiff = $bin;
}
}
$user = new User();
$this->options = ParserOptions::newFromUser($user);
if ($this->hasOption('tidy')) {
global $wgUseTidy;
if (!$wgUseTidy) {
$this->error('Tidy was requested but $wgUseTidy is not set in LocalSettings.php', true);
}
$this->options->setTidy(true);
}
$this->failed = 0;
}
示例8: testBug8689
function testBug8689()
{
global $wgUser;
$longLine = '1.' . str_repeat('1234567890', 100000) . "\n";
$t = Title::newFromText('Unit test');
$options = ParserOptions::newFromUser($wgUser);
$this->assertEquals("<p>{$longLine}</p>", $this->parser->parse($longLine, $t, $options)->getText());
}
示例9: getRevIncludes
/**
* Get template and image versions from parsing a revision
* @param Page $article
* @param Revision $rev
* @param User $user
* @param string $regen use 'regen' to force regeneration
* @return array( templateIds, fileSHA1Keys )
* templateIds like ParserOutput->mTemplateIds
* fileSHA1Keys like ParserOutput->mImageTimeKeys
*/
public static function getRevIncludes(Page $article, Revision $rev, User $user, $regen = '')
{
global $wgParser, $wgMemc;
wfProfileIn(__METHOD__);
$versions = false;
$key = self::getCacheKey($article->getTitle(), $rev->getId());
if ($regen !== 'regen') {
// check cache
$versions = FlaggedRevs::getMemcValue($wgMemc->get($key), $article, 'allowStale');
}
if (!is_array($versions)) {
// cache miss
$pOut = false;
if ($rev->isCurrent()) {
$parserCache = ParserCache::singleton();
# Try current version parser cache (as anon)...
$pOut = $parserCache->get($article, $article->makeParserOptions($user));
if ($pOut == false && $rev->getUser()) {
// try the user who saved the change
$author = User::newFromId($rev->getUser());
$pOut = $parserCache->get($article, $article->makeParserOptions($author));
}
}
// ParserOutput::mImageTimeKeys wasn't always there
if ($pOut == false || !FlaggedRevs::parserOutputIsVersioned($pOut)) {
$title = $article->getTitle();
$pOpts = ParserOptions::newFromUser($user);
// Note: tidy off
$pOut = $wgParser->parse($rev->getText(), $title, $pOpts, true, true, $rev->getId());
}
# Get the template/file versions used...
$versions = array($pOut->getTemplateIds(), $pOut->getFileSearchOptions());
# Save to cache (check cache expiry for dynamic elements)...
$data = FlaggedRevs::makeMemcObj($versions);
$wgMemc->set($key, $data, $pOut->getCacheExpiry());
} else {
$tVersions =& $versions[0];
// templates
# Do a link batch query for page_latest...
$lb = new LinkBatch();
foreach ($tVersions as $ns => $tmps) {
foreach ($tmps as $dbKey => $revIdDraft) {
$lb->add($ns, $dbKey);
}
}
$lb->execute();
# Update array with the current page_latest values.
# This kludge is there since $newTemplates (thus $revIdDraft) is cached.
foreach ($tVersions as $ns => &$tmps) {
foreach ($tmps as $dbKey => &$revIdDraft) {
$title = Title::makeTitle($ns, $dbKey);
$revIdDraft = (int) $title->getLatestRevID();
}
}
}
wfProfileOut(__METHOD__);
return $versions;
}
示例10: getRevIncludes
/**
* Get template and image versions from parsing a revision
* @param Page $article
* @param Revision $rev
* @param User $user
* @param string $regen use 'regen' to force regeneration
* @return array( templateIds, fileSHA1Keys )
* templateIds like ParserOutput->mTemplateIds
* fileSHA1Keys like ParserOutput->mImageTimeKeys
*/
public static function getRevIncludes(Page $article, Revision $rev, User $user, $regen = '')
{
global $wgMemc;
wfProfileIn(__METHOD__);
$key = self::getCacheKey($article->getTitle(), $rev->getId());
if ($regen === 'regen') {
$versions = false;
// skip cache
} elseif ($rev->isCurrent()) {
// Check cache entry against page_touched
$versions = FlaggedRevs::getMemcValue($wgMemc->get($key), $article);
} else {
// Old revs won't always be invalidated with template/file changes.
// Also, we don't care if page_touched changed due to a direct edit.
$versions = FlaggedRevs::getMemcValue($wgMemc->get($key), $article, 'allowStale');
if (is_array($versions)) {
// entry exists
// Sanity check that the cache is reasonably up to date
list($templates, $files) = $versions;
if (self::templatesStale($templates) || self::filesStale($files)) {
$versions = false;
// no good
}
}
}
if (!is_array($versions)) {
// cache miss
$pOut = false;
if ($rev->isCurrent()) {
$parserCache = ParserCache::singleton();
# Try current version parser cache for this user...
$pOut = $parserCache->get($article, $article->makeParserOptions($user));
if ($pOut == false) {
# Try current version parser cache for the revision author...
$optsUser = $rev->getUser() ? User::newFromId($rev->getUser()) : 'canonical';
$pOut = $parserCache->get($article, $article->makeParserOptions($optsUser));
}
}
// ParserOutput::mImageTimeKeys wasn't always there
if ($pOut == false || !FlaggedRevs::parserOutputIsVersioned($pOut)) {
$content = $rev->getContent(Revision::RAW);
if (!$content) {
// Just for extra sanity
$pOut = new ParserOutput();
} else {
$pOut = $content->getParserOutput($article->getTitle(), $rev->getId(), ParserOptions::newFromUser($user));
}
}
# Get the template/file versions used...
$versions = array($pOut->getTemplateIds(), $pOut->getFileSearchOptions());
# Save to cache (check cache expiry for dynamic elements)...
$data = FlaggedRevs::makeMemcObj($versions);
$wgMemc->set($key, $data, $pOut->getCacheExpiry());
}
wfProfileOut(__METHOD__);
return $versions;
}
示例11: parseText
function parseText($text)
{
#still need to make it actually parse the input.
global $wgOut, $wgUser, $wgTitle, $wgParser, $wgAllowDiffPreview, $wgEnableDiffPreviewPreference;
$parserOptions = ParserOptions::newFromUser($wgUser);
$parserOptions->setEditSection(false);
$output = $wgParser->parse($text, $wgTitle, $parserOptions);
$wgOut->setArticleBodyOnly(true);
$wgOut->addHTML($output->mText);
}
示例12: getPages
function getPages($query)
{
global $wgTitle, $wgParser, $wgUser;
$fname = 'NukeDPLForm::getNewPages';
$query = trim($query) . "\nmode=userformat\nlistseparators=,\\n\$\$\$%PAGE%\$\$\$,,\n";
$opt = ParserOptions::newFromUser($wgUser);
$out = $wgParser->parse("<dpl>{$query}</dpl>", $wgTitle, $opt, false, true);
preg_match_all('|\\${3}(.+?)\\${3}|m', $out->getText(), $matches);
return str_replace(array(' ', '&'), array(' ', '&'), $matches[1]);
}
示例13: testPreSaveTransform
/**
* @dataProvider providePreSaveTransform
* @covers Parser::preSaveTransform
*/
public function testPreSaveTransform($text, $expected)
{
global $wgParser;
$title = Title::newFromText(str_replace('::', '__', __METHOD__));
$user = new User();
$user->setName("127.0.0.1");
$popts = ParserOptions::newFromUser($user);
$text = $wgParser->preSaveTransform($text, $title, $user, $popts);
$this->assertEquals($expected, $text);
}
示例14: execute
function execute($params)
{
global $wgRequest, $wgOut, $wgTitle, $wgUser;
global $wgContLang, $wgProxyKey, $wgParser;
$article = $wgRequest->getText('article', $params);
$map = $wgRequest->getText('map', $params);
$wgOut->disable();
header("Cache-Control: no-cache, must-revalidate");
header("Content-type: application/vnd.google-earth.kml+xml");
header('Content-Disposition: attachment; filename="' . $article . '.kml"');
$title = Title::newFromText($article);
/* Wikia change begin - @author: Sebastian Marzjan */
/* fogbugz BugID #18043 */
if ($title instanceof Title) {
/* Wikia change end */
$revision = Revision::newFromTitle($title);
/* Wikia change begin - @author: Sebastian Marzjan */
/* fogbugz BugID #18043 */
if (!$revision instanceof Revision) {
$errorMessage = 'SpecialGoogleMapsKML.php ' . __LINE__ . ' - no revision for ' . $article . ' / ' . $title->getArticleID();
Wikia::log(__METHOD__, false, $errorMessage);
echo "No article revisions found by the name of {$article}";
return false;
}
/* Wikia change end */
$mapOptions = GoogleMaps::getMapSettings($title, array('icons' => 'http://maps.google.com/mapfiles/kml/pal4/{label}.png', 'icon' => 'icon57'));
$exporter = new GoogleMapsKmlExporter($wgContLang, str_replace('{label}', $mapOptions['icon'], $mapOptions['icons']));
$wgParser->mOptions = ParserOptions::newFromUser($wgUser);
$wgParser->mOptions->setEditSection(false);
$wgParser->mTitle = $wgTitle;
$wgParser->clearState();
$localParser = new Parser();
$localParser->mTitle = $title;
$localParser->mOptions = $wgParser->mOptions;
if (preg_match_all("/<googlemap( .*?|)>(.*?)<\\/googlemap>/s", $revision->getText(), $matches)) {
$exporter->addFileHeader();
for ($i = 0; $i < count($matches[2]); $i++) {
$attrs = Sanitizer::decodeTagAttributes($matches[1][$i]);
$mapOptions['version'] = isset($attrs['version']) ? $attrs['version'] : "0";
$exporter->addHeader(isset($attrs['title']) ? $attrs['title'] : "Map #" . ($i + 1));
GoogleMaps::renderContent($matches[2][$i], $wgParser, $localParser, $exporter, $mapOptions);
$exporter->addTrailer();
}
$exporter->addFileTrailer();
echo $exporter->render();
} else {
echo "No maps in {$article}!";
}
} else {
echo "No article found by the name of {$article}";
}
}
示例15: getPages
function getPages($query)
{
global $wgParser;
$user = $this->getUser();
$title = $this->getTitle();
$query = trim($query) . PHP_EOL . "format=,\$\$\$%PAGE%\$\$\$,,";
//Enclose each title with $$$
$parserOptions = ParserOptions::newFromUser($user);
$parserOutput = $wgParser->parse('<dpl>' . $query . '</dpl>', $title, $parserOptions, false, true);
preg_match_all('|\\$\\$\\$(.+)\\$\\$\\$|U', $parserOutput->getText(), $matches);
//Extract the titles from the output
return $matches[1];
//Return an array of titles
}