示例#1
0
 /**
  * Delete all previously generated thumbnails, refresh metadata in memcached and purge the squid
  */
 function purgeCache($archiveFiles = array(), $shared = false)
 {
     global $wgInternalServer, $wgUseSquid;
     // Refresh metadata cache
     clearstatcache();
     $this->loadFromFile();
     $this->saveToCache();
     // Delete thumbnails
     $files = $this->getThumbnails($shared);
     $dir = wfImageThumbDir($this->name, $shared);
     $urls = array();
     foreach ($files as $file) {
         if (preg_match('/^(\\d+)px/', $file, $m)) {
             $urls[] = $wgInternalServer . $this->thumbUrl($m[1], $this->fromSharedDirectory);
             @unlink("{$dir}/{$file}");
         }
     }
     // Purge the squid
     if ($wgUseSquid) {
         $urls[] = $wgInternalServer . $this->getViewURL();
         foreach ($archiveFiles as $file) {
             $urls[] = $wgInternalServer . wfImageArchiveUrl($file);
         }
         wfPurgeSquidServers($urls);
     }
 }
示例#2
0
 function imageHistoryLine($iscur, $timestamp, $img, $user, $usertext, $size, $description, $width, $height)
 {
     global $wgUser, $wgLang, $wgTitle, $wgContLang;
     $datetime = $wgLang->timeanddate($timestamp, true);
     $del = wfMsg('deleteimg');
     $delall = wfMsg('deleteimgcompletely');
     $cur = wfMsg('cur');
     if ($iscur) {
         $url = Image::imageUrl($img);
         $rlink = $cur;
         if ($wgUser->isAllowed('delete')) {
             $link = $wgTitle->escapeLocalURL('image=' . $wgTitle->getPartialURL() . '&action=delete');
             $style = $this->skin->getInternalLinkAttributes($link, $delall);
             $dlink = '<a href="' . $link . '"' . $style . '>' . $delall . '</a>';
         } else {
             $dlink = $del;
         }
     } else {
         $url = htmlspecialchars(wfImageArchiveUrl($img));
         if ($wgUser->getID() != 0 && $wgTitle->userCanEdit()) {
             $token = urlencode($wgUser->editToken($img));
             $rlink = $this->skin->makeKnownLinkObj($wgTitle, wfMsg('revertimg'), 'action=revert&oldimage=' . urlencode($img) . "&wpEditToken={$token}");
             $dlink = $this->skin->makeKnownLinkObj($wgTitle, $del, 'action=delete&oldimage=' . urlencode($img) . "&wpEditToken={$token}");
         } else {
             # Having live active links for non-logged in users
             # means that bots and spiders crawling our site can
             # inadvertently change content. Baaaad idea.
             $rlink = wfMsg('revertimg');
             $dlink = $del;
         }
     }
     $userlink = $this->skin->userLink($user, $usertext) . $this->skin->userToolLinks($user, $usertext);
     $nbytes = wfMsgExt('nbytes', array('parsemag', 'escape'), $wgLang->formatNum($size));
     $widthheight = wfMsg('widthheight', $width, $height);
     $style = $this->skin->getInternalLinkAttributes($url, $datetime);
     $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a> . . {$userlink} . . {$widthheight} ({$nbytes})";
     $s .= $this->skin->commentBlock($description, $wgTitle);
     $s .= "</li>\n";
     return $s;
 }
示例#3
0
 /**
  * Delete an old version of the image.
  *
  * Moves the file into an archive directory (or deletes it)
  * and removes the database row.
  *
  * Cache purging is done; logging is caller's responsibility.
  *
  * @param $reason
  * @throws MWException or FSException on database or filestore failure
  * @return true on success, false on some kind of failure
  */
 function deleteOld($archiveName, $reason, $suppress = false)
 {
     $transaction = new FSTransaction();
     $urlArr = array();
     if (!FileStore::lock()) {
         wfDebug(__METHOD__ . ": failed to acquire file store lock, aborting\n");
         return false;
     }
     $transaction = new FSTransaction();
     try {
         $dbw = wfGetDB(DB_MASTER);
         $dbw->begin();
         $transaction->add($this->prepareDeleteOld($archiveName, $reason, $suppress));
         $dbw->immediateCommit();
     } catch (MWException $e) {
         wfDebug(__METHOD__ . ": db error, rolling back file transaction\n");
         $transaction->rollback();
         FileStore::unlock();
         throw $e;
     }
     wfDebug(__METHOD__ . ": deleted db items, applying file transaction\n");
     $transaction->commit();
     FileStore::unlock();
     $this->purgeDescription();
     // Squid purging
     global $wgUseSquid;
     if ($wgUseSquid) {
         $urlArr = array(wfImageArchiveUrl($archiveName));
         wfPurgeSquidServers($urlArr);
     }
     return true;
 }