aboutsummaryrefslogtreecommitdiffstats
path: root/includes/filerepo/file/OldLocalFile.php
Commit message (Collapse)AuthorAgeFilesLines
* file: Set fr_deletedAmir Sarabadani2025-01-061-0/+1
| | | | | | | Error 1364: Field 'fr_deleted' doesn't have a default value Bug: T383093 Change-Id: I023ededba880f9aaad66226d692be2276e835b57
* file: Basic support for writing to the new file tablesAmir Sarabadani2025-01-061-1/+46
| | | | | Bug: T368113 Change-Id: I8d98d187ba4f1342167820b5710f5382b2ac4831
* Replace isset() with null checksUmherirrender2024-12-191-2/+2
| | | | | | | | | isset() should only be used to suppress errors, not for null check. When the property is always defined, there is no need to use isset. Found by a new phan plugin (2efea9f989) https://www.mediawiki.org/wiki/Manual:Coding_conventions/PHP#isset Change-Id: Ib84b7d71e8308a36409f30ecfd16e9de149e97b3
* Add namespace to IDBAccessObject and DBAccessObjectUtilsJames D. Forrester2024-09-271-0/+1
| | | | | Bug: T353458 Change-Id: I23cf7991f8792d4d000d1780463d8ce76dc0aee0
* Change uses of getDBLoadBalancerFactory() to getConnectionProvider()Bartosz Dziewoński2024-01-221-1/+1
| | | | | | | | | | | | Update cases where one of the IConnectionProvider methods is called immediately. This doesn't really change anything, but I hope it helps promote getConnectionProvider() as the common way to do this. Follow-up to 8604c384f624273f46b653ec252ffaed30e6ff89. Change-Id: Id0e7d02bab0c570343c2b1f03c70b44ee39db112
* Replace more usages of deprecated MWExceptionDaimona Eaytoy2024-01-191-1/+1
| | | | | Bug: T328220 Change-Id: Ie9b56bcf5e962e275d80570cad98d676da505894
* Merge "Replace deprecated MWException"jenkins-bot2024-01-161-4/+2
|\
| * Replace deprecated MWExceptionDaimona Eaytoy2024-01-161-4/+2
| | | | | | | | | | Bug: T328220 Change-Id: Ic45438d9e6bbf127f1415add81ab902044765840
* | Directly call IDBAccessObject constants instead of implementing itAmir Sarabadani2024-01-101-1/+1
|/ | | | | | | | | | | | Instead of calling self::READ_* on these constants, just directly call it. Since these classes are public and might be relied on directly in other places, we can't remove the "implements IDBAccessObject" yet but we will start doing that soon. Bug: T354194 Change-Id: I3e26b9fc7f93efdfc55a1790a7cdfa5c0d562303
* In query builders, use insertInto() and deleteFrom() instead of insert() and ↵Tim Starling2023-09-081-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | delete() The design principle for SelectQueryBuilder was to make the chained builder calls look as much like SQL as possible, so that developers could leverage their knowledge of SQL to understand what the query builder is doing. That's why SelectQueryBuilder::select() takes a list of fields, and by the same principle, it makes sense for UpdateQueryBuilder::update() to take a table. However with "insert" and "delete", the SQL designers chose to add prepositions "into" and "from", and I think it makes sense to follow that here. In terms of natural language, we update a table, but we don't delete a table, or insert a table. We delete rows from a table, or insert rows into a table. The table is not the object of the verb. So, add insertInto() as an alias for insert(), and add deleteFrom() as an alias for delete(). Use the new methods in MW core callers where PHPStorm knows the type. Change-Id: Idb327a54a57a0fb2288ea067472c1e9727016000
* Reorg: Move Status to MediaWiki\Status\Amir Sarabadani2023-08-251-0/+1
| | | | | | | | | | This class is used heavily basically everywhere, moving it to Utils wouldn't make much sense. Also with this change, we can move StatusValue to MediaWiki\Status as well. Bug: T321882 Depends-On: I5f89ecf27ce1471a74f31c6018806461781213c3 Change-Id: I04c1dcf5129df437589149f0f3e284974d7c98fa
* Merge "Mass migrate Database::insert calls to InsertQueryBuilder"jenkins-bot2023-08-081-4/+5
|\
| * Mass migrate Database::insert calls to InsertQueryBuilderAmir Sarabadani2023-08-071-4/+5
| | | | | | | | | | | | | | Done automatically based on a php parser written on top of ANTLR4 Bug: T335377 Change-Id: Ie8fabc594edab18e55cb1d5bbf573762106e3d71
* | Introduce FileSelectQueryBuilderAmir Sarabadani2023-08-071-82/+33
|/ | | | | | | So much can be cleaned up with this Bug: T311866 Change-Id: Ia4d46679c540c731b2ae8da2f8022fd6f5b931a4
* Clean up UpdateQueryBuilder usageLucas Werkmeister2023-06-081-1/+4
| | | | | | | | | | | | | | | This follows up change I608566700c, which was mainly generated by a script. Most of the clean up here is fixing cases where it seems the script for some reason collapsed multi-line arrays into single-line ones and/or removed spaces after commas. A handful of other improvements are included too (split merged conditions into ->where()->andWhere(), use buildComparison()). In RevDelArchiveItem, a comment is restored that I assume was removed accidentally (perhaps because the script didn’t expect comments inside the conditions). Bug: T330640 Change-Id: If27bafb12fdaa05d3dc1ae6da820e1630ae2742e Follows-Up: I608566700c6d737ee986bf47dda87effc69614d6
* Migrate Database::update() to UpdateQueryBuilderAmir Sarabadani2023-06-081-7/+6
| | | | | | | | I did this using a script written on top of antlr4 parser so it doesn't have some clean ups a human would do but it's pretty nice already. Bug: T330640 Change-Id: I608566700c6d737ee986bf47dda87effc69614d6
* Reorg: Namespace the Title classJames D. Forrester2023-03-021-0/+1
| | | | | | | | | | | | | | | | | | | This is moderately messy. Process was principally: * xargs rg --files-with-matches '^use Title;' | grep 'php$' | \ xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1' * rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \ xargs rg --files-with-matches 'Title\b' | \ xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1' * composer fix Then manual fix-ups for a few files that don't have any use statements. Bug: T166010 Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
* Various doc fixes about false and null on method arguments/return typesUmherirrender2022-11-031-2/+2
| | | | | | Doc-only changes Change-Id: Ice974b3ba41708859dfe646e94b31c5ebbf26410
* Use short array destructuring instead of list()Tim Starling2022-10-211-1/+1
| | | | | | | | Introduced in PHP 7.1. Because it's shorter and looks nice. I used regex replacement. Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
* Improve docs of various ::getQueryInfo functionsUmherirrender2022-08-131-3/+4
| | | | | | Explict types helps phan to detect errors with keys like ef82d95 Change-Id: Iee4d964ecc58273eb9c73356ed34e13f29fbd275
* filerepo: Clean up file and class doc commentsTimo Tijhof2022-04-071-4/+1
| | | | | | | | | | | | | | | | * Remove copy-paste descriptions that are unrelated to the file. * Move any useful information from file block to class block. * Ensure any relevant `ingroup` is set on the class block. * Remove left-over ingroup and class description from file block, which pollutes the doc index for no gain. * Mark some obscure classes that have no references outside core in Codesearch Everywhere as internal. Change-Id: If2360596b4a7511db7439b4b9867b0600ce2d5f8
* file: Move json metadata storage out of LocalFileAmir Sarabadani2022-04-071-4/+4
| | | | | | | | So ArchivedFile could use it as well Bug: T298417 Bug: T298398 Change-Id: Idd258437d9f91824195ed0c12b5694841cb365b0
* Remove or replace usages of "sanity"Reedy2021-11-191-1/+1
| | | | | Bug: T254646 Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
* Stop using LocalFile::lock()Tim Starling2021-11-151-4/+2
| | | | | | | | | | | | | | | | | | | | LocalFile::lock() held an explicit DB transaction open while a potentially slow file backend operation was in progress, causing production errors. Instead, protect write operations with non-blocking locks. If a file is locked, report the failure to the user. Like an edit conflict, informing the user is appropriate in most cases. For example, if two admins try to delete the same file at the same time, only one should succeed, and the second does not need to wait for the first. In upgradeRow(), locks were used to protect operations which read from a file and write the result back to the database. The lock was supposed to prevent overwriting of fresh data with stale data. Use a timestamp check instead. Bug: T283045 Change-Id: Iaf9c9eef617044656b5b0d91a9632eacd84a5a78
* docs: Change wording master to primary in comments and log textUmherirrender2021-09-011-1/+1
| | | | | Bug: T254646 Change-Id: I5379dc79be60c99f0a30f74e5d624f81fe6f921b
* Replace getMasterDB methods with getPrimaryDBJames D. Forrester2021-07-141-4/+4
| | | | | Bug: T254646 Change-Id: I68198bc39b174ea1920b4acc2617cb6c6ce406e9
* In recordOldUpload, use source path when computing propertiesTim Starling2021-06-291-4/+5
| | | | | | | | | During a file import, it's inefficient to upload the image to Swift and then download it again to compute its properties. The arrangement predates Swift -- it was efficient at the time. Instead, use the source path which is always available. Change-Id: I60dfb82f577479419ea663cd996738f1e90d5d3f
* Manual and automatic image metadata reserializationTim Starling2021-06-261-0/+6
| | | | | | | | | | | | | | | | | | | | | | | * Add automatic splitting of large metadata on upload or refresh. If the reserializeMetadata option is enabled, metadata stored with PHP serialization will be automatically reserialized to JSON. * Inject configuration variable $wgUpdateCompatibleMetadata via LocalRepo instead of accessing it directly. * In refreshImageMetadata.php and rebuildImages.php, construct a new LocalRepo with config overrides, instead of overwriting config globals. Add a helper to RepoGroup to help with this. * In refreshImageMetadata.php, add new options --convert-to-json and --split which reserialize metadata and optionally split out large items to blob storage. Also, refreshImageMetadata.php was totally broken in the non-force mode since metadata refresh on page view was disabled in b814245d9f3bb. The maintenance script was relying on newFileFromRow() magically upgrading the row, which doesn't happen anymore. So, call maybeUpgradeRow() directly. Bug: T275268 Change-Id: I7bf7d9cef71641e287ca4346b568b381f4ada50e
* Use the unserialized form of image metadata internallyTim Starling2021-06-081-2/+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
* Stop requiring full User to upload a File.Petr Pchelko2021-06-071-1/+1
| | | | | | | | | | | | | | This is slightly weird, cause we don't realllly need authority there, it's required for creating a file description page. Good enough probably. Manual testing: - uploaded a new file - uploaded a modified version of a file - deleted old version of a file - restored old version of a file - rotated image with api Change-Id: I3d6337be974d6b2c7b055fe23875ff9d36174477
* Reapply "LocalFile: don't use dynamic property assignment when loading from ↵Tim Starling2021-06-071-0/+9
| | | | | | | | | | | | the DB" Reapply the reverted commit which removed dynamic property assignment. But continue to allow extra fields to be passed to newFromRow() for the benefit of subclasses. This reverts commit 9e8ff12a59fd7093bbb51b41511874ce7a121a9d. Change-Id: Ia3c14c51541e06264891a51763a8dadde83fbab7
* OldLocalFile::uploadOld() accept UserIdentityDannyS7122021-06-031-1/+1
| | | | | | | Only used to pass the user to recordOldUpload(), which already only needs a UserIdentity Change-Id: I73dcd62f01cf7a03e25ac6d4edb6d0309a7fcd77
* Convert File to Authority/UserIdentityPetr Pchelko2021-05-101-4/+6
| | | | | | | | None of the changed methods actually are overridden according to codesearch, so I guess it is ok to change signatures. Change-Id: I35bafb303163dfc1584a13b29675b5e10cd055fd
* Stop using legacy ActorMigration fields img_user/oi_user/fa_userTim Starling2021-04-261-6/+20
| | | | | Bug: T278917 Change-Id: If7dd7d2198bd79636fdfb8b5644fb7cd8ae2901f
* Revert "Revert "Remove support for (Archived|OldLocal)File::userCan without ↵DannyS7122020-09-271-7/+2
| | | | | | | | | | | a user"" This reverts commit a66e7a6b0c7c1cc46af9c938355e04d955d0d29a. Reason for revert: all remaining uses should be resolved now Bug: T247801 Change-Id: Ib43634553113f0d55ee2b7a269a85d13d1655f22
* Revert "Remove support for (Archived|OldLocal)File::userCan without a user"Jforrester2020-09-161-2/+7
| | | | | | | | | This reverts commit 264d043d0400d4a0353df03eb5b431dcf25ad0ae. Reason for revert: Parsoid is still using this. Bug: T263014 Change-Id: I9d6b65b319a45bbdbd479eda0d0580296ceb7f62
* Remove support for (Archived|OldLocal)File::userCan without a userDannyS7122020-09-101-7/+2
| | | | | Bug: T247801 Change-Id: I7424e354c29ad706c02e6d00e5689100572b33e7
* Merge "Replace "@stable for subclassing" with "@stable to extend""jenkins-bot2020-07-131-1/+1
|\
| * Replace "@stable for subclassing" with "@stable to extend"daniel2020-07-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | For compliance with the new version of the table interface policy (T255803). This patch was created by an automated search & replace operation on the includes/ directory. Bug: T257789 Change-Id: Ie32c1b11b3d16ddfc0c83a757327d449ff80b2e4
* | Merge "Replace "@stable for calling" by "@stable to call""jenkins-bot2020-07-131-1/+1
|\ \
| * | Replace "@stable for calling" by "@stable to call"daniel2020-07-131-1/+1
| |/ | | | | | | | | | | | | | | | | | | | | For compliance with the new version of the table interface policy (T255803). This patch was created by an automated search & replace operation on the includes/ directory. Bug: T257789 Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
* / Replace "@stable for overriding" with "@stable to override"daniel2020-07-131-14/+14
|/ | | | | | | | | | | For compliance with the new version of the table interface policy (T255803). This patch was created by an automated search & replace operation on the includes/ directory. Bug: T257789 Change-Id: I5ffbb91882ecce2019ab644839eab5e8fb8a1c5f
* Mark File base classes as extensible.daniel2020-07-091-1/+29
| | | | | | | | Methods identified to be stable to override are mostly the ones that are currently already overridden by subclasses. Bug: T247862 Change-Id: I635f0fd7dda5feecec4b868c3a84f92764980bae
* Remove terminating line breaks from debug messagesTim Starling2020-06-031-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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 more of includes/filerepo/ Squiz.Scope.MethodScope.MissingReedy2020-05-191-16/+16
| | | | Change-Id: I7a36fb8fa191374831ad06ed66eeb923fb0c78c2
* Fix even more PSR12.Properties.ConstantVisibility.NotFoundReedy2020-05-161-2/+1
| | | | Change-Id: I4a30a44bc33fc98479799438d65342f6529e14f9
* Hard deprecate not passing a user to OldLocalFile::userCanDannyS7122020-03-161-1/+1
| | | | | Bug: T246189 Change-Id: I8a40578dc2131086d010709f4ecfd3356ac10e1a
* Hard deprecate Revision::userCanBitfieldDannyS7122020-02-241-2/+12
| | | | | | | | | | Also replace uses. Some callers had a user that could be null; RevisionRecord::userCanBitfield requires a user, so add $wgUser fallbacks at the callers with soft deprecations for using them, and will hard deprecate in a subsequent task. Bug: T245958 Change-Id: I137e21e3883b149fdd98d1b59d4e498d15b39dd9
* Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNullJames D. Forrester2020-01-101-3/+3
| | | | Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
* Mostly drop old pre-actor user schemasBrad Jorsch2019-09-091-40/+0
| | | | | | | | | | | | | | | | | | | | This removes most of the pre-actor user and user_text columns, and the $wgActorTableSchemaMigrationStage setting that used to determine whether the columns were used. rev_user and rev_user_text remain in the code, as on Wikimedia wikis the revision table is too large to alter at this time. A future change will combine that with the removal of rev_comment, rev_content_model, and rev_content_format (and the addition of rev_comment_id and rev_actor). ActorMigration's constructor continues to take a $stage parameter, and continues to have the logic for handling it, for the benefit of extensions that might need their own migration process. Code using ActorMigration for accessing the core fields should be updated to use the new actor fields directly. That will be done for in a followup. Bug: T188327 Change-Id: Id35544b879af1cd708f3efd303fce8d9a1b9eb02