本文整理汇总了PHP中Revision::getContentModel方法的典型用法代码示例。如果您正苦于以下问题:PHP Revision::getContentModel方法的具体用法?PHP Revision::getContentModel怎么用?PHP Revision::getContentModel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Revision
的用法示例。
在下文中一共展示了Revision::getContentModel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateRevisionOn
/**
* Update the page record to point to a newly saved revision.
*
* @param IDatabase $dbw
* @param Revision $revision For ID number, and text used to set
* length and redirect status fields
* @param int $lastRevision If given, will not overwrite the page field
* when different from the currently set value.
* Giving 0 indicates the new page flag should be set on.
* @param bool $lastRevIsRedirect If given, will optimize adding and
* removing rows in redirect table.
* @return bool Success; false if the page row was missing or page_latest changed
*/
public function updateRevisionOn($dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null)
{
global $wgContentHandlerUseDB;
// Assertion to try to catch T92046
if ((int) $revision->getId() === 0) {
throw new InvalidArgumentException(__METHOD__ . ': Revision has ID ' . var_export($revision->getId(), 1));
}
$content = $revision->getContent();
$len = $content ? $content->getSize() : 0;
$rt = $content ? $content->getUltimateRedirectTarget() : null;
$conditions = ['page_id' => $this->getId()];
if (!is_null($lastRevision)) {
// An extra check against threads stepping on each other
$conditions['page_latest'] = $lastRevision;
}
$row = ['page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp($revision->getTimestamp()), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => $rt !== null ? 1 : 0, 'page_len' => $len];
if ($wgContentHandlerUseDB) {
$row['page_content_model'] = $revision->getContentModel();
}
$dbw->update('page', $row, $conditions, __METHOD__);
$result = $dbw->affectedRows() > 0;
if ($result) {
$this->updateRedirectOn($dbw, $rt, $lastRevIsRedirect);
$this->setLastEdit($revision);
$this->mLatest = $revision->getId();
$this->mIsRedirect = (bool) $rt;
// Update the LinkCache.
LinkCache::singleton()->addGoodLinkObj($this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest, $revision->getContentModel());
}
return $result;
}
示例2: extractRevisionInfo
/**
* Extract information from the Revision
*
* @param Revision $revision
* @param object $row Should have a field 'ts_tags' if $this->fld_tags is set
* @return array
*/
protected function extractRevisionInfo(Revision $revision, $row)
{
$title = $revision->getTitle();
$user = $this->getUser();
$vals = array();
$anyHidden = false;
if ($this->fld_ids) {
$vals['revid'] = intval($revision->getId());
if (!is_null($revision->getParentId())) {
$vals['parentid'] = intval($revision->getParentId());
}
}
if ($this->fld_flags) {
$vals['minor'] = $revision->isMinor();
}
if ($this->fld_user || $this->fld_userid) {
if ($revision->isDeleted(Revision::DELETED_USER)) {
$vals['userhidden'] = true;
$anyHidden = true;
}
if ($revision->userCan(Revision::DELETED_USER, $user)) {
if ($this->fld_user) {
$vals['user'] = $revision->getUserText(Revision::RAW);
}
$userid = $revision->getUser(Revision::RAW);
if (!$userid) {
$vals['anon'] = true;
}
if ($this->fld_userid) {
$vals['userid'] = $userid;
}
}
}
if ($this->fld_timestamp) {
$vals['timestamp'] = wfTimestamp(TS_ISO_8601, $revision->getTimestamp());
}
if ($this->fld_size) {
if (!is_null($revision->getSize())) {
$vals['size'] = intval($revision->getSize());
} else {
$vals['size'] = 0;
}
}
if ($this->fld_sha1) {
if ($revision->isDeleted(Revision::DELETED_TEXT)) {
$vals['sha1hidden'] = true;
$anyHidden = true;
}
if ($revision->userCan(Revision::DELETED_TEXT, $user)) {
if ($revision->getSha1() != '') {
$vals['sha1'] = wfBaseConvert($revision->getSha1(), 36, 16, 40);
} else {
$vals['sha1'] = '';
}
}
}
if ($this->fld_contentmodel) {
$vals['contentmodel'] = $revision->getContentModel();
}
if ($this->fld_comment || $this->fld_parsedcomment) {
if ($revision->isDeleted(Revision::DELETED_COMMENT)) {
$vals['commenthidden'] = true;
$anyHidden = true;
}
if ($revision->userCan(Revision::DELETED_COMMENT, $user)) {
$comment = $revision->getComment(Revision::RAW);
if ($this->fld_comment) {
$vals['comment'] = $comment;
}
if ($this->fld_parsedcomment) {
$vals['parsedcomment'] = Linker::formatComment($comment, $title);
}
}
}
if ($this->fld_tags) {
if ($row->ts_tags) {
$tags = explode(',', $row->ts_tags);
ApiResult::setIndexedTagName($tags, 'tag');
$vals['tags'] = $tags;
} else {
$vals['tags'] = array();
}
}
$content = null;
global $wgParser;
if ($this->fetchContent) {
$content = $revision->getContent(Revision::FOR_THIS_USER, $this->getUser());
// Expand templates after getting section content because
// template-added sections don't count and Parser::preprocess()
// will have less input
if ($content && $this->section !== false) {
$content = $content->getSection($this->section, false);
if (!$content) {
//.........这里部分代码省略.........
示例3: assertRevEquals
protected function assertRevEquals(Revision $orig, Revision $rev = null)
{
$this->assertNotNull($rev, 'missing revision');
$this->assertEquals($orig->getId(), $rev->getId());
$this->assertEquals($orig->getPage(), $rev->getPage());
$this->assertEquals($orig->getTimestamp(), $rev->getTimestamp());
$this->assertEquals($orig->getUser(), $rev->getUser());
$this->assertEquals($orig->getContentModel(), $rev->getContentModel());
$this->assertEquals($orig->getContentFormat(), $rev->getContentFormat());
$this->assertEquals($orig->getSha1(), $rev->getSha1());
}
示例4: 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());
}
示例5: extractRowInfo
private function extractRowInfo($row)
{
$revision = new Revision($row);
$title = $revision->getTitle();
$vals = array();
if ($this->fld_ids) {
$vals['revid'] = intval($revision->getId());
// $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
if (!is_null($revision->getParentId())) {
$vals['parentid'] = intval($revision->getParentId());
}
}
if ($this->fld_flags && $revision->isMinor()) {
$vals['minor'] = '';
}
if ($this->fld_user || $this->fld_userid) {
if ($revision->isDeleted(Revision::DELETED_USER)) {
$vals['userhidden'] = '';
} else {
if ($this->fld_user) {
$vals['user'] = $revision->getUserText();
}
$userid = $revision->getUser();
if (!$userid) {
$vals['anon'] = '';
}
if ($this->fld_userid) {
$vals['userid'] = $userid;
}
}
}
if ($this->fld_timestamp) {
$vals['timestamp'] = wfTimestamp(TS_ISO_8601, $revision->getTimestamp());
}
if ($this->fld_size) {
if (!is_null($revision->getSize())) {
$vals['size'] = intval($revision->getSize());
} else {
$vals['size'] = 0;
}
}
if ($this->fld_sha1) {
if ($revision->getSha1() != '') {
$vals['sha1'] = wfBaseConvert($revision->getSha1(), 36, 16, 40);
} else {
$vals['sha1'] = '';
}
}
if ($this->fld_contentmodel) {
$vals['contentmodel'] = $revision->getContentModel();
}
if ($this->fld_comment || $this->fld_parsedcomment) {
if ($revision->isDeleted(Revision::DELETED_COMMENT)) {
$vals['commenthidden'] = '';
} else {
$comment = $revision->getComment();
if ($this->fld_comment) {
$vals['comment'] = $comment;
}
if ($this->fld_parsedcomment) {
$vals['parsedcomment'] = Linker::formatComment($comment, $title);
}
}
}
if ($this->fld_tags) {
if ($row->ts_tags) {
$tags = explode(',', $row->ts_tags);
$this->getResult()->setIndexedTagName($tags, 'tag');
$vals['tags'] = $tags;
} else {
$vals['tags'] = array();
}
}
if (!is_null($this->token)) {
$tokenFunctions = $this->getTokenFunctions();
foreach ($this->token as $t) {
$val = call_user_func($tokenFunctions[$t], $title->getArticleID(), $title, $revision);
if ($val === false) {
$this->setWarning("Action '{$t}' is not allowed for the current user");
} else {
$vals[$t . 'token'] = $val;
}
}
}
$content = null;
global $wgParser;
if ($this->fld_content || !is_null($this->difftotext)) {
$content = $revision->getContent();
// Expand templates after getting section content because
// template-added sections don't count and Parser::preprocess()
// will have less input
if ($this->section !== false) {
$content = $content->getSection($this->section, false);
if (!$content) {
$this->dieUsage("There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection');
}
}
}
if ($this->fld_content && !$revision->isDeleted(Revision::DELETED_TEXT)) {
$text = null;
//.........这里部分代码省略.........
示例6: updateRevisionOn
/**
* Update the page record to point to a newly saved revision.
*
* @param DatabaseBase $dbw
* @param Revision $revision For ID number, and text used to set
* length and redirect status fields
* @param int $lastRevision If given, will not overwrite the page field
* when different from the currently set value.
* Giving 0 indicates the new page flag should be set on.
* @param bool $lastRevIsRedirect If given, will optimize adding and
* removing rows in redirect table.
* @return bool True on success, false on failure
*/
public function updateRevisionOn($dbw, $revision, $lastRevision = null, $lastRevIsRedirect = null)
{
global $wgContentHandlerUseDB;
wfProfileIn(__METHOD__);
$content = $revision->getContent();
$len = $content ? $content->getSize() : 0;
$rt = $content ? $content->getUltimateRedirectTarget() : null;
$conditions = array('page_id' => $this->getId());
if (!is_null($lastRevision)) {
// An extra check against threads stepping on each other
$conditions['page_latest'] = $lastRevision;
}
$now = wfTimestampNow();
$row = array('page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp($now), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => $rt !== null ? 1 : 0, 'page_len' => $len);
if ($wgContentHandlerUseDB) {
$row['page_content_model'] = $revision->getContentModel();
}
$dbw->update('page', $row, $conditions, __METHOD__);
$result = $dbw->affectedRows() > 0;
if ($result) {
$this->updateRedirectOn($dbw, $rt, $lastRevIsRedirect);
$this->setLastEdit($revision);
$this->setCachedLastEditTime($now);
$this->mLatest = $revision->getId();
$this->mIsRedirect = (bool) $rt;
// Update the LinkCache.
LinkCache::singleton()->addGoodLinkObj($this->getId(), $this->mTitle, $len, $this->mIsRedirect, $this->mLatest, $revision->getContentModel());
}
wfProfileOut(__METHOD__);
return $result;
}