X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2Fupload%2FUploadBase.php;h=5b15e82f34e121ca613c222b13fd9d90e599571c;hp=597c2777cffc14f9d9d837f29f4ca7fd0a4d83e2;hb=bd5a37aacf600bdd5f3a6e7998f92bd1d9326a8a;hpb=7b0f667d62cde98122d82002d5394e7c3963ab31 diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 597c2777cf..5b15e82f34 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -20,7 +20,6 @@ * @file * @ingroup Upload */ -use MediaWiki\MediaWikiServices; use MediaWiki\Shell\Shell; /** @@ -42,13 +41,36 @@ abstract class UploadBase { protected $mTempPath; /** @var TempFSFile|null Wrapper to handle deleting the temp file */ protected $tempFileObj; - - protected $mDesiredDestName, $mDestName, $mRemoveTempFile, $mSourceType; - protected $mTitle = false, $mTitleError = 0; - protected $mFilteredName, $mFinalExtension; - protected $mLocalFile, $mStashFile, $mFileSize, $mFileProps; + /** @var string|null */ + protected $mDesiredDestName; + /** @var string|null */ + protected $mDestName; + /** @var string|null */ + protected $mRemoveTempFile; + /** @var string|null */ + protected $mSourceType; + /** @var Title|bool */ + protected $mTitle = false; + /** @var int */ + protected $mTitleError = 0; + /** @var string|null */ + protected $mFilteredName; + /** @var string|null */ + protected $mFinalExtension; + /** @var LocalFile */ + protected $mLocalFile; + /** @var UploadStashFile */ + protected $mStashFile; + /** @var int|null */ + protected $mFileSize; + /** @var array|null */ + protected $mFileProps; + /** @var string[] */ protected $mBlackListedExtensions; - protected $mJavaDetected, $mSVGNSError; + /** @var bool|null */ + protected $mJavaDetected; + /** @var string|null */ + protected $mSVGNSError; protected static $safeXmlEncodings = [ 'UTF-8', @@ -357,13 +379,6 @@ abstract class UploadBase { return $result; } - $error = ''; - if ( !Hooks::run( 'UploadVerification', - [ $this->mDestName, $this->mTempPath, &$error ], '1.28' ) - ) { - return [ 'status' => self::HOOK_ABORTED, 'error' => $error ]; - } - return [ 'status' => self::OK ]; } @@ -1107,6 +1122,8 @@ abstract class UploadBase { * @throws UploadStashNotLoggedInException */ public function stashFile( User $user = null ) { + wfDeprecated( __METHOD__, '1.28' ); + return $this->doStashFile( $user ); } @@ -1124,29 +1141,6 @@ abstract class UploadBase { return $file; } - /** - * Stash a file in a temporary directory, returning a key which can be used - * to find the file again. See stashFile(). - * - * @deprecated since 1.28 - * @return string File key - */ - public function stashFileGetKey() { - wfDeprecated( __METHOD__, '1.28' ); - return $this->doStashFile()->getFileKey(); - } - - /** - * alias for stashFileGetKey, for backwards compatibility - * - * @deprecated since 1.28 - * @return string File key - */ - public function stashSession() { - wfDeprecated( __METHOD__, '1.28' ); - return $this->doStashFile()->getFileKey(); - } - /** * If we've modified the upload file we need to manually remove it * on exit to clean up. @@ -1508,7 +1502,7 @@ abstract class UploadBase { * @todo Replace this with a whitelist filter! * @param string $element * @param array $attribs - * @param array|null $data + * @param string|null $data * @return bool|array */ public function checkSvgScriptCallback( $element, $attribs, $data = null ) { @@ -2069,10 +2063,10 @@ abstract class UploadBase { $partname = $n ? substr( $filename, 0, $n ) : $filename; return ( - substr( $partname, 3, 3 ) == 'px-' || - substr( $partname, 2, 3 ) == 'px-' - ) && - preg_match( "/[0-9]{2}/", substr( $partname, 0, 2 ) ); + substr( $partname, 3, 3 ) == 'px-' || + substr( $partname, 2, 3 ) == 'px-' + ) && + preg_match( "/[0-9]{2}/", substr( $partname, 0, 2 ) ); } /** @@ -2191,10 +2185,10 @@ abstract class UploadBase { * @return Status[]|bool */ public static function getSessionStatus( User $user, $statusKey ) { - $cache = MediaWikiServices::getInstance()->getMainObjectStash(); - $key = $cache->makeKey( 'uploadstatus', $user->getId() ?: md5( $user->getName() ), $statusKey ); + $store = self::getUploadSessionStore(); + $key = self::getUploadSessionKey( $store, $user, $statusKey ); - return $cache->get( $key ); + return $store->get( $key ); } /** @@ -2202,19 +2196,42 @@ abstract class UploadBase { * * The value will be set in cache for 1 day * + * Avoid triggering this method on HTTP GET/HEAD requests + * * @param User $user * @param string $statusKey * @param array|bool $value * @return void */ public static function setSessionStatus( User $user, $statusKey, $value ) { - $cache = MediaWikiServices::getInstance()->getMainObjectStash(); - $key = $cache->makeKey( 'uploadstatus', $user->getId() ?: md5( $user->getName() ), $statusKey ); + $store = self::getUploadSessionStore(); + $key = self::getUploadSessionKey( $store, $user, $statusKey ); if ( $value === false ) { - $cache->delete( $key ); + $store->delete( $key ); } else { - $cache->set( $key, $value, $cache::TTL_DAY ); + $store->set( $key, $value, $store::TTL_DAY ); } } + + /** + * @param BagOStuff $store + * @param User $user + * @param string $statusKey + * @return string + */ + private static function getUploadSessionKey( BagOStuff $store, User $user, $statusKey ) { + return $store->makeKey( + 'uploadstatus', + $user->getId() ?: md5( $user->getName() ), + $statusKey + ); + } + + /** + * @return BagOStuff + */ + private static function getUploadSessionStore() { + return ObjectCache::getInstance( 'db-replicated' ); + } }