aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/importImages.php
Commit message (Collapse)AuthorAgeFilesLines
* maintenance: Use type declaration on undocumented private functionsUmherirrender2025-03-311-1/+1
| | | | Change-Id: I2c1bc3b4e0ee782076ddaeae133672b730d345d9
* Namespace all remaining files in includes/changetagsJames D. Forrester2025-03-251-0/+1
| | | | | Bug: T353458 Change-Id: I3cf44dfe5425f2efb8409c83571c427447b053af
* ImportImages: Exit with non-zero code if import failsBlankEclair2025-03-081-1/+5
| | | | | | | | | | | | | | | | | When scripting, folks generally check the exit code of a program to be zero if it is successful, and non-zero if it isn't. Since importImages can be used in third-party scripts to automate wiki imports, it is paramount that import failures are detected. However, since it doesn't exit with a failure code (i.e. a non-zero exit code) when a file fails to import or when there are no files found, it is much more difficult to detect import failures. Therefore, we exit with a non-zero return code to make import failures much more easier to detect for scripts. Bug: T388296 Change-Id: I5d9ede123355d63267793133287253a86faecda5
* Use ++ and -- rather than += 1 and -= 1Reedy2024-10-171-1/+1
| | | | Change-Id: I27b9a19ab952ede1267921bd042af0fe1c89e228
* Replace uses of deprecated ChangeTags static methodsJames D. Forrester2024-10-161-1/+4
| | | | | Bug: T360664 Change-Id: I3363a225e54bb2cae01ba066d432a8b7b21933d2
* Add namespace to maintenance/includes classesJames D. Forrester2024-10-091-1/+2
| | | | | | | Also a few other fixes of PHP class aliases spotted by phan. Bug: T353458 Change-Id: Ie79d65722c47c24f8f20f1293355cfd3c2e8c2ad
* Add namespace to remaining parts of Wikimedia\FileBackendJames D. Forrester2024-10-031-0/+1
| | | | | Bug: T353458 Change-Id: I49c843c9d8f6459c0fbf774afeea7a82fa564b59
* build: Use inline ignore for Generic.CodeAnalysis.AssignmentInConditionUmherirrender2024-09-011-0/+1
| | | | | | | | | | | Avoid that new code contains this pattern. Depends-On: I7a9b5c89129fe4b555d03861f2c3ce3e9e2b2446 Depends-On: Ic2bcc7eeb16d3333dcd019bd209bd7fde843dab9 Depends-On: If20eddd8376ae2e8e29c4e56cd51f7b8eb6642b0 Depends-On: I3414f7e17f4bcb801857bc986bae8eb97aa2bfb8 Depends-On: I38b2729418e8389c681c6cd84858f5e5ed25bd3e Change-Id: I7cfd2e027edd327cf8be6471e348c137fefacda0
* Exclude boilerplate maintenance code from code coverage reportsDreamy Jazz2024-08-271-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | Why: * Maintenance scripts in core have bolierplate code that is added before and after the class to allow directly running the maintenance script. * Running the maintenance script directly has been deprecated since 1.40, so this boilerplate code is only to support a now deprecated method of running maintenance scripts. * This code cannot also be marked as covered, due to PHPUnit not recognising code coverage for files. * Therefore, it is best to ignore this boilerplate code in code coverage reports as it cannot be marked as covered and also is for deprecated code. What: * Wrap the boilerplate code (requiring Maintenance.php and then later defining the maintenance script class and running if the maintenance script was called directly) with @codeCoverageIgnore comments. * Some files use a different boilerplate code, however, these should also be marked as ignored for coverage for the same reason that coverage is not properly reported for files. Bug: T371167 Change-Id: I32f5c6362dfb354149a48ce9c28da9a7fc494f7c
* Namespace User under \MediaWiki\UserJames D. Forrester2023-09-191-0/+1
| | | | | Bug: T166010 Change-Id: I7257302b485588af31384d4f7fc8e30551f161f1
* Namespace SpecialU* under \MediaWiki\SpecialsJames D. Forrester2023-09-141-0/+1
| | | | Change-Id: I75b04a7a65f8d37da12d2ed3892e065e97c92437
* maintenance: Begin using `Maintenance::getServiceContainer()`Derick Alangi2023-09-041-4/+3
| | | | | | | | | | | Maintenance class provides a method for getting a fresh reference of the MW services container instance. Let's make use of these in maintenance scripts now that we have it. NOTE: There are still some static methods like in refreshLinks.php that makes use of services that we can't use this method for now. Change-Id: Idba744057577896fc97c9ecf4724db27542bf01c
* maintenance: Separate variable assignment in importImages.phpTimo Tijhof2023-03-031-1/+2
| | | | | | Follows-up Iafb4a2e00ed71 (51ffcb06b). Change-Id: Iee21cf787fd5f6e01cd6350d7d0b86f095edaac9
* 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
* importImages: Use yield to reduce the memory usageFunc2023-02-111-10/+8
| | | | | | | When there are many files to import, the enumeration can take a long time before any output, and use lots of memory. Change-Id: Iafb4a2e00ed71de839f600f9b8618f1b3020bc8d
* Rewrite parts of importImages maintenance script for readabilityThiemo Kreuz2022-12-161-39/+28
| | | | | | | | | Most notably: Instead of having a bunch of counter variables with unclear purpose, we clearly mark them as statistics. They are only for the report in the end but don't affect how the script works. In contrast to $processed and $limit, which do. Change-Id: I7ca714b89e14dd74999c9842a1f1d17381192fb7
* Merge "Various doc fixes about false on method arguments/return types"jenkins-bot2022-11-171-2/+2
|\
| * Various doc fixes about false on method arguments/return typesUmherirrender2022-11-101-2/+2
| | | | | | | | | | | | Doc-only changes Change-Id: I5177f582ae7ee70c357e9389fed14819faf79463
* | Refresh some http://*.wikipedia.org URLsLucas Werkmeister2022-11-071-1/+1
|/ | | | | | | | | | | | | | Update the protocol to HTTPS. Update the titles of the Wikipedia articles mentioned in qqq.json – [[Exchangeable image file format]] became [[Exif]] and [[Dilution of precision (GPS)]] became [[Dilution of precision (navigation)]]. Fix the importImages.php --source-wiki-url documentation – the private methods getFileCommentFromSourceWiki() and getFileUserFromSourceWiki() directly append /api.php to the URL, so it needs to include the script path. And update the broken mailing list archive URLs (manually found the matching threads in the archives for the respective months). Change-Id: I1f085532ab720265acb1213f33869f759a987d92
* Merge "maintenance: Use $this->waitForReplication()"jenkins-bot2022-10-271-2/+1
|\
| * maintenance: Use $this->waitForReplication()Amir Sarabadani2022-10-241-2/+1
| | | | | | | | | | | | | | This adds reconfiguring db pools in case a replica gets depooled Bug: T298485 Change-Id: Id052ce8ed45c51e51b071778858d27b48605bf93
* | Reorg: Move StubObject classes in includes to its own directoryAmir Sarabadani2022-10-251-0/+1
|/ | | | | Bug: T166010 Change-Id: Idcf0e9dc6e0841e4f132207bce0f96774dad898c
* Replace deep nesting in importImages script with guard clausesThiemo Kreuz2022-07-181-208/+207
| | | | | | | As it turns out we can move the "no files → nothing to do" check way up. Change-Id: I851ce4ba55bd838bfc6c5baff386343d8202d90d
* Fix confusing $$var indirection in importImages scriptThiemo Kreuz2022-07-171-10/+10
| | | | | | | | My PHPStorm IDE keeps complaining about unused variables in this maintenance script. As it turns out this is just not necessary. By simply flipping the array we can address the variables directly. Change-Id: If3e213a85dd646aeff1a8edbd8e874c803ff3cc1
* Maintenance scripts: replace most globals with ConfigFerran Tufan2022-07-121-4/+4
| | | | | Bug: T72673 Change-Id: Idc46e88756b1aa20f5dccbe7ab3e661b2b102964
* Do minor code cleanupMatěj Suchánek2022-06-241-1/+1
| | | | | | Remove dead code and fix typos. Should cause no change in behavior. Change-Id: I5d293b842bc93a28b8bcd799a31b5e6e30fe692e
* Fix many typos in commentsMatěj Suchánek2022-05-101-1/+1
| | | | | | Found using IntelliJ's "Typo" code inspection. Change-Id: I746220ebe6e1e39f6cb503390ec9053e6518cf16
* Remove usages of deprecated Title::getRestrictionTypesUmherirrender2022-04-131-1/+2
| | | | | Bug: T306131 Change-Id: Id7b2849bb1c31dbd79acbeb607dfc4f7869e6142
* phan: Remove PhanPossiblyUndeclaredVariable suppressionUmherirrender2022-03-301-1/+2
| | | | | | | | | Make phan stricter about conditional variable declaration Remaining false positive issues are suppressed. The suppression and the setting change can only be done together Bug: T259172 Change-Id: I1f200ac37df7448453688bf464a8250c97313e5d
* phan: Disable null_casts_as_any_type settingUmherirrender2022-03-211-0/+2
| | | | | | | | | | | Make phan stricter about null types by setting null_casts_as_any_type to false (the default in mediawiki-phan-config) Remaining false positive issues are suppressed. The suppression and the setting change can only be done together Bug: T242536 Bug: T301991 Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
* Remove or replace usages of "sane"Reedy2021-11-221-1/+1
| | | | | Bug: T254646 Change-Id: I096b2cf738a1395a14f1d47bcbed0c2c686c2581
* Emit deprecation warnings reading from $wgUserDannyS7122021-09-151-3/+3
| | | | | | | | | | | | | | | | | | With this patch deprecation warnings will be emitted if $wgUser is accessed or written into. The only pattern of usage still allowed is $oldUser = $wgUser; $wgUser = $newUser; // Do something $wgUser = $oldUser; Once there is no deprecation warnings, we know that nothing legitimately depends on $wgUser being set, so we can safely remove the code that's still allowed as well. Bug: T267861 Change-Id: Ia1c42b3a32acd0e2bb9b0e93f1dc3c82640dcb22
* Cleanup mixed space/tab line indentUmherirrender2021-09-041-3/+3
| | | | Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
* Merge "Remove trailing dot/space from some exception messages and output ↵jenkins-bot2021-08-161-4/+4
|\ | | | | | | strings"
| * Remove trailing dot/space from some exception messages and output stringsTimo Tijhof2021-08-041-4/+4
| | | | | | | | | | | | | | | | | | | | One exception message contained a trailing dot/space, which I removed as well, following I935835316c0. A very small number of exceptions and output() calls contained trailing space, which I removed for consistency. Change-Id: I16f48c1a051c452bbef699eb9b7476d83f8821d8
* | Replace deprecated Http::get in importImages.php scriptUmherirrender2021-08-041-2/+2
|/ | | | Change-Id: I917769f93af9da7147760b7191957986cea15bcd
* Use the unserialized form of image metadata internallyTim Starling2021-06-081-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* Use a constant for 'Maintenance script' usernameGergő Tisza2021-05-031-2/+2
| | | | | | | | | | | The user 'Maintenance script' is often used to perform various automated tasks. Providing it everywhere as a string literal is error-prone, and errors can be somewhat disruptive (e.g. with User::newSystemUser with steal=true it can erase the credentials of a legitimate account). Provide a constant instead. Also replace existing uses for consistency. Change-Id: I685a5bfe56bbf1a47f35072f7f7c8be320ee27db
* Add change tag for media uploaded using importImages.phpTaavi Väänänen2021-04-171-1/+6
| | | | Change-Id: I74a7d6f9e5e7bada4803f7e807c7c74d237e9d47
* Replace deprecated WikiPage::factory/newFromID in maintenance scriptsUmherirrender2020-11-121-5/+6
| | | | Change-Id: I5b2d4313f986484368da9b63c9a19892c2328dae
* Use recordUpload3, hard deprecate recordUpload2DannyS7122020-09-101-5/+8
| | | | | | | Also reduces references to $wgUser in importImages Bug: T248813 Change-Id: I17c850000044f65f2fcfdfcfb82f852583a99000
* Narrow MediaWiki.Commenting.FunctionComment.WrongStyleReedy2020-05-201-2/+9
| | | | Change-Id: I95d1195f09a806910559a0c5106d472addd3dec4
* Replace wfWaitForSlaves() with LBFactory::waitForReplication()Reedy2020-05-021-1/+2
| | | | Change-Id: I337147d61e2ec686a8672d0340dff4b6783f78cd
* Do not output wikitext in maintenance scriptUmherirrender2019-09-201-1/+1
| | | | | | | | Also remove print_r with a string Always use english for maintenance scripts Bug: T229843 Change-Id: I539a1ac1f6a201dd8ee9ce89599cc34bebfba79f
* Merge "Make some whitespace fixes to importImages maintenance script"jenkins-bot2019-09-051-4/+8
|\
| * Make some whitespace fixes to importImages maintenance scriptThalia2019-09-051-4/+8
| | | | | | | | Change-Id: I0c3537393767e46642fbe48315618fe0980e4993
* | Merge "Allow partially blocked users to import images"jenkins-bot2019-09-051-6/+10
|\ \ | |/ |/|
| * Allow partially blocked users to import imagesDavid Barratt2019-07-241-6/+10
| | | | | | | | | | | | | | | | | | If a user is partially blocked they are prevented from importing images. These users should be allowed to import images unless they are blocked from existing images that they are going to overwrite or the File namespace. Bug: T228539 Change-Id: I251a3c151f81df828c0f45c0d78d479e94ff1880
* | filerepo: Use @method LocalRepo::newFile() to document the return typeAaron Schulz2019-09-041-1/+0
| | | | | | | | | | | | This avoids PhpStorm IDE warnings Change-Id: I521aa1b1243ceabd40e7da18bf73ab95af7039cc
* | Upgrade phan config to 0.7.1Daimona Eaytoy2019-09-041-1/+1
| | | | | | | | | | | | | | | | This allows us to remove many suppressions for phan false positives. Bug: T231636 Depends-On: I82a279e1f7b0fdefd3bb712e46c7d0665429d065 Change-Id: I5c251e9584a1ae9fb1577afcafb5001e0dcd41c7