示例#1
0
 static function onFileThumbName($image, $rawParams, $params, &$thumbName)
 {
     if (!$rawParams) {
         $rawParams = $params;
     }
     if ($image->getUser('text') && WatermarkSupport::isWikihowCreator($image->getUser('text')) && isset($params[WatermarkSupport::NO_WATERMARK]) && $params[WatermarkSupport::NO_WATERMARK] == true) {
         $wm = 'nowatermark-';
         $thumbName = $image->getHandler()->makeParamString($params) . '-' . $wm . $image->getName();
     }
     if (isset($params['crop']) && $params['crop'] == 1) {
         // if the requested width was passed in, we have a thumbnail name where the crop width
         // didn't match the "px" width. The crop width is the one used in generating the image,
         // but we need to reflect the requested "px" width in the URL generated by these functions
         // because it must match the input "canonical" url.
         // Example: /images/thumb/8/87/Manage-Fats-and-Sugars-on-the-Volumetrics-Diet-Step-12.jpg/-crop-342-254-300px-nowatermark-Manage-Fats-and-Sugars-on-the-Volumetrics-Diet-Step-12.jpg
         if (isset($params['reqwidth']) && $params['reqwidth'] > 0) {
             $wm = isset($params[WatermarkSupport::NO_WATERMARK]) && $params[WatermarkSupport::NO_WATERMARK] ? 'nowatermark-' : '';
             $thumbName = "-crop-{$rawParams['width']}-{$rawParams['height']}-" . "{$params['reqwidth']}px-" . $wm . $image->getName();
         } else {
             $thumbName = "-crop-{$rawParams['width']}-{$rawParams['height']}-" . $thumbName;
         }
     }
     return true;
 }
 public function execute()
 {
     global $IP;
     require_once "{$IP}/extensions/wikihow/common/S3.php";
     define('WH_USE_BACKUP_DB', true);
     $pageIds = array();
     // allow for the input files to be specified on the command line
     if ($this->getOption('stream')) {
         $data = stream_get_contents(STDIN);
         $data = array_map('trim', explode("\n", $data));
         foreach ($data as $inputTitle) {
             $title = Title::newFromText($inputTitle, 6);
             if (!$title) {
                 continue;
             }
             $id = $title->getArticleID();
             $pageIds[] = $id;
         }
     }
     // if provided title, add that to the array
     $titleText = $this->getOption('title');
     if ($titleText) {
         $title = Title::newFromText($titleText, 6);
         $id = $title->getArticleID();
         $pageIds[] = $id;
     }
     // if there is a start, add articles to the array
     $start = $this->getOption('start');
     if ($start) {
         $dbr = wfGetDB(DB_SLAVE);
         $options = array("page_id > {$start}", "page_namespace = 6");
         $stop = $this->getOption('stop');
         if ($stop) {
             $options[] = "page_id < {$stop}";
         }
         $res = $dbr->select("page", "page_id", $options, __FILE__);
         // put them all into an array first
         foreach ($res as $row) {
             $pageIds[] = $row->page_id;
         }
     }
     $purgeTitles = array();
     $filesToPurgeFromCDN = array();
     foreach ($pageIds as $pageId) {
         $title = Title::newFromID($pageId);
         $file = wfLocalFile($title);
         if (!$file) {
             continue;
         }
         $userName = $file->getUser("text");
         if (WatermarkSupport::isWikihowCreator($userName)) {
             decho("file", $title->getText(), false);
             if ($this->getOption('s3')) {
                 decho("will purge from s3", false, false);
                 self::purgeThumbnailsFromS3($file);
             }
             if ($this->getOption('regenerate')) {
                 decho("will regenerate thumbnails", $file->getThumbnails(), false);
                 WatermarkSupport::recreateThumbnails($file);
                 decho("regeneration of thumbnails complete", false, false);
             }
             if ($this->getOption('purgelocal')) {
                 decho("will purge local cache thumbnails", $file->getThumbnails(), false);
                 $file->purgeCache();
                 // get titles that point here so we can purge them and
                 // regenerate those pages so the thumbnails come back
                 $purgeTitles = array_unique(array_merge($purgeTitles, ImageHelper::getLinkedArticles($title)));
                 decho("purging of thumbnails complete", false, false);
             }
             if ($this->getOption('cdn')) {
                 $filesToPurgeFromCDN[] = $file;
             }
         }
     }
     //purge the titles that have linked to these images
     foreach ($purgeTitles as $linkedTitle) {
         decho('will purge', $linkedTitle, false);
         // will now get the parser output to refresh the thumbnail
         // or else cdn may get reset before the thumbnails are regenerated
         $wp = new WikiPage($linkedTitle);
         $wp->doPurge();
         $po = ParserOptions::newFromUser($wgUser);
         $wp->getParserOutput($po);
     }
     if ($this->getOption('cdn')) {
         decho("will purge from cdn", false, false);
         $this->purgeThumbnailsFromCDNetworks($filesToPurgeFromCDN);
     }
 }