From d185ec734ae67e61fe03d1b56d9dc387ff375e19 Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Fri, 9 May 2014 19:56:05 +0200 Subject: [PATCH] Pass phpcs-strict on includes/upload Change-Id: I80eaa22398227a4edb7160d560b625102c7436ac --- includes/upload/UploadBase.php | 141 +++++++++++++++++++++---------- includes/upload/UploadStash.php | 144 ++++++++++++++++++++------------ 2 files changed, 191 insertions(+), 94 deletions(-) diff --git a/includes/upload/UploadBase.php b/includes/upload/UploadBase.php index 9d56479045..bef80be2eb 100644 --- a/includes/upload/UploadBase.php +++ b/includes/upload/UploadBase.php @@ -44,7 +44,13 @@ abstract class UploadBase { protected $mBlackListedExtensions; protected $mJavaDetected, $mSVGNSError; - protected static $safeXmlEncodings = array( 'UTF-8', 'ISO-8859-1', 'ISO-8859-2', 'UTF-16', 'UTF-32' ); + protected static $safeXmlEncodings = array( + 'UTF-8', + 'ISO-8859-1', + 'ISO-8859-2', + 'UTF-16', + 'UTF-32' + ); const SUCCESS = 0; const OK = 0; @@ -125,7 +131,7 @@ abstract class UploadBase { } // Upload handlers. Should probably just be a global. - static $uploadHandlers = array( 'Stash', 'File', 'Url' ); + private static $uploadHandlers = array( 'Stash', 'File', 'Url' ); /** * Create a form of UploadBase depending on wpSourceType and initializes it @@ -259,8 +265,9 @@ abstract class UploadBase { wfProfileIn( __METHOD__ ); $repo = RepoGroup::singleton()->getLocalRepo(); if ( $repo->isVirtualUrl( $srcPath ) ) { - // @todo just make uploads work with storage paths - // UploadFromStash loads files via virtual URLs + /** @todo Just make uploads work with storage paths UploadFromStash + * loads files via virtual URLs. + */ $tmpFile = $repo->getLocalCopy( $srcPath ); if ( $tmpFile ) { $tmpFile->bind( $this ); // keep alive with $this @@ -567,8 +574,10 @@ abstract class UploadBase { } /** - * Alias for verifyTitlePermissions. The function was originally 'verifyPermissions' - * but that suggests it's checking the user, when it's really checking the title + user combination. + * Alias for verifyTitlePermissions. The function was originally + * 'verifyPermissions', but that suggests it's checking the user, when it's + * really checking the title + user combination. + * * @param User $user User object to verify the permissions against * @return mixed An array as returned by getUserPermissionsErrors or true * in case the user has proper permissions. @@ -645,7 +654,8 @@ abstract class UploadBase { if ( $this->mDesiredDestName != $filename && $comparableName != $filename ) { $warnings['badfilename'] = $filename; // Debugging for bug 62241 - wfDebugLog( 'upload', "Filename: '$filename', mDesiredDestName: '$this->mDesiredDestName', comparableName: '$comparableName'" ); + wfDebugLog( 'upload', "Filename: '$filename', mDesiredDestName: " + . "'$this->mDesiredDestName', comparableName: '$comparableName'" ); } // Check whether the file extension is on the unwanted list @@ -727,7 +737,11 @@ abstract class UploadBase { if ( $status->isGood() ) { if ( $watch ) { - WatchAction::doWatch( $this->getLocalFile()->getTitle(), $user, WatchedItem::IGNORE_USER_RIGHTS ); + WatchAction::doWatch( + $this->getLocalFile()->getTitle(), + $user, + WatchedItem::IGNORE_USER_RIGHTS + ); } wfRunHooks( 'UploadComplete', array( &$this ) ); } @@ -844,7 +858,8 @@ abstract class UploadBase { # If there was more than one "extension", reassemble the base # filename to prevent bogus complaints about length if ( count( $ext ) > 1 ) { - for ( $i = 0; $i < count( $ext ) - 1; $i++ ) { + $iterations = count( $ext ) - 1; + for ( $i = 0; $i < $iterations; $i++ ) { $partname .= '.' . $ext[$i]; } } @@ -876,13 +891,16 @@ abstract class UploadBase { } /** - * If the user does not supply all necessary information in the first upload form submission (either by accident or - * by design) then we may want to stash the file temporarily, get more information, and publish the file later. + * If the user does not supply all necessary information in the first upload + * form submission (either by accident or by design) then we may want to + * stash the file temporarily, get more information, and publish the file + * later. * - * This method will stash a file in a temporary directory for later processing, and save the necessary descriptive info - * into the database. - * This method returns the file object, which also has a 'fileKey' property which can be passed through a form or - * API request to find this stashed file again. + * This method will stash a file in a temporary directory for later + * processing, and save the necessary descriptive info into the database. + * This method returns the file object, which also has a 'fileKey' property + * which can be passed through a form or API request to find this stashed + * file again. * * @param User $user * @return UploadStashFile Stashed file @@ -901,7 +919,8 @@ abstract class UploadBase { } /** - * Stash a file in a temporary directory, returning a key which can be used to find the file again. See stashFile(). + * Stash a file in a temporary directory, returning a key which can be used + * to find the file again. See stashFile(). * * @return string File key */ @@ -1012,10 +1031,11 @@ abstract class UploadBase { } elseif ( $match === true ) { wfDebug( __METHOD__ . ": mime type $mime matches extension $extension, passing file\n" ); - #TODO: if it's a bitmap, make sure PHP or ImageMagic resp. can handle it! + /** @todo If it's a bitmap, make sure PHP or ImageMagick resp. can handle it! */ return true; } else { - wfDebug( __METHOD__ . ": mime type $mime mismatches file extension $extension, rejecting file\n" ); + wfDebug( __METHOD__ + . ": mime type $mime mismatches file extension $extension, rejecting file\n" ); return false; } @@ -1070,7 +1090,7 @@ abstract class UploadBase { $chunk = trim( $chunk ); - # @todo FIXME: Convert from UTF-16 if necessary! + /** @todo FIXME: Convert from UTF-16 if necessary! */ wfDebug( __METHOD__ . ": checking for embedded scripts and HTML stuff\n" ); # check for HTML doctype @@ -1315,7 +1335,7 @@ abstract class UploadBase { if ( !in_array( $namespace, $validNamespaces ) ) { wfDebug( __METHOD__ . ": Non-svg namespace '$namespace' in uploaded file.\n" ); - // @TODO return a status object to a closure in XmlTypeCheck, for MW1.21+ + /** @todo Return a status object to a closure in XmlTypeCheck, for MW1.21+ */ $this->mSVGNSError = $namespace; return true; @@ -1330,7 +1350,8 @@ abstract class UploadBase { return true; } - # e.g., alert(1) + # e.g., + # alert(1) if ( $strippedElement == 'handler' ) { wfDebug( __METHOD__ . ": Found scriptable element '$element' in uploaded file.\n" ); @@ -1356,48 +1377,62 @@ abstract class UploadBase { $value = strtolower( $value ); if ( substr( $stripped, 0, 2 ) == 'on' ) { - wfDebug( __METHOD__ . ": Found event-handler attribute '$attrib'='$value' in uploaded file.\n" ); + wfDebug( __METHOD__ + . ": Found event-handler attribute '$attrib'='$value' in uploaded file.\n" ); return true; } # href with javascript target if ( $stripped == 'href' && strpos( strtolower( $value ), 'javascript:' ) !== false ) { - wfDebug( __METHOD__ . ": Found script in href attribute '$attrib'='$value' in uploaded file.\n" ); + wfDebug( __METHOD__ + . ": Found script in href attribute '$attrib'='$value' in uploaded file.\n" ); return true; } # href with embedded svg as target if ( $stripped == 'href' && preg_match( '!data:[^,]*image/svg[^,]*,!sim', $value ) ) { - wfDebug( __METHOD__ . ": Found href to embedded svg \"<$strippedElement '$attrib'='$value'...\" in uploaded file.\n" ); + wfDebug( __METHOD__ . ": Found href to embedded svg " + . "\"<$strippedElement '$attrib'='$value'...\" in uploaded file.\n" ); return true; } # href with embedded (text/xml) svg as target if ( $stripped == 'href' && preg_match( '!data:[^,]*text/xml[^,]*,!sim', $value ) ) { - wfDebug( __METHOD__ . ": Found href to embedded svg \"<$strippedElement '$attrib'='$value'...\" in uploaded file.\n" ); + wfDebug( __METHOD__ . ": Found href to embedded svg " + . "\"<$strippedElement '$attrib'='$value'...\" in uploaded file.\n" ); return true; } # use set/animate to add event-handler attribute to parent - if ( ( $strippedElement == 'set' || $strippedElement == 'animate' ) && $stripped == 'attributename' && substr( $value, 0, 2 ) == 'on' ) { - wfDebug( __METHOD__ . ": Found svg setting event-handler attribute with \"<$strippedElement $stripped='$value'...\" in uploaded file.\n" ); + if ( ( $strippedElement == 'set' || $strippedElement == 'animate' ) + && $stripped == 'attributename' + && substr( $value, 0, 2 ) == 'on' + ) { + wfDebug( __METHOD__ . ": Found svg setting event-handler attribute with " + . "\"<$strippedElement $stripped='$value'...\" in uploaded file.\n" ); return true; } # use set to add href attribute to parent element - if ( $strippedElement == 'set' && $stripped == 'attributename' && strpos( $value, 'href' ) !== false ) { + if ( $strippedElement == 'set' + && $stripped == 'attributename' + && strpos( $value, 'href' ) !== false + ) { wfDebug( __METHOD__ . ": Found svg setting href attribute '$value' in uploaded file.\n" ); return true; } # use set to add a remote / data / script target to an element - if ( $strippedElement == 'set' && $stripped == 'to' && preg_match( '!(http|https|data|script):!sim', $value ) ) { + if ( $strippedElement == 'set' + && $stripped == 'to' + && preg_match( '!(http|https|data|script):!sim', $value ) + ) { wfDebug( __METHOD__ . ": Found svg setting attribute to '$value' in uploaded file.\n" ); return true; @@ -1405,17 +1440,26 @@ abstract class UploadBase { # use handler attribute with remote / data / script if ( $stripped == 'handler' && preg_match( '!(http|https|data|script):!sim', $value ) ) { - wfDebug( __METHOD__ . ": Found svg setting handler with remote/data/script '$attrib'='$value' in uploaded file.\n" ); + wfDebug( __METHOD__ . ": Found svg setting handler with remote/data/script " + . "'$attrib'='$value' in uploaded file.\n" ); return true; } # use CSS styles to bring in remote code # catch url("http:..., url('http:..., url(http:..., but not url("#..., url('#..., url(#.... - if ( $stripped == 'style' && preg_match_all( '!((?:font|clip-path|fill|filter|marker|marker-end|marker-mid|marker-start|mask|stroke)\s*:\s*url\s*\(\s*["\']?\s*[^#]+.*?\))!sim', $value, $matches ) ) { + $tagsList = "font|clip-path|fill|filter|marker|marker-end|marker-mid|marker-start|mask|stroke"; + if ( $stripped == 'style' + && preg_match_all( + '!((?:' . $tagsList . ')\s*:\s*url\s*\(\s*["\']?\s*[^#]+.*?\))!sim', + $value, + $matches + ) + ) { foreach ( $matches[1] as $match ) { - if ( !preg_match( '!(?:font|clip-path|fill|filter|marker|marker-end|marker-mid|marker-start|mask|stroke)\s*:\s*url\s*\(\s*(#|\'#|"#)!sim', $match ) ) { - wfDebug( __METHOD__ . ": Found svg setting a style with remote url '$attrib'='$value' in uploaded file.\n" ); + if ( !preg_match( '!(?:' . $tagsList . ')\s*:\s*url\s*\(\s*(#|\'#|"#)!sim', $match ) ) { + wfDebug( __METHOD__ . ": Found svg setting a style with " + . "remote url '$attrib'='$value' in uploaded file.\n" ); return true; } @@ -1423,8 +1467,12 @@ abstract class UploadBase { } # image filters can pull in url, which could be svg that executes scripts - if ( $strippedElement == 'image' && $stripped == 'filter' && preg_match( '!url\s*\(!sim', $value ) ) { - wfDebug( __METHOD__ . ": Found image filter with url: \"<$strippedElement $stripped='$value'...\" in uploaded file.\n" ); + if ( $strippedElement == 'image' + && $stripped == 'filter' + && preg_match( '!url\s*\(!sim', $value ) + ) { + wfDebug( __METHOD__ . ": Found image filter with url: " + . "\"<$strippedElement $stripped='$value'...\" in uploaded file.\n" ); return true; } @@ -1529,7 +1577,9 @@ abstract class UploadBase { # scan failed (code was mapped to false by $exitCodeMap) wfDebug( __METHOD__ . ": failed to scan $file (code $exitCode).\n" ); - $output = $wgAntivirusRequired ? wfMessage( 'virus-scanfailed', array( $exitCode ) )->text() : null; + $output = $wgAntivirusRequired + ? wfMessage( 'virus-scanfailed', array( $exitCode ) )->text() + : null; } elseif ( $mappedCode === AV_SCAN_ABORTED ) { # scan failed because filetype is unknown (probably imune) wfDebug( __METHOD__ . ": unsupported file type $file (code $exitCode).\n" ); @@ -1679,7 +1729,10 @@ abstract class UploadBase { if ( self::isThumbName( $file->getName() ) ) { # Check for filenames like 50px- or 180px-, these are mostly thumbnails - $nt_thb = Title::newFromText( substr( $partname, strpos( $partname, '-' ) + 1 ) . '.' . $extension, NS_FILE ); + $nt_thb = Title::newFromText( + substr( $partname, strpos( $partname, '-' ) + 1 ) . '.' . $extension, + NS_FILE + ); $file_thb = wfLocalFile( $nt_thb ); if ( $file_thb->exists() ) { return array( @@ -1757,17 +1810,21 @@ abstract class UploadBase { /** * Gets image info about the file just uploaded. * - * Also has the effect of setting metadata to be an 'indexed tag name' in returned API result if - * 'metadata' was requested. Oddly, we have to pass the "result" object down just so it can do that - * with the appropriate format, presumably. + * Also has the effect of setting metadata to be an 'indexed tag name' in + * returned API result if 'metadata' was requested. Oddly, we have to pass + * the "result" object down just so it can do that with the appropriate + * format, presumably. * * @param ApiResult $result * @return array Image info */ public function getImageInfo( $result ) { $file = $this->getLocalFile(); - // TODO This cries out for refactoring. We really want to say $file->getAllInfo(); here. - // Perhaps "info" methods should be moved into files, and the API should just wrap them in queries. + /** @todo This cries out for refactoring. + * We really want to say $file->getAllInfo(); here. + * Perhaps "info" methods should be moved into files, and the API should + * just wrap them in queries. + */ if ( $file instanceof UploadStashFile ) { $imParam = ApiQueryStashImageInfo::getPropertyNames(); $info = ApiQueryStashImageInfo::getInfo( $file, array_flip( $imParam ), $result ); diff --git a/includes/upload/UploadStash.php b/includes/upload/UploadStash.php index 51efdcafe4..a7e7100248 100644 --- a/includes/upload/UploadStash.php +++ b/includes/upload/UploadStash.php @@ -23,21 +23,31 @@ /** * UploadStash is intended to accomplish a few things: - * - enable applications to temporarily stash files without publishing them to the wiki. - * - Several parts of MediaWiki do this in similar ways: UploadBase, UploadWizard, and FirefoggChunkedExtension - * And there are several that reimplement stashing from scratch, in idiosyncratic ways. The idea is to unify them all here. - * Mostly all of them are the same except for storing some custom fields, which we subsume into the data array. - * - enable applications to find said files later, as long as the db table or temp files haven't been purged. - * - enable the uploading user (and *ONLY* the uploading user) to access said files, and thumbnails of said files, via a URL. - * We accomplish this using a database table, with ownership checking as you might expect. See SpecialUploadStash, which - * implements a web interface to some files stored this way. + * - Enable applications to temporarily stash files without publishing them to + * the wiki. + * - Several parts of MediaWiki do this in similar ways: UploadBase, + * UploadWizard, and FirefoggChunkedExtension. + * And there are several that reimplement stashing from scratch, in + * idiosyncratic ways. The idea is to unify them all here. + * Mostly all of them are the same except for storing some custom fields, + * which we subsume into the data array. + * - Enable applications to find said files later, as long as the db table or + * temp files haven't been purged. + * - Enable the uploading user (and *ONLY* the uploading user) to access said + * files, and thumbnails of said files, via a URL. We accomplish this using + * a database table, with ownership checking as you might expect. See + * SpecialUploadStash, which implements a web interface to some files stored + * this way. * - * UploadStash right now is *mostly* intended to show you one user's slice of the entire stash. The user parameter is only optional - * because there are few cases where we clean out the stash from an automated script. In the future we might refactor this. + * UploadStash right now is *mostly* intended to show you one user's slice of + * the entire stash. The user parameter is only optional because there are few + * cases where we clean out the stash from an automated script. In the future we + * might refactor this. * * UploadStash represents the entire stash of temporary files. * UploadStashFile is a filestore for the actual physical disk files. - * UploadFromStash extends UploadBase, and represents a single stashed file as it is moved from the stash to the regular file repository + * UploadFromStash extends UploadBase, and represents a single stashed file as + * it is moved from the stash to the regular file repository * * @ingroup Upload */ @@ -94,7 +104,8 @@ class UploadStash { /** * Get a file and its metadata from the stash. - * The noAuth param is a bit janky but is required for automated scripts which clean out the stash. + * The noAuth param is a bit janky but is required for automated scripts + * which clean out the stash. * * @param string $key Key under which file information is stored * @param bool $noAuth (optional) Don't check authentication. Used by maintenance scripts. @@ -116,7 +127,8 @@ class UploadStash { if ( !isset( $this->fileMetadata[$key] ) ) { if ( !$this->fetchFileMetadata( $key ) ) { - // If nothing was received, it's likely due to replication lag. Check the master to see if the record is there. + // If nothing was received, it's likely due to replication lag. + // Check the master to see if the record is there. $this->fetchFileMetadata( $key, DB_MASTER ); } @@ -144,7 +156,8 @@ class UploadStash { if ( !$noAuth ) { if ( $this->fileMetadata[$key]['us_user'] != $this->userId ) { - throw new UploadStashWrongOwnerException( "This file ($key) doesn't belong to the current user." ); + throw new UploadStashWrongOwnerException( "This file ($key) doesn't " + . "belong to the current user." ); } } @@ -176,10 +189,12 @@ class UploadStash { } /** - * Stash a file in a temp directory and record that we did this in the database, along with other metadata. + * Stash a file in a temp directory and record that we did this in the + * database, along with other metadata. * * @param string $path Path to file you want stashed - * @param string $sourceType The type of upload that generated this file (currently, I believe, 'file' or null) + * @param string $sourceType The type of upload that generated this file + * (currently, I believe, 'file' or null) * @throws UploadStashBadPathException * @throws UploadStashFileException * @throws UploadStashNotLoggedInException @@ -202,10 +217,11 @@ class UploadStash { $pathWithGoodExtension = $path; } - // If no key was supplied, make one. a mysql insertid would be totally reasonable here, except - // that for historical reasons, the key is this random thing instead. At least it's not guessable. + // If no key was supplied, make one. a mysql insertid would be totally + // reasonable here, except that for historical reasons, the key is this + // random thing instead. At least it's not guessable. // - // some things that when combined will make a suitably unique key. + // Some things that when combined will make a suitably unique key. // see: http://www.jwz.org/doc/mid.html list( $usec, $sec ) = explode( ' ', microtime() ); $usec = substr( $usec, 2 ); @@ -226,11 +242,14 @@ class UploadStash { $storeStatus = $this->repo->storeTemp( basename( $pathWithGoodExtension ), $path ); if ( !$storeStatus->isOK() ) { - // It is a convention in MediaWiki to only return one error per API exception, even if multiple errors - // are available. We use reset() to pick the "first" thing that was wrong, preferring errors to warnings. - // This is a bit lame, as we may have more info in the $storeStatus and we're throwing it away, but to fix it means + // It is a convention in MediaWiki to only return one error per API + // exception, even if multiple errors are available. We use reset() + // to pick the "first" thing that was wrong, preferring errors to + // warnings. This is a bit lame, as we may have more info in the + // $storeStatus and we're throwing it away, but to fix it means // redesigning API errors significantly. - // $storeStatus->value just contains the virtual URL (if anything) which is probably useless to the caller + // $storeStatus->value just contains the virtual URL (if anything) + // which is probably useless to the caller. $error = $storeStatus->getErrorsArray(); $error = reset( $error ); if ( !count( $error ) ) { @@ -240,15 +259,18 @@ class UploadStash { $error = array( 'unknown', 'no error recorded' ); } } - // at this point, $error should contain the single "most important" error, plus any parameters. + // At this point, $error should contain the single "most important" + // error, plus any parameters. $errorMsg = array_shift( $error ); - throw new UploadStashFileException( "Error storing file in '$path': " . wfMessage( $errorMsg, $error )->text() ); + throw new UploadStashFileException( "Error storing file in '$path': " + . wfMessage( $errorMsg, $error )->text() ); } $stashPath = $storeStatus->value; // fetch the current user ID if ( !$this->isLoggedIn ) { - throw new UploadStashNotLoggedInException( __METHOD__ . ' No user is logged in, files must belong to users' ); + throw new UploadStashNotLoggedInException( __METHOD__ + . ' No user is logged in, files must belong to users' ); } // insert the file metadata into the db. @@ -280,7 +302,8 @@ class UploadStash { __METHOD__ ); - // store the insertid in the class variable so immediate retrieval (possibly laggy) isn't necesary. + // store the insertid in the class variable so immediate retrieval + // (possibly laggy) isn't necesary. $this->fileMetadata[$key]['us_id'] = $dbw->insertId(); # create the UploadStashFile object for this file. @@ -298,7 +321,8 @@ class UploadStash { */ public function clear() { if ( !$this->isLoggedIn ) { - throw new UploadStashNotLoggedInException( __METHOD__ . ' No user is logged in, files must belong to users' ); + throw new UploadStashNotLoggedInException( __METHOD__ + . ' No user is logged in, files must belong to users' ); } wfDebug( __METHOD__ . ' clearing all rows for user ' . $this->userId . "\n" ); @@ -320,18 +344,20 @@ class UploadStash { * Remove a particular file from the stash. Also removes it from the repo. * * @param string $key - * @throws UploadStashNoSuchKeyException|UploadStashNotLoggedInException|UploadStashWrongOwnerException + * @throws UploadStashNoSuchKeyException|UploadStashNotLoggedInException + * @throws UploadStashWrongOwnerException * @return bool Success */ public function removeFile( $key ) { if ( !$this->isLoggedIn ) { - throw new UploadStashNotLoggedInException( __METHOD__ . ' No user is logged in, files must belong to users' ); + throw new UploadStashNotLoggedInException( __METHOD__ + . ' No user is logged in, files must belong to users' ); } $dbw = $this->repo->getMasterDb(); - // this is a cheap query. it runs on the master so that this function still works when there's lag. - // it won't be called all that often. + // this is a cheap query. it runs on the master so that this function + // still works when there's lag. It won't be called all that often. $row = $dbw->selectRow( 'uploadstash', 'us_user', @@ -344,7 +370,8 @@ class UploadStash { } if ( $row->us_user != $this->userId ) { - throw new UploadStashWrongOwnerException( "Can't delete: the file ($key) doesn't belong to this user." ); + throw new UploadStashWrongOwnerException( "Can't delete: " + . "the file ($key) doesn't belong to this user." ); } return $this->removeFileNoAuth( $key ); @@ -370,8 +397,9 @@ class UploadStash { __METHOD__ ); - // TODO: look into UnregisteredLocalFile and find out why the rv here is sometimes wrong (false when file was removed) - // for now, ignore. + /** @todo Look into UnregisteredLocalFile and find out why the rv here is + * sometimes wrong (false when file was removed). For now, ignore. + */ $this->files[$key]->remove(); unset( $this->files[$key] ); @@ -388,7 +416,8 @@ class UploadStash { */ public function listFiles() { if ( !$this->isLoggedIn ) { - throw new UploadStashNotLoggedInException( __METHOD__ . ' No user is logged in, files must belong to users' ); + throw new UploadStashNotLoggedInException( __METHOD__ + . ' No user is logged in, files must belong to users' ); } $dbr = $this->repo->getSlaveDb(); @@ -515,8 +544,10 @@ class UploadStashFile extends UnregisteredLocalFile { protected $url; /** - * A LocalFile wrapper around a file that has been temporarily stashed, so we can do things like create thumbnails for it - * Arguably UnregisteredLocalFile should be handling its own file repo but that class is a bit retarded currently + * A LocalFile wrapper around a file that has been temporarily stashed, + * so we can do things like create thumbnails for it. Arguably + * UnregisteredLocalFile should be handling its own file repo but that + * class is a bit retarded currently. * * @param FileRepo $repo Repository where we should find the path * @param string $path Path to file @@ -531,18 +562,21 @@ class UploadStashFile extends UnregisteredLocalFile { if ( $repo->isVirtualUrl( $path ) ) { $path = $repo->resolveVirtualUrl( $path ); } else { - // check if path appears to be sane, no parent traversals, and is in this repo's temp zone. + // check if path appears to be sane, no parent traversals, + // and is in this repo's temp zone. $repoTempPath = $repo->getZonePath( 'temp' ); if ( ( !$repo->validateFilename( $path ) ) || ( strpos( $path, $repoTempPath ) !== 0 ) ) { - wfDebug( "UploadStash: tried to construct an UploadStashFile from a file that should already exist at '$path', but path is not valid\n" ); + wfDebug( "UploadStash: tried to construct an UploadStashFile " + . "from a file that should already exist at '$path', but path is not valid\n" ); throw new UploadStashBadPathException( 'path is not valid' ); } // check if path exists! and is a plain file. if ( !$repo->fileExists( $path ) ) { - wfDebug( "UploadStash: tried to construct an UploadStashFile from a file that should already exist at '$path', but path is not found\n" ); + wfDebug( "UploadStash: tried to construct an UploadStashFile from " + . "a file that should already exist at '$path', but path is not found\n" ); throw new UploadStashFileNotFoundException( 'cannot find path, or not a plain file' ); } } @@ -555,8 +589,8 @@ class UploadStashFile extends UnregisteredLocalFile { /** * A method needed by the file transforming and scaling routines in File.php * We do not necessarily care about doing the description at this point - * However, we also can't return the empty string, as the rest of MediaWiki demands this (and calls to imagemagick - * convert require it to be there) + * However, we also can't return the empty string, as the rest of MediaWiki + * demands this (and calls to imagemagick convert require it to be there) * * @return string Dummy value */ @@ -569,8 +603,10 @@ class UploadStashFile extends UnregisteredLocalFile { * The actual argument is the result of thumbName although we seem to have * buggy code elsewhere that expects a boolean 'suffix' * - * @param string $thumbName Name of thumbnail (e.g. "120px-123456.jpg" ), or false to just get the path - * @return string Path thumbnail should take on filesystem, or containing directory if thumbname is false + * @param string $thumbName Name of thumbnail (e.g. "120px-123456.jpg" ), + * or false to just get the path + * @return string Path thumbnail should take on filesystem, or containing + * directory if thumbname is false */ public function getThumbPath( $thumbName = false ) { $path = dirname( $this->path ); @@ -595,7 +631,8 @@ class UploadStashFile extends UnregisteredLocalFile { } /** - * Helper function -- given a 'subpage', return the local URL e.g. /wiki/Special:UploadStash/subpage + * Helper function -- given a 'subpage', return the local URL, + * e.g. /wiki/Special:UploadStash/subpage * @param string $subPage * @return string Local URL for this subpage in the Special:UploadStash space. */ @@ -606,10 +643,11 @@ class UploadStashFile extends UnregisteredLocalFile { /** * Get a URL to access the thumbnail * This is required because the model of how files work requires that - * the thumbnail urls be predictable. However, in our model the URL is not based on the filename - * (that's hidden in the db) + * the thumbnail urls be predictable. However, in our model the URL is + * not based on the filename (that's hidden in the db) * - * @param string $thumbName Basename of thumbnail file -- however, we don't want to use the file exactly + * @param string $thumbName Basename of thumbnail file -- however, we don't + * want to use the file exactly * @return string URL to access thumbnail, or URL with partial path */ public function getThumbUrl( $thumbName = false ) { @@ -647,8 +685,9 @@ class UploadStashFile extends UnregisteredLocalFile { } /** - * Parent classes use this method, for no obvious reason, to return the path (relative to wiki root, I assume). - * But with this class, the URL is unrelated to the path. + * Parent classes use this method, for no obvious reason, to return the path + * (relative to wiki root, I assume). But with this class, the URL is + * unrelated to the path. * * @return string Url */ @@ -657,7 +696,8 @@ class UploadStashFile extends UnregisteredLocalFile { } /** - * Getter for file key (the unique id by which this file's location & metadata is stored in the db) + * Getter for file key (the unique id by which this file's location & + * metadata is stored in the db) * * @return string File key */ -- 2.20.1