本文整理汇总了PHP中Revision::getText方法的典型用法代码示例。如果您正苦于以下问题:PHP Revision::getText方法的具体用法?PHP Revision::getText怎么用?PHP Revision::getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Revision
的用法示例。
在下文中一共展示了Revision::getText方法的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 $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;
}
示例2: getText
/**
* Get the text of the current revision. No side-effects...
*
* @param int $audience One of:
* Revision::FOR_PUBLIC to be displayed to all users
* Revision::FOR_THIS_USER to be displayed to the given user
* Revision::RAW get the text regardless of permissions
* @param User $user User object to check for, only if FOR_THIS_USER is passed
* to the $audience parameter
* @return string|bool The text of the current revision
* @deprecated since 1.21, getContent() should be used instead.
*/
public function getText($audience = Revision::FOR_PUBLIC, User $user = null)
{
wfDeprecated(__METHOD__, '1.21');
$this->loadLastEdit();
if ($this->mLastRevision) {
return $this->mLastRevision->getText($audience, $user);
}
return false;
}
示例3: getText
/**
* Get the text of the current revision. No side-effects...
*
* @param $audience Integer: one of:
* Revision::FOR_PUBLIC to be displayed to all users
* Revision::FOR_THIS_USER to be displayed to the given user
* Revision::RAW get the text regardless of permissions
* @param $user User object to check for, only if FOR_THIS_USER is passed
* to the $audience parameter
* @return String|false The text of the current revision
* @deprecated as of 1.21, getContent() should be used instead.
*/
public function getText( $audience = Revision::FOR_PUBLIC, User $user = null ) { // @todo deprecated, replace usage!
ContentHandler::deprecated( __METHOD__, '1.21' );
$this->loadLastEdit();
if ( $this->mLastRevision ) {
return $this->mLastRevision->getText( $audience, $user );
}
return false;
}
示例4: runForTitleInternal
public static function runForTitleInternal(Title $title, Revision $revision, $fname)
{
global $wgParser, $wgContLang;
wfProfileIn($fname . '-parse');
$options = ParserOptions::newFromUserAndLang(new User(), $wgContLang);
$parserOutput = $wgParser->parse($revision->getText(), $title, $options, true, true, $revision->getId());
wfProfileOut($fname . '-parse');
wfProfileIn($fname . '-update');
$updates = $parserOutput->getSecondaryDataUpdates($title, false);
DataUpdate::runUpdates($updates);
wfProfileOut($fname . '-update');
}
示例5: fetchContent
/**
* Get text of an article from database
* Does *NOT* follow redirects.
*
* @return mixed string containing article contents, or false if null
*/
function fetchContent()
{
if ($this->mContentLoaded) {
return $this->mContent;
}
wfProfileIn(__METHOD__);
$this->mContentLoaded = true;
$oldid = $this->getOldID();
# Pre-fill content with error message so that if something
# fails we'll have something telling us what we intended.
$t = $this->getTitle()->getPrefixedText();
$d = $oldid ? wfMsgExt('missingarticle-rev', array('escape'), $oldid) : '';
$this->mContent = wfMsgNoTrans('missing-article', $t, $d);
if ($oldid) {
# $this->mRevision might already be fetched by getOldIDFromRequest()
if (!$this->mRevision) {
$this->mRevision = Revision::newFromId($oldid);
if (!$this->mRevision) {
wfDebug(__METHOD__ . " failed to retrieve specified revision, id {$oldid}\n");
Wikia::log(__METHOD__, 1, "failed to retrieve specified revision, title '{$t}', id {$oldid}", true);
# Wikia change - @author macbre
wfProfileOut(__METHOD__);
return false;
}
}
} else {
if (!$this->mPage->getLatest()) {
wfDebug(__METHOD__ . " failed to find page data for title " . $this->getTitle()->getPrefixedText() . "\n");
wfProfileOut(__METHOD__);
return false;
}
$this->mRevision = $this->mPage->getRevision();
if (!$this->mRevision) {
wfDebug(__METHOD__ . " failed to retrieve current page, rev_id " . $this->mPage->getLatest() . "\n");
Wikia::log(__METHOD__, 3, "failed to retrieve current page, title '{$t}', rev_id " . $this->mPage->getLatest(), true);
# Wikia change - @author macbre
wfProfileOut(__METHOD__);
return false;
}
}
// @todo FIXME: Horrible, horrible! This content-loading interface just plain sucks.
// We should instead work with the Revision object when we need it...
$this->mContent = $this->mRevision->getText(Revision::FOR_THIS_USER);
// Loads if user is allowed
$this->mRevIdFetched = $this->mRevision->getId();
wfRunHooks('ArticleAfterFetchContent', array(&$this, &$this->mContent));
wfProfileOut(__METHOD__);
return $this->mContent;
}
示例6: cleanupArticle
/**
* Find the latest revision of the article that does not contain spam and revert to it
*/
function cleanupArticle(Revision $rev, $regexes, $match)
{
$title = $rev->getTitle();
$revId = $rev->getId();
while ($rev) {
$matches = false;
foreach ($regexes as $regex) {
$matches = $matches || preg_match($regex, $rev->getText());
}
if (!$matches) {
// Didn't find any spam
break;
}
# Revision::getPrevious can't be used in this way before MW 1.6 (Revision.php 1.26)
#$rev = $rev->getPrevious();
$revId = $title->getPreviousRevisionID($revId);
if ($revId) {
$rev = Revision::newFromTitle($title, $revId);
} else {
$rev = false;
}
}
$dbw = wfGetDB(DB_MASTER);
$dbw->begin();
if (!$rev) {
// Didn't find a non-spammy revision, delete the page
/*
print "All revisions are spam, deleting...\n";
$article = new Article( $title );
$article->doDeleteArticle( "All revisions matched the spam blacklist" );
*/
// Too scary, blank instead
print "All revisions are spam, blanking...\n";
$text = '';
$comment = "All revisions matched the spam blacklist ({$match}), blanking";
} else {
// Revert to this revision
$text = $rev->getText();
$comment = "Cleaning up links to {$match}";
}
$wikiPage = new WikiPage($title);
$wikiPage->doEdit($text, $comment);
$dbw->commit();
}
示例7: showDiff
/**
* Render the inline difference between two revisions
* using InlineDiffEngine
*/
function showDiff()
{
$ctx = MobileContext::singleton();
$prevId = $this->prevRev ? $this->prevRev->getId() : 0;
$unhide = (bool) $this->getRequest()->getVal('unhide');
$contentHandler = $this->rev->getContentHandler();
$de = $contentHandler->createDifferenceEngine($this->getContext(), $prevId, $this->revId);
// HACK:
if (get_class($de) == 'DifferenceEngine') {
$de = new $this->diffClass($this->getContext(), $prevId, $this->revId, 0, false, $unhide);
} else {
$de->showDiffPage();
return;
}
$this->mDiffEngine = $de;
$diff = $de->getDiffBody();
if (!$prevId) {
$audience = $unhide ? Revision::FOR_THIS_USER : Revision::FOR_PUBLIC;
$diff = '<ins>' . nl2br(htmlspecialchars($this->rev->getText($audience))) . '</ins>';
}
$warnings = $de->getWarningMessageText();
if ($warnings) {
$warnings = MobileUI::warningBox($warnings);
}
$this->getOutput()->addHtml($warnings . '<div id="mw-mf-minidiff">' . $diff . '</div>');
$prev = $this->rev->getPrevious();
$next = $this->rev->getNext();
if ($prev || $next) {
$history = Html::openElement('ul', array('class' => 'hlist revision-history-links'));
if ($prev) {
$history .= Html::openElement('li') . Html::element('a', array('href' => SpecialPage::getTitleFor('MobileDiff', $prev->getId())->getLocalUrl()), $this->msg('previousdiff')) . Html::closeElement('li');
}
if ($next) {
$history .= Html::openElement('li') . Html::element('a', array('href' => SpecialPage::getTitleFor('MobileDiff', $next->getId())->getLocalUrl()), $this->msg('nextdiff')) . Html::closeElement('li');
}
$history .= Html::closeElement('ul');
$this->getOutput()->addHtml($history);
}
}
示例8: getUndoText
/**
* Get the text that needs to be saved in order to undo all revisions
* between $undo and $undoafter. Revisions must belong to the same page,
* must exist and must not be deleted
* @param $undo Revision
* @param $undoafter Revision Must be an earlier revision than $undo
* @return mixed string on success, false on failure
*/
public function getUndoText(Revision $undo, Revision $undoafter = null)
{
$currentRev = Revision::newFromTitle($this->mTitle);
if (!$currentRev) {
return false;
// no page
}
$undo_text = $undo->getText();
$undoafter_text = $undoafter->getText();
$cur_text = $currentRev->getText();
if ($cur_text == $undo_text) {
# No use doing a merge if it's just a straight revert.
return $undoafter_text;
}
$undone_text = '';
if (!wfMerge($undo_text, $undoafter_text, $cur_text, $undone_text)) {
return false;
}
return $undone_text;
}
示例9: initText
/**
* Lazy initialization of article text from DB
*/
protected function initText()
{
if (!isset($this->mText)) {
if ($this->mRevision != null) {
$this->mText = $this->mRevision->getText();
} else {
// TODO: can we fetch raw wikitext for commons images?
$this->mText = '';
}
}
}
示例10: 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.
*
* @private
* @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 $wgDeferredUpdateList, $wgEnableParserCache;
wfProfileIn(__METHOD__);
$options += array('changed' => true, 'created' => false, 'oldcountable' => null);
$text = $revision->getText();
# 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, $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
$u = new LinksUpdate($this->mTitle, $editInfo->output);
$u->doUpdate();
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__);
}
}
$id = $this->getId();
$title = $this->mTitle->getPrefixedDBkey();
$shortTitle = $this->mTitle->getDBkey();
if (0 == $id) {
wfProfileOut(__METHOD__);
return;
}
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;
}
$wgDeferredUpdateList[] = new SiteStatsUpdate(0, 1, $good, $total);
$wgDeferredUpdateList[] = new SearchUpdate($id, $title, $text);
# 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);
} elseif ($other->isLoggedIn()) {
$other->setNewtalk(true);
} else {
wfDebug(__METHOD__ . ": don't need to notify a nonexistent user\n");
}
}
}
if ($this->mTitle->getNamespace() == NS_MEDIAWIKI) {
MessageCache::singleton()->replace($shortTitle, $text);
}
if ($options['created']) {
self::onArticleCreate($this->mTitle);
} else {
self::onArticleEdit($this->mTitle);
}
wfProfileOut(__METHOD__);
//.........这里部分代码省略.........
示例11: createUpdates
/**
* Perform article updates on a special page creation.
*
* @param Revision $rev
*
* @fixme This is a shitty interface function. Kill it and replace the
* other shitty functions like editUpdates and such so it's not needed
* anymore.
*/
function createUpdates($rev)
{
$this->mGoodAdjustment = $this->isCountable($rev->getText());
$this->mTotalAdjustment = 1;
$this->editUpdates($rev->getText(), $rev->getComment(), $rev->isMinor(), wfTimestamp(), $rev->getId(), true);
}
示例12: testConstructWithContent
public function testConstructWithContent()
{
$this->hideDeprecated("Revision::getText");
$title = Title::newFromText('RevisionTest_testConstructWithContent');
$rev = new Revision(array('content' => ContentHandler::makeContent('hello world.', $title, CONTENT_MODEL_JAVASCRIPT)));
$this->assertNotNull($rev->getText(), 'no content text');
$this->assertNotNull($rev->getContent(), 'no content object available');
$this->assertEquals(CONTENT_MODEL_JAVASCRIPT, $rev->getContent()->getModel());
$this->assertEquals(CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel());
}
示例13: fetchTranslatorsPortal
public function fetchTranslatorsPortal( $natives ) {
$titles = array();
foreach ( $natives as $code => $_ ) {
$titles[] = Title::capitalize( $code, NS_PORTAL ) . '/translators';
}
$dbr = wfGetDB( DB_SLAVE );
$tables = array( 'page', 'revision', 'text' );
$vars = array_merge( Revision::selectTextFields(), array( 'page_title', 'page_namespace' ), Revision::selectFields() );
$conds = array(
'page_latest = rev_id',
'rev_text_id = old_id',
'page_namespace' => NS_PORTAL,
'page_title' => $titles,
);
$res = $dbr->select( $tables, $vars, $conds, __METHOD__ );
$users = array();
$lb = new LinkBatch;
foreach ( $res as $row ) {
$rev = new Revision( $row );
$text = $rev->getText();
$code = strtolower( preg_replace( '!/translators$!', '', $row->page_title ) );
preg_match_all( '!{{[Uu]ser\|([^}|]+)!', $text, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
$user = Title::capitalize( $match[1], NS_USER );
$lb->add( NS_USER, $user );
$lb->add( NS_USER_TALK, $user );
if ( !isset( $users[$code] ) ) $users[$code] = array();
$users[$code][strtr( $user, '_', ' ' )] = -1;
}
}
$lb->execute();
return $users;
}
示例14: extractRowInfo
private function extractRowInfo($oRow, $deleted = 0)
{
wfProfileIn(__METHOD__);
$vals = array();
if ($deleted == 0) {
$oRevision = new Revision($oRow);
if (isset($oRow->is_archive) && $oRow->is_archive == 1) {
$this->mTitle = Title::makeTitle($oRow->page_namespace, $oRow->page_title);
} else {
$this->mTitle = $oRevision->getTitle();
}
$this->mContent = $oRevision->getText(Revision::FOR_THIS_USER);
# revision id
$vals['revid'] = intval($oRevision->getId());
# username
$vals['username'] = $oRevision->getUserText();
# user id
$vals['userid'] = $oRevision->getUser();
# user ip
$vals['user_ip'] = IP::isIPAddress($vals['username']) ? $vals['username'] : $this->_get_user_ip($vals['userid'], $oRow->page_title, $oRow->page_namespace);
# user is bot
$vals['userisbot'] = intval($this->_user_is_bot($vals['username']));
# is new
$is_archive = isset($oRow->is_archive);
$vals['isnew'] = $this->checkIsNew($is_archive);
# timestamp
$vals['timestamp'] = wfTimestamp(TS_DB, $oRevision->getTimestamp());
$vals['date'] = gmdate('Y-m-d', wfTimestamp(TS_UNIX, $oRevision->getTimestamp()));
# size
$vals['size'] = intval($oRevision->getSize());
#words
$vals['words'] = str_word_count($this->mContent);
# revision is redirect
$vals['isredirect'] = intval($this->_revision_is_redirect());
# revision is content
$vals['iscontent'] = intval($this->_revision_is_content());
# is deleted
$vals['isdeleted'] = $deleted;
# links
$links = $this->_make_links();
$vals['imagelinks'] = $links['image'];
$vals['video'] = $links['video'];
} else {
$this->mTitle = Title::makeTitle($oRow->page_namespace, $oRow->page_title);
# revision id
$vals['revid'] = intval($oRow->rev_id);
# username
$vals['username'] = $oRow->rev_user_text;
# user id
$vals['userid'] = intval($oRow->rev_user);
# user ip
$vals['user_ip'] = IP::isIPAddress($vals['username']) ? $vals['username'] : $this->_get_user_ip($vals['userid'], $oRow->page_title, $oRow->page_namespace);
# user is bot
$vals['userisbot'] = intval($this->_user_is_bot($vals['username']));
# is new
$vals['isnew'] = 0;
# timestamp
$vals['timestamp'] = wfTimestamp(TS_DB, $oRow->rev_timestamp);
# size
$vals['size'] = intval($oRow->rev_len);
# words
$vals['words'] = 0;
# revision is redirect
$vals['isredirect'] = 0;
# revision is content
$vals['iscontent'] = intval($this->_revision_is_content());
# is deleted
$vals['isdeleted'] = $deleted;
# links
$vals['imagelinks'] = 0;
$vals['video'] = 0;
}
$vals['media_type'] = $this->getMediaType($oRow->page_namespace);
$vals['page_latest'] = $this->mTitle->getLatestRevID();
wfProfileOut(__METHOD__);
return $vals;
}
示例15: showDiff
function showDiff($revision)
{
global $wgOut;
$dbr = wfGetDB(DB_SLAVE);
$result = $this->getRevisions($dbr, array('hidden_rev_id' => $revision));
while ($row = $dbr->fetchObject($result)) {
$info = $this->listRow($row);
$list = $this->revisionInfo($row);
$rev = new Revision($row);
$rev->mTitle = Title::makeTitle($row->page_namespace, $row->page_title);
$prevId = $rev->mTitle->getPreviousRevisionID($row->rev_id);
if ($prevId) {
$prev = Revision::newFromTitle($rev->mTitle, $prevId);
$otext = strval($prev->getText());
} else {
$wgOut->addHtml("<ul>" . $info . "</ul>\n" . $list);
$wgOut->addWikiText(wfMsgNoTrans('oversight-nodiff'));
return;
}
$ntext = strval($rev->getText());
$diffEngine = new DifferenceEngine();
$diffEngine->showDiffStyle();
$wgOut->addHtml("<ul>" . $info . "</ul>\n" . $list . "<p><strong>" . wfMsgHTML('oversight-difference') . "</strong>" . "</p>" . "<div>" . "<table border='0' width='98%' cellpadding='0' cellspacing='4' class='diff'>" . "<col class='diff-marker' />" . "<col class='diff-content' />" . "<col class='diff-marker' />" . "<col class='diff-content' />" . "<tr>" . "<td colspan='2' width='50%' align='center' class='diff-otitle'>" . wfMsgHTML('oversight-prev') . " (#{$prevId})" . "</td>" . "<td colspan='2' width='50%' align='center' class='diff-ntitle'>" . wfMsgHTML('oversight-hidden') . "</td>" . "</tr>" . $diffEngine->generateDiffBody($otext, $ntext) . "</table>" . "</div>\n");
}
$dbr->freeResult($result);
}