本文整理汇总了PHP中RequestContext::newExtraneousContext方法的典型用法代码示例。如果您正苦于以下问题:PHP RequestContext::newExtraneousContext方法的具体用法?PHP RequestContext::newExtraneousContext怎么用?PHP RequestContext::newExtraneousContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RequestContext
的用法示例。
在下文中一共展示了RequestContext::newExtraneousContext方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateCheckUserData
/**
* Hook function for RecentChange_save
* Saves user data into the cu_changes table
*/
public static function updateCheckUserData(RecentChange $rc)
{
global $wgRequest;
// Extract params
extract($rc->mAttribs);
// Get IP
$ip = wfGetIP();
// Get XFF header
$xff = $wgRequest->getHeader('X-Forwarded-For');
list($xff_ip, $isSquidOnly) = IP::getClientIPfromXFF($xff);
// Get agent
$agent = $wgRequest->getHeader('User-Agent');
// Store the log action text for log events
// $rc_comment should just be the log_comment
// BC: check if log_type and log_action exists
// If not, then $rc_comment is the actiontext and comment
if (isset($rc_log_type) && $rc_type == RC_LOG) {
$target = Title::makeTitle($rc_namespace, $rc_title);
$context = RequestContext::newExtraneousContext($target);
$formatter = LogFormatter::newFromRow($rc->mAttribs);
$formatter->setContext($context);
$actionText = $formatter->getPlainActionText();
} else {
$actionText = '';
}
$dbw = wfGetDB(DB_MASTER);
$cuc_id = $dbw->nextSequenceValue('cu_changes_cu_id_seq');
$rcRow = array('cuc_id' => $cuc_id, 'cuc_namespace' => $rc_namespace, 'cuc_title' => $rc_title, 'cuc_minor' => $rc_minor, 'cuc_user' => $rc_user, 'cuc_user_text' => $rc_user_text, 'cuc_actiontext' => $actionText, 'cuc_comment' => $rc_comment, 'cuc_this_oldid' => $rc_this_oldid, 'cuc_last_oldid' => $rc_last_oldid, 'cuc_type' => $rc_type, 'cuc_timestamp' => $rc_timestamp, 'cuc_ip' => IP::sanitizeIP($ip), 'cuc_ip_hex' => $ip ? IP::toHex($ip) : null, 'cuc_xff' => !$isSquidOnly ? $xff : '', 'cuc_xff_hex' => $xff_ip && !$isSquidOnly ? IP::toHex($xff_ip) : null, 'cuc_agent' => $agent);
# On PG, MW unsets cur_id due to schema incompatibilites. So it may not be set!
if (isset($rc_cur_id)) {
$rcRow['cuc_page_id'] = $rc_cur_id;
}
$dbw->insert('cu_changes', $rcRow, __METHOD__);
return true;
}
示例2: testSpecialPage
/**
* @dataProvider provideSpecialPages
*/
public function testSpecialPage($name)
{
$page = SpecialPageFactory::getPage($name);
$title = $page->getPageTitle();
$context = RequestContext::newExtraneousContext($title);
$page->setContext($context);
try {
$page->run(null);
} catch (PermissionsError $e) {
// This is okay
wfDebug('Permissions error caught; expected.');
} catch (ErrorPageError $e) {
// This is okay as well
wfDebug('Page error caught; expected.');
}
$this->assertTrue(true, "Special page {$name} was executed succesfully with anon user");
$user = new MockSuperUser();
$context->setUser($user);
$page->setContext($context);
// This should not throw permission errors
try {
$page->run(null);
} catch (ErrorPageError $e) {
// This is okay here
wfDebug('Page error caught; expected.');
}
$this->assertTrue(true, "Special page {$name} was executed succesfully with super user");
}
示例3: __construct
public function __construct()
{
parent::__construct();
$this->title = Title::newFromText('SomeTitle');
$this->target = Title::newFromText('TestTarget');
$this->user = User::newFromName('UserName');
$this->user_comment = '<User comment about action>';
$this->context = RequestContext::newExtraneousContext($this->title);
}
示例4: 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;
}
示例5: recordUpload2
/**
* Record a file upload in the upload log and the image table
* @param string $oldver
* @param string $comment
* @param string $pageText
* @param bool|array $props
* @param string|bool $timestamp
* @param null|User $user
* @param string[] $tags
* @return bool
*/
function recordUpload2($oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null, $tags = array())
{
if (is_null($user)) {
global $wgUser;
$user = $wgUser;
}
$dbw = $this->repo->getMasterDB();
# Imports or such might force a certain timestamp; otherwise we generate
# it and can fudge it slightly to keep (name,timestamp) unique on re-upload.
if ($timestamp === false) {
$timestamp = $dbw->timestamp();
$allowTimeKludge = true;
} else {
$allowTimeKludge = false;
}
$props = $props ?: $this->repo->getFileProps($this->getVirtualUrl());
$props['description'] = $comment;
$props['user'] = $user->getId();
$props['user_text'] = $user->getName();
$props['timestamp'] = wfTimestamp(TS_MW, $timestamp);
// DB -> TS_MW
$this->setProps($props);
# Fail now if the file isn't there
if (!$this->fileExists) {
wfDebug(__METHOD__ . ": File " . $this->getRel() . " went missing!\n");
return false;
}
$dbw->startAtomic(__METHOD__);
# Test to see if the row exists using INSERT IGNORE
# This avoids race conditions by locking the row until the commit, and also
# doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
$dbw->insert('image', array('img_name' => $this->getName(), 'img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $dbw->encodeBlob($this->metadata), 'img_sha1' => $this->sha1), __METHOD__, 'IGNORE');
$reupload = $dbw->affectedRows() == 0;
if ($reupload) {
if ($allowTimeKludge) {
# Use LOCK IN SHARE MODE to ignore any transaction snapshotting
$ltimestamp = $dbw->selectField('image', 'img_timestamp', array('img_name' => $this->getName()), __METHOD__, array('LOCK IN SHARE MODE'));
$lUnixtime = $ltimestamp ? wfTimestamp(TS_UNIX, $ltimestamp) : false;
# Avoid a timestamp that is not newer than the last version
# TODO: the image/oldimage tables should be like page/revision with an ID field
if ($lUnixtime && wfTimestamp(TS_UNIX, $timestamp) <= $lUnixtime) {
sleep(1);
// fast enough re-uploads would go far in the future otherwise
$timestamp = $dbw->timestamp($lUnixtime + 1);
$this->timestamp = wfTimestamp(TS_MW, $timestamp);
// DB -> TS_MW
}
}
# (bug 34993) Note: $oldver can be empty here, if the previous
# version of the file was broken. Allow registration of the new
# version to continue anyway, because that's better than having
# an image that's not fixable by user operations.
# Collision, this is an update of a file
# Insert previous contents into oldimage
$dbw->insertSelect('oldimage', 'image', array('oi_name' => 'img_name', 'oi_archive_name' => $dbw->addQuotes($oldver), 'oi_size' => 'img_size', 'oi_width' => 'img_width', 'oi_height' => 'img_height', 'oi_bits' => 'img_bits', 'oi_timestamp' => 'img_timestamp', 'oi_description' => 'img_description', 'oi_user' => 'img_user', 'oi_user_text' => 'img_user_text', 'oi_metadata' => 'img_metadata', 'oi_media_type' => 'img_media_type', 'oi_major_mime' => 'img_major_mime', 'oi_minor_mime' => 'img_minor_mime', 'oi_sha1' => 'img_sha1'), array('img_name' => $this->getName()), __METHOD__);
# Update the current image row
$dbw->update('image', array('img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $dbw->encodeBlob($this->metadata), 'img_sha1' => $this->sha1), array('img_name' => $this->getName()), __METHOD__);
}
$descTitle = $this->getTitle();
$descId = $descTitle->getArticleID();
$wikiPage = new WikiFilePage($descTitle);
$wikiPage->setFile($this);
// Add the log entry...
$logEntry = new ManualLogEntry('upload', $reupload ? 'overwrite' : 'upload');
$logEntry->setTimestamp($this->timestamp);
$logEntry->setPerformer($user);
$logEntry->setComment($comment);
$logEntry->setTarget($descTitle);
// Allow people using the api to associate log entries with the upload.
// Log has a timestamp, but sometimes different from upload timestamp.
$logEntry->setParameters(array('img_sha1' => $this->sha1, 'img_timestamp' => $timestamp));
// Note we keep $logId around since during new image
// creation, page doesn't exist yet, so log_page = 0
// but we want it to point to the page we're making,
// so we later modify the log entry.
// For a similar reason, we avoid making an RC entry
// now and wait until the page exists.
$logId = $logEntry->insert();
if ($descTitle->exists()) {
// Use own context to get the action text in content language
$formatter = LogFormatter::newFromEntry($logEntry);
$formatter->setContext(RequestContext::newExtraneousContext($descTitle));
$editSummary = $formatter->getPlainActionText();
$nullRevision = Revision::newNullRevision($dbw, $descId, $editSummary, false, $user);
if ($nullRevision) {
$nullRevision->insertOn($dbw);
Hooks::run('NewRevisionFromEditComplete', array($wikiPage, $nullRevision, $nullRevision->getParentId(), $user));
$wikiPage->updateRevisionOn($dbw, $nullRevision);
// Associate null revision id
//.........这里部分代码省略.........
示例6: addEntry
/**
* Add a log entry
*
* @param string $action One of '', 'block', 'protect', 'rights', 'delete',
* 'upload', 'move', 'move_redir'
* @param Title $target Title object
* @param string $comment Description associated
* @param array $params Parameters passed later to wfMessage function
* @param null|int|User $doer The user doing the action. null for $wgUser
*
* @return int The log_id of the inserted log entry
*/
public function addEntry($action, $target, $comment, $params = array(), $doer = null)
{
global $wgContLang;
if (!is_array($params)) {
$params = array($params);
}
if ($comment === null) {
$comment = '';
}
# Trim spaces on user supplied text
$comment = trim($comment);
# Truncate for whole multibyte characters.
$comment = $wgContLang->truncate($comment, 255);
$this->action = $action;
$this->target = $target;
$this->comment = $comment;
$this->params = LogPage::makeParamBlob($params);
if ($doer === null) {
global $wgUser;
$doer = $wgUser;
} elseif (!is_object($doer)) {
$doer = User::newFromId($doer);
}
$this->doer = $doer;
$logEntry = new ManualLogEntry($this->type, $action);
$logEntry->setTarget($target);
$logEntry->setPerformer($doer);
$logEntry->setParameters($params);
// All log entries using the LogPage to insert into the logging table
// are using the old logging system and therefore the legacy flag is
// needed to say the LogFormatter the parameters have numeric keys
$logEntry->setLegacy(true);
$formatter = LogFormatter::newFromEntry($logEntry);
$context = RequestContext::newExtraneousContext($target);
$formatter->setContext($context);
$this->actionText = $formatter->getPlainActionText();
$this->ircActionText = $formatter->getIRCActionText();
return $this->saveContent();
}
示例7: recordUpload2
/**
* Record a file upload in the upload log and the image table
*/
function recordUpload2($oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null)
{
if (is_null($user)) {
global $wgUser;
$user = $wgUser;
}
$dbw = $this->repo->getMasterDB();
$dbw->begin();
if (!$props) {
$props = $this->repo->getFileProps($this->getVirtualUrl());
}
$props['description'] = $comment;
$props['user'] = $user->getId();
$props['user_text'] = $user->getName();
$props['timestamp'] = wfTimestamp(TS_MW);
$this->setProps($props);
// Delete thumbnails and refresh the metadata cache
$this->purgeThumbnails();
$this->saveToCache();
SquidUpdate::purge(array($this->getURL()));
// Fail now if the file isn't there
if (!$this->fileExists) {
wfDebug(__METHOD__ . ": File " . $this->getPath() . " went missing!\n");
return false;
}
$reupload = false;
if ($timestamp === false) {
$timestamp = $dbw->timestamp();
}
# Test to see if the row exists using INSERT IGNORE
# This avoids race conditions by locking the row until the commit, and also
# doesn't deadlock. SELECT FOR UPDATE causes a deadlock for every race condition.
$dbw->insert('image', array('img_name' => $this->getName(), 'img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $this->metadata, 'img_sha1' => $this->sha1), __METHOD__, 'IGNORE');
if ($dbw->affectedRows() == 0) {
$reupload = true;
# Collision, this is an update of a file
# Insert previous contents into oldimage
$dbw->insertSelect('oldimage', 'image', array('oi_name' => 'img_name', 'oi_archive_name' => $dbw->addQuotes($oldver), 'oi_size' => 'img_size', 'oi_width' => 'img_width', 'oi_height' => 'img_height', 'oi_bits' => 'img_bits', 'oi_timestamp' => 'img_timestamp', 'oi_description' => 'img_description', 'oi_user' => 'img_user', 'oi_user_text' => 'img_user_text', 'oi_metadata' => 'img_metadata', 'oi_media_type' => 'img_media_type', 'oi_major_mime' => 'img_major_mime', 'oi_minor_mime' => 'img_minor_mime', 'oi_sha1' => 'img_sha1'), array('img_name' => $this->getName()), __METHOD__);
# Update the current image row
$dbw->update('image', array('img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $this->metadata, 'img_sha1' => $this->sha1), array('img_name' => $this->getName()), __METHOD__);
} else {
# This is a new file
# Update the image count
$site_stats = $dbw->tableName('site_stats');
$dbw->query("UPDATE {$site_stats} SET ss_images=ss_images+1", __METHOD__);
}
$descTitle = $this->getTitle();
$wikiPage = new WikiFilePage($descTitle);
$wikiPage->setFile($this);
# Add the log entry...
$action = $reupload ? 'overwrite' : 'upload';
$logEntry = new ManualLogEntry('upload', $action);
$logEntry->setTimestamp($this->timestamp);
$logEntry->setPerformer($user);
$logEntry->setComment($comment);
$logEntry->setTarget($descTitle);
// Allow people using the api to associate log entries with the upload.
// Log has a timestamp, but sometimes different from upload timestamp.
$logEntry->setParameters(array('img_sha1' => $this->sha1, 'img_timestamp' => $timestamp));
// Note we keep $logId around since during new image
// creation, page doesn't exist yet, so log_page = 0
// but we want it to point to the page we're making,
// so we later modify the log entry.
// For a similar reason, we avoid making an RC entry
// now and wait until the page exists.
$logId = $logEntry->insert();
$exists = $descTitle->exists();
if ($exists) {
// Page exists, do RC entry now (otherwise we wait for later).
$logEntry->publish($logId);
// TODO: same if statement twice? pointless?
//}
//if ( $exists ) {
// Create a null revision
$latest = $descTitle->getLatestRevID();
// Use own context to get the action text in content language
$formatter = LogFormatter::newFromEntry($logEntry);
$formatter->setContext(RequestContext::newExtraneousContext($descTitle));
$editSummary = $formatter->getPlainActionText();
$nullRevision = Revision::newNullRevision($dbw, $descTitle->getArticleID(), $editSummary, false, $user);
if (!is_null($nullRevision)) {
$nullRevision->insertOn($dbw);
Hooks::run('NewRevisionFromEditComplete', array($wikiPage, $nullRevision, $nullRevision->getParentId(), $user));
$wikiPage->updateRevisionOn($dbw, $nullRevision);
}
}
# Commit the transaction now, in case something goes wrong later
# The most important thing is that files don't get lost, especially archives
# NOTE: once we have support for nested transactions, the commit may be moved
# to after $wikiPage->doEdit has been called.
$dbw->commit(__METHOD__);
# Update memcache after the commit
$this->invalidateCache();
if ($exists) {
# Invalidate the cache for the description page
$descTitle->invalidateCache();
$descTitle->purgeSquid();
//.........这里部分代码省略.........
示例8: moveToInternal
/**
* Move page to a title which is either a redirect to the
* source page or nonexistent
*
* @param Title $nt The page to move to, which should be a redirect or nonexistent
* @param string $reason The reason for the move
* @param bool $createRedirect Whether to leave a redirect at the old title. Does not check
* if the user has the suppressredirect right
* @throws MWException
*/
private function moveToInternal(&$nt, $reason = '', $createRedirect = true)
{
global $wgUser, $wgContLang;
if ($nt->exists()) {
$moveOverRedirect = true;
$logType = 'move_redir';
} else {
$moveOverRedirect = false;
$logType = 'move';
}
if ($createRedirect) {
if ($this->getNamespace() == NS_CATEGORY && !wfMessage('category-move-redirect-override')->inContentLanguage()->isDisabled()) {
$redirectContent = new WikitextContent(wfMessage('category-move-redirect-override')->params($nt->getPrefixedText())->inContentLanguage()->plain());
} else {
$contentHandler = ContentHandler::getForTitle($this);
$redirectContent = $contentHandler->makeRedirectContent($nt, wfMessage('move-redirect-text')->inContentLanguage()->plain());
}
// NOTE: If this page's content model does not support redirects, $redirectContent will be null.
} else {
$redirectContent = null;
}
// bug 57084: log_page should be the ID of the *moved* page
$oldid = $this->getArticleID();
$logTitle = clone $this;
$logEntry = new ManualLogEntry('move', $logType);
$logEntry->setPerformer($wgUser);
$logEntry->setTarget($logTitle);
$logEntry->setComment($reason);
$logEntry->setParameters(array('4::target' => $nt->getPrefixedText(), '5::noredir' => $redirectContent ? '0' : '1'));
$formatter = LogFormatter::newFromEntry($logEntry);
$formatter->setContext(RequestContext::newExtraneousContext($this));
$comment = $formatter->getPlainActionText();
if ($reason) {
$comment .= wfMessage('colon-separator')->inContentLanguage()->text() . $reason;
}
# Truncate for whole multibyte characters.
$comment = $wgContLang->truncate($comment, 255);
$dbw = wfGetDB(DB_MASTER);
$newpage = WikiPage::factory($nt);
if ($moveOverRedirect) {
$newid = $nt->getArticleID();
$newcontent = $newpage->getContent();
# Delete the old redirect. We don't save it to history since
# by definition if we've got here it's rather uninteresting.
# We have to remove it so that the next step doesn't trigger
# a conflict on the unique namespace+title index...
$dbw->delete('page', array('page_id' => $newid), __METHOD__);
$newpage->doDeleteUpdates($newid, $newcontent);
}
# Save a null revision in the page's history notifying of the move
$nullRevision = Revision::newNullRevision($dbw, $oldid, $comment, true, $wgUser);
if (!is_object($nullRevision)) {
throw new MWException('No valid null revision produced in ' . __METHOD__);
}
$nullRevision->insertOn($dbw);
# Change the name of the target page:
$dbw->update('page', array('page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey()), array('page_id' => $oldid), __METHOD__);
// clean up the old title before reset article id - bug 45348
if (!$redirectContent) {
WikiPage::onArticleDelete($this);
}
$this->resetArticleID(0);
// 0 == non existing
$nt->resetArticleID($oldid);
$newpage->loadPageData(WikiPage::READ_LOCKING);
// bug 46397
$newpage->updateRevisionOn($dbw, $nullRevision);
wfRunHooks('NewRevisionFromEditComplete', array($newpage, $nullRevision, $nullRevision->getParentId(), $wgUser));
$newpage->doEditUpdates($nullRevision, $wgUser, array('changed' => false));
if (!$moveOverRedirect) {
WikiPage::onArticleCreate($nt);
}
# Recreate the redirect, this time in the other direction.
if ($redirectContent) {
$redirectArticle = WikiPage::factory($this);
$redirectArticle->loadFromRow(false, WikiPage::READ_LOCKING);
// bug 46397
$newid = $redirectArticle->insertOn($dbw);
if ($newid) {
// sanity
$this->resetArticleID($newid);
$redirectRevision = new Revision(array('title' => $this, 'page' => $newid, 'user_text' => $wgUser->getName(), 'user' => $wgUser->getId(), 'comment' => $comment, 'content' => $redirectContent));
$redirectRevision->insertOn($dbw);
$redirectArticle->updateRevisionOn($dbw, $redirectRevision, 0);
wfRunHooks('NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false, $wgUser));
$redirectArticle->doEditUpdates($redirectRevision, $wgUser, array('created' => true));
}
}
# Log the move
$logid = $logEntry->insert();
//.........这里部分代码省略.........
示例9: addEntry
/**
* Add a log entry
*
* @param $action String: one of '', 'block', 'protect', 'rights', 'delete', 'upload', 'move', 'move_redir'
* @param $target Title object
* @param $comment String: description associated
* @param $params Array: parameters passed later to wfMessage function
* @param $doer User object: the user doing the action
*
* @return int log_id of the inserted log entry
*/
public function addEntry($action, $target, $comment, $params = array(), $doer = null)
{
global $wgContLang;
if (!is_array($params)) {
$params = array($params);
}
if ($comment === null) {
$comment = '';
}
# Truncate for whole multibyte characters.
$comment = $wgContLang->truncate($comment, 255);
$this->action = $action;
$this->target = $target;
$this->comment = $comment;
$this->params = LogPage::makeParamBlob($params);
if ($doer === null) {
global $wgUser;
$doer = $wgUser;
} elseif (!is_object($doer)) {
$doer = User::newFromId($doer);
}
$this->doer = $doer;
$logEntry = new ManualLogEntry($this->type, $action);
$logEntry->setTarget($target);
$logEntry->setPerformer($doer);
$logEntry->setParameters($params);
$formatter = LogFormatter::newFromEntry($logEntry);
$context = RequestContext::newExtraneousContext($target);
$formatter->setContext($context);
$this->actionText = $formatter->getPlainActionText();
$this->ircActionText = $formatter->getIRCActionText();
return $this->saveContent();
}
示例10: moveToInternal
/**
* Move page to a title which is either a redirect to the
* source page or nonexistent
*
* @param $nt Title the page to move to, which should be a redirect or nonexistent
* @param $reason String The reason for the move
* @param $createRedirect Bool Whether to leave a redirect at the old title. Ignored
* if the user doesn't have the suppressredirect right
*/
private function moveToInternal(&$nt, $reason = '', $createRedirect = true)
{
global $wgUser, $wgContLang;
if ($nt->exists()) {
$moveOverRedirect = true;
$logType = 'move_redir';
} else {
$moveOverRedirect = false;
$logType = 'move';
}
$redirectSuppressed = !$createRedirect && $wgUser->isAllowed('suppressredirect');
$logEntry = new ManualLogEntry('move', $logType);
$logEntry->setPerformer($wgUser);
$logEntry->setTarget($this);
$logEntry->setComment($reason);
$logEntry->setParameters(array('4::target' => $nt->getPrefixedText(), '5::noredir' => $redirectSuppressed ? '1' : '0'));
$formatter = LogFormatter::newFromEntry($logEntry);
$formatter->setContext(RequestContext::newExtraneousContext($this));
$comment = $formatter->getPlainActionText();
if ($reason) {
$comment .= wfMsgForContent('colon-separator') . $reason;
}
# Truncate for whole multibyte characters.
$comment = $wgContLang->truncate($comment, 255);
$oldid = $this->getArticleID();
$latest = $this->getLatestRevID();
$dbw = wfGetDB(DB_MASTER);
$newpage = WikiPage::factory($nt);
if ($moveOverRedirect) {
$newid = $nt->getArticleID();
# Delete the old redirect. We don't save it to history since
# by definition if we've got here it's rather uninteresting.
# We have to remove it so that the next step doesn't trigger
# a conflict on the unique namespace+title index...
$dbw->delete('page', array('page_id' => $newid), __METHOD__);
$newpage->doDeleteUpdates($newid);
}
# Save a null revision in the page's history notifying of the move
$nullRevision = Revision::newNullRevision($dbw, $oldid, $comment, true);
if (!is_object($nullRevision)) {
throw new MWException('No valid null revision produced in ' . __METHOD__);
}
$nullRevId = $nullRevision->insertOn($dbw);
# Change the name of the target page:
$dbw->update('page', array('page_namespace' => $nt->getNamespace(), 'page_title' => $nt->getDBkey()), array('page_id' => $oldid), __METHOD__);
$this->resetArticleID(0);
$nt->resetArticleID($oldid);
$newpage->updateRevisionOn($dbw, $nullRevision);
wfRunHooks('NewRevisionFromEditComplete', array($newpage, $nullRevision, $latest, $wgUser));
$newpage->doEditUpdates($nullRevision, $wgUser, array('changed' => false));
if (!$moveOverRedirect) {
WikiPage::onArticleCreate($nt);
}
# Recreate the redirect, this time in the other direction.
if ($redirectSuppressed) {
WikiPage::onArticleDelete($this);
} else {
$mwRedir = MagicWord::get('redirect');
$redirectText = $mwRedir->getSynonym(0) . ' [[' . $nt->getPrefixedText() . "]]\n";
$redirectArticle = WikiPage::factory($this);
$newid = $redirectArticle->insertOn($dbw);
if ($newid) {
// sanity
$redirectRevision = new Revision(array('page' => $newid, 'comment' => $comment, 'text' => $redirectText));
$redirectRevision->insertOn($dbw);
$redirectArticle->updateRevisionOn($dbw, $redirectRevision, 0);
wfRunHooks('NewRevisionFromEditComplete', array($redirectArticle, $redirectRevision, false, $wgUser));
$redirectArticle->doEditUpdates($redirectRevision, $wgUser, array('created' => true));
}
}
# Log the move
$logid = $logEntry->insert();
$logEntry->publish($logid);
}
示例11: userCanVote
/**
* Checks if the user has already casted a vote
*
* @author ADi
* @return boolean true if no vote has been recorded for the user, false otherwise
*/
public function userCanVote()
{
$pageId = $this->getArticle()->getId();
$oContext = RequestContext::newExtraneousContext(RequestContext::getMain()->getTitle(), array("action" => "query", "list" => "wkvoteart", "wkpage" => $pageId, "wkuservote" => 1));
$oContext->setUser(F::app()->wg->User);
$oApi = new ApiMain($oContext, F::app()->wg->EnableWriteAPI);
$oApi->execute();
$aResult = $oApi->GetResultData();
if (isset($aResult['query']['wkvoteart'][$pageId]['uservote'])) {
$result = false;
} else {
$result = true;
}
return $result;
}
示例12: getRecentChange
/**
* Get a RecentChanges object for the log entry
* @param int $newId
* @return RecentChange
* @since 1.23
*/
public function getRecentChange($newId = 0)
{
$formatter = LogFormatter::newFromEntry($this);
$context = RequestContext::newExtraneousContext($this->getTarget());
$formatter->setContext($context);
$logpage = SpecialPage::getTitleFor('Log', $this->getType());
$user = $this->getPerformer();
$ip = "";
if ($user->isAnon()) {
/*
* "MediaWiki default" and friends may have
* no IP address in their name
*/
if (IP::isIPAddress($user->getName())) {
$ip = $user->getName();
}
}
return RecentChange::newLogEntry($this->getTimestamp(), $logpage, $user, $formatter->getPlainActionText(), $ip, $this->getType(), $this->getSubtype(), $this->getTarget(), $this->getComment(), LogEntryBase::makeParamBlob($this->getParameters()), $newId, $formatter->getIRCActionComment());
}
示例13: publish
/**
* Publishes the log entry.
* @param int $newId id of the log entry.
* @param string $to rcandudp (default), rc, udp
*/
public function publish($newId, $to = 'rcandudp')
{
$log = new LogPage($this->getType());
if ($log->isRestricted()) {
return;
}
$formatter = LogFormatter::newFromEntry($this);
$context = RequestContext::newExtraneousContext($this->getTarget());
$formatter->setContext($context);
$logpage = SpecialPage::getTitleFor('Log', $this->getType());
$user = $this->getPerformer();
$ip = "";
if ($user->isAnon()) {
/*
* "MediaWiki default" and friends may have
* no IP address in their name
*/
if (IP::isIPAddress($user->getName())) {
$ip = $user->getName();
}
}
$rc = RecentChange::newLogEntry($this->getTimestamp(), $logpage, $user, $formatter->getPlainActionText(), $ip, $this->getType(), $this->getSubtype(), $this->getTarget(), $this->getComment(), serialize((array) $this->getParameters()), $newId, $formatter->getIRCActionComment());
if ($to === 'rc' || $to === 'rcandudp') {
$rc->save('pleasedontudp');
}
if ($to === 'udp' || $to === 'rcandudp') {
$rc->notifyRC2UDP();
}
}
示例14: publish
/**
* Publishes the log entry.
* @param $newId int id of the log entry.
* @param $to string: rcandudp (default), rc, udp
*/
public function publish($newId, $to = 'rcandudp')
{
$log = new LogPage($this->getType());
if ($log->isRestricted()) {
return;
}
$formatter = LogFormatter::newFromEntry($this);
$context = RequestContext::newExtraneousContext($this->getTarget());
$formatter->setContext($context);
$logpage = SpecialPage::getTitleFor('Log', $this->getType());
$user = $this->getPerformer();
$rc = RecentChange::newLogEntry($this->getTimestamp(), $logpage, $user, $formatter->getPlainActionText(), $user->isAnon() ? $user->getName() : '', $this->getType(), $this->getSubtype(), $this->getTarget(), $this->getComment(), serialize((array) $this->getParameters()), $newId, $formatter->getIRCActionComment());
if ($to === 'rc' || $to === 'rcandudp') {
$rc->save('pleasedontudp');
}
if ($to === 'udp' || $to === 'rcandudp') {
$rc->notifyRC2UDP();
}
}
示例15: recordUpload2
//.........这里部分代码省略.........
$timestamp = $dbw->timestamp($lUnixtime + 1);
$this->timestamp = wfTimestamp(TS_MW, $timestamp);
// DB -> TS_MW
}
}
# (bug 34993) Note: $oldver can be empty here, if the previous
# version of the file was broken. Allow registration of the new
# version to continue anyway, because that's better than having
# an image that's not fixable by user operations.
$reupload = true;
# Collision, this is an update of a file
# Insert previous contents into oldimage
$dbw->insertSelect('oldimage', 'image', array('oi_name' => 'img_name', 'oi_archive_name' => $dbw->addQuotes($oldver), 'oi_size' => 'img_size', 'oi_width' => 'img_width', 'oi_height' => 'img_height', 'oi_bits' => 'img_bits', 'oi_timestamp' => 'img_timestamp', 'oi_description' => 'img_description', 'oi_user' => 'img_user', 'oi_user_text' => 'img_user_text', 'oi_metadata' => 'img_metadata', 'oi_media_type' => 'img_media_type', 'oi_major_mime' => 'img_major_mime', 'oi_minor_mime' => 'img_minor_mime', 'oi_sha1' => 'img_sha1'), array('img_name' => $this->getName()), __METHOD__);
# Update the current image row
$dbw->update('image', array('img_size' => $this->size, 'img_width' => intval($this->width), 'img_height' => intval($this->height), 'img_bits' => $this->bits, 'img_media_type' => $this->media_type, 'img_major_mime' => $this->major_mime, 'img_minor_mime' => $this->minor_mime, 'img_timestamp' => $timestamp, 'img_description' => $comment, 'img_user' => $user->getId(), 'img_user_text' => $user->getName(), 'img_metadata' => $dbw->encodeBlob($this->metadata), 'img_sha1' => $this->sha1), array('img_name' => $this->getName()), __METHOD__);
} else {
# This is a new file, so update the image count
DeferredUpdates::addUpdate(SiteStatsUpdate::factory(array('images' => 1)));
}
$descTitle = $this->getTitle();
$wikiPage = new WikiFilePage($descTitle);
$wikiPage->setFile($this);
# Add the log entry
$action = $reupload ? 'overwrite' : 'upload';
$logEntry = new ManualLogEntry('upload', $action);
$logEntry->setPerformer($user);
$logEntry->setComment($comment);
$logEntry->setTarget($descTitle);
// Allow people using the api to associate log entries with the upload.
// Log has a timestamp, but sometimes different from upload timestamp.
$logEntry->setParameters(array('img_sha1' => $this->sha1, 'img_timestamp' => $timestamp));
// Note we keep $logId around since during new image
// creation, page doesn't exist yet, so log_page = 0
// but we want it to point to the page we're making,
// so we later modify the log entry.
// For a similar reason, we avoid making an RC entry
// now and wait until the page exists.
$logId = $logEntry->insert();
$exists = $descTitle->exists();
if ($exists) {
// Page exists, do RC entry now (otherwise we wait for later).
$logEntry->publish($logId);
}
if ($exists) {
# Create a null revision
$latest = $descTitle->getLatestRevID();
// Use own context to get the action text in content language
$formatter = LogFormatter::newFromEntry($logEntry);
$formatter->setContext(RequestContext::newExtraneousContext($descTitle));
$editSummary = $formatter->getPlainActionText();
$nullRevision = Revision::newNullRevision($dbw, $descTitle->getArticleID(), $editSummary, false, $user);
if (!is_null($nullRevision)) {
$nullRevision->insertOn($dbw);
Hooks::run('NewRevisionFromEditComplete', array($wikiPage, $nullRevision, $latest, $user));
$wikiPage->updateRevisionOn($dbw, $nullRevision);
}
}
# Commit the transaction now, in case something goes wrong later
# The most important thing is that files don't get lost, especially archives
# NOTE: once we have support for nested transactions, the commit may be moved
# to after $wikiPage->doEdit has been called.
$dbw->commit(__METHOD__);
# Update memcache after the commit
$this->invalidateCache();
if ($exists) {
# Invalidate the cache for the description page
$descTitle->invalidateCache();
$descTitle->purgeSquid();
} else {
# New file; create the description page.
# There's already a log entry, so don't make a second RC entry
# Squid and file cache for the description page are purged by doEditContent.
$content = ContentHandler::makeContent($pageText, $descTitle);
$status = $wikiPage->doEditContent($content, $comment, EDIT_NEW | EDIT_SUPPRESS_RC, false, $user);
$dbw->begin(__METHOD__);
// XXX; doEdit() uses a transaction
// Now that the page exists, make an RC entry.
$logEntry->publish($logId);
if (isset($status->value['revision'])) {
$dbw->update('logging', array('log_page' => $status->value['revision']->getPage()), array('log_id' => $logId), __METHOD__);
}
$dbw->commit(__METHOD__);
// commit before anything bad can happen
}
if ($reupload) {
# Delete old thumbnails
$this->purgeThumbnails();
# Remove the old file from the squid cache
SquidUpdate::purge(array($this->getURL()));
}
# Hooks, hooks, the magic of hooks...
Hooks::run('FileUpload', array($this, $reupload, $descTitle->exists()));
# Invalidate cache for all pages using this file
$update = new HTMLCacheUpdate($this->getTitle(), 'imagelinks');
$update->doUpdate();
if (!$reupload) {
LinksUpdate::queueRecursiveJobsForTable($this->getTitle(), 'imagelinks');
}
return true;
}