本文整理汇总了PHP中SquidUpdate类的典型用法代码示例。如果您正苦于以下问题:PHP SquidUpdate类的具体用法?PHP SquidUpdate怎么用?PHP SquidUpdate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SquidUpdate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
$stdin = $this->getStdin();
$urls = array();
while (!feof($stdin)) {
$page = trim(fgets($stdin));
if (substr($page, 0, 7) == 'http://') {
$urls[] = $page;
} elseif ($page !== '') {
$title = Title::newFromText($page);
if ($title) {
$url = $title->getFullUrl();
$this->output("{$url}\n");
$urls[] = $url;
if (isset($options['purge'])) {
$title->invalidateCache();
}
} else {
$this->output("(Invalid title '{$page}')\n");
}
}
}
$this->output("Purging " . count($urls) . " urls...\n");
$u = new SquidUpdate($urls);
$u->doUpdate();
$this->output("Done!\n");
}
示例2: execute
public function execute()
{
global $wgUser, $wgArticleFeedbackRatingTypes, $wgArticleFeedbackSMaxage, $wgArticleFeedbackNamespaces;
$params = $this->extractRequestParams();
// Anon token check
if ($wgUser->isAnon()) {
if (!isset($params['anontoken'])) {
$this->dieUsageMsg(array('missingparam', 'anontoken'));
} elseif (strlen($params['anontoken']) != 32) {
$this->dieUsage('The anontoken is not 32 characters', 'invalidtoken');
}
$token = $params['anontoken'];
} else {
$token = '';
}
// Load check, is this page ArticleFeedback-enabled ?
// Keep in sync with ext.articleFeedback.startup.js
$title = Title::newFromID($params['pageid']);
if (is_null($title) || !in_array($title->getNamespace(), $wgArticleFeedbackNamespaces) || $title->isRedirect()) {
// ...then error out
$this->dieUsage('ArticleFeedback is not enabled on this page', 'invalidpage');
}
$dbw = wfGetDB(DB_MASTER);
// Query the latest ratings by this user for this page,
// possibly for an older revision
// Select from the master to prevent replag-induced bugs
$res = $dbw->select('article_feedback', array('aa_rating_id', 'aa_rating_value', 'aa_revision'), array('aa_user_text' => $wgUser->getName(), 'aa_page_id' => $params['pageid'], 'aa_rating_id' => array_keys($wgArticleFeedbackRatingTypes), 'aa_user_anon_token' => $token), __METHOD__, array('ORDER BY' => 'aa_revision DESC', 'LIMIT' => count($wgArticleFeedbackRatingTypes)));
$lastRatings = array();
foreach ($res as $row) {
$lastRatings[$row->aa_rating_id]['value'] = $row->aa_rating_value;
$lastRatings[$row->aa_rating_id]['revision'] = $row->aa_revision;
}
$pageId = $params['pageid'];
$revisionId = $params['revid'];
foreach ($wgArticleFeedbackRatingTypes as $ratingID => $unused) {
$lastPageRating = false;
$lastRevRating = false;
if (isset($lastRatings[$ratingID])) {
$lastPageRating = intval($lastRatings[$ratingID]['value']);
if (intval($lastRatings[$ratingID]['revision']) == $revisionId) {
$lastRevRating = $lastPageRating;
}
}
$thisRating = false;
if (isset($params["r{$ratingID}"])) {
$thisRating = intval($params["r{$ratingID}"]);
}
$this->insertRevisionRating($pageId, $revisionId, $ratingID, $thisRating - $lastRevRating, $thisRating, $lastRevRating);
$this->insertPageRating($pageId, $ratingID, $thisRating - $lastPageRating, $thisRating, $lastPageRating);
$this->insertUserRatings($pageId, $revisionId, $wgUser, $token, $ratingID, $thisRating, $params['bucket']);
}
$this->insertProperties($revisionId, $wgUser, $token, $params);
$squidUpdate = new SquidUpdate(array(wfAppendQuery(wfScript('api'), array('action' => 'query', 'format' => 'json', 'list' => 'articlefeedback', 'afpageid' => $pageId, 'afanontoken' => '', 'afuserrating' => 0, 'maxage' => 0, 'smaxage' => $wgArticleFeedbackSMaxage))));
$squidUpdate->doUpdate();
wfRunHooks('ArticleFeedbackChangeRating', array($params));
$r = array('result' => 'Success');
$this->getResult()->addValue(null, $this->getModuleName(), $r);
}
示例3: purgeVarnish
public function purgeVarnish()
{
global $wgHubRssFeeds, $wgServer;
echo "| Purging varnishen..." . PHP_EOL;
$urls = [];
foreach ($wgHubRssFeeds as $feedEndpoint) {
$urls[] = SpecialPage::getTitleFor(HubRssFeedSpecialController::SPECIAL_NAME)->getFullUrl() . '/' . $feedEndpoint;
$urls[] = implode('/', [$wgServer, 'rss', $feedEndpoint]);
}
$u = new SquidUpdate($urls);
$u->doUpdate();
}
示例4: renderTimeline
function renderTimeline($timelinesrc)
{
global $wgUploadDirectory, $wgUploadPath, $IP, $wgTimelineSettings, $wgArticlePath, $wgTmpDirectory;
$hash = md5($timelinesrc);
$dest = $wgUploadDirectory . "/timeline/";
if (!is_dir($dest)) {
mkdir($dest, 0777);
}
if (!is_dir($wgTmpDirectory)) {
mkdir($wgTmpDirectory, 0777);
}
$fname = $dest . $hash;
$previouslyFailed = file_exists($fname . ".err");
$previouslyRendered = file_exists($fname . ".png");
$expired = $previouslyRendered && filemtime($fname . ".png") < wfTimestamp(TS_UNIX, $wgTimelineSettings->epochTimestamp);
if ($expired || !$previouslyRendered && !$previouslyFailed) {
$handle = fopen($fname, "w");
fwrite($handle, $timelinesrc);
fclose($handle);
$cmdline = wfEscapeShellArg($wgTimelineSettings->perlCommand, $wgTimelineSettings->timelineFile) . " -i " . wfEscapeShellArg($fname) . " -m -P " . wfEscapeShellArg($wgTimelineSettings->ploticusCommand) . " -T " . wfEscapeShellArg($wgTmpDirectory) . " -A " . wfEscapeShellArg($wgArticlePath);
$ret = `{$cmdline}`;
unlink($fname);
if ($ret == "") {
// Message not localized, only relevant during install
return "<div id=\"toc\"><tt>Timeline error: Executable not found. Command line was: {$cmdline}</tt></div>";
}
}
@($err = file_get_contents($fname . ".err"));
if ($err != "") {
$txt = "<div id=\"toc\"><tt>{$err}</tt></div>";
} else {
@($map = file_get_contents($fname . ".map"));
if (substr(php_uname(), 0, 7) == "Windows") {
$ext = "gif";
} else {
$ext = "png";
}
$url = "{$wgUploadPath}/timeline/{$hash}.{$ext}";
$txt = "<map name=\"{$hash}\">{$map}</map>" . "<img usemap=\"#{$hash}\" src=\"{$url}\">";
if ($expired) {
// Replacing an older file, we may need to purge the old one.
global $wgUseSquid;
if ($wgUseSquid) {
$u = new SquidUpdate(array($url));
$u->doUpdate();
}
}
}
return $txt;
}
示例5: purge
/**
* 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;
}
示例6: invalidate
/**
* 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);
}
}
}
示例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()));
/* Wikia change begin - @author: Marooned, see RT#44185 */
global $wgLogo;
if ($this->url == $wgLogo) {
SquidUpdate::purge(array($this->url));
}
/* Wikia change end */
// 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__);
}
# Commit the transaction now, in case something goes wrong later
# The most important thing is that files don't get lost, especially archives
$dbw->commit();
# Invalidate cache for all pages using this file
$update = new HTMLCacheUpdate($this->getTitle(), 'imagelinks');
$update->doUpdate();
return true;
}
示例8: purge
private function purge($url, $var, $typeVal, $val, $likeVal)
{
$wikis = $this->getListOfWikisWithVar($var, $typeVal, $val, $likeVal);
$purgeUrls = array();
foreach ($wikis as $cityId => $wikiData) {
$purgeUrls[] = $wikiData['u'] . $url;
}
SquidUpdate::purge($purgeUrls);
return $purgeUrls;
}
示例9: benchSquid
/** @todo document */
function benchSquid($urls, $trials = 1)
{
$start = wfTime();
for ($i = 0; $i < $trials; $i++) {
SquidUpdate::purge($urls);
}
$delta = wfTime() - $start;
$pertrial = $delta / $trials;
$pertitle = $pertrial / count($urls);
return sprintf("%4d titles in %6.2fms (%6.2fms each)", count($urls), $pertrial * 1000.0, $pertitle * 1000.0);
}
示例10: purgeThumb
/**
* Remove the thumb from DFS and purge it from CDN
*
* @param string $thumb
*/
private function purgeThumb($thumb)
{
$url = sprintf("http://images.wikia.com/%s%s/%s", $this->storage->getContainerName(), $this->storage->getPathPrefix(), $thumb);
#$this->output(sprintf("%s: %s <%s>...", __METHOD__, $thumb, $url));
$this->output(sprintf("%s: '%s'... ", __METHOD__, $thumb));
if ($this->isDryRun) {
$this->output("dry run!\n");
} else {
$this->storage->remove($thumb);
SquidUpdate::purge([$url]);
$this->output("done\n");
}
}
示例11: execute
public function execute()
{
$this->dryRun = $this->hasOption('dry-run');
$this->verbose = $this->hasOption('verbose');
$wikiId = $this->getOption('wikiId', '');
if (empty($wikiId)) {
die("Error: Empty wiki id.\n");
}
$dbname = WikiFactory::IDtoDB($wikiId);
if (empty($dbname)) {
die("Error: Cannot find dbname.\n");
}
$pageLimit = 20000;
$totalLimit = $this->getOption('limit', $pageLimit);
if (empty($totalLimit) || $totalLimit < -1) {
die("Error: invalid limit.\n");
}
if ($totalLimit == -1) {
$totalLimit = $this->getTotalPages($dbname);
}
$maxSet = ceil($totalLimit / $pageLimit);
$limit = $totalLimit > $pageLimit ? $pageLimit : $totalLimit;
$totalPages = 0;
for ($set = 1; $set <= $maxSet; $set++) {
$cnt = 0;
if ($set == $maxSet) {
$limit = $totalLimit - $pageLimit * ($set - 1);
}
$offset = ($set - 1) * $pageLimit;
$pages = $this->getAllPages($dbname, $limit, $offset);
$total = count($pages);
foreach ($pages as $page) {
$cnt++;
echo "Wiki {$wikiId} - Page {$page['id']} [{$cnt} of {$total}, set {$set} of {$maxSet}]: ";
$title = GlobalTitle::newFromId($page['id'], $wikiId);
if ($title instanceof GlobalTitle) {
$url = $title->getFullURL();
echo "{$url}\n";
if (!$this->dryRun) {
SquidUpdate::purge([$url]);
}
$this->success++;
} else {
echo "ERROR: Cannot find global title for {$page['title']}\n";
}
}
$totalPages = $totalPages + $total;
}
echo "\nWiki {$wikiId}: Total pages: {$totalPages}, Success: {$this->success}, Failed: " . ($totalPages - $this->success) . "\n\n";
}
示例12: purge
/**
* Add array of URLs to the purger queue
*
* @param Array $urlArr list of URLs to purge
* @throws WikiaException
*/
static function purge($urlArr)
{
global $wgEnableScribeReport;
wfProfileIn(__METHOD__);
if (empty($wgEnableScribeReport)) {
wfProfileOut(__METHOD__);
return;
}
foreach ($urlArr as $url) {
if (!is_string($url)) {
throw new WikiaException('Bad purge URL');
}
$url = SquidUpdate::expand($url);
$method = self::getPurgeCaller();
wfDebug("Purging URL {$url} from {$method} via Scribe\n");
wfDebug("Purging backtrace: " . wfGetAllCallers(false) . "\n");
// add to the queue, will be sent by onRestInPeace method
self::$urls[$url] = ['url' => $url, 'time' => time(), 'method' => $method];
self::$urlsCount++;
}
wfProfileOut(__METHOD__);
}
示例13: invalidateTitles
/**
* 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);
}
}
}
示例14: sendPurgeRequest
/**
* Helper to purge an array of $urls
* @param array $urls List of URLS to purge from squids
*/
private function sendPurgeRequest($urls)
{
if ($this->hasOption('delay')) {
$delay = floatval($this->getOption('delay'));
foreach ($urls as $url) {
if ($this->hasOption('verbose')) {
$this->output($url . "\n");
}
$u = new SquidUpdate(array($url));
$u->doUpdate();
usleep($delay * 1000000.0);
}
} else {
if ($this->hasOption('verbose')) {
$this->output(implode("\n", $urls) . "\n");
}
$u = new SquidUpdate($urls);
$u->doUpdate();
}
}
示例15: recordUpload
function recordUpload($oldver, $desc, $copyStatus = '', $source = '', $watch = false)
{
global $wgUser, $wgLang, $wgTitle, $wgDeferredUpdateList;
global $wgUseCopyrightUpload, $wgUseSquid, $wgPostCommitUpdateList;
$img = Image::newFromName($this->mUploadSaveName);
$fname = 'Image::recordUpload';
$dbw =& wfGetDB(DB_MASTER);
Image::checkDBSchema($dbw);
// Delete thumbnails and refresh the metadata cache
$img->purgeCache();
// Fail now if the image isn't there
if (!$img->fileExists || $img->fromSharedDirectory) {
wfDebug("Image::recordUpload: File " . $img->imagePath . " went missing!\n");
return false;
}
if ($wgUseCopyrightUpload) {
$textdesc = '== ' . wfMsg('filedesc') . " ==\n" . $desc . "\n" . '== ' . wfMsg('filestatus') . " ==\n" . $copyStatus . "\n" . '== ' . wfMsg('filesource') . " ==\n" . $source;
} else {
$textdesc = $desc;
}
$now = $dbw->timestamp();
#split mime type
if (strpos($img->mime, '/') !== false) {
list($major, $minor) = explode('/', $img->mime, 2);
} else {
$major = $img->mime;
$minor = "unknown";
}
# 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' => $img->name, 'img_size' => $img->size, 'img_width' => IntVal($img->width), 'img_height' => IntVal($img->height), 'img_bits' => $img->bits, 'img_media_type' => $img->type, 'img_major_mime' => $major, 'img_minor_mime' => $minor, 'img_timestamp' => $now, 'img_description' => $desc, 'img_user' => $wgUser->getID(), 'img_user_text' => $wgUser->getName(), 'img_metadata' => $img->metadata), $fname, 'IGNORE');
$descTitle = $img->getTitle();
$purgeURLs = array();
$article = new Article($descTitle);
$minor = false;
$watch = $watch || $wgUser->isWatched($descTitle);
$suppressRC = true;
// There's already a log entry, so don't double the RC load
if ($descTitle->exists()) {
// TODO: insert a null revision into the page history for this update.
if ($watch) {
$wgUser->addWatch($descTitle);
}
# Invalidate the cache for the description page
$descTitle->invalidateCache();
$purgeURLs[] = $descTitle->getInternalURL();
} else {
$this->insertNewArticle($article, $textdesc, $desc, $minor, $watch, $suppressRC);
}
# Invalidate cache for all pages using this image
$linksTo = $img->getLinksTo();
if ($wgUseSquid) {
$u = SquidUpdate::newFromTitles($linksTo, $purgeURLs);
array_push($wgPostCommitUpdateList, $u);
}
Title::touchArray($linksTo);
$log = new LogPage('upload');
$log->addEntry('upload', $descTitle, $desc);
return true;
}