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


PHP Revision::getContent方法代码示例

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


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

示例1: 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;
 }
开发者ID:crippsy14,项目名称:orange-smorange,代码行数:67,代码来源:FRInclusionCache.php

示例2: initText

 /**
  * Lazy initialization of article text from DB
  */
 protected function initText()
 {
     if (!isset($this->mText)) {
         if ($this->mRevision != null) {
             $this->mText = SearchEngine::create()->getTextFromContent($this->mTitle, $this->mRevision->getContent());
         } else {
             // TODO: can we fetch raw wikitext for commons images?
             $this->mText = '';
         }
     }
 }
开发者ID:Tarendai,项目名称:spring-website,代码行数:14,代码来源:SearchResult.php

示例3: loadNewText

 /**
  * Load the text of the new revision, not the old one
  *
  * @return bool
  */
 public function loadNewText()
 {
     if ($this->mTextLoaded >= 1) {
         return true;
     }
     $this->mTextLoaded = 1;
     if (!$this->loadRevisionData()) {
         return false;
     }
     $this->mNewContent = $this->mNewRev->getContent(Revision::FOR_THIS_USER, $this->getUser());
     return true;
 }
开发者ID:guochangjiang,项目名称:mediawiki,代码行数:17,代码来源:DifferenceEngine.php

示例4: processRevision

 /**
  * Callback function for each revision, preprocessToObj()
  * @param Revision $rev
  */
 public function processRevision($rev)
 {
     $content = $rev->getContent(Revision::RAW);
     if ($content->getModel() !== CONTENT_MODEL_WIKITEXT) {
         return;
     }
     try {
         $this->mPreprocessor->preprocessToObj(strval($content->getNativeData()), 0);
     } catch (Exception $e) {
         $this->error("Caught exception " . $e->getMessage() . " in " . $rev->getTitle()->getPrefixedText());
     }
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:16,代码来源:preprocessDump.php

示例5: runForTitleInternal

 public static function runForTitleInternal(Title $title, Revision $revision, $fname)
 {
     global $wgContLang;
     wfProfileIn($fname . '-parse');
     $options = ParserOptions::newFromUserAndLang(new User(), $wgContLang);
     $content = $revision->getContent();
     $parserOutput = $content->getParserOutput($title, $revision->getId(), $options, false);
     wfProfileOut($fname . '-parse');
     wfProfileIn($fname . '-update');
     $updates = $content->getSecondaryDataUpdates($title, null, false, $parserOutput);
     DataUpdate::runUpdates($updates);
     wfProfileOut($fname . '-update');
 }
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:13,代码来源:RefreshLinksJob.php

示例6: runForTitleInternal

 /**
  * @param $title Title
  * @param $revision Revision
  * @param $fname string
  * @return void
  */
 public static function runForTitleInternal(Title $title, Revision $revision, $fname)
 {
     wfProfileIn($fname);
     $content = $revision->getContent(Revision::RAW);
     if (!$content) {
         // if there is no content, pretend the content is empty
         $content = $revision->getContentHandler()->makeEmptyContent();
     }
     // Revision ID must be passed to the parser output to get revision variables correct
     $parserOutput = $content->getParserOutput($title, $revision->getId(), null, false);
     $updates = $content->getSecondaryDataUpdates($title, null, false, $parserOutput);
     DataUpdate::runUpdates($updates);
     InfoAction::invalidateCache($title);
     wfProfileOut($fname);
 }
开发者ID:mangowi,项目名称:mediawiki,代码行数:21,代码来源:RefreshLinksJob.php

示例7: doDBUpdates

 public function doDBUpdates()
 {
     $db = $this->getDB(DB_MASTER);
     if (!$db->tableExists('revision')) {
         $this->error("revision table does not exist", true);
     } else {
         if (!$db->fieldExists('revision', 'rev_sha1', __METHOD__)) {
             $this->output("rev_sha1 column does not exist\n\n", true);
             return false;
         }
     }
     $this->output("Populating rev_len column\n");
     $start = $db->selectField('revision', 'MIN(rev_id)', false, __METHOD__);
     $end = $db->selectField('revision', 'MAX(rev_id)', false, __METHOD__);
     if (!$start || !$end) {
         $this->output("...revision table seems to be empty.\n");
         return true;
     }
     # Do remaining chunks
     $blockStart = intval($start);
     $blockEnd = intval($start) + $this->mBatchSize - 1;
     $count = 0;
     $missing = 0;
     $fields = Revision::selectFields();
     while ($blockStart <= $end) {
         $this->output("...doing rev_id from {$blockStart} to {$blockEnd}\n");
         $res = $db->select('revision', $fields, array("rev_id >= {$blockStart}", "rev_id <= {$blockEnd}", "rev_len IS NULL"), __METHOD__);
         # Go through and update rev_len from these rows.
         foreach ($res as $row) {
             $rev = new Revision($row);
             $content = $rev->getContent();
             if (!$content) {
                 # This should not happen, but sometimes does (bug 20757)
                 $this->output("Content of revision {$row->rev_id} unavailable!\n");
                 $missing++;
             } else {
                 # Update the row...
                 $db->update('revision', array('rev_len' => $content->getSize()), array('rev_id' => $row->rev_id), __METHOD__);
                 $count++;
             }
         }
         $blockStart += $this->mBatchSize;
         $blockEnd += $this->mBatchSize;
         wfWaitForSlaves();
     }
     $this->output("rev_len population complete ... {$count} rows changed ({$missing} missing)\n");
     return true;
 }
开发者ID:Grprashanthkumar,项目名称:ColfusionWeb,代码行数:48,代码来源:populateRevisionLength.php

示例8: doEditUpdates

 /**
  * 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.
  *
  * @param $revision Revision object
  * @param $user User object that did the revision
  * @param $options Array of options, following indexes are used:
  * - changed: boolean, whether the revision changed the content (default true)
  * - created: boolean, whether the revision created the page (default false)
  * - oldcountable: boolean or null (default null):
  *   - boolean: whether the page was counted as an article before that
  *     revision, only used in changed is true and created is false
  *   - null: don't change the article count
  */
 public function doEditUpdates(Revision $revision, User $user, array $options = array())
 {
     global $wgEnableParserCache;
     wfProfileIn(__METHOD__);
     $options += array('changed' => true, 'created' => false, 'oldcountable' => null);
     $content = $revision->getContent();
     # 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->prepareContentForEdit($content, $revision->getId(), $user);
     } else {
         wfDebug(__METHOD__ . ": No vary-revision, using prepared edit...\n");
         $editInfo = $this->mPreparedEdit;
     }
     # Save it to the parser cache
     if ($wgEnableParserCache) {
         $parserCache = ParserCache::singleton();
         $parserCache->save($editInfo->output, $this, $editInfo->popts);
     }
     # Update the links tables and other secondary data
     $updates = $content->getSecondaryDataUpdates($this->getTitle(), null, true, $editInfo->output);
     DataUpdate::runUpdates($updates);
     wfRunHooks('ArticleEditUpdates', array(&$this, &$editInfo, $options['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);
             $dbw->delete('recentchanges', array("rc_timestamp < '{$cutoff}'"), __METHOD__);
         }
     }
     if (!$this->mTitle->exists()) {
         wfProfileOut(__METHOD__);
         return;
     }
     $id = $this->getId();
     $title = $this->mTitle->getPrefixedDBkey();
     $shortTitle = $this->mTitle->getDBkey();
     if (!$options['changed']) {
         $good = 0;
         $total = 0;
     } elseif ($options['created']) {
         $good = (int) $this->isCountable($editInfo);
         $total = 1;
     } elseif ($options['oldcountable'] !== null) {
         $good = (int) $this->isCountable($editInfo) - (int) $options['oldcountable'];
         $total = 0;
     } else {
         $good = 0;
         $total = 0;
     }
     DeferredUpdates::addUpdate(new SiteStatsUpdate(0, 1, $good, $total));
     DeferredUpdates::addUpdate(new SearchUpdate($id, $title, $content->getTextForSearchIndex()));
     #@TODO: let the search engine decide what to do with the content object
     # If this is another user's talk page, update newtalk.
     # Don't do this if $options['changed'] = false (null-edits) nor if
     # it's a minor edit and the user doesn't want notifications for those.
     if ($options['changed'] && $this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $user->getTitleKey() && !($revision->isMinor() && $user->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, $revision);
             } elseif ($other->isLoggedIn()) {
                 $other->setNewtalk(true, $revision);
             } else {
                 wfDebug(__METHOD__ . ": don't need to notify a nonexistent user\n");
             }
         }
     }
     if ($this->mTitle->getNamespace() == NS_MEDIAWIKI) {
         #XXX: could skip pseudo-messages like js/css here, based on content model.
         $msgtext = $content->getWikitextForTransclusion();
         if ($msgtext === false || $msgtext === null) {
             $msgtext = '';
         }
         MessageCache::singleton()->replace($shortTitle, $msgtext);
     }
     if ($options['created']) {
//.........这里部分代码省略.........
开发者ID:nischayn22,项目名称:mediawiki-core,代码行数:101,代码来源:WikiPage.php

示例9: onSubmit

 public function onSubmit(array $data)
 {
     global $wgContLang;
     if ($data['pagetitle'] === '') {
         // Initial form view of special page, pass
         return false;
     }
     // At this point, it has to be a POST request. This is enforced by HTMLForm,
     // but lets be safe verify that.
     if (!$this->getRequest()->wasPosted()) {
         throw new RuntimeException("Form submission was not POSTed");
     }
     $this->title = Title::newFromText($data['pagetitle']);
     $user = $this->getUser();
     // Check permissions and make sure the user has permission to edit the specific page
     $errors = $this->title->getUserPermissionsErrors('editcontentmodel', $user);
     $errors = wfMergeErrorArrays($errors, $this->title->getUserPermissionsErrors('edit', $user));
     if ($errors) {
         $out = $this->getOutput();
         $wikitext = $out->formatPermissionsErrorMessage($errors);
         // Hack to get our wikitext parsed
         return Status::newFatal(new RawMessage('$1', array($wikitext)));
     }
     $page = WikiPage::factory($this->title);
     if ($this->oldRevision === null) {
         $this->oldRevision = $page->getRevision() ?: false;
     }
     $oldModel = $this->title->getContentModel();
     if ($this->oldRevision) {
         $oldContent = $this->oldRevision->getContent();
         try {
             $newContent = ContentHandler::makeContent($oldContent->getNativeData(), $this->title, $data['model']);
         } catch (MWException $e) {
             return Status::newFatal($this->msg('changecontentmodel-cannot-convert')->params($this->title->getPrefixedText(), ContentHandler::getLocalizedName($data['model'])));
         }
     } else {
         // Page doesn't exist, create an empty content object
         $newContent = ContentHandler::getForModelID($data['model'])->makeEmptyContent();
     }
     $flags = $this->oldRevision ? EDIT_UPDATE : EDIT_NEW;
     if ($user->isAllowed('bot')) {
         $flags |= EDIT_FORCE_BOT;
     }
     $log = new ManualLogEntry('contentmodel', 'change');
     $log->setPerformer($user);
     $log->setTarget($this->title);
     $log->setComment($data['reason']);
     $log->setParameters(array('4::oldmodel' => $oldModel, '5::newmodel' => $data['model']));
     $formatter = LogFormatter::newFromEntry($log);
     $formatter->setContext(RequestContext::newExtraneousContext($this->title));
     $reason = $formatter->getPlainActionText();
     if ($data['reason'] !== '') {
         $reason .= $this->msg('colon-separator')->inContentLanguage()->text() . $data['reason'];
     }
     # Truncate for whole multibyte characters.
     $reason = $wgContLang->truncate($reason, 255);
     $status = $page->doEditContent($newContent, $reason, $flags, $this->oldRevision ? $this->oldRevision->getId() : false, $user);
     if (!$status->isOK()) {
         return $status;
     }
     $logid = $log->insert();
     $log->publish($logid);
     return $status;
 }
开发者ID:D66Ha,项目名称:mediawiki,代码行数:64,代码来源:SpecialChangeContentModel.php

示例10: testGetContent_failure

 /**
  * @covers Revision::getContent
  */
 public function testGetContent_failure()
 {
     $rev = new Revision(['page' => $this->the_page->getId(), 'content_model' => $this->the_page->getContentModel(), 'text_id' => 123456789]);
     $this->assertNull($rev->getContent(), "getContent() should return null if the revision's text blob could not be loaded.");
     // NOTE: check this twice, once for lazy initialization, and once with the cached value.
     $this->assertNull($rev->getContent(), "getContent() should return null if the revision's text blob could not be loaded.");
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:10,代码来源:RevisionStorageTest.php

示例11: getCategoriesAtRev

 /**
  * @param Title $title
  * @param Revision $rev
  * @param string $parseTimestamp TS_MW
  *
  * @return string[] category names
  */
 private function getCategoriesAtRev(Title $title, Revision $rev, $parseTimestamp)
 {
     $content = $rev->getContent();
     $options = $content->getContentHandler()->makeParserOptions('canonical');
     $options->setTimestamp($parseTimestamp);
     // This could possibly use the parser cache if it checked the revision ID,
     // but that's more complicated than it's worth.
     $output = $content->getParserOutput($title, $rev->getId(), $options);
     // array keys will cast numeric category names to ints
     // so we need to cast them back to strings to avoid breaking things!
     return array_map('strval', array_keys($output->getCategories()));
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:19,代码来源:CategoryMembershipChangeJob.php

示例12: processRevision

 /**
  * Callback function for each revision, parse with both parsers and compare
  * @param Revision $rev
  */
 public function processRevision($rev)
 {
     $title = $rev->getTitle();
     $parser1Name = $this->getOption('parser1');
     $parser2Name = $this->getOption('parser2');
     self::checkParserLocally($parser1Name);
     self::checkParserLocally($parser2Name);
     $parser1 = new $parser1Name();
     $parser2 = new $parser2Name();
     $content = $rev->getContent();
     if ($content->getModel() !== CONTENT_MODEL_WIKITEXT) {
         $this->error("Page {$title->getPrefixedText()} does not contain wikitext " . "but {$content->getModel()}\n");
         return;
     }
     $text = strval($content->getNativeData());
     $output1 = $parser1->parse($text, $title, $this->options);
     $output2 = $parser2->parse($text, $title, $this->options);
     if ($output1->getText() != $output2->getText()) {
         $this->failed++;
         $this->error("Parsing for {$title->getPrefixedText()} differs\n");
         if ($this->saveFailed) {
             file_put_contents($this->saveFailed . '/' . rawurlencode($title->getPrefixedText()) . ".txt", $text);
         }
         if ($this->showDiff) {
             $this->output(wfDiff($this->stripParameters($output1->getText()), $this->stripParameters($output2->getText()), ''));
         }
     } else {
         $this->output($title->getPrefixedText() . "\tOK\n");
         if ($this->showParsedOutput) {
             $this->output($this->stripParameters($output1->getText()));
         }
     }
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:37,代码来源:compareParsers.php

示例13: doEditUpdates

 /**
  * 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.
  *
  * @param Revision $revision
  * @param User $user User object that did the revision
  * @param array $options Array of options, following indexes are used:
  * - changed: boolean, whether the revision changed the content (default true)
  * - created: boolean, whether the revision created the page (default false)
  * - moved: boolean, whether the page was moved (default false)
  * - oldcountable: boolean, null, or string 'no-change' (default null):
  *   - boolean: whether the page was counted as an article before that
  *     revision, only used in changed is true and created is false
  *   - null: if created is false, don't update the article count; if created
  *     is true, do update the article count
  *   - 'no-change': don't update the article count, ever
  */
 public function doEditUpdates(Revision $revision, User $user, array $options = array())
 {
     $options += array('changed' => true, 'created' => false, 'moved' => false, 'oldcountable' => null);
     $content = $revision->getContent();
     // Parse the text
     // Be careful not to do pre-save transform twice: $text is usually
     // already pre-save transformed once.
     if (!$this->mPreparedEdit || $this->mPreparedEdit->output->getFlag('vary-revision')) {
         wfDebug(__METHOD__ . ": No prepared edit or vary-revision is set...\n");
         $editInfo = $this->prepareContentForEdit($content, $revision, $user);
     } else {
         wfDebug(__METHOD__ . ": No vary-revision, using prepared edit...\n");
         $editInfo = $this->mPreparedEdit;
     }
     // Save it to the parser cache.
     // Make sure the cache time matches page_touched to avoid double parsing.
     ParserCache::singleton()->save($editInfo->output, $this, $editInfo->popts, $revision->getTimestamp(), $editInfo->revid);
     // Update the links tables and other secondary data
     if ($content) {
         $recursive = $options['changed'];
         // bug 50785
         $updates = $content->getSecondaryDataUpdates($this->getTitle(), null, $recursive, $editInfo->output);
         foreach ($updates as $update) {
             if ($update instanceof LinksUpdate) {
                 $update->setRevision($revision);
                 $update->setTriggeringUser($user);
             }
             DeferredUpdates::addUpdate($update);
         }
     }
     Hooks::run('ArticleEditUpdates', array(&$this, &$editInfo, $options['changed']));
     if (Hooks::run('ArticleEditUpdatesDeleteFromRecentchanges', array(&$this))) {
         // Flush old entries from the `recentchanges` table
         if (mt_rand(0, 9) == 0) {
             JobQueueGroup::singleton()->lazyPush(RecentChangesUpdateJob::newPurgeJob());
         }
     }
     if (!$this->exists()) {
         return;
     }
     $id = $this->getId();
     $title = $this->mTitle->getPrefixedDBkey();
     $shortTitle = $this->mTitle->getDBkey();
     if ($options['oldcountable'] === 'no-change' || !$options['changed'] && !$options['moved']) {
         $good = 0;
     } elseif ($options['created']) {
         $good = (int) $this->isCountable($editInfo);
     } elseif ($options['oldcountable'] !== null) {
         $good = (int) $this->isCountable($editInfo) - (int) $options['oldcountable'];
     } else {
         $good = 0;
     }
     $edits = $options['changed'] ? 1 : 0;
     $total = $options['created'] ? 1 : 0;
     DeferredUpdates::addUpdate(new SiteStatsUpdate(0, $edits, $good, $total));
     DeferredUpdates::addUpdate(new SearchUpdate($id, $title, $content));
     // If this is another user's talk page, update newtalk.
     // Don't do this if $options['changed'] = false (null-edits) nor if
     // it's a minor edit and the user doesn't want notifications for those.
     if ($options['changed'] && $this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $user->getTitleKey() && !($revision->isMinor() && $user->isAllowed('nominornewtalk'))) {
         $recipient = User::newFromName($shortTitle, false);
         if (!$recipient) {
             wfDebug(__METHOD__ . ": invalid username\n");
         } else {
             // Allow extensions to prevent user notification
             // when a new message is added to their talk page
             if (Hooks::run('ArticleEditUpdateNewTalk', array(&$this, $recipient))) {
                 if (User::isIP($shortTitle)) {
                     // An anonymous user
                     $recipient->setNewtalk(true, $revision);
                 } elseif ($recipient->isLoggedIn()) {
                     $recipient->setNewtalk(true, $revision);
                 } else {
                     wfDebug(__METHOD__ . ": don't need to notify a nonexistent user\n");
                 }
             }
         }
     }
     if ($this->mTitle->getNamespace() == NS_MEDIAWIKI) {
         // XXX: could skip pseudo-messages like js/css here, based on content model.
         $msgtext = $content ? $content->getWikitextForTransclusion() : null;
//.........这里部分代码省略.........
开发者ID:huatuoorg,项目名称:mediawiki,代码行数:101,代码来源:WikiPage.php

示例14: showDiff

 /**
  * Build a diff display between this and the previous either deleted
  * or non-deleted edit.
  *
  * @param Revision $previousRev
  * @param Revision $currentRev
  * @return string HTML
  */
 function showDiff($previousRev, $currentRev)
 {
     $diffContext = clone $this->getContext();
     $diffContext->setTitle($currentRev->getTitle());
     $diffContext->setWikiPage(WikiPage::factory($currentRev->getTitle()));
     $diffEngine = $currentRev->getContentHandler()->createDifferenceEngine($diffContext);
     $diffEngine->showDiffStyle();
     $formattedDiff = $diffEngine->generateContentDiffBody($previousRev->getContent(Revision::FOR_THIS_USER, $this->getUser()), $currentRev->getContent(Revision::FOR_THIS_USER, $this->getUser()));
     $formattedDiff = $diffEngine->addHeader($formattedDiff, $this->diffHeader($previousRev, 'o'), $this->diffHeader($currentRev, 'n'));
     $this->getOutput()->addHTML("<div>{$formattedDiff}</div>\n");
 }
开发者ID:raymondzhangl,项目名称:mediawiki,代码行数:19,代码来源:SpecialUndelete.php

示例15: doEditUpdates

 /**
  * 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.
  *
  * @param Revision $revision
  * @param User $user User object that did the revision
  * @param array $options Array of options, following indexes are used:
  * - changed: boolean, whether the revision changed the content (default true)
  * - created: boolean, whether the revision created the page (default false)
  * - moved: boolean, whether the page was moved (default false)
  * - restored: boolean, whether the page was undeleted (default false)
  * - oldrevision: Revision object for the pre-update revision (default null)
  * - oldcountable: boolean, null, or string 'no-change' (default null):
  *   - boolean: whether the page was counted as an article before that
  *     revision, only used in changed is true and created is false
  *   - null: if created is false, don't update the article count; if created
  *     is true, do update the article count
  *   - 'no-change': don't update the article count, ever
  */
 public function doEditUpdates(Revision $revision, User $user, array $options = [])
 {
     global $wgRCWatchCategoryMembership, $wgContLang;
     $options += ['changed' => true, 'created' => false, 'moved' => false, 'restored' => false, 'oldrevision' => null, 'oldcountable' => null];
     $content = $revision->getContent();
     $logger = LoggerFactory::getInstance('SaveParse');
     // See if the parser output before $revision was inserted is still valid
     $editInfo = false;
     if (!$this->mPreparedEdit) {
         $logger->debug(__METHOD__ . ": No prepared edit...\n");
     } elseif ($this->mPreparedEdit->output->getFlag('vary-revision')) {
         $logger->info(__METHOD__ . ": Prepared edit has vary-revision...\n");
     } elseif ($this->mPreparedEdit->output->getFlag('vary-revision-id') && $this->mPreparedEdit->output->getSpeculativeRevIdUsed() !== $revision->getId()) {
         $logger->info(__METHOD__ . ": Prepared edit has vary-revision-id with wrong ID...\n");
     } elseif ($this->mPreparedEdit->output->getFlag('vary-user') && !$options['changed']) {
         $logger->info(__METHOD__ . ": Prepared edit has vary-user and is null...\n");
     } else {
         wfDebug(__METHOD__ . ": Using prepared edit...\n");
         $editInfo = $this->mPreparedEdit;
     }
     if (!$editInfo) {
         // Parse the text again if needed. Be careful not to do pre-save transform twice:
         // $text is usually already pre-save transformed once. Avoid using the edit stash
         // as any prepared content from there or in doEditContent() was already rejected.
         $editInfo = $this->prepareContentForEdit($content, $revision, $user, null, false);
     }
     // Save it to the parser cache.
     // Make sure the cache time matches page_touched to avoid double parsing.
     ParserCache::singleton()->save($editInfo->output, $this, $editInfo->popts, $revision->getTimestamp(), $editInfo->revid);
     // Update the links tables and other secondary data
     if ($content) {
         $recursive = $options['changed'];
         // bug 50785
         $updates = $content->getSecondaryDataUpdates($this->getTitle(), null, $recursive, $editInfo->output);
         foreach ($updates as $update) {
             if ($update instanceof LinksUpdate) {
                 $update->setRevision($revision);
                 $update->setTriggeringUser($user);
             }
             DeferredUpdates::addUpdate($update);
         }
         if ($wgRCWatchCategoryMembership && $this->getContentHandler()->supportsCategories() === true && ($options['changed'] || $options['created']) && !$options['restored']) {
             // Note: jobs are pushed after deferred updates, so the job should be able to see
             // the recent change entry (also done via deferred updates) and carry over any
             // bot/deletion/IP flags, ect.
             JobQueueGroup::singleton()->lazyPush(new CategoryMembershipChangeJob($this->getTitle(), ['pageId' => $this->getId(), 'revTimestamp' => $revision->getTimestamp()]));
         }
     }
     Hooks::run('ArticleEditUpdates', [&$this, &$editInfo, $options['changed']]);
     if (Hooks::run('ArticleEditUpdatesDeleteFromRecentchanges', [&$this])) {
         // Flush old entries from the `recentchanges` table
         if (mt_rand(0, 9) == 0) {
             JobQueueGroup::singleton()->lazyPush(RecentChangesUpdateJob::newPurgeJob());
         }
     }
     if (!$this->exists()) {
         return;
     }
     $id = $this->getId();
     $title = $this->mTitle->getPrefixedDBkey();
     $shortTitle = $this->mTitle->getDBkey();
     if ($options['oldcountable'] === 'no-change' || !$options['changed'] && !$options['moved']) {
         $good = 0;
     } elseif ($options['created']) {
         $good = (int) $this->isCountable($editInfo);
     } elseif ($options['oldcountable'] !== null) {
         $good = (int) $this->isCountable($editInfo) - (int) $options['oldcountable'];
     } else {
         $good = 0;
     }
     $edits = $options['changed'] ? 1 : 0;
     $total = $options['created'] ? 1 : 0;
     DeferredUpdates::addUpdate(new SiteStatsUpdate(0, $edits, $good, $total));
     DeferredUpdates::addUpdate(new SearchUpdate($id, $title, $content));
     // If this is another user's talk page, update newtalk.
     // Don't do this if $options['changed'] = false (null-edits) nor if
     // it's a minor edit and the user doesn't want notifications for those.
     if ($options['changed'] && $this->mTitle->getNamespace() == NS_USER_TALK && $shortTitle != $user->getTitleKey() && !($revision->isMinor() && $user->isAllowed('nominornewtalk'))) {
         $recipient = User::newFromName($shortTitle, false);
//.........这里部分代码省略.........
开发者ID:paladox,项目名称:mediawiki,代码行数:101,代码来源:WikiPage.php


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