コード例 #1
0
 public function execute()
 {
     $out = $this->mSpecial->getOutput();
     $dbr = wfGetDB(DB_SLAVE);
     $row = $dbr->selectRow('moderation', array('mod_user AS user', 'mod_user_text AS user_text', 'mod_title AS title', 'mod_stash_key AS stash_key'), array('mod_id' => $this->id), __METHOD__);
     if (!$row) {
         throw new ModerationError('moderation-edit-not-found');
     }
     $user = $row->user ? User::newFromId($row->user) : User::newFromName($row->user_text, false);
     $stash = RepoGroup::singleton()->getLocalRepo()->getUploadStash($user);
     try {
         $file = $stash->getFile($row->stash_key);
     } catch (MWException $e) {
         return $this->send404ImageNotFound();
     }
     $is_thumb = $this->mSpecial->getRequest()->getVal('thumb');
     if ($is_thumb) {
         $thumb = $file->transform(array('width' => self::THUMB_WIDTH), File::RENDER_NOW);
         if ($thumb) {
             if ($thumb->fileIsSource()) {
                 $is_thumb = false;
             } else {
                 $file = new UnregisteredLocalFile(false, $stash->repo, $thumb->getStoragePath(), false);
             }
         }
     }
     if (!$file) {
         return $this->send404ImageNotFound();
     }
     $thumb_filename = '';
     if ($is_thumb) {
         $thumb_filename .= $file->getWidth() . 'px-';
     }
     $thumb_filename .= $row->title;
     $headers = array();
     $headers[] = "Content-Disposition: " . FileBackend::makeContentDisposition('inline', $thumb_filename);
     $out->disable();
     # No HTML output (image only)
     $file->getRepo()->streamFile($file->getPath(), $headers);
 }
コード例 #2
0
ファイル: File.php プロジェクト: mangowi/mediawiki
 /**
  * @param string $thumbName Thumbnail name
  * @return string Content-Disposition header value
  */
 function getThumbDisposition($thumbName)
 {
     $fileName = $this->name;
     // file name to suggest
     $thumbExt = FileBackend::extensionFromPath($thumbName);
     if ($thumbExt != '' && $thumbExt !== $this->getExtension()) {
         $fileName .= ".{$thumbExt}";
     }
     return FileBackend::makeContentDisposition('inline', $fileName);
 }
コード例 #3
0
 /**
  * Send response headers (using the header() function) that are necessary to correctly serve the
  * image data for this image, as returned by getImageData().
  *
  * Note that the headers are independent of the language or image variant.
  *
  * @param ResourceLoaderContext $context Image context
  */
 public function sendResponseHeaders(ResourceLoaderContext $context)
 {
     $format = $context->getFormat();
     $mime = $this->getMimeType($format);
     $filename = $this->getName() . '.' . $this->getExtension($format);
     header('Content-Type: ' . $mime);
     header('Content-Disposition: ' . FileBackend::makeContentDisposition('inline', $filename));
 }
コード例 #4
0
 public function testSanitizeOpHeaders()
 {
     $be = TestingAccessWrapper::newFromObject(new MemoryFileBackend(array('name' => 'localtesting', 'wikiId' => wfWikiID())));
     $name = wfRandomString(300);
     $input = array('headers' => array('content-Disposition' => FileBackend::makeContentDisposition('inline', $name), 'Content-dUration' => 25.6, 'X-LONG-VALUE' => str_pad('0', 300), 'CONTENT-LENGTH' => 855055));
     $expected = array('headers' => array('content-disposition' => FileBackend::makeContentDisposition('inline', $name), 'content-duration' => 25.6, 'content-length' => 855055));
     MediaWiki\suppressWarnings();
     $actual = $be->sanitizeOpHeaders($input);
     MediaWiki\restoreWarnings();
     $this->assertEquals($expected, $actual, "Header sanitized properly");
 }