本文整理汇总了PHP中ParserOptions::setTidy方法的典型用法代码示例。如果您正苦于以下问题:PHP ParserOptions::setTidy方法的具体用法?PHP ParserOptions::setTidy怎么用?PHP ParserOptions::setTidy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParserOptions
的用法示例。
在下文中一共展示了ParserOptions::setTidy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
function execute($subpage)
{
global $wgRequest, $wgParser, $wgOut;
$this->setHeaders();
$this->isNewParser = is_callable(array($wgParser, 'preprocessToDom'));
$titleStr = $wgRequest->getText('contexttitle');
$title = Title::newFromText($titleStr);
$selfTitle = $this->getTitle();
if (!$title) {
$title = $selfTitle;
}
$input = $wgRequest->getText('input');
$this->generateXML = $this->isNewParser ? $wgRequest->getBool('generate_xml') : false;
if (strlen($input)) {
$this->removeComments = $wgRequest->getBool('removecomments', false);
$this->removeNowiki = $wgRequest->getBool('removenowiki', false);
$options = new ParserOptions();
$options->setRemoveComments($this->removeComments);
$options->setTidy(true);
$options->setMaxIncludeSize(self::MAX_INCLUDE_SIZE);
if ($this->generateXML) {
$wgParser->startExternalParse($title, $options, OT_PREPROCESS);
$dom = $wgParser->preprocessToDom($input);
if (is_callable(array($dom, 'saveXML'))) {
$xml = $dom->saveXML();
} else {
$xml = $dom->__toString();
}
}
$output = $wgParser->preprocess($input, $title, $options);
} else {
$this->removeComments = $wgRequest->getBool('removecomments', true);
$this->removeNowiki = $wgRequest->getBool('removenowiki', false);
$output = false;
}
$wgOut->addWikiText(wfMsg('expand_templates_intro'));
$wgOut->addHTML($this->makeForm($titleStr, $input));
if ($output !== false) {
global $wgUseTidy, $wgAlwaysUseTidy;
if ($this->generateXML) {
$wgOut->addHTML($this->makeOutput($xml, 'expand_templates_xml_output'));
}
$tmp = $this->makeOutput($output);
if ($this->removeNowiki) {
$tmp = preg_replace(array('_<nowiki>_', '_</nowiki>_', '_<nowiki */>_'), '', $tmp);
}
if ($wgUseTidy && $options->getTidy() || $wgAlwaysUseTidy) {
$tmp = MWTidy::tidy($tmp);
}
$wgOut->addHTML($tmp);
$this->showHtmlPreview($title, $output, $wgOut);
}
}
示例2: sandboxParse
function sandboxParse($wikiText)
{
global $wgTitle, $wgParser, $wgVersion;
// temporarily replace the global parser
$old_wgParser = $wgParser;
$wgParser = new Parser();
$myParserOptions = new ParserOptions();
// Setup extension functions for new parser. This allows things like ParserFunctions to work 1.11.1 or greater
// THIS DOES NOT WORK IN 1.7.1 AT ALL!!!!
if (version_compare($wgVersion, "1.11.1", '>=')) {
/**
* Wikia change - begin (@author: macbre)
* Commented out due to BugId:6864
foreach ( $wgExtensionFunctions as $func )
{
$profName = __METHOD__.'-extensions-'.strval( $func );
wfProfileIn( $profName );
call_user_func( $func );
wfProfileOut( $profName );
};
* Wikia change - end
*/
$myParserOptions->setRemoveComments(true);
}
// use some sensible defaults
$myParserOptions->setTidy(true);
// do the parsing
wfRunHooks('custom_SandboxParse', array(&$wikiText));
$wgTitle = empty($wgTitle) ? new Title() : $wgTitle;
$result = $wgParser->parse($wikiText, $wgTitle, $myParserOptions);
/* @var $result ParserOutput */
$result = $result->getText();
// restore the global parser
$wgParser = $old_wgParser;
// give the result
return $result;
}
示例3: 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'];
$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']);
$revid = false;
// The parser needs $wgTitle to be set, apparently the
// $title parameter in Parser::parse isn't enough *sigh*
global $wgParser, $wgUser, $wgTitle, $wgEnableParserCache;
$popts = new ParserOptions();
$popts->setTidy(true);
$popts->enableLimitReport();
$redirValues = null;
if (!is_null($oldid) || !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->dieUsage("You don't have permission to view deleted revisions", 'permissiondenied');
}
$text = $rev->getText(Revision::FOR_THIS_USER);
$titleObj = $rev->getTitle();
$wgTitle = $titleObj;
$p_result = $wgParser->parse($text, $titleObj, $popts);
} else {
if ($params['redirects']) {
$req = new FauxRequest(array('action' => 'query', 'redirects' => '', 'titles' => $page));
$main = new ApiMain($req);
$main->execute();
$data = $main->getResultData();
$redirValues = @$data['query']['redirects'];
$to = $page;
foreach ((array) $redirValues as $r) {
$to = $r['to'];
}
} else {
$to = $page;
}
$titleObj = Title::newFromText($to);
if (!$titleObj) {
$this->dieUsage("The page you specified doesn't exist", 'missingtitle');
}
$articleObj = new Article($titleObj);
if (isset($prop['revid'])) {
$oldid = $articleObj->getRevIdFetched();
}
// Try the parser cache first
$p_result = false;
$pcache = ParserCache::singleton();
if ($wgEnableParserCache) {
$p_result = $pcache->get($articleObj, $wgUser);
}
if (!$p_result) {
$p_result = $wgParser->parse($articleObj->getContent(), $titleObj, $popts);
if ($wgEnableParserCache) {
$pcache->save($p_result, $articleObj, $popts);
}
}
}
} else {
$titleObj = Title::newFromText($title);
if (!$titleObj) {
$titleObj = Title::newFromText("API");
}
$wgTitle = $titleObj;
if ($params['pst'] || $params['onlypst']) {
$text = $wgParser->preSaveTransform($text, $titleObj, $wgUser, $popts);
}
if ($params['onlypst']) {
// Build a result and bail out
$result_array['text'] = array();
$this->getResult()->setContent($result_array['text'], $text);
$this->getResult()->addValue(null, $this->getModuleName(), $result_array);
return;
}
$p_result = $wgParser->parse($text, $titleObj, $popts);
}
// Return result
$result = $this->getResult();
$result_array = array();
if ($params['redirects'] && !is_null($redirValues)) {
$result_array['redirects'] = $redirValues;
}
if (isset($prop['text'])) {
$result_array['text'] = array();
$result->setContent($result_array['text'], $p_result->getText());
}
if (!is_null($params['summary'])) {
//.........这里部分代码省略.........
示例4: parseNonEditWikitext
/**
* It's like Article::prepareTextForEdit, but not for editing (old wikitext usually)
*
*
* @param string $wikitext
* @param WikiPage $article
*
* @return object
*/
function parseNonEditWikitext($wikitext, $article)
{
static $cache = array();
$cacheKey = md5($wikitext) . ':' . $article->getTitle()->getPrefixedText();
if (isset($cache[$cacheKey])) {
return $cache[$cacheKey];
}
global $wgParser;
$edit = (object) array();
$options = new ParserOptions();
$options->setTidy(true);
$edit->output = $wgParser->parse($wikitext, $article->getTitle(), $options);
$cache[$cacheKey] = $edit;
return $edit;
}
示例5: parser
/**
* Convert from/to wikitext/html using Parser.
*
* This only supports wikitext to HTML.
*
* @param string $from Format of content to convert: wikitext
* @param string $to Format to convert to: html
* @param string $content
* @param Title $title
* @return string
* @throws WikitextException When the conversion is unsupported
*/
protected static function parser($from, $to, $content, Title $title)
{
if ($from !== 'wikitext' && $to !== 'html') {
throw new WikitextException("Conversion from '{$from}' to '{$to}' was requested, but core's Parser only supports 'wikitext' to 'html' conversion", 'process-wikitext');
}
global $wgParser;
$options = new \ParserOptions();
$options->setTidy(true);
$options->setEditSection(false);
$output = $wgParser->parse($content, $title, $options);
return $output->getText();
}
示例6: getParserOptions
/**
* Get parser options suitable for rendering the primary article wikitext
* @param $canonical boolean Determines that the generated options must not depend on user preferences (see bug 14404)
* @return mixed ParserOptions object or boolean false
*/
public function getParserOptions($canonical = false)
{
global $wgUser, $wgLanguageCode;
if (!$this->mParserOptions || $canonical) {
$user = !$canonical ? $wgUser : new User();
$parserOptions = new ParserOptions($user);
$parserOptions->setTidy(true);
$parserOptions->enableLimitReport();
if ($canonical) {
$parserOptions->setUserLang($wgLanguageCode);
# Must be set explicitely
return $parserOptions;
}
$this->mParserOptions = $parserOptions;
}
// Clone to allow modifications of the return value without affecting cache
return clone $this->mParserOptions;
}
示例7: editUpdates
/**
* Do standard deferred updates after page edit.
* Update links tables, site stats, search index and message cache.
* Every 1000th edit, prune the recent changes table.
*
* @private
* @param $text New text of the article
* @param $summary Edit summary
* @param $minoredit Minor edit
* @param $timestamp_of_pagechange Timestamp associated with the page change
* @param $newid rev_id value of the new revision
* @param $changed Whether or not the content actually changed
*/
function editUpdates($text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true)
{
global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser;
wfProfileIn(__METHOD__);
# Parse the text
$options = new ParserOptions();
$options->setTidy(true);
$poutput = $wgParser->parse($text, $this->mTitle, $options, true, true, $newid);
# Save it to the parser cache
$parserCache =& ParserCache::singleton();
$parserCache->save($poutput, $this, $wgUser);
# Update the links tables
$u = new LinksUpdate($this->mTitle, $poutput);
$u->doUpdate();
if (wfRunHooks('ArticleEditUpdatesDeleteFromRecentchanges', array(&$this))) {
wfSeedRandom();
if (0 == mt_rand(0, 999)) {
# Periodically flush old entries from the recentchanges table.
global $wgRCMaxAge;
$dbw =& wfGetDB(DB_MASTER);
$cutoff = $dbw->timestamp(time() - $wgRCMaxAge);
$recentchanges = $dbw->tableName('recentchanges');
$sql = "DELETE FROM {$recentchanges} WHERE rc_timestamp < '{$cutoff}'";
$dbw->query($sql);
}
}
$id = $this->getID();
$title = $this->mTitle->getPrefixedDBkey();
$shortTitle = $this->mTitle->getDBkey();
if (0 == $id) {
wfProfileOut(__METHOD__);
return;
}
$u = new SiteStatsUpdate(0, 1, $this->mGoodAdjustment, $this->mTotalAdjustment);
array_push($wgDeferredUpdateList, $u);
$u = new SearchUpdate($id, $title, $text);
array_push($wgDeferredUpdateList, $u);
# If this is another user's talk page, update newtalk
# Don't do this if $changed = false otherwise some idiot can null-edit a
# load of user talk pages and piss people off, nor if it's a minor edit
# by a properly-flagged bot.
if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getTitleKey() && $changed && !($minoredit && $wgUser->isAllowed('nominornewtalk'))) {
if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this))) {
$other = User::newFromName($shortTitle);
if (is_null($other) && User::isIP($shortTitle)) {
// An anonymous user
$other = new User();
$other->setName($shortTitle);
}
if ($other) {
$other->setNewtalk(true);
}
}
}
if ($this->mTitle->getNamespace() == NS_MEDIAWIKI) {
$wgMessageCache->replace($shortTitle, $text);
}
wfProfileOut(__METHOD__);
}
示例8: getMentionedUsersFromWikitext
/**
* Examines a wikitext string and finds users that were mentioned
* @param string $wikitext
* @return array Array of User objects
*/
protected function getMentionedUsersFromWikitext($wikitext)
{
global $wgParser;
$title = Title::newMainPage();
// Bogus title used for parser
$options = new \ParserOptions();
$options->setTidy(true);
$options->setEditSection(false);
$output = $wgParser->parse($wikitext, $title, $options);
$links = $output->getLinks();
if (!isset($links[NS_USER]) || !is_array($links[NS_USER])) {
// Nothing
return array();
}
$users = array();
foreach ($links[NS_USER] as $dbk => $page_id) {
$user = User::newFromName($dbk);
if (!$user || $user->isAnon()) {
continue;
}
$users[$user->getId()] = $user;
// If more than 20 users are being notified this is probably a spam/attack vector.
// Don't send any mention notifications
if (count($users) > 20) {
return array();
}
}
return $users;
}
示例9: strtolower
function parse_format_text(&$text, &$mvdTile, &$mvd_page = '', $absolute_links = false)
{
global $wgOut, $mvgScriptPath;
global $wgParser, $wgUser, $wgTitle, $wgContLang;
$template_key = '';
if (is_object($mvdTile)) {
$template_key = strtolower($mvdTile->getMvdTypeKey());
}
// $wgOut->addHTML('looking at: ' . strtolower($template_key));
$sk =& $wgUser->getSkin();
$pre_text_html = $post_text_html = '';
$added_play_link = false;
$smw_text_html = '';
switch ($template_key) {
case 'ht_en':
case 'anno_en':
$play_link_o = '<a href="javascript:mv_do_play(' . htmlspecialchars($mvd_page->id) . ')">';
$play_link_img_close = '<img border="0" src="' . htmlspecialchars($mvgScriptPath) . '/skins/images/button_play.png">' . '</a>';
$smw_attr = $this->get_and_strip_semantic_tags($text);
foreach ($smw_attr as $smw_key => $smw_attr_val) {
// do special display for given values:
switch ($smw_key) {
case 'speech_by':
case 'spoken_by':
$pTitle = Title::newFromText($smw_attr_val);
if ($pTitle->exists()) {
$pimg = mv_get_person_img($smw_attr_val);
$pre_text_html .= '<p class="mvd_page_image">';
if ($mvd_page != '') {
$pre_text_html .= $play_link_o;
$added_play_link = true;
}
$pre_text_html .= '<img width="44" alt="' . $pTitle->getText() . '" ' . 'src="' . htmlspecialchars($pimg->getURL()) . '">';
if ($mvd_page != '') {
$pre_text_html .= $play_link_img_close;
}
$pre_text_html .= '</p>';
}
break;
}
// @@todo we should just use semantic mediaWikis info box with some custom style .
$smwKeyTitle = Title::newFromText($smw_key);
$valueTitle = Title::newFromText($smw_attr_val);
if ($template_key == 'anno_en') {
$smw_text_html .= ucwords($smwKeyTitle->getText()) . ': ' . $sk->makeLinkObj($valueTitle) . '<br />';
}
}
if (!$added_play_link && $mvd_page != '') {
$pre_text_html .= '<p class="mvd_page_image">' . $play_link_o . $play_link_img_close . '</p>';
// print "SHOULD HAVE PUT IN pre_text:$pre_text_html";
}
$pre_text_html .= '<p class="text">';
if ($mvd_page != '') {
$pre_text_html .= '<span class="mvd_menu_header">' . $this->get_mvd_menu($mvd_page) . '</span>';
}
// if absolute links clear out links:
if ($absolute_links) {
$pre_text_html = '';
}
$pre_text_html .= '<span class="description">';
$pre_text_html .= $smw_text_html;
// for ht_en add spoken by add name to start of text:
if ($template_key == 'ht_en') {
// if we have the person title add them to start of the text output:
if (isset($pTitle)) {
// have to prepend it cuz of <p> insertion for first paragraph
$text = '[[' . $pTitle->getText() . ']]: ' . trim($text);
}
}
$post_text_html .= '</span></p>';
break;
default:
break;
}
// now add the text with categories if present:
$sk =& $wgUser->getSkin();
// run via parser to add in Category info:
// $parserOptions = ParserOptions::newFromUser( $wgUser );
$parserOptions = new ParserOptions();
$parserOptions->setEditSection(false);
$parserOptions->setTidy(true);
$parserOutput = $wgParser->parse($text, $mvdTile, $parserOptions, true, true);
$wgOut->addCategoryLinks($parserOutput->getCategories());
$parserOutput->mText .= $sk->getCategories();
$parserOutput->mText = $pre_text_html . $parserOutput->mText . $post_text_html;
// empty out the categories (should work)
$wgOut->mCategoryLinks = array();
$parserOutput->mCategories = null;
return $parserOutput;
}
示例10: parsePage
/**
*/
private function parsePage(&$text, &$title, &$article)
{
global $wgParser;
global $wgUser;
# Parse the text
$options = new ParserOptions();
$options->setTidy(true);
$poutput = $wgParser->parse($text, $title, $options);
return $poutput;
}
示例11: 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*
global $wgParser, $wgUser, $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 = new ParserOptions();
$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->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)) {
$articleObj = new Article($titleObj, 0);
$p_result = $this->getParsedSectionOrText($articleObj, $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);
$wgTitle = $titleObj;
if ($this->section !== false) {
$this->text = $this->getSectionText($this->text, 'r' . $rev->getId());
}
$p_result = $wgParser->parse($this->text, $titleObj, $popts);
}
} else {
// Not $oldid
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');
}
$wgTitle = $titleObj;
//.........这里部分代码省略.........
示例12: execute
public function execute()
{
// Get parameters
$params = $this->extractRequestParams();
$text = $params['text'];
$title = $params['title'];
$page = $params['page'];
$prop = array_flip($params['prop']);
global $wgParser, $wgUser;
if (!is_null($page)) {
$titleObj = Title::newFromText($page);
if (!$titleObj) {
$this->dieUsageMsg(array('missingtitle', $page));
}
// Try the parser cache first
$articleObj = new Article($titleObj);
$pcache =& ParserCache::singleton();
$p_result = $pcache->get($articleObj, $wgUser);
if (!$p_result) {
$popts = new ParserOptions();
$popts->setTidy(true);
$p_result = $wgParser->parse($articleObj->getContent(), $titleObj, $popts);
$popts->setTidy(false);
global $wgUseParserCache;
if ($wgUseParserCache) {
$pcache->save($p_result, $articleObj, $wgUser);
}
}
} else {
$titleObj = Title::newFromText($title);
if (!$titleObj) {
$titleObj = Title::newFromText("API");
}
$p_result = $wgParser->parse($text, $titleObj, new ParserOptions());
}
// Return result
$result = $this->getResult();
$result_array = array();
if (isset($prop['text'])) {
$result_array['text'] = array();
$result->setContent($result_array['text'], $p_result->getText());
}
if (isset($prop['langlinks'])) {
$result_array['langlinks'] = $this->formatLangLinks($p_result->getLanguageLinks());
}
if (isset($prop['categories'])) {
$result_array['categories'] = $this->formatCategoryLinks($p_result->getCategories());
}
if (isset($prop['links'])) {
$result_array['links'] = $this->formatLinks($p_result->getLinks());
}
if (isset($prop['templates'])) {
$result_array['templates'] = $this->formatLinks($p_result->getTemplates());
}
if (isset($prop['images'])) {
$result_array['images'] = array_keys($p_result->getImages());
}
if (isset($prop['externallinks'])) {
$result_array['externallinks'] = array_keys($p_result->getExternalLinks());
}
if (isset($prop['sections'])) {
$result_array['sections'] = $p_result->getSections();
}
$result_mapping = array('langlinks' => 'll', 'categories' => 'cl', 'links' => 'pl', 'templates' => 'tl', 'images' => 'img', 'externallinks' => 'el', 'sections' => 's');
$this->setIndexedTagNames($result_array, $result_mapping);
$result->addValue(null, $this->getModuleName(), $result_array);
}
示例13: prepareTextForEdit
/**
* Prepare text which is about to be saved.
* Returns a stdclass with source, pst and output members
*/
public function prepareTextForEdit($text, $revid = null)
{
if ($this->mPreparedEdit && $this->mPreparedEdit->newText == $text && $this->mPreparedEdit->revid == $revid) {
// Already prepared
return $this->mPreparedEdit;
}
global $wgParser;
$edit = (object) array();
$edit->revid = $revid;
$edit->newText = $text;
$edit->pst = $this->preSaveTransform($text);
$options = new ParserOptions();
$options->setTidy(true);
$options->enableLimitReport();
$edit->output = $wgParser->parse($edit->pst, $this->mTitle, $options, true, true, $revid);
$edit->oldText = $this->getContent();
$this->mPreparedEdit = $edit;
return $edit;
}
示例14: extractRowInfo
//.........这里部分代码省略.........
global $wgUser;
$vals['parsedcomment'] = $wgUser->getSkin()->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, new ParserOptions(), OT_PREPROCESS);
$dom = $wgParser->preprocessToDom($text);
if (is_callable(array($dom, 'saveXML'))) {
$xml = $dom->saveXML();
} else {
$xml = $dom->__toString();
}
$vals['parsetree'] = $xml;
}
if ($this->expandTemplates && !$this->parseContent) {
$text = $wgParser->preprocess($text, $title, new ParserOptions());
}
if ($this->parseContent) {
global $wgEnableParserCache;
$popts = new ParserOptions();
$popts->setTidy(true);
$articleObj = new Article($title);
$p_result = false;
$pcache = ParserCache::singleton();
if ($wgEnableParserCache) {
$p_result = $pcache->get($articleObj, $popts);
}
if (!$p_result) {
$p_result = $wgParser->parse($text, $title, $popts);
if ($wgEnableParserCache) {
$pcache->save($p_result, $articleObj, $popts);
}
}
$text = $p_result->getText();
}
ApiResult::setContent($vals, $text);
} elseif ($this->fld_content) {
$vals['texthidden'] = '';
}
if (!is_null($this->diffto) || !is_null($this->difftotext)) {
global $wgAPIMaxUncachedDiffs;
static $n = 0;
// Number of uncached diffs we've had
if ($n < $wgAPIMaxUncachedDiffs) {
$vals['diff'] = array();
if (!is_null($this->difftotext)) {
$engine = new DifferenceEngine($title);
$engine->setText($text, $this->difftotext);
} else {
$engine = new DifferenceEngine($title, $revision->getID(), $this->diffto);
$vals['diff']['from'] = $engine->getOldid();
$vals['diff']['to'] = $engine->getNewid();
}
$difftext = $engine->getDiffBody();
ApiResult::setContent($vals['diff'], $difftext);
if (!$engine->wasCacheHit()) {
$n++;
}
} else {
$vals['diff']['notcached'] = '';
}
}
return $vals;
}
示例15: editUpdates
/**
* Do standard deferred updates after page edit.
* Update links tables, site stats, search index and message cache.
* Purges pages that include this page if the text was changed here.
* Every 100th edit, prune the recent changes table.
*
* @private
* @param $text New text of the article
* @param $summary Edit summary
* @param $minoredit Minor edit
* @param $timestamp_of_pagechange Timestamp associated with the page change
* @param $newid rev_id value of the new revision
* @param $changed Whether or not the content actually changed
*/
public function editUpdates($text, $summary, $minoredit, $timestamp_of_pagechange, $newid, $changed = true)
{
global $wgDeferredUpdateList, $wgMessageCache, $wgUser, $wgParser, $wgEnableParserCache;
wfProfileIn(__METHOD__);
# Parse the text
# Be careful not to double-PST: $text is usually already PST-ed once
if (!$this->mPreparedEdit || $this->mPreparedEdit->output->getFlag('vary-revision')) {
wfDebug(__METHOD__ . ": No prepared edit or vary-revision is set...\n");
$editInfo = $this->prepareTextForEdit($text, $newid);
} else {
wfDebug(__METHOD__ . ": No vary-revision, using prepared edit...\n");
$editInfo = $this->mPreparedEdit;
}
# Save it to the parser cache
if ($wgEnableParserCache) {
$popts = new ParserOptions();
$popts->setTidy(true);
$popts->enableLimitReport();
$parserCache = ParserCache::singleton();
$parserCache->save($editInfo->output, $this, $popts);
}
# Update the links tables
$u = new LinksUpdate($this->mTitle, $editInfo->output);
$u->doUpdate();
wfRunHooks('ArticleEditUpdates', array(&$this, &$editInfo, $changed));
if (wfRunHooks('ArticleEditUpdatesDeleteFromRecentchanges', array(&$this))) {
if (0 == mt_rand(0, 99)) {
// Flush old entries from the `recentchanges` table; we do this on
// random requests so as to avoid an increase in writes for no good reason
global $wgRCMaxAge;
$dbw = wfGetDB(DB_MASTER);
$cutoff = $dbw->timestamp(time() - $wgRCMaxAge);
$recentchanges = $dbw->tableName('recentchanges');
$sql = "DELETE FROM {$recentchanges} WHERE rc_timestamp < '{$cutoff}'";
$dbw->query($sql);
}
}
$id = $this->getID();
$title = $this->mTitle->getPrefixedDBkey();
$shortTitle = $this->mTitle->getDBkey();
if (0 == $id) {
wfProfileOut(__METHOD__);
return;
}
$u = new SiteStatsUpdate(0, 1, $this->mGoodAdjustment, $this->mTotalAdjustment);
array_push($wgDeferredUpdateList, $u);
$u = new SearchUpdate($id, $title, $text);
array_push($wgDeferredUpdateList, $u);
# If this is another user's talk page, update newtalk
# Don't do this if $changed = false otherwise some idiot can null-edit a
# load of user talk pages and piss people off, nor if it's a minor edit
# by a properly-flagged bot.
if ($this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $wgUser->getTitleKey() && $changed && !($minoredit && $wgUser->isAllowed('nominornewtalk'))) {
if (wfRunHooks('ArticleEditUpdateNewTalk', array(&$this))) {
$other = User::newFromName($shortTitle, false);
if (!$other) {
wfDebug(__METHOD__ . ": invalid username\n");
} elseif (User::isIP($shortTitle)) {
// An anonymous user
$other->setNewtalk(true);
} elseif ($other->isLoggedIn()) {
$other->setNewtalk(true);
} else {
wfDebug(__METHOD__ . ": don't need to notify a nonexistent user\n");
}
}
}
if ($this->mTitle->getNamespace() == NS_MEDIAWIKI) {
$wgMessageCache->replace($shortTitle, $text);
}
wfProfileOut(__METHOD__);
}