aboutsummaryrefslogtreecommitdiffstats
path: root/includes/media/BitmapMetadataHandler.php
Commit message (Collapse)AuthorAgeFilesLines
* Use MainConfigNames instead of string literals, #4Aryeh Gregor2022-04-261-1/+2
| | | | | | | | | | | | | | | | | | | | | Now largely automated: VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \ tr "\n" '|' | sed "s/|$/\n/;s/'//g") sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \ $(grep -ERIl "'($VARS)'" includes/) Then git add -p with lots of error-prone manual checking. Then semi-manually add all the necessary "use" lines: vim $(grep -L 'use MediaWiki\\MainConfigNames;' \ $(git diff --cached --name-only --diff-filter=M HEAD^)) I didn't bother fixing lines that were over 100 characters unless they were over 120 and triggered phpcs. Bug: T305805 Change-Id: I74e0ab511abecb276717ad4276a124760a268147
* phan: Remove PhanTypePossiblyInvalidDimOffset suppressionUmherirrender2022-03-281-0/+1
| | | | | | | | | | | Make phan stricter about array keys Remaining false positive issues are suppressed. The suppression and the setting change can only be done together Bug: T304887 Depends-On: I3105a5fd4826f8667b5232834defc5ec93be32a1 Depends-On: Ie9610a6e83731468311edb3ed17f80fc509de385 Change-Id: I701f12ab94478c3b8e7fd82110ade74a8e6b04ef
* Try not to discard Excimer timeout exceptionsTim Starling2022-02-021-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | Don't catch and discard exceptions from the RequestTimeout library, except when the exception is properly handled and the code seems to be trying to wrap things up. In most cases the exception is rethrown. Ideally it should instead be done by narrowing the catch, and this was feasible in a few cases. But sometimes the exception being caught is an instance of the base class (notably DateTime::__construct()). Often Exception is the root of the hierarchy of exceptions being thrown and so is the obvious catch-all. Notes on specific callers: * In the case of ResourceLoader::respond(), exceptions were caught for API correctness, but processing continued. I added an outer try block for timeout handling so that termination would be more prompt. * In LCStoreCDB the Exception being caught was Cdb\Exception not \Exception. I added an alias to avoid confusion. * In ImageGallery I added a special exception class. * In Message::__toString() the rationale for catching disappears in PHP 7.4.0+, so I added a PHP version check. * In PoolCounterRedis, let the shutdown function do its thing, but rethrow the exception for logging. Change-Id: I4c3770b9efc76a1ce42ed9f59329c36de04d657c
* Refactor global variables to use MediaWikiServices insteadTChin2022-01-101-2/+3
| | | | | | | | | | | | Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI. Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228 * This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it. A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
* Fix typos in comments (A-B)Siddharth VP2021-12-261-1/+1
| | | | Change-Id: I852453fbeeebdc4e34c0b35c0fdca4b4ab74fde9
* media: Add missing false return types to docUmherirrender2021-10-161-1/+1
| | | | Change-Id: Ieefa5bbfddb803ceb41196725c1f344f175c10c3
* Remove some more comments that literally repeat the codeThiemo Kreuz2021-06-181-1/+1
| | | | | | | | | | | | | … including PHPDoc tags like `@return <type> $variableName`. A return value doesn't have a variable name. I can see that some people do this intentionally, repeating the variable name that was used in the final `return $var;` at the end of a method. This can indeed be helpful. I leave a lot of these untouched and removed them only when it's obviously wrong, or does not provide any additional information in addition to what the code already says. Change-Id: Ia18cd9f25ef658b08ad25b97a744897e2a8deffc
* Use the unserialized form of image metadata internallyTim Starling2021-06-081-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Image metadata is usually a serialized string representing an array. Passing the string around internally and having everything unserialize it is an awkward convention. Also, many image handlers were reading the file twice: once for getMetadata() and again for getImageSize(). Often getMetadata() would actually read the width and height and then throw it away. So, in filerepo: * Add File::getMetadataItem(), which promises to allow partial loading of metadata per my proposal on T275268 in a future commit. * Add File::getMetadataArray(), which returns the unserialized array. Some file handlers were returning non-serializable strings from getMetadata(), so I gave them a legacy array form ['_error' => ...] * Changed MWFileProps to return the array form of metadata. * Deprecate the weird File::getImageSize(). It was apparently not called by anything, but was overridden by UnregisteredLocalFile. * Wrap serialize/unserialize with File::getMetadataForDb() and File::loadMetadataFromDb() in preparation for T275268. In MediaHandler: * Merged MediaHandler::getImageSize() and MediaHandler::getMetadata() into getSizeAndMetadata(). Deprecated the old methods. * Instead of isMetadataValid() we now have isFileMetadataValid(), which only gets a File object, so it can decide what data it needs to load. * Simplified getPageDimensions() by having it return false for non-paged media. It was not called in that case, but was implemented anyway. In specific handlers: * Rename DjVuHandler::getUnserializedMetadata() and extractTreesFromMetadata() for clarity. "Metadata" in these function names meant an XML string. * Updated DjVuImage::getImageSize() to provide image sizes in the new style. * In ExifBitmapHandler, getRotationForExif() now takes just the Orientation tag, rather than a serialized string. Also renamed for clarity. * In GIFMetadataExtractor, return the width, height and bits per channel instead of throwing them away. There was some conflation in decodeBPP() which I picked apart. Refer to GIF89a section 18. * In JpegMetadataExtractor, process the SOF0/SOF2 segment to extract bits per channel, width, height and components (channel count). This is essentially a port of PHP's getimagesize(), so should be bugwards compatible. * In PNGMetadataExtractor, return the width and height, which were previously assigned to unused local variables. I verified the implementation by referring to the specification. * In SvgHandler, retain the version validation from unpackMetadata(), but rename the function since it now takes an array as input. In tests: * In ExifBitmapTest, refactored some tests by using a provider. * In GIFHandlerTest and PNGHandlerTest, I removed the tests in which getMetadata() returns null, since it doesn't make sense when ported to getMetadataArray(). I added tests for empty arrays instead. * In tests, I retained serialization of input data since I figure it's useful to confirm that existing database rows will continue to be read correctly. I removed serialization of expected values, replacing them with plain data. * In tests, I replaced access to private class constants like BROKEN_FILE with string literals, since stability is essential. If the class constant changes, the test should fail. Elsewhere: * In maintenance/refreshImageMetadata.php, I removed the check for shrinking image metadata, since it's not easy to implement and is not future compatible. Image metadata is expected to shrink in future. Bug: T275268 Change-Id: I039785d5b6439d71dcc21dcb972177dba5c3a67d
* includes: Use expression assignment operator += or |= where possibleUmherirrender2020-07-311-2/+2
| | | | | | It is easier to read. Change-Id: Ia3965b80153d64f95b415c6c30f526efa252f554
* Mark additional classes as newable for now.daniel2020-07-081-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | The following glasses are marked as newable per the Stable Interface Policy, even though logically, they should not be newable. This is done for classes that are currently instantiated by extensions, and lack an alternative. A better way for obtaining an instance of these classes should be created in the future. At that point, direct instantiation should be deprecated and replaced. - includes/ApiMain.php - needs factory - includes/media/BitmapMetadataHandler.php - should become a stateless service or use handler pattern - includes/GitInfo.php - should become a stateless service - includes/logging/LogPage.php - should become a stateless service or use command pattern - includes/logging/ManualLogEntry.php - should become a stateless service or use command pattern - includes/poolcounter/PoolCounterWorkViaCallback.php - needs a factory - includes/context/RequestContext.php - needs to be narrowed down, and should use a factory - includes/search/SearchHighlighter.php - should have a factory - includes/TitleArrayFromResult.php - should perhaps be part of TitleFactory - includes/user/User.php - should at least get a factory method for anons - includes/diff/Diff.php: needs a TextDiffGenerator service or a factory - includes/EditPage.php: needs a factory Bug: T247862 Change-Id: I033158e693c98630ee167d9528fc8c9936f978d4
* Remove terminating line breaks from debug messagesTim Starling2020-06-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | A terminating line break has not been required in wfDebug() since 2014, however no migration was done. Some of these line breaks found their way into LoggerInterface::debug() calls, where they mess up the formatting of the debug log. So, remove terminating line breaks from wfDebug() and LoggerInterface::debug() calls. Also: * Fix the stripping of leading line breaks from the log header emitted by Setup.php. This feature, accidentally broken in 2014, allows requests to be distinguished in the log file. * Avoid using the global variable $self. * Move the logging of the client IP back to Setup.php. It was moved to WebRequest in the hopes that it would not always be needed, however $wgRequest->getIP() is now called unconditionally a few lines up in Setup.php. This means that it is put in its proper place after the "start request" message. * Wrap the log header code in a closure so that variables like $name do not leak into global scope. * In Linker.php, remove a few instances of an unnecessary second parameter to wfDebug(). Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
* Fix includes/media/ Squiz.Scope.MethodScope.MissingReedy2020-05-181-5/+5
| | | | Change-Id: I2bf5543b99dc2ae05f7de02940d120dee353adfe
* Collapse some nested if statementsReedy2019-04-041-7/+7
| | | | Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
* Fix some of the common typospetarpetkovic2018-08-161-1/+1
| | | | | | | | | | * supress -> suppress (Except in backup_LogTest.php) * recomend -> recommend * becuase -> because * accross -> across Bug: T201491 Change-Id: I8faa4e6cc688b3ee204b3f79ab55eb7b65cc1fdd
* Use wikimedia/xmp-reader libraryKunal Mehta2018-05-311-0/+1
| | | | | | Bug: T100922 Depends-On: I9bec4e03c49baafda30fb44cc793fa31b36e400d Change-Id: Ic9044bf3260d1a474a6c74844949602441ffc865
* Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenientBartosz Dziewoński2018-05-301-1/+1
| | | | | | | | | | | | | | Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/ Replace with: '\1 ?? ' (Everywhere except includes/PHPVersionCheck.php) (Then, manually fix some line length and indentation issues) Then manually reviewed the replacements for cases where confusing operator precedence would result in incorrect results (fixing those in I478db046a1cc162c6767003ce45c9b56270f3372). Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
* Remove @param comments that literally repeat what the code saysThiemo Mättig2018-01-101-1/+1
| | | | | | | | | These comments do not add anything. I argue they are worse than having no comments, because I have to read them first to understand they actually don't explain anything. Removing them makes room for actual improvements in the future (if needed). Change-Id: Iee70aad681b3385e9af282d5581c10addbb91ac4
* XMPReader: Log filename if availableBryan Davis2017-12-021-3/+3
| | | | | | | | Add a means to pass a filename into XMPReader and use it when creating debug log events. Bug: T118799 Change-Id: I68968d1ee12295d6f4a0a4356def562ead09d712
* Remove empty lines at begin of function, if, foreach, switchUmherirrender2017-07-011-1/+0
| | | | | | Organize phpcs.xml a bit Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
* Apply EXIF rotation to X-Content-DimensionsGilles Dubuc2017-05-161-3/+3
| | | | | | | Also adds integration tests for a few formats. Bug: T150741 Change-Id: I686f7ef42457faf5bc688e60e6ce09a8550ca5aa
* Convert all array() syntax to []Kunal Mehta2016-02-171-14/+14
| | | | | | | | | | Per wikitech-l consensus: https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html Notes: * Disabled CallTimePassByReference due to false positives (T127163) Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
* XMP: Use structured logging instead of wfDebugLogKunal Mehta2015-05-231-3/+5
| | | | | Co-Authored-By: Brian Wolff <bawolff+wn@gmail.com> Change-Id: I486192a718576a4d1e585ffb390e297b14dde087
* SECURITY: Don't allow entities in XMP with HHVMcsteipp2015-04-011-3/+3
| | | | | | | | Test for, and refuse to parse, XMP chunks with a doctype declaration when parsing XMP under HHVM. Bug: T85848 Change-Id: Iea4feb077ee85a35509a920153daaa9321ee69f3
* Updated some try-catch statements: MWException -> ExceptionAaron Schulz2015-01-091-1/+1
| | | | Change-Id: I76601a86e30f4984e3b1a8c8ec5ef5a0f652433a
* Correct variable names in @param to match method declarationsumherirrender2014-08-131-1/+1
| | | | | | | Some @param have a typo in the variable name, some @param's were in wrong order. Change-Id: Ie25806831027112b398f6f4a909c59147ac3a5fa
* Cleanup some docs (includes/[m-r])umherirrender2014-07-241-4/+4
| | | | | | | | | | - Swap "$variable type" to "type $variable" - Added missing types - Fixed spacing inside docs - Makes beginning of @param/@return/@var/@throws in capital - Changed some types to match the more common spelling Change-Id: I8ebfbcea0e2ae2670553822acedde49c1aa7e98d
* Update documentation for media related classesSiebrand Mazeland2013-12-061-14/+16
| | | | Change-Id: I7a9c8d59f88c68dc3835cb8a18f22a77cd7890fc
* Break long lines in media related classesSiebrand Mazeland2013-12-051-1/+3
| | | | Change-Id: I94653b4cde14f75180dae795d1fdaa1b073ec1d1
* Update formatting for media related classesSiebrand Mazeland2013-12-051-3/+9
| | | | Change-Id: Iaa81af5b65a650222fa65bf8c368e4f1ec3ce9c0
* Use lowercase key wordsumherirrender2013-11-231-2/+2
| | | Change-Id: I57569b7082a0decc8128ecadd8ec5d1a5c327673
* Added space after switch/Removed spaces after unsetumherirrender2013-04-261-1/+1
| | | | | | While at it, added/removed some other spaces in the same files Change-Id: I84d8001aa123a008807ad5eb76f396aed7c899a4
* Fixed spacing in context/installer/media/templates/upload folderumherirrender2013-04-211-2/+4
| | | | | | | Added spaces before if, foreach Added some braces for one line statements Change-Id: I9761be9fa47adc3554852a97b19792b4648466ad
* Remove spaces in function signatureumherirrender2013-03-181-8/+8
| | | | Change-Id: I45aea7a7af88cd913b2f485913620a8af0ab2fed
* Fixed @param tags to conform with Doxygen format.Tyler Anthony Romeo2013-03-111-6/+6
| | | | | | | | | | | Doxygen expects parameter types to come before the parameter name in @param tags. Used a quick regex to switch everything around where possible. This only fixes cases where a primitve variable (or a primitive followed by other types) is the variable type. Other cases will need to be fixed manually. Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
* Merge "fix some spacing"jenkins-bot2013-03-071-3/+0
|\
| * fix some spacingumherirrender2013-03-071-3/+0
| | | | | | | | | | | | | | | | Added/removed spaces around logical/arithmetic operator Reduced multiple empty lines to one empty line Removed wrong tabs before comments at end of line Removed too many spaces in assigments Change-Id: I2bba4e72f9b5f88c53324d7b70e6042f1aad8f6b
* | Fix align of block commentsumherirrender2013-03-071-20/+20
|/ | | | Change-Id: I88ea33a125a71671886b49e4ebf4c1d0a1cce572
* The static declaration must come after the visibility declarationumherirrender2013-01-261-3/+3
| | | | | | From phpcs Change-Id: Ieab0207f965630eda113abdc0259aa2eddcf5ca7
* Remove a bunch of trailing spaces and unneeded newlinesumherirrender2012-10-191-1/+1
| | | | Change-Id: I166a171c196f4c2c75886be12f913ffa9a4a35ad
* Update docs for return and exception infoSiebrand Mazeland2012-10-091-0/+1
| | | | | | | * Removed some inline tabs in the process. * IDE fixed some incorrect leading spaces, too. Change-Id: Ic9303eff6db4424ac3f1fa2816839692b43e6190
* Added missing GPLv2 headers in some places.Alexandre Emsenhuber2012-05-031-7/+30
| | | | | | Also made file/class documentation more consistent. Change-Id: I26a320bcddd4122ce423f536609d5794446d743e
* Fixing some of the "@return true" or "@return false", need to be "@return ↵Sam Reed2012-02-091-1/+1
| | | | | | | | | bool" and then the metadata can say true if foo, false if bar Other documentation improvements Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/111072
* Fixing some of the "@return true" or "@return false", need to be "@return ↵Sam Reed2012-02-091-1/+1
| | | | | | | | | bool" and then the metadata can say true if foo, false if bar Other documentation improvements Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/111052
* Fix doxygen docs before REL1_19 branchingAntoine Musso2012-02-011-0/+3
| | | | Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/110518
* Make sure that if we fail to read the App13 (iptc) block of a JPG file, that ↵Brian Wolff2012-01-051-3/+13
| | | | | | | that doesn't block other metadata from being read. Also makes sure if more then one app13 block is in the file, they are all read, not just the last one that appears in the file (This required some changes to tests since before the intermediate value was just one value, now its an array of all such blocks) Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/108183
* follow-up r86169 - 2 minor issues found while writing unit testsBrian Wolff2011-08-211-6/+64
| | | | | | | | | | | | # Some really obscure Exif properties did not have the Exif byte order taken into account and were being extracted with the bytes reversed (for example user comment when encoded as utf-16). Not a major issue as these properties are very rare in practise, but certainly not a good thing. ( One would think php's exif support would take care of that, but no it does not...) # Change the fallback encoding for Gif comments to be windows-1252 instead of iso 8859-1. More to be consitent with jpg and iptc then anything else. Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/95155
* Even more documentation in various filesSam Reed2011-05-291-12/+13
| | | | Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/89104
* And even more documentationSam Reed2011-05-281-4/+8
| | | | Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/89062
* Few style/whitespace/comment issues from r86169Sam Reed2011-04-181-10/+10
| | | | Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/86307
* Remove some unused variablesSam Reed2011-04-161-1/+1
| | | | | | | | | Fix typo in wfDeprecated usage Fix some more unreachable code Notes: http://mediawiki.org/wiki/Special:Code/MediaWiki/86195