/**
  * Updates cache as necessary when message page is changed
  *
  * @param string $title name of the page changed.
  * @param $text Mixed: new contents of the page.
  */
 public function replace($title, $text)
 {
     global $wgMaxMsgCacheEntrySize;
     wfProfileIn(__METHOD__);
     if ($this->mDisable) {
         wfProfileOut(__METHOD__);
         return;
     }
     list($msg, $code) = $this->figureMessage($title);
     $cacheKey = wfMemcKey('messages', $code);
     $this->load($code);
     $this->lock($cacheKey);
     $titleKey = wfMemcKey('messages', 'individual', $title);
     if ($text === false) {
         # Article was deleted
         $this->mCache[$code][$title] = '!NONEXISTENT';
         $this->mMemc->delete($titleKey);
     } elseif (strlen($text) > $wgMaxMsgCacheEntrySize) {
         # Check for size
         $this->mCache[$code][$title] = '!TOO BIG';
         $this->mMemc->set($titleKey, ' ' . $text, $this->mExpiry);
     } else {
         $this->mCache[$code][$title] = ' ' . $text;
         $this->mMemc->delete($titleKey);
     }
     # Update caches
     $this->saveToCaches($this->mCache[$code], true, $code);
     $this->unlock($cacheKey);
     // Also delete cached sidebar... just in case it is affected
     $codes = array($code);
     if ($code === 'en') {
         // Delete all sidebars, like for example on action=purge on the
         // sidebar messages
         $codes = array_keys(Language::fetchLanguageNames());
     }
     global $wgMemc;
     foreach ($codes as $code) {
         $sidebarKey = wfMemcKey('sidebar', $code);
         $wgMemc->delete($sidebarKey);
     }
     // Update the message in the message blob store
     global $wgContLang;
     MessageBlobStore::updateMessage($wgContLang->lcfirst($msg));
     wfRunHooks('MessageCacheReplace', array($title, $text));
     wfProfileOut(__METHOD__);
 }
 /**
  * Updates cache as necessary when message page is changed
  *
  * @param string|bool $title Name of the page changed (false if deleted)
  * @param mixed $text New contents of the page.
  */
 public function replace($title, $text)
 {
     global $wgMaxMsgCacheEntrySize, $wgContLang, $wgLanguageCode;
     if ($this->mDisable) {
         return;
     }
     list($msg, $code) = $this->figureMessage($title);
     if (strpos($title, '/') !== false && $code === $wgLanguageCode) {
         // Content language overrides do not use the /<code> suffix
         return;
     }
     // Note that if the cache is volatile, load() may trigger a DB fetch.
     // In that case we reenter/reuse the existing cache key lock to avoid
     // a self-deadlock. This is safe as no reads happen *directly* in this
     // method between getReentrantScopedLock() and load() below. There is
     // no risk of data "changing under our feet" for replace().
     $cacheKey = wfMemcKey('messages', $code);
     $scopedLock = $this->getReentrantScopedLock($cacheKey);
     $this->load($code, self::FOR_UPDATE);
     $titleKey = wfMemcKey('messages', 'individual', $title);
     if ($text === false) {
         // Article was deleted
         $this->mCache[$code][$title] = '!NONEXISTENT';
         $this->wanCache->delete($titleKey);
     } elseif (strlen($text) > $wgMaxMsgCacheEntrySize) {
         // Check for size
         $this->mCache[$code][$title] = '!TOO BIG';
         $this->wanCache->set($titleKey, ' ' . $text, $this->mExpiry);
     } else {
         $this->mCache[$code][$title] = ' ' . $text;
         $this->wanCache->delete($titleKey);
     }
     // Mark this cache as definitely "latest" (non-volatile) so
     // load() calls do try to refresh the cache with slave data
     $this->mCache[$code]['LATEST'] = time();
     // Update caches if the lock was acquired
     if ($scopedLock) {
         $this->saveToCaches($this->mCache[$code], 'all', $code);
     }
     ScopedCallback::consume($scopedLock);
     // Relay the purge to APC and other DCs
     $this->wanCache->touchCheckKey(wfMemcKey('messages', $code));
     // Also delete cached sidebar... just in case it is affected
     $codes = array($code);
     if ($code === 'en') {
         // Delete all sidebars, like for example on action=purge on the
         // sidebar messages
         $codes = array_keys(Language::fetchLanguageNames());
     }
     foreach ($codes as $code) {
         $sidebarKey = wfMemcKey('sidebar', $code);
         $this->wanCache->delete($sidebarKey, 5);
     }
     // Update the message in the message blob store
     $blobStore = new MessageBlobStore();
     $blobStore->updateMessage($wgContLang->lcfirst($msg));
     Hooks::run('MessageCacheReplace', array($title, $text));
 }
Exemple #3
0
 /**
  * Updates cache as necessary when message page is changed
  *
  * @param string $title Name of the page changed.
  * @param mixed $text New contents of the page.
  */
 public function replace($title, $text)
 {
     global $wgMaxMsgCacheEntrySize, $wgContLang, $wgLanguageCode;
     if ($this->mDisable) {
         return;
     }
     list($msg, $code) = $this->figureMessage($title);
     if (strpos($title, '/') !== false && $code === $wgLanguageCode) {
         # Content language overrides do not use the /<code> suffix
         return;
     }
     $cacheKey = wfMemcKey('messages', $code);
     $this->lock($cacheKey);
     $this->load($code, self::FOR_UPDATE);
     $titleKey = wfMemcKey('messages', 'individual', $title);
     if ($text === false) {
         # Article was deleted
         $this->mCache[$code][$title] = '!NONEXISTENT';
         $this->mMemc->delete($titleKey);
     } elseif (strlen($text) > $wgMaxMsgCacheEntrySize) {
         # Check for size
         $this->mCache[$code][$title] = '!TOO BIG';
         $this->mMemc->set($titleKey, ' ' . $text, $this->mExpiry);
     } else {
         $this->mCache[$code][$title] = ' ' . $text;
         $this->mMemc->delete($titleKey);
     }
     # Update caches
     $this->saveToCaches($this->mCache[$code], 'all', $code);
     $this->unlock($cacheKey);
     $this->wanCache->touchCheckKey(wfMemcKey('messages', $code));
     // Also delete cached sidebar... just in case it is affected
     $codes = array($code);
     if ($code === 'en') {
         // Delete all sidebars, like for example on action=purge on the
         // sidebar messages
         $codes = array_keys(Language::fetchLanguageNames());
     }
     foreach ($codes as $code) {
         $sidebarKey = wfMemcKey('sidebar', $code);
         $this->wanCache->delete($sidebarKey, 5);
     }
     // Update the message in the message blob store
     $blobStore = new MessageBlobStore();
     $blobStore->updateMessage($wgContLang->lcfirst($msg));
     Hooks::run('MessageCacheReplace', array($title, $text));
 }