本文整理汇总了PHP中DeferredUpdates::addCallableUpdate方法的典型用法代码示例。如果您正苦于以下问题:PHP DeferredUpdates::addCallableUpdate方法的具体用法?PHP DeferredUpdates::addCallableUpdate怎么用?PHP DeferredUpdates::addCallableUpdate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DeferredUpdates
的用法示例。
在下文中一共展示了DeferredUpdates::addCallableUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: enableCXBetaFeature
public function enableCXBetaFeature()
{
$user = $this->getUser();
$out = $this->getOutput();
$user->setOption('cx', '1');
// Promise to persist the setting post-send
DeferredUpdates::addCallableUpdate(function () use($user) {
$user->saveSettings();
});
$out->addModules('ext.cx.beta.notification');
}
开发者ID:Rjaylyn,项目名称:mediawiki-extensions-ContentTranslation,代码行数:11,代码来源:SpecialContentTranslation.php
示例2: execute
public function execute()
{
$user = $this->getUser();
if ($this->getRequest()->wasPosted()) {
$user->setNewtalk(false);
} else {
DeferredUpdates::addCallableUpdate(function () use($user) {
$user->setNewtalk(false);
});
}
$this->getResult()->addValue(null, $this->getModuleName(), 'success');
}
示例3: execute
public function execute($par)
{
$this->useTransactionalTimeLimit();
$this->checkReadOnly();
$this->setHeaders();
$this->outputHeader();
$request = $this->getRequest();
$target = !is_null($par) ? $par : $request->getVal('target');
// Yes, the use of getVal() and getText() is wanted, see bug 20365
$oldTitleText = $request->getVal('wpOldTitle', $target);
$this->oldTitle = Title::newFromText($oldTitleText);
if (!$this->oldTitle) {
// Either oldTitle wasn't passed, or newFromText returned null
throw new ErrorPageError('notargettitle', 'notargettext');
}
if (!$this->oldTitle->exists()) {
throw new ErrorPageError('nopagetitle', 'nopagetext');
}
$newTitleTextMain = $request->getText('wpNewTitleMain');
$newTitleTextNs = $request->getInt('wpNewTitleNs', $this->oldTitle->getNamespace());
// Backwards compatibility for forms submitting here from other sources
// which is more common than it should be..
$newTitleText_bc = $request->getText('wpNewTitle');
$this->newTitle = strlen($newTitleText_bc) > 0 ? Title::newFromText($newTitleText_bc) : Title::makeTitleSafe($newTitleTextNs, $newTitleTextMain);
$user = $this->getUser();
# Check rights
$permErrors = $this->oldTitle->getUserPermissionsErrors('move', $user);
if (count($permErrors)) {
// Auto-block user's IP if the account was "hard" blocked
DeferredUpdates::addCallableUpdate(function () use($user) {
$user->spreadAnyEditBlock();
});
throw new PermissionsError('move', $permErrors);
}
$def = !$request->wasPosted();
$this->reason = $request->getText('wpReason');
$this->moveTalk = $request->getBool('wpMovetalk', $def);
$this->fixRedirects = $request->getBool('wpFixRedirects', $def);
$this->leaveRedirect = $request->getBool('wpLeaveRedirect', $def);
$this->moveSubpages = $request->getBool('wpMovesubpages', false);
$this->deleteAndMove = $request->getBool('wpDeleteAndMove') && $request->getBool('wpConfirm');
$this->moveOverShared = $request->getBool('wpMoveOverSharedFile', false);
$this->watch = $request->getCheck('wpWatch') && $user->isLoggedIn();
if ('submit' == $request->getVal('action') && $request->wasPosted() && $user->matchEditToken($request->getVal('wpEditToken'))) {
$this->doSubmit();
} else {
$this->showForm(array());
}
}
示例4: doUpdate
public function doUpdate()
{
global $wgSiteStatsAsyncFactor;
$this->doUpdateContextStats();
$rate = $wgSiteStatsAsyncFactor;
// convenience
// If set to do so, only do actual DB updates 1 every $rate times.
// The other times, just update "pending delta" values in memcached.
if ($rate && ($rate < 0 || mt_rand(0, $rate - 1) != 0)) {
$this->doUpdatePendingDeltas();
} else {
// Need a separate transaction because this a global lock
DeferredUpdates::addCallableUpdate([$this, 'tryDBUpdateInternal']);
}
}
示例5: testDoUpdates
public function testDoUpdates()
{
$updates = array('1' => 'deferred update 1', '2' => 'deferred update 2', '3' => 'deferred update 3', '2-1' => 'deferred update 1 within deferred update 2');
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['1'];
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['2'];
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['2-1'];
});
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates[3];
});
$this->expectOutputString(implode('', $updates));
DeferredUpdates::doUpdates();
}
示例6: testDoUpdatesCLI
public function testDoUpdatesCLI()
{
$this->setMwGlobals('wgCommandLineMode', true);
$updates = array('1' => 'deferred update 1', '2' => 'deferred update 2', '2-1' => 'deferred update 1 within deferred update 2', '3' => 'deferred update 3');
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['1'];
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['2'];
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['2-1'];
});
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates[3];
});
$this->expectOutputString(implode('', $updates));
DeferredUpdates::doUpdates();
}
示例7: executeWhenAvailable
/**
* Render the special page
* @param string $par parameter submitted as subpage
*/
function executeWhenAvailable($par)
{
// Anons don't get a watchlist
$this->requireLogin('mobile-frontend-watchlist-purpose');
$ctx = MobileContext::singleton();
$this->usePageImages = !$ctx->imagesDisabled() && defined('PAGE_IMAGES_INSTALLED');
$user = $this->getUser();
$output = $this->getOutput();
$output->addModules('skins.minerva.special.watchlist.scripts');
// FIXME: Loads twice with JS enabled (T87871)
$output->addModuleStyles(array('skins.minerva.special.watchlist.styles', 'mobile.pagelist.styles', 'mobile.pagesummary.styles'));
$req = $this->getRequest();
$this->view = $req->getVal('watchlistview', 'a-z');
$this->filter = $req->getVal('filter', 'all');
$this->fromPageTitle = Title::newFromText($req->getVal('from', false));
$output->setPageTitle($this->msg('watchlist'));
// This needs to be done before calling getWatchlistHeader
$this->updateStickyTabs();
if ($this->optionsChanged) {
DeferredUpdates::addCallableUpdate(function () use($user) {
$user->saveSettings();
});
}
if ($this->view === 'feed') {
$output->addHtml($this->getWatchlistHeader($user));
$output->addHtml(Html::openElement('div', array('class' => 'content-unstyled')));
$this->showRecentChangesHeader();
$res = $this->doFeedQuery();
if ($res->numRows()) {
$this->showFeedResults($res);
} else {
$this->showEmptyList(true);
}
$output->addHtml(Html::closeElement('div'));
} else {
$output->redirect(SpecialPage::getTitleFor('EditWatchlist')->getLocalURL());
}
}
示例8: testDoUpdatesCLI
public function testDoUpdatesCLI()
{
$this->setMwGlobals('wgCommandLineMode', true);
$updates = ['1' => "deferred update 1;\n", '2' => "deferred update 2;\n", '2-1' => "deferred update 1 within deferred update 2;\n", '2-2' => "deferred update 2 within deferred update 2;\n", '3' => "deferred update 3;\n", '3-1' => "deferred update 1 within deferred update 3;\n", '3-2' => "deferred update 2 within deferred update 3;\n", '3-1-1' => "deferred update 1 within deferred update 1 within deferred update 3;\n", '3-2-1' => "deferred update 1 within deferred update 2 with deferred update 3;\n"];
wfGetLBFactory()->commitMasterChanges(__METHOD__);
// clear anything
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['1'];
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['2'];
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['2-1'];
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['2-2'];
});
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['3'];
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['3-1'];
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['3-1-1'];
});
});
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['3-2'];
DeferredUpdates::addCallableUpdate(function () use($updates) {
echo $updates['3-2-1'];
});
});
});
$this->expectOutputString(implode('', $updates));
DeferredUpdates::doUpdates();
}
示例9: trackGroup
/**
* Keeps track of recently used message groups per user.
*/
public static function trackGroup(MessageGroup $group, User $user)
{
if ($user->isAnon()) {
return true;
}
$groups = $user->getOption('translate-recent-groups', '');
if ($groups === '') {
$groups = array();
} else {
$groups = explode('|', $groups);
}
if (isset($groups[0]) && $groups[0] === $group->getId()) {
return true;
}
array_unshift($groups, $group->getId());
$groups = array_unique($groups);
$groups = array_slice($groups, 0, 5);
$user->setOption('translate-recent-groups', implode('|', $groups));
// Promise to persist the data post-send
DeferredUpdates::addCallableUpdate(function () use($user) {
$user->saveSettings();
});
return true;
}
示例10: cleanupWatchlist
/**
* Attempts to clean up broken items
*/
private function cleanupWatchlist()
{
if (!count($this->badItems)) {
return;
// nothing to do
}
$user = $this->getUser();
$badItems = $this->badItems;
DeferredUpdates::addCallableUpdate(function () use($user, $badItems) {
$store = MediaWikiServices::getInstance()->getWatchedItemStore();
foreach ($badItems as $row) {
list($title, $namespace, $dbKey) = $row;
$action = $title ? 'cleaning up' : 'deleting';
wfDebug("User {$user->getName()} has broken watchlist item " . "ns({$namespace}):{$dbKey}, {$action}.\n");
$store->removeWatch($user, new TitleValue((int) $namespace, $dbKey));
// Can't just do an UPDATE instead of DELETE/INSERT due to unique index
if ($title) {
$user->addWatch($title);
}
}
});
}
示例11: initialize
/**
* Set up all member variables using a database query.
* @throws MWException
* @return bool True on success, false on failure.
*/
protected function initialize()
{
if ($this->mName === null && $this->mID === null) {
throw new MWException(__METHOD__ . ' has both names and IDs null');
} elseif ($this->mID === null) {
$where = ['cat_title' => $this->mName];
} elseif ($this->mName === null) {
$where = ['cat_id' => $this->mID];
} else {
# Already initialized
return true;
}
$dbr = wfGetDB(DB_REPLICA);
$row = $dbr->selectRow('category', ['cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files'], $where, __METHOD__);
if (!$row) {
# Okay, there were no contents. Nothing to initialize.
if ($this->mTitle) {
# If there is a title object but no record in the category table,
# treat this as an empty category.
$this->mID = false;
$this->mName = $this->mTitle->getDBkey();
$this->mPages = 0;
$this->mSubcats = 0;
$this->mFiles = 0;
# If the title exists, call refreshCounts to add a row for it.
if ($this->mTitle->exists()) {
DeferredUpdates::addCallableUpdate([$this, 'refreshCounts']);
}
return true;
} else {
return false;
# Fail
}
}
$this->mID = $row->cat_id;
$this->mName = $row->cat_title;
$this->mPages = $row->cat_pages;
$this->mSubcats = $row->cat_subcats;
$this->mFiles = $row->cat_files;
# (bug 13683) If the count is negative, then 1) it's obviously wrong
# and should not be kept, and 2) we *probably* don't have to scan many
# rows to obtain the correct figure, so let's risk a one-time recount.
if ($this->mPages < 0 || $this->mSubcats < 0 || $this->mFiles < 0) {
$this->mPages = max($this->mPages, 0);
$this->mSubcats = max($this->mSubcats, 0);
$this->mFiles = max($this->mFiles, 0);
DeferredUpdates::addCallableUpdate([$this, 'refreshCounts']);
}
return true;
}
示例12: schedulePingback
/**
* Schedule a deferred callable that will check if a pingback should be
* sent and (if so) proceed to send it.
*/
public static function schedulePingback()
{
DeferredUpdates::addCallableUpdate(function () {
$instance = new Pingback();
if ($instance->shouldSend()) {
$instance->sendPingback();
}
});
}
示例13: notify
/**
* Processes notifications for a newly-created EchoEvent
*
* @param $event EchoEvent to do notifications for
* @param $defer bool Defer to job queue
*/
public static function notify($event, $defer = true)
{
if ($defer) {
// defer job insertion till end of request when all primary db transactions
// have been committed
DeferredUpdates::addCallableUpdate(function () use($event) {
global $wgEchoCluster;
$params = array('event' => $event);
if (wfGetLB()->getServerCount() > 1) {
$params['mainDbMasterPos'] = wfGetLB()->getMasterPos();
}
if ($wgEchoCluster) {
$lb = wfGetLBFactory()->getExternalLB($wgEchoCluster);
if ($lb->getServerCount() > 1) {
$params['echoDbMasterPos'] = $lb->getMasterPos();
}
}
$title = $event->getTitle() ? $event->getTitle() : Title::newMainPage();
$job = new EchoNotificationJob($title, $params);
JobQueueGroup::singleton()->push($job);
});
return;
}
// Check if the event object has valid event type. Events with invalid
// event types left in the job queue should not be processed
if (!$event->isEnabledEvent()) {
return;
}
// Only send web notification for welcome event
if ($event->getType() == 'welcome') {
self::doNotification($event, $event->getAgent(), 'web');
} else {
// Get the notification types for this event, eg, web/email
global $wgEchoDefaultNotificationTypes;
$notifyTypes = $wgEchoDefaultNotificationTypes['all'];
if (isset($wgEchoDefaultNotificationTypes[$event->getType()])) {
$notifyTypes = array_merge($notifyTypes, $wgEchoDefaultNotificationTypes[$event->getType()]);
}
$notifyTypes = array_keys(array_filter($notifyTypes));
$users = self::getUsersToNotifyForEvent($event);
$blacklisted = self::isBlacklisted($event);
foreach ($users as $user) {
//XXCHANGEDXX - allow anons [sc|rs]
// Notification should not be sent to anonymous user
// if ( $user->isAnon() ) {
// continue;
// }
if ($blacklisted && !self::isWhitelistedByUser($event, $user)) {
continue;
}
wfRunHooks('EchoGetNotificationTypes', array($user, $event, &$notifyTypes));
foreach ($notifyTypes as $type) {
self::doNotification($event, $user, $type);
}
}
}
}
示例14: updateWatchlist
/**
* Register the change of watch status
*/
protected function updateWatchlist()
{
global $wgUser;
if (!$wgUser->isLoggedIn()) {
return;
}
$user = $wgUser;
$title = $this->mTitle;
$watch = $this->watchthis;
// Do this in its own transaction to reduce contention...
DeferredUpdates::addCallableUpdate(function () use($user, $title, $watch) {
if ($watch == $user->isWatched($title, WatchedItem::IGNORE_USER_RIGHTS)) {
return;
// nothing to change
}
WatchAction::doWatchOrUnwatch($watch, $title, $user);
});
}
示例15: beginPrimaryAuthentication
public function beginPrimaryAuthentication(array $reqs)
{
$req = AuthenticationRequest::getRequestByClass($reqs, PasswordAuthenticationRequest::class);
if (!$req) {
return AuthenticationResponse::newAbstain();
}
if ($req->username === null || $req->password === null) {
return AuthenticationResponse::newAbstain();
}
$username = User::getCanonicalName($req->username, 'usable');
if ($username === false) {
return AuthenticationResponse::newAbstain();
}
$fields = ['user_id', 'user_password', 'user_password_expires'];
$dbr = wfGetDB(DB_REPLICA);
$row = $dbr->selectRow('user', $fields, ['user_name' => $username], __METHOD__);
if (!$row) {
return AuthenticationResponse::newAbstain();
}
$oldRow = clone $row;
// Check for *really* old password hashes that don't even have a type
// The old hash format was just an md5 hex hash, with no type information
if (preg_match('/^[0-9a-f]{32}$/', $row->user_password)) {
if ($this->config->get('PasswordSalt')) {
$row->user_password = ":A:{$row->user_id}:{$row->user_password}";
} else {
$row->user_password = ":A:{$row->user_password}";
}
}
$status = $this->checkPasswordValidity($username, $req->password);
if (!$status->isOK()) {
// Fatal, can't log in
return AuthenticationResponse::newFail($status->getMessage());
}
$pwhash = $this->getPassword($row->user_password);
if (!$pwhash->equals($req->password)) {
if ($this->config->get('LegacyEncoding')) {
// Some wikis were converted from ISO 8859-1 to UTF-8, the passwords can't be converted
// Check for this with iconv
$cp1252Password = iconv('UTF-8', 'WINDOWS-1252//TRANSLIT', $req->password);
if ($cp1252Password === $req->password || !$pwhash->equals($cp1252Password)) {
return $this->failResponse($req);
}
} else {
return $this->failResponse($req);
}
}
// @codeCoverageIgnoreStart
if ($this->getPasswordFactory()->needsUpdate($pwhash)) {
$pwhash = $this->getPasswordFactory()->newFromPlaintext($req->password);
\DeferredUpdates::addCallableUpdate(function () use($pwhash, $oldRow) {
$dbw = wfGetDB(DB_MASTER);
$dbw->update('user', ['user_password' => $pwhash->toString()], ['user_id' => $oldRow->user_id, 'user_password' => $oldRow->user_password], __METHOD__);
});
}
// @codeCoverageIgnoreEnd
$this->setPasswordResetFlag($username, $status, $row);
return AuthenticationResponse::newPass($username);
}