/**
  * Purge the cache for pages containing gallery tags
  */
 public function purge()
 {
     global $wgUseFileCache, $wgUseSquid;
     $totalGalleryPageCount = 0;
     // Keeps track of actual existing titles with gallery
     $dbGalleryCount = $this->getGalleryPageCount();
     // All counts including those with missing titles
     // Paginate the operation to prevent db/memory overload
     for ($limitCount = 0; $limitCount < $dbGalleryCount; $limitCount += self::PAGE_COUNT_LIMIT) {
         $galleryPageIds = $this->getGalleryPageIds($limitCount);
         $galleryPageTitles = \Title::newFromIDs($galleryPageIds);
         $galleryPageCount = count($galleryPageTitles);
         // abort if no pages were found
         if ($galleryPageCount == 0) {
             continue;
         }
         // Update squid/varnish/parser cache
         if ($wgUseSquid) {
             foreach ($galleryPageTitles as $title) {
                 $title->purgeSquid();
             }
         }
         // Update file cache if used
         if ($wgUseFileCache) {
             foreach ($galleryPageTitles as $title) {
                 \HTMLFileCache::clearFileCache($title);
             }
         }
         $totalGalleryPageCount += $galleryPageCount;
     }
     $this->info('Gallery page purge request', ['title' => __METHOD__, 'count' => $totalGalleryPageCount]);
     return $totalGalleryPageCount;
 }
 /**
  * Purge the cache for backlinking pages (that is, pages containing
  * a reference to the Title associated with this task)
  *
  * @param string|array $tables
  */
 public function purge($tables)
 {
     global $wgUseFileCache, $wgUseSquid;
     $affectedTitles = $this->getAffectedTitles((array) $tables);
     $affectedCount = count($affectedTitles);
     $this->info("Purge Request", ['title' => $this->title->getPrefixedText(), 'count' => $affectedCount, 'tables' => $tables]);
     // abort if no pages link to the associated Title
     if ($affectedCount == 0) {
         return 0;
     }
     $dbw = wfGetDB(DB_MASTER);
     (new \WikiaSQL())->UPDATE('page')->SET('page_touched', $dbw->timestamp())->WHERE('page_id')->IN(array_map(function ($t) {
         return $t->getArticleID();
     }, $affectedTitles))->run($dbw);
     // Update squid/varnish
     if ($wgUseSquid) {
         \SquidUpdate::newFromTitles($affectedTitles)->doUpdate();
     }
     // Update file cache
     if ($wgUseFileCache) {
         foreach ($affectedTitles as $title) {
             \HTMLFileCache::clearFileCache($title);
         }
     }
     return $affectedCount;
 }
Exemplo n.º 3
0
 /**
  * @since 2.1
  */
 public function doPurgeHtmlCache()
 {
     foreach ($this->titles as $title) {
         $title->touchLinks();
         // @see MW 1.19 Title::invalidateCache
         \HTMLFileCache::clearFileCache($title);
     }
 }
Exemplo n.º 4
0
 /**
  * Purge caches on page update etc
  *
  * @param $title Title object
  * @todo:  verify that $title is always a Title object (and never false or null), add Title hint to parameter $title
  */
 public static function onArticleEdit($title)
 {
     global $wgDeferredUpdateList;
     // Invalidate caches of articles which include this page
     $wgDeferredUpdateList[] = new HTMLCacheUpdate($title, 'templatelinks');
     // Invalidate the caches of all pages which redirect here
     $wgDeferredUpdateList[] = new HTMLCacheUpdate($title, 'redirect');
     # Purge squid for this page only
     $title->purgeSquid();
     # Clear file cache for this page only
     HTMLFileCache::clearFileCache($title);
 }
Exemplo n.º 5
0
 /**
  * Updates page_touched for this page; called from LinksUpdate.php
  *
  * @return Bool true if the update succeded
  */
 public function invalidateCache()
 {
     if (wfReadOnly()) {
         return;
     }
     $dbw = wfGetDB(DB_MASTER);
     $success = $dbw->update('page', array('page_touched' => $dbw->timestamp()), $this->pageCond(), __METHOD__);
     HTMLFileCache::clearFileCache($this);
     return $success;
 }
Exemplo n.º 6
0
 /**
  * @param array $pages Map of (page ID => (namespace, DB key)) entries
  */
 protected function invalidateTitles(array $pages)
 {
     global $wgUpdateRowsPerQuery, $wgUseFileCache;
     // Get all page IDs in this query into an array
     $pageIds = array_keys($pages);
     if (!$pageIds) {
         return;
     }
     // The page_touched field will need to be bumped for these pages.
     // Only bump it to the present time if no "rootJobTimestamp" was known.
     // If it is known, it can be used instead, which avoids invalidating output
     // that was in fact generated *after* the relevant dependency change time
     // (e.g. template edit). This is particularily useful since refreshLinks jobs
     // save back parser output and usually run along side htmlCacheUpdate jobs;
     // their saved output would be invalidated by using the current timestamp.
     if (isset($this->params['rootJobTimestamp'])) {
         $touchTimestamp = $this->params['rootJobTimestamp'];
     } else {
         $touchTimestamp = wfTimestampNow();
     }
     $dbw = wfGetDB(DB_MASTER);
     // Update page_touched (skipping pages already touched since the root job).
     // Check $wgUpdateRowsPerQuery for sanity; batch jobs are sized by that already.
     foreach (array_chunk($pageIds, $wgUpdateRowsPerQuery) as $batch) {
         $dbw->commit(__METHOD__, 'flush');
         wfWaitForSlaves();
         $dbw->update('page', array('page_touched' => $dbw->timestamp($touchTimestamp)), array('page_id' => $batch, "page_touched < " . $dbw->addQuotes($dbw->timestamp($touchTimestamp))), __METHOD__);
     }
     // Get the list of affected pages (races only mean something else did the purge)
     $titleArray = TitleArray::newFromResult($dbw->select('page', array('page_namespace', 'page_title'), array('page_id' => $pageIds, 'page_touched' => $dbw->timestamp($touchTimestamp)), __METHOD__));
     // Update squid
     $u = SquidUpdate::newFromTitles($titleArray);
     $u->doUpdate();
     // Update file cache
     if ($wgUseFileCache) {
         foreach ($titleArray as $title) {
             HTMLFileCache::clearFileCache($title);
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Updates page_touched for this page; called from LinksUpdate.php
  *
  * @return Bool true if the update succeded
  */
 public function invalidateCache()
 {
     if (wfReadOnly()) {
         return false;
     }
     $dbw = wfGetDB(DB_MASTER);
     $success = $dbw->update('page', array('page_touched' => $dbw->timestamp()), $this->pageCond(), __METHOD__);
     # start wikia change
     global $wgMemc;
     $wgMemc->set(wfMemcKey("page_touched", implode("_", $this->pageCond())), $dbw->timestamp(), 60);
     $this->mTouchedCached = null;
     # end wikia change
     HTMLFileCache::clearFileCache($this);
     return $success;
 }
Exemplo n.º 8
0
 /**
  * Update the semantic data stored for some individual. The data is
  * given as a SMWSemanticData object, which contains all semantic data
  * for one particular subject.
  *
  * @param $data SMWSemanticData
  */
 public function updateData(SMWSemanticData $data)
 {
     /**
      * @since 1.6
      */
     wfRunHooks('SMWStore::updateDataBefore', array($this, $data));
     // Invalidate the page, so data stored on it gets displayed immediately in queries.
     global $smwgAutoRefreshSubject;
     if ($smwgAutoRefreshSubject && !wfReadOnly()) {
         $title = Title::makeTitle($data->getSubject()->getNamespace(), $data->getSubject()->getDBkey());
         $dbw = wfGetDB(DB_MASTER);
         $dbw->update('page', array('page_touched' => $dbw->timestamp(time() + 4)), $title->pageCond(), __METHOD__);
         HTMLFileCache::clearFileCache($title);
     }
     $this->doDataUpdate($data);
     /**
      * @since 1.6
      */
     wfRunHooks('SMWStore::updateDataAfter', array($this, $data));
 }
 protected function purge_reviewable_pages($fileHandle)
 {
     global $wgUseSquid, $wgUseFileCache;
     $this->output("Purging squid cache for list of pages to purge ...\n");
     if (!$wgUseSquid && !$wgUseFileCache) {
         $this->output("Squid/file cache not enabled ... nothing to purge.\n");
         return;
     }
     $count = 0;
     while (!feof($fileHandle)) {
         $dbKey = trim(fgets($fileHandle));
         if ($dbKey == '') {
             continue;
             // last line?
         }
         $title = Title::newFromDBkey($dbKey);
         if ($title) {
             $title->purgeSquid();
             // send PURGE
             HTMLFileCache::clearFileCache($title);
             // purge poor-mans's squid
             $this->output("... {$dbKey}\n");
             $count++;
             if ($count % $this->mBatchSize == 0) {
                 wfWaitForSlaves(5);
                 // not really needed
             }
         } else {
             $this->output("Invalid title - cannot purge: {$dbKey}\n");
         }
     }
     $this->output("Squid/file cache purge of page list complete ... {$count} pages\n");
 }
Exemplo n.º 10
0
 /**
  * Invalidate an array (or iterator) of Title objects, right now
  * @param $titleArray array
  */
 protected function invalidateTitles($titleArray)
 {
     global $wgUseFileCache, $wgUseSquid;
     $dbw = wfGetDB(DB_MASTER);
     $timestamp = $dbw->timestamp();
     # Get all IDs in this query into an array
     $ids = array();
     foreach ($titleArray as $title) {
         $ids[] = $title->getArticleID();
     }
     if (!$ids) {
         return;
     }
     # Update page_touched
     $batches = array_chunk($ids, $this->mRowsPerQuery);
     foreach ($batches as $batch) {
         $dbw->update('page', array('page_touched' => $timestamp), array('page_id' => $batch), __METHOD__);
     }
     # Update squid
     if ($wgUseSquid) {
         $u = SquidUpdate::newFromTitles($titleArray);
         $u->doUpdate();
     }
     # Update file cache
     if ($wgUseFileCache) {
         foreach ($titleArray as $title) {
             HTMLFileCache::clearFileCache($title);
         }
     }
 }
Exemplo n.º 11
0
 /**
  * @param array $pages Map of (page ID => (namespace, DB key)) entries
  */
 protected function invalidateTitles(array $pages)
 {
     global $wgUpdateRowsPerQuery, $wgUseFileCache;
     // Get all page IDs in this query into an array
     $pageIds = array_keys($pages);
     if (!$pageIds) {
         return;
     }
     // Bump page_touched to the current timestamp. This used to use the root job timestamp
     // (e.g. template/file edit time), which was a bit more efficient when template edits are
     // rare and don't effect the same pages much. However, this way allows for better
     // de-duplication, which is much more useful for wikis with high edit rates. Note that
     // RefreshLinksJob, which is enqueued alongside HTMLCacheUpdateJob, saves the parser output
     // since it has to parse anyway. We assume that vast majority of the cache jobs finish
     // before the link jobs, so using the current timestamp instead of the root timestamp is
     // not expected to invalidate these cache entries too often.
     $touchTimestamp = wfTimestampNow();
     $dbw = wfGetDB(DB_MASTER);
     $factory = wfGetLBFactory();
     $ticket = $factory->getEmptyTransactionTicket(__METHOD__);
     // Update page_touched (skipping pages already touched since the root job).
     // Check $wgUpdateRowsPerQuery for sanity; batch jobs are sized by that already.
     foreach (array_chunk($pageIds, $wgUpdateRowsPerQuery) as $batch) {
         $factory->commitAndWaitForReplication(__METHOD__, $ticket);
         $dbw->update('page', ['page_touched' => $dbw->timestamp($touchTimestamp)], ['page_id' => $batch, "page_touched < " . $dbw->addQuotes($dbw->timestamp($touchTimestamp))], __METHOD__);
     }
     // Get the list of affected pages (races only mean something else did the purge)
     $titleArray = TitleArray::newFromResult($dbw->select('page', ['page_namespace', 'page_title'], ['page_id' => $pageIds, 'page_touched' => $dbw->timestamp($touchTimestamp)], __METHOD__));
     // Update CDN
     $u = CdnCacheUpdate::newFromTitles($titleArray);
     $u->doUpdate();
     // Update file cache
     if ($wgUseFileCache) {
         foreach ($titleArray as $title) {
             HTMLFileCache::clearFileCache($title);
         }
     }
 }
 /**
  * Invalidate a set of IDs, right now
  */
 public function invalidateIDs(ResultWrapper $res)
 {
     global $wgUseFileCache, $wgUseSquid;
     if ($res->numRows() == 0) {
         return;
     }
     // sanity check
     $dbw = wfGetDB(DB_MASTER);
     $timestamp = $dbw->timestamp();
     $done = false;
     while (!$done) {
         # Get all IDs in this query into an array
         $ids = array();
         for ($i = 0; $i < $this->mRowsPerQuery; $i++) {
             $row = $res->fetchRow();
             if ($row) {
                 $ids[] = $row[0];
             } else {
                 $done = true;
                 break;
             }
         }
         if (count($ids) == 0) {
             break;
         }
         # Update page_touched
         $dbw->update('page', array('page_touched' => $timestamp), array('page_id' => $ids), __METHOD__);
         # Update static caches
         if ($wgUseSquid || $wgUseFileCache) {
             $titles = Title::newFromIDs($ids);
             # Update squid cache
             if ($wgUseSquid) {
                 $u = SquidUpdate::newFromTitles($titles);
                 $u->doUpdate();
             }
             # Update file cache
             if ($wgUseFileCache) {
                 foreach ($titles as $title) {
                     HTMLFileCache::clearFileCache($title);
                 }
             }
         }
     }
 }
 function doUpdate()
 {
     # Purge squid for this page only
     $this->title->purgeSquid();
     # Clear file cache for this page only
     HTMLFileCache::clearFileCache($this->title);
 }
Exemplo n.º 14
0
 /**
  * Invalidate a set of pages, right now
  */
 public function invalidate($startId = false, $endId = false)
 {
     global $wgUseFileCache, $wgUseSquid;
     $titleArray = $this->mCache->getLinks($this->mTable, $startId, $endId);
     if ($titleArray->count() == 0) {
         return;
     }
     $dbw = wfGetDB(DB_MASTER);
     $timestamp = $dbw->timestamp();
     # Get all IDs in this query into an array
     $ids = array();
     foreach ($titleArray as $title) {
         $ids[] = $title->getArticleID();
     }
     # Update page_touched
     $dbw->update('page', array('page_touched' => $timestamp), array('page_id IN (' . $dbw->makeList($ids) . ')'), __METHOD__);
     # Update squid
     if ($wgUseSquid) {
         $u = SquidUpdate::newFromTitles($titleArray);
         $u->doUpdate();
     }
     # Update file cache
     if ($wgUseFileCache) {
         foreach ($titleArray as $title) {
             HTMLFileCache::clearFileCache($title);
         }
     }
 }
 /**
  * Invalidate an array (or iterator) of Title objects, right now
  * @param $titleArray array
  */
 protected function invalidateTitles($titleArray)
 {
     global $wgUseFileCache, $wgUseSquid;
     $dbw = wfGetDB(DB_MASTER);
     $timestamp = $dbw->timestamp();
     # Get all IDs in this query into an array
     $ids = array();
     foreach ($titleArray as $title) {
         $ids[] = $title->getArticleID();
     }
     if (!$ids) {
         return;
     }
     # Don't invalidated pages that were already invalidated
     $touchedCond = isset($this->params['rootJobTimestamp']) ? array("page_touched < " . $dbw->addQuotes($dbw->timestamp($this->params['rootJobTimestamp']))) : array();
     # Update page_touched
     $batches = array_chunk($ids, $this->rowsPerQuery);
     foreach ($batches as $batch) {
         $dbw->update('page', array('page_touched' => $timestamp), array('page_id' => $batch) + $touchedCond, __METHOD__);
     }
     # Update squid
     if ($wgUseSquid) {
         $u = SquidUpdate::newFromTitles($titleArray);
         $u->doUpdate();
     }
     # Update file cache
     if ($wgUseFileCache) {
         foreach ($titleArray as $title) {
             HTMLFileCache::clearFileCache($title);
         }
     }
 }
Exemplo n.º 16
0
 /**
  * Purge caches on page update etc
  *
  * @param Title $title
  * @param Revision|null $revision Revision that was just saved, may be null
  */
 public static function onArticleEdit(Title $title, Revision $revision = null)
 {
     // Invalidate caches of articles which include this page
     DeferredUpdates::addUpdate(new HTMLCacheUpdate($title, 'templatelinks'));
     // Invalidate the caches of all pages which redirect here
     DeferredUpdates::addUpdate(new HTMLCacheUpdate($title, 'redirect'));
     MediaWikiServices::getInstance()->getLinkCache()->invalidateTitle($title);
     // Purge CDN for this page only
     $title->purgeSquid();
     // Clear file cache for this page only
     HTMLFileCache::clearFileCache($title);
     $revid = $revision ? $revision->getId() : null;
     DeferredUpdates::addCallableUpdate(function () use($title, $revid) {
         InfoAction::invalidateCache($title, $revid);
     });
 }
Exemplo n.º 17
0
 /**
  * @param Title $title
  * Updates squid cache for a title. Defers till after main commit().
  */
 public static function purgeSquid(Title $title)
 {
     DeferredUpdates::addCallableUpdate(function () use($title) {
         $title->purgeSquid();
         HTMLFileCache::clearFileCache($title);
     });
 }
Exemplo n.º 18
0
	/**
	 * Purge caches on page update etc
	 *
	 * @param $title Title object
	 * @todo Verify that $title is always a Title object (and never false or null), add Title hint to parameter $title
	 */
	public static function onArticleEdit( $title ) {
		// Invalidate caches of articles which include this page
		DeferredUpdates::addHTMLCacheUpdate( $title, 'templatelinks' );

		// Invalidate the caches of all pages which redirect here
		DeferredUpdates::addHTMLCacheUpdate( $title, 'redirect' );

		// Purge squid for this page only
		$title->purgeSquid();

		// Clear file cache for this page only
		HTMLFileCache::clearFileCache( $title );
		InfoAction::invalidateCache( $title );
	}
Exemplo n.º 19
0
 /**
  * Updates page_touched for this page; called from LinksUpdate.php
  *
  * @return Bool true if the update succeeded
  */
 public function invalidateCache()
 {
     global $wgMemc;
     if (wfReadOnly()) {
         return false;
     }
     $dbw = wfGetDB(DB_MASTER);
     $success = $dbw->update('page', array('page_touched' => $dbw->timestamp()), $this->pageCond(), __METHOD__);
     HTMLFileCache::clearFileCache($this);
     // Clear page info.
     $revision = WikiPage::factory($this)->getRevision();
     if ($revision !== null) {
         $memcKey = wfMemcKey('infoaction', $this->getPrefixedText(), $revision->getId());
         $success = $success && $wgMemc->delete($memcKey);
     }
     return $success;
 }