当前位置: 首页>>代码示例>>PHP>>正文


PHP MediaHandler类代码示例

本文整理汇总了PHP中MediaHandler的典型用法代码示例。如果您正苦于以下问题:PHP MediaHandler类的具体用法?PHP MediaHandler怎么用?PHP MediaHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MediaHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPropsFromPath

 /**
  * Get an associative array containing information about
  * a file with the given storage path.
  *
  * Resulting array fields include:
  *   - fileExists
  *   - size (filesize in bytes)
  *   - mime (as major/minor)
  *   - media_type (value to be used with the MEDIATYPE_xxx constants)
  *   - metadata (handler specific)
  *   - sha1 (in base 36)
  *   - width
  *   - height
  *   - bits (bitrate)
  *   - file-mime
  *   - major_mime
  *   - minor_mime
  *
  * @param string $path Filesystem path to a file
  * @param string|bool $ext The file extension, or true to extract it from the filename.
  *             Set it to false to ignore the extension.
  * @return array
  * @since 1.28
  */
 public function getPropsFromPath($path, $ext)
 {
     $fsFile = new FSFile($path);
     $info = $this->newPlaceholderProps();
     $info['fileExists'] = $fsFile->exists();
     if ($info['fileExists']) {
         $info['size'] = $fsFile->getSize();
         // bytes
         $info['sha1'] = $fsFile->getSha1Base36();
         # MIME type according to file contents
         $info['file-mime'] = $this->magic->guessMimeType($path, false);
         # Logical MIME type
         $ext = $ext === true ? FileBackend::extensionFromPath($path) : $ext;
         $info['mime'] = $this->magic->improveTypeFromExtension($info['file-mime'], $ext);
         list($info['major_mime'], $info['minor_mime']) = File::splitMime($info['mime']);
         $info['media_type'] = $this->magic->getMediaType($path, $info['mime']);
         # Height, width and metadata
         $handler = MediaHandler::getHandler($info['mime']);
         if ($handler) {
             $info['metadata'] = $handler->getMetadata($fsFile, $path);
             /** @noinspection PhpMethodParametersCountMismatchInspection */
             $gis = $handler->getImageSize($fsFile, $path, $info['metadata']);
             if (is_array($gis)) {
                 $info = $this->extractImageSizeInfo($gis) + $info;
             }
         }
     }
     return $info;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:53,代码来源:MWFileProps.php

示例2: testFitBoxWidth

 /**
  * @covers MediaHandler::fitBoxWidth
  *
  * @dataProvider provideTestFitBoxWidth
  */
 public function testFitBoxWidth($width, $height, $max, $expected)
 {
     $y = round($expected * $height / $width);
     $result = MediaHandler::fitBoxWidth($width, $height, $max);
     $y2 = round($result * $height / $width);
     $this->assertEquals($expected, $result, "({$width}, {$height}, {$max}) wanted: {$expected}x{$y}, got: {z{$result}}x{$y2}");
 }
开发者ID:MediaWiki-stable,项目名称:1.26.1,代码行数:12,代码来源:MediaHandlerTest.php

示例3: newFromTitle

	/**
	 * @param $title Title
	 * @param $repo ForeignApiRepo
	 * @return ForeignAPIFile|null
	 */
	static function newFromTitle( Title $title, $repo ) {
		$data = $repo->fetchImageQuery( array(
			'titles' => 'File:' . $title->getDBkey(),
			'iiprop' => self::getProps(),
			'prop' => 'imageinfo',
			'iimetadataversion' => MediaHandler::getMetadataVersion()
		) );

		$info = $repo->getImageInfo( $data );

		if ( $info ) {
			$lastRedirect = isset( $data['query']['redirects'] )
				? count( $data['query']['redirects'] ) - 1
				: -1;
			if ( $lastRedirect >= 0 ) {
				$newtitle = Title::newFromText( $data['query']['redirects'][$lastRedirect]['to'] );
				$img = new self( $newtitle, $repo, $info, true );
				if ( $img ) {
					$img->redirectedFrom( $title->getDBkey() );
				}
			} else {
				$img = new self( $title, $repo, $info, true );
			}
			return $img;
		} else {
			return null;
		}
	}
开发者ID:nahoj,项目名称:mediawiki_ynh,代码行数:33,代码来源:ForeignAPIFile.php

示例4: testFitBoxWidth

 /**
  * @covers MediaHandler::fitBoxWidth
  * @todo split into a dataprovider and test method
  */
 public function testFitBoxWidth()
 {
     $vals = array(array('width' => 50, 'height' => 50, 'tests' => array(50 => 50, 17 => 17, 18 => 18)), array('width' => 366, 'height' => 300, 'tests' => array(50 => 61, 17 => 21, 18 => 22)), array('width' => 300, 'height' => 366, 'tests' => array(50 => 41, 17 => 14, 18 => 15)), array('width' => 100, 'height' => 400, 'tests' => array(50 => 12, 17 => 4, 18 => 4)));
     foreach ($vals as $row) {
         $tests = $row['tests'];
         $height = $row['height'];
         $width = $row['width'];
         foreach ($tests as $max => $expected) {
             $y = round($expected * $height / $width);
             $result = MediaHandler::fitBoxWidth($width, $height, $max);
             $y2 = round($result * $height / $width);
             $this->assertEquals($expected, $result, "({$width}, {$height}, {$max}) wanted: {$expected}x{$y}, got: {$result}x{$y2}");
         }
     }
 }
开发者ID:Habatchii,项目名称:wikibase-for-mediawiki,代码行数:19,代码来源:MediaHandlerTest.php

示例5: upload

 /**
  * Upload a file and record it in the DB
  * @param string $srcPath Source storage path, virtual URL, or filesystem path
  * @param string $comment Upload description
  * @param string $pageText Text to use for the new description page,
  *   if a new description page is created
  * @param int|bool $flags Flags for publish()
  * @param array|bool $props File properties, if known. This can be used to
  *   reduce the upload time when uploading virtual URLs for which the file
  *   info is already known
  * @param string|bool $timestamp Timestamp for img_timestamp, or false to use the
  *   current time
  * @param User|null $user User object or null to use $wgUser
  * @param string[] $tags Change tags to add to the log entry and page revision.
  *   (This doesn't check $user's permissions.)
  * @return FileRepoStatus On success, the value member contains the
  *     archive name, or an empty string if it was a new file.
  */
 function upload($srcPath, $comment, $pageText, $flags = 0, $props = false, $timestamp = false, $user = null, $tags = array())
 {
     global $wgContLang;
     if ($this->getRepo()->getReadOnlyReason() !== false) {
         return $this->readOnlyFatalStatus();
     }
     if (!$props) {
         if ($this->repo->isVirtualUrl($srcPath) || FileBackend::isStoragePath($srcPath)) {
             $props = $this->repo->getFileProps($srcPath);
         } else {
             $props = FSFile::getPropsFromPath($srcPath);
         }
     }
     $options = array();
     $handler = MediaHandler::getHandler($props['mime']);
     if ($handler) {
         $options['headers'] = $handler->getStreamHeaders($props['metadata']);
     } else {
         $options['headers'] = array();
     }
     // Trim spaces on user supplied text
     $comment = trim($comment);
     // Truncate nicely or the DB will do it for us
     // non-nicely (dangling multi-byte chars, non-truncated version in cache).
     $comment = $wgContLang->truncate($comment, 255);
     $this->lock();
     // begin
     $status = $this->publish($srcPath, $flags, $options);
     if ($status->successCount >= 2) {
         // There will be a copy+(one of move,copy,store).
         // The first succeeding does not commit us to updating the DB
         // since it simply copied the current version to a timestamped file name.
         // It is only *preferable* to avoid leaving such files orphaned.
         // Once the second operation goes through, then the current version was
         // updated and we must therefore update the DB too.
         $oldver = $status->value;
         if (!$this->recordUpload2($oldver, $comment, $pageText, $props, $timestamp, $user, $tags)) {
             $status->fatal('filenotfound', $srcPath);
         }
     }
     $this->unlock();
     // done
     return $status;
 }
开发者ID:paladox,项目名称:2,代码行数:62,代码来源:LocalFile.php

示例6: tearDown

 protected function tearDown()
 {
     wfProfileIn(__METHOD__);
     // Cleaning up temporary files
     foreach ($this->tmpFiles as $fileName) {
         if (is_file($fileName) || is_link($fileName)) {
             unlink($fileName);
         } elseif (is_dir($fileName)) {
             wfRecursiveRemoveDir($fileName);
         }
     }
     if ($this->needsDB() && $this->db) {
         // Clean up open transactions
         while ($this->db->trxLevel() > 0) {
             $this->db->rollback();
         }
         // don't ignore DB errors
         $this->db->ignoreErrors(false);
     }
     // Restore mw globals
     foreach ($this->mwGlobals as $key => $value) {
         $GLOBALS[$key] = $value;
     }
     $this->mwGlobals = array();
     RequestContext::resetMain();
     MediaHandler::resetCache();
     $phpErrorLevel = intval(ini_get('error_reporting'));
     if ($phpErrorLevel !== $this->phpErrorLevel) {
         ini_set('error_reporting', $this->phpErrorLevel);
         $oldHex = strtoupper(dechex($this->phpErrorLevel));
         $newHex = strtoupper(dechex($phpErrorLevel));
         $message = "PHP error_reporting setting was left dirty: " . "was 0x{$oldHex} before test, 0x{$newHex} after test!";
         $this->fail($message);
     }
     parent::tearDown();
     wfProfileOut(__METHOD__);
 }
开发者ID:Habatchii,项目名称:wikibase-for-mediawiki,代码行数:37,代码来源:MediaWikiTestCase.php

示例7: array

                 echo " Failed to load comment file {$f}, using default comment. ";
             }
         }
     }
     if (!$commentText) {
         $commentText = $comment;
     }
 }
 # Import the file
 if (isset($options['dry'])) {
     echo " publishing {$file} by '" . $wgUser->getName() . "', comment '{$commentText}'... ";
 } else {
     $props = FSFile::getPropsFromPath($file);
     $flags = 0;
     $publishOptions = array();
     $handler = MediaHandler::getHandler($props['mime']);
     if ($handler) {
         $publishOptions['headers'] = $handler->getStreamHeaders($props['metadata']);
     } else {
         $publishOptions['headers'] = array();
     }
     $archive = $image->publish($file, $flags, $publishOptions);
     if (!$archive->isGood()) {
         echo "failed. (" . $archive->getWikiText() . ")\n";
         $failed++;
         continue;
     }
 }
 $commentText = SpecialUpload::getInitialPageText($commentText, $license);
 if (!isset($options['summary'])) {
     $summary = $commentText;
开发者ID:eliagbayani,项目名称:LiteratureEditor,代码行数:31,代码来源:importImages.php

示例8: getThumbType

 /**
  * Get the thumbnail extension and MIME type for a given source MIME type
  * @return array thumbnail extension and MIME type
  */
 static function getThumbType($ext, $mime)
 {
     $handler = MediaHandler::getHandler($mime);
     if ($handler) {
         return $handler->getThumbType($ext, $mime);
     } else {
         return array($ext, $mime);
     }
 }
开发者ID:Jobava,项目名称:diacritice-meta-repo,代码行数:13,代码来源:Image.php

示例9: execute

	function execute() {
		global $wgUploadBaseUrl, $wgUploadPath, $wgScriptPath, $wgServer;

		// Determine URI
		if ( $_SERVER['REQUEST_URI'][0] == '/' ) {
			$url = ( !empty( $_SERVER['HTTPS'] ) ? 'https://' : 'http://' ) . 
				$_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
		} else {
			$url = $_SERVER['REQUEST_URI'];
		}

		if ( $wgUploadBaseUrl ) {
			$thumbBase = $wgUploadBaseUrl . $wgUploadPath . '/thumb';
		} else {
			$thumbBase = $wgServer . $wgUploadPath . '/thumb';
		}
		if ( substr( $url, 0, strlen( $thumbBase ) ) != $thumbBase ) {
			// Not a thumbnail URL
			header( 'X-Debug: not thumb' );
			$this->real404();
			return true;
		}

		$rel = substr( $url, strlen( $thumbBase ) + 1 ); // plus one for slash
		// Check for path traversal
		if ( !$this->validateFilename( $rel ) ) {
			header( 'X-Debug: invalid path traversal' );
			$this->real404();
			return false;
		}

		if ( !preg_match( '!^(\w)/(\w\w)/([^/]*)/([^/]*)$!', $rel, $parts ) ) {
			header( 'X-Debug: regex mismatch' );
			$this->real404();
			return false;
		}

		list( $all, $hash1, $hash2, $filename, $thumbName ) = $parts;
		$srcNamePos = strrpos( $thumbName, $filename );
		if ( $srcNamePos === false ) {
			header( 'X-Debug: filename/fn2 mismatch' );
			$this->real404();
			return false;
		}
		$extraExt = substr( $thumbName, $srcNamePos + strlen( $filename ) );
		if ( $extraExt != '' && $extraExt[0] != '.' ) {
			header( "X-Debug: invalid trailing characters in filename: $extraExt" );
			$this->real404();
			return false;
		}
		// Determine MIME type
		$extPos = strrpos( $filename, '.' );
		$srcExt = $extPos === false ? '' : substr( $filename, $extPos + 1 );
		$magic = MimeMagic::singleton();
		$mime = $magic->guessTypesForExtension( $srcExt );
		$handler = MediaHandler::getHandler( $mime );
		if ( !$handler ) {
			header( 'X-Debug: no handler' );
			$this->real404();
			return false;
		}

		// Parse parameter string
		$paramString = substr( $thumbName, 0, $srcNamePos - 1 );
		$params = $handler->parseParamString( $paramString );
		if ( !$params ) {
			header( "X-Debug: handler for $mime says param string is invalid" );
			$this->real404();
			return false;
		}

		// Open the destination temporary file
		$dstPath = "{$this->publicDir}/thumb/$rel";
		$tmpPath = "$dstPath.temp.MW_WebStore";
		$tmpFile = @fopen( $tmpPath, 'a+' );
		if ( !$tmpFile ) {
			$this->htmlError( 500, 'webstore_temp_open', $tmpPath );
			return false;
		}

		// Get an exclusive lock
		if ( !flock( $tmpFile, LOCK_EX | LOCK_NB ) ) {
			wfDebug( "Waiting for shared lock..." );
			if ( !flock( $tmpFile, LOCK_SH ) ) {
				wfDebug( "failed\n" );
				$this->htmlError( 500, 'webstore_temp_lock' );
				return false;
			}
			wfDebug( "OK\n" );
			// Close it and see if it appears at $dstPath
			fclose( $tmpFile );
			if ( $this->windows ) {
				// Rename happens after unlock on windows, so we have to wait for it
				usleep( 200000 );
			}
			if ( file_exists( $dstPath ) ) {
				// Stream it out
				$magic = MimeMagic::singleton();
				$type = $magic->guessMimeType( $dstPath );
				$dstFile = fopen( $dstPath, 'r' );
//.........这里部分代码省略.........
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:101,代码来源:404-handler.php

示例10: upload

 /**
  * Upload a file and record it in the DB
  * @param string $srcPath Source storage path, virtual URL, or filesystem path
  * @param string $comment Upload description
  * @param string $pageText Text to use for the new description page,
  *   if a new description page is created
  * @param int|bool $flags Flags for publish()
  * @param array|bool $props File properties, if known. This can be used to
  *   reduce the upload time when uploading virtual URLs for which the file
  *   info is already known
  * @param string|bool $timestamp Timestamp for img_timestamp, or false to use the
  *   current time
  * @param User|null $user User object or null to use $wgUser
  *
  * @return FileRepoStatus object. On success, the value member contains the
  *     archive name, or an empty string if it was a new file.
  */
 function upload($srcPath, $comment, $pageText, $flags = 0, $props = false, $timestamp = false, $user = null)
 {
     global $wgContLang;
     if ($this->getRepo()->getReadOnlyReason() !== false) {
         return $this->readOnlyFatalStatus();
     }
     if (!$props) {
         wfProfileIn(__METHOD__ . '-getProps');
         if ($this->repo->isVirtualUrl($srcPath) || FileBackend::isStoragePath($srcPath)) {
             $props = $this->repo->getFileProps($srcPath);
         } else {
             $props = FSFile::getPropsFromPath($srcPath);
         }
         wfProfileOut(__METHOD__ . '-getProps');
     }
     $options = array();
     $handler = MediaHandler::getHandler($props['mime']);
     if ($handler) {
         $options['headers'] = $handler->getStreamHeaders($props['metadata']);
     } else {
         $options['headers'] = array();
     }
     // Trim spaces on user supplied text
     $comment = trim($comment);
     // truncate nicely or the DB will do it for us
     // non-nicely (dangling multi-byte chars, non-truncated version in cache).
     $comment = $wgContLang->truncate($comment, 255);
     $this->lock();
     // begin
     $status = $this->publish($srcPath, $flags, $options);
     if ($status->successCount > 0) {
         # Essentially we are displacing any existing current file and saving
         # a new current file at the old location. If just the first succeeded,
         # we still need to displace the current DB entry and put in a new one.
         if (!$this->recordUpload2($status->value, $comment, $pageText, $props, $timestamp, $user)) {
             $status->fatal('filenotfound', $srcPath);
         }
     }
     $this->unlock();
     // done
     return $status;
 }
开发者ID:spring,项目名称:spring-website,代码行数:59,代码来源:LocalFile.php

示例11: getShortDesc

 /**
  * @return string
  */
 function getShortDesc()
 {
     $handler = $this->getHandler();
     if ($handler) {
         return $handler->getShortDesc($this);
     } else {
         return MediaHandler::getGeneralShortDesc($this);
     }
 }
开发者ID:mangowi,项目名称:mediawiki,代码行数:12,代码来源:File.php

示例12: verifyFile

 /**
  * Verifies that it's ok to include the uploaded file
  *
  * @return mixed True of the file is verified, array otherwise.
  */
 protected function verifyFile()
 {
     global $wgVerifyMimeType, $wgDisableUploadScriptChecks;
     $status = $this->verifyPartialFile();
     if ($status !== true) {
         return $status;
     }
     $mwProps = new MWFileProps(MimeMagic::singleton());
     $this->mFileProps = $mwProps->getPropsFromPath($this->mTempPath, $this->mFinalExtension);
     $mime = $this->mFileProps['mime'];
     if ($wgVerifyMimeType) {
         # XXX: Missing extension will be caught by validateName() via getTitle()
         if ($this->mFinalExtension != '' && !$this->verifyExtension($mime, $this->mFinalExtension)) {
             return ['filetype-mime-mismatch', $this->mFinalExtension, $mime];
         }
     }
     # check for htmlish code and javascript
     if (!$wgDisableUploadScriptChecks) {
         if ($this->mFinalExtension == 'svg' || $mime == 'image/svg+xml') {
             $svgStatus = $this->detectScriptInSvg($this->mTempPath, false);
             if ($svgStatus !== false) {
                 return $svgStatus;
             }
         }
     }
     $handler = MediaHandler::getHandler($mime);
     if ($handler) {
         $handlerStatus = $handler->verifyUpload($this->mTempPath);
         if (!$handlerStatus->isOK()) {
             $errors = $handlerStatus->getErrorsArray();
             return reset($errors);
         }
     }
     $error = true;
     Hooks::run('UploadVerifyFile', [$this, $mime, &$error]);
     if ($error !== true) {
         if (!is_array($error)) {
             $error = [$error];
         }
         return $error;
     }
     wfDebug(__METHOD__ . ": all clear; passing.\n");
     return true;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:49,代码来源:UploadBase.php

示例13: getProps

 /**
  * Get an associative array containing information about
  * a file with the given storage path.
  *
  * @param $ext Mixed: the file extension, or true to extract it from the filename.
  *             Set it to false to ignore the extension.
  *
  * @return array
  */
 public function getProps($ext = true)
 {
     wfProfileIn(__METHOD__);
     wfDebug(__METHOD__ . ": Getting file info for {$this->path}\n");
     $info = self::placeholderProps();
     $info['fileExists'] = $this->exists();
     if ($info['fileExists']) {
         $magic = MimeMagic::singleton();
         # get the file extension
         if ($ext === true) {
             $ext = self::extensionFromPath($this->path);
         }
         # mime type according to file contents
         $info['file-mime'] = $this->getMimeType();
         # logical mime type
         $info['mime'] = $magic->improveTypeFromExtension($info['file-mime'], $ext);
         list($info['major_mime'], $info['minor_mime']) = File::splitMime($info['mime']);
         $info['media_type'] = $magic->getMediaType($this->path, $info['mime']);
         # Get size in bytes
         $info['size'] = $this->getSize();
         # Height, width and metadata
         $handler = MediaHandler::getHandler($info['mime']);
         if ($handler) {
             $tempImage = (object) array();
             $info['metadata'] = $handler->getMetadata($tempImage, $this->path);
             $gis = $handler->getImageSize($tempImage, $this->path, $info['metadata']);
             if (is_array($gis)) {
                 $info = $this->extractImageSizeInfo($gis) + $info;
             }
         }
         $info['sha1'] = $this->getSha1Base36();
         wfDebug(__METHOD__ . ": {$this->path} loaded, {$info['size']} bytes, {$info['mime']}.\n");
     } else {
         wfDebug(__METHOD__ . ": {$this->path} NOT FOUND!\n");
     }
     wfProfileOut(__METHOD__);
     return $info;
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:47,代码来源:FSFile.php

示例14: outputHook

 static function outputHook($outputPage, $parserOutput, $data)
 {
     $instance = MediaHandler::getHandler('application/ogg');
     if ($instance) {
         $instance->setHeaders($outputPage);
     }
 }
开发者ID:yusufchang,项目名称:app,代码行数:7,代码来源:OggHandler_body.php

示例15: verifyFile

 /**
  * Verifies that it's ok to include the uploaded file
  *
  * @return mixed true of the file is verified, array otherwise.
  */
 protected function verifyFile()
 {
     global $wgVerifyMimeType;
     wfProfileIn(__METHOD__);
     $status = $this->verifyPartialFile();
     if ($status !== true) {
         wfProfileOut(__METHOD__);
         return $status;
     }
     $this->mFileProps = FSFile::getPropsFromPath($this->mTempPath, $this->mFinalExtension);
     $mime = $this->mFileProps['file-mime'];
     if ($wgVerifyMimeType) {
         # XXX: Missing extension will be caught by validateName() via getTitle()
         if ($this->mFinalExtension != '' && !$this->verifyExtension($mime, $this->mFinalExtension)) {
             wfProfileOut(__METHOD__);
             return array('filetype-mime-mismatch', $this->mFinalExtension, $mime);
         }
     }
     $handler = MediaHandler::getHandler($mime);
     if ($handler) {
         $handlerStatus = $handler->verifyUpload($this->mTempPath);
         if (!$handlerStatus->isOK()) {
             $errors = $handlerStatus->getErrorsArray();
             wfProfileOut(__METHOD__);
             return reset($errors);
         }
     }
     wfRunHooks('UploadVerifyFile', array($this, $mime, &$status));
     if ($status !== true) {
         wfProfileOut(__METHOD__);
         return $status;
     }
     wfDebug(__METHOD__ . ": all clear; passing.\n");
     wfProfileOut(__METHOD__);
     return true;
 }
开发者ID:elf-pavlik,项目名称:web-payments.org,代码行数:41,代码来源:UploadBase.php


注:本文中的MediaHandler类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。