/**
  * Clear total videos by category cache when video categories are added via the Category Select extension,
  * after checking if it was associated with one of the categories filtered in Special Videos.
  * @param $title
  * @param $categories
  * @return true
  */
 public static function onCategorySelectSave($title, $categories)
 {
     if ($title instanceof Title && WikiaFileHelper::isFileTypeVideo($title)) {
         VideoInfoHooksHelper::clearCategories($title);
     }
     return true;
 }
Пример #2
0
 /**
  * Record a file upload in the upload log and the image table
  */
 function recordUpload2($oldver, $comment, $pageText, $props = false, $timestamp = false, $user = null)
 {
     global $wgCityId;
     if (is_null($user)) {
         global $wgUser;
         $user = $wgUser;
     }
     $dbw = $this->repo->getMasterDB();
     $dbw->begin();
     if (!$props) {
         $props = $this->repo->getFileProps($this->getVirtualUrl());
     }
     if ($timestamp === false) {
         $timestamp = $dbw->timestamp();
     }
     $props['description'] = $comment;
     $props['user'] = $user->getId();
     $props['user_text'] = $user->getName();
     $props['timestamp'] = wfTimestamp(TS_MW, $timestamp);
     // DB -> TS_MW
     $this->setProps($props);
     # Fail now if the file isn't there
     if (!$this->fileExists) {
         wfDebug(__METHOD__ . ": File " . $this->getRel() . " went missing!\n");
         return false;
     }
     $reupload = false;
     # 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) {
         if ($oldver == '') {
             // XXX
             # (bug 34993) publish() can displace the current file and yet fail to save
             # a new one. The next publish attempt will treat the file as a brand new file
             # and pass an empty $oldver. Allow this bogus value so we can displace the
             # `image` row to `oldimage`, leaving room for the new current file `image` row.
             #throw new MWException( "Empty oi_archive_name. Database and storage out of sync?" );
             Wikia::logBacktrace(__METHOD__ . "::oi_archive_name - [{$this->getName()}]");
             // Wikia change (BAC-1068)
         }
         $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
         $dbw->begin(__METHOD__);
         $dbw->update('site_stats', array('ss_images = ss_images+1'), '*', __METHOD__);
         $dbw->commit(__METHOD__);
     }
     $descTitle = $this->getTitle();
     $wikiPage = new WikiFilePage($descTitle);
     $wikiPage->setFile($this);
     # Add the log entry
     $log = new LogPage('upload');
     $action = $reupload ? 'overwrite' : 'upload';
     $log->addEntry($action, $descTitle, $comment, array(), $user);
     if ($descTitle->exists()) {
         # Create a null revision
         $latest = $descTitle->getLatestRevID();
         $nullRevision = Revision::newNullRevision($dbw, $descTitle->getArticleId(), $log->getRcComment(), false);
         if (!is_null($nullRevision)) {
             $nullRevision->insertOn($dbw);
             wfRunHooks('NewRevisionFromEditComplete', array($wikiPage, $nullRevision, $latest, $user));
             $wikiPage->updateRevisionOn($dbw, $nullRevision);
         }
         # Invalidate the cache for the description page
         $descTitle->invalidateCache();
         $descTitle->purgeSquid();
     } else {
         # New file; create the description page.
         # There's already a log entry, so don't make a second RC entry
         # Squid and file cache for the description page are purged by doEdit.
         $wikiPage->doEdit($pageText, $comment, EDIT_NEW | EDIT_SUPPRESS_RC, false, $user);
     }
     /* wikia change - begin (VID-1568) */
     // Update/Insert video info
     try {
         \VideoInfoHooksHelper::upsertVideoInfo($this, $reupload);
     } catch (\Exception $e) {
         $dbw->rollback();
         return false;
     }
     /* wikia change - end (VID-1568) */
     # 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();
     # Save to cache and purge the squid
     # We shall not saveToCache before the commit since otherwise
     # in case of a rollback there is an usable file from memcached
     # which in fact doesn't really exist (bug 24978)
     $this->saveToCache();
     if ($reupload) {
         # Delete old thumbnails
         wfProfileIn(__METHOD__ . '-purge');
         $this->purgeThumbnails();
         wfProfileOut(__METHOD__ . '-purge');
         # Remove the old file from the squid cache
         SquidUpdate::purge(array($this->getURL()));
         /* wikia change - begin (VID-1568) */
         \VideoInfoHooksHelper::purgeVideoInfoCache($this);
         /* wikia change - end (VID-1568) */
     }
     # Hooks, hooks, the magic of hooks...
     wfRunHooks('FileUpload', array($this, $reupload, $descTitle->exists()));
     # Invalidate cache for all pages using this file
     // Wikia change begin @author Scott Rabin (srabin@wikia-inc.com)
     $task = (new \Wikia\Tasks\Tasks\HTMLCacheUpdateTask())->wikiId($wgCityId)->title($this->getTitle());
     $task->call('purge', 'imagelinks');
     $task->queue();
     // Wikia change end
     # Invalidate cache for all pages that redirects on this page
     $redirs = $this->getTitle()->getRedirectsHere();
     foreach ($redirs as $redir) {
         // Wikia change begin @author Scott Rabin (srabin@wikia-inc.com)
         $task = (new \Wikia\Tasks\Tasks\HTMLCacheUpdateTask())->wikiId($wgCityId)->title($redir);
         $task->call('purge', 'imagelinks');
         $task->queue();
         // Wikia change end
     }
     return true;
 }