本文整理汇总了PHP中Revision::userWasLastToEdit方法的典型用法代码示例。如果您正苦于以下问题:PHP Revision::userWasLastToEdit方法的具体用法?PHP Revision::userWasLastToEdit怎么用?PHP Revision::userWasLastToEdit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Revision
的用法示例。
在下文中一共展示了Revision::userWasLastToEdit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: internalAttemptSave
//.........这里部分代码省略.........
$content = $textbox_content;
$result['sectionanchor'] = '';
if ($this->section == 'new') {
if ($this->sectiontitle !== '') {
// Insert the section title above the content.
$content = $content->addSectionHeader($this->sectiontitle);
} elseif ($this->summary !== '') {
// Insert the section title above the content.
$content = $content->addSectionHeader($this->summary);
}
$this->summary = $this->newSectionSummary($result['sectionanchor']);
}
$status->value = self::AS_SUCCESS_NEW_ARTICLE;
} else {
# not $new
# Article exists. Check for edit conflict.
$this->mArticle->clear();
# Force reload of dates, etc.
$timestamp = $this->mArticle->getTimestamp();
wfDebug("timestamp: {$timestamp}, edittime: {$this->edittime}\n");
if ($timestamp != $this->edittime) {
$this->isConflict = true;
if ($this->section == 'new') {
if ($this->mArticle->getUserText() == $wgUser->getName() && $this->mArticle->getComment() == $this->newSectionSummary()) {
// Probably a duplicate submission of a new comment.
// This can happen when squid resends a request after
// a timeout but the first one actually went through.
wfDebug(__METHOD__ . ": duplicate new section submission; trigger edit conflict!\n");
} else {
// New comment; suppress conflict.
$this->isConflict = false;
wfDebug(__METHOD__ . ": conflict suppressed; new section\n");
}
} elseif ($this->section == '' && Revision::userWasLastToEdit(DB_MASTER, $this->mTitle->getArticleID(), $wgUser->getId(), $this->edittime)) {
# Suppress edit conflict with self, except for section edits where merging is required.
wfDebug(__METHOD__ . ": Suppressing edit conflict, same user.\n");
$this->isConflict = false;
}
}
// If sectiontitle is set, use it, otherwise use the summary as the section title.
if ($this->sectiontitle !== '') {
$sectionTitle = $this->sectiontitle;
} else {
$sectionTitle = $this->summary;
}
$content = null;
if ($this->isConflict) {
wfDebug(__METHOD__ . ": conflict! getting section '{$this->section}' for time '{$this->edittime}'" . " (article time '{$timestamp}')\n");
$content = $this->mArticle->replaceSectionContent($this->section, $textbox_content, $sectionTitle, $this->edittime);
} else {
wfDebug(__METHOD__ . ": getting section '{$this->section}'\n");
$content = $this->mArticle->replaceSectionContent($this->section, $textbox_content, $sectionTitle);
}
if (is_null($content)) {
wfDebug(__METHOD__ . ": activating conflict; section replace failed.\n");
$this->isConflict = true;
$content = $textbox_content;
// do not try to merge here!
} elseif ($this->isConflict) {
# Attempt merge
if ($this->mergeChangesIntoContent($content)) {
// Successful merge! Maybe we should tell the user the good news?
$this->isConflict = false;
wfDebug(__METHOD__ . ": Suppressing edit conflict, successful merge.\n");
} else {
$this->section = '';
示例2: testUserWasLastToEdit
/**
* @dataProvider provideUserWasLastToEdit
*/
public function testUserWasLastToEdit($sinceIdx, $expectedLast)
{
$userA = User::newFromName("RevisionStorageTest_userA");
$userB = User::newFromName("RevisionStorageTest_userB");
if ($userA->getId() === 0) {
$userA = User::createNew($userA->getName());
}
if ($userB->getId() === 0) {
$userB = User::createNew($userB->getName());
}
$ns = $this->getDefaultWikitextNS();
$dbw = wfGetDB(DB_MASTER);
$revisions = [];
// create revisions -----------------------------
$page = WikiPage::factory(Title::newFromText('RevisionStorageTest_testUserWasLastToEdit', $ns));
$page->insertOn($dbw);
# zero
$revisions[0] = new Revision(['page' => $page->getId(), 'title' => $page->getTitle(), 'timestamp' => '20120101000000', 'user' => $userA->getId(), 'text' => 'zero', 'content_model' => CONTENT_MODEL_WIKITEXT, 'summary' => 'edit zero']);
$revisions[0]->insertOn($dbw);
# one
$revisions[1] = new Revision(['page' => $page->getId(), 'title' => $page->getTitle(), 'timestamp' => '20120101000100', 'user' => $userA->getId(), 'text' => 'one', 'content_model' => CONTENT_MODEL_WIKITEXT, 'summary' => 'edit one']);
$revisions[1]->insertOn($dbw);
# two
$revisions[2] = new Revision(['page' => $page->getId(), 'title' => $page->getTitle(), 'timestamp' => '20120101000200', 'user' => $userB->getId(), 'text' => 'two', 'content_model' => CONTENT_MODEL_WIKITEXT, 'summary' => 'edit two']);
$revisions[2]->insertOn($dbw);
# three
$revisions[3] = new Revision(['page' => $page->getId(), 'title' => $page->getTitle(), 'timestamp' => '20120101000300', 'user' => $userA->getId(), 'text' => 'three', 'content_model' => CONTENT_MODEL_WIKITEXT, 'summary' => 'edit three']);
$revisions[3]->insertOn($dbw);
# four
$revisions[4] = new Revision(['page' => $page->getId(), 'title' => $page->getTitle(), 'timestamp' => '20120101000200', 'user' => $userA->getId(), 'text' => 'zero', 'content_model' => CONTENT_MODEL_WIKITEXT, 'summary' => 'edit four']);
$revisions[4]->insertOn($dbw);
// test it ---------------------------------
$since = $revisions[$sinceIdx]->getTimestamp();
$wasLast = Revision::userWasLastToEdit($dbw, $page->getId(), $userA->getId(), $since);
$this->assertEquals($expectedLast, $wasLast);
}
示例3: internalAttemptSave
//.........这里部分代码省略.........
// passed.
if ($this->summary === '') {
$cleanSectionTitle = $wgParser->stripSectionName($this->sectiontitle);
$this->summary = wfMessage('newsectionsummary')->rawParams($cleanSectionTitle)->inContentLanguage()->text();
}
} elseif ($this->summary !== '') {
// Insert the section title above the content.
$text = wfMessage('newsectionheaderdefaultlevel', $this->summary)->inContentLanguage()->text() . "\n\n" . $text;
// Jump to the new section
$result['sectionanchor'] = $wgParser->guessLegacySectionNameFromWikiText($this->summary);
// Create a link to the new section from the edit summary.
$cleanSummary = $wgParser->stripSectionName($this->summary);
$this->summary = wfMessage('newsectionsummary')->rawParams($cleanSummary)->inContentLanguage()->text();
}
}
$status->value = self::AS_SUCCESS_NEW_ARTICLE;
} else {
# Article exists. Check for edit conflict.
$timestamp = $this->mArticle->getTimestamp();
wfDebug("timestamp: {$timestamp}, edittime: {$this->edittime}\n");
if ($timestamp != $this->edittime) {
$this->isConflict = true;
if ($this->section == 'new') {
if ($this->mArticle->getUserText() == $wgUser->getName() && $this->mArticle->getComment() == $this->summary) {
// Probably a duplicate submission of a new comment.
// This can happen when squid resends a request after
// a timeout but the first one actually went through.
wfDebug(__METHOD__ . ": duplicate new section submission; trigger edit conflict!\n");
} else {
// New comment; suppress conflict.
$this->isConflict = false;
wfDebug(__METHOD__ . ": conflict suppressed; new section\n");
}
} elseif ($this->section == '' && Revision::userWasLastToEdit(DB_MASTER, $this->mTitle->getArticleID(), $wgUser->getId(), $this->edittime)) {
# Suppress edit conflict with self, except for section edits where merging is required.
wfDebug(__METHOD__ . ": Suppressing edit conflict, same user.\n");
$this->isConflict = false;
}
}
// If sectiontitle is set, use it, otherwise use the summary as the section title (for
// backwards compatibility with old forms/bots).
if ($this->sectiontitle !== '') {
$sectionTitle = $this->sectiontitle;
} else {
$sectionTitle = $this->summary;
}
if ($this->isConflict) {
wfDebug(__METHOD__ . ": conflict! getting section '{$this->section}' for time '{$this->edittime}' (article time '{$timestamp}')\n");
$text = $this->mArticle->replaceSection($this->section, $this->textbox1, $sectionTitle, $this->edittime);
} else {
wfDebug(__METHOD__ . ": getting section '{$this->section}'\n");
$text = $this->mArticle->replaceSection($this->section, $this->textbox1, $sectionTitle);
}
if (is_null($text)) {
wfDebug(__METHOD__ . ": activating conflict; section replace failed.\n");
$this->isConflict = true;
$text = $this->textbox1;
// do not try to merge here!
} elseif ($this->isConflict) {
# Attempt merge
if ($this->mergeChangesInto($text)) {
// Successful merge! Maybe we should tell the user the good news?
$this->isConflict = false;
wfDebug(__METHOD__ . ": Suppressing edit conflict, successful merge.\n");
} else {
$this->section = '';