Commit graph

1819 commits

Author SHA1 Message Date
James D. Forrester
9fe4138f3d Follow-up I68198bc3: Hard-deprecate getMasterDB() methods
Also switch one use that we missed in the rebase.

Bug: T254646
Depends-On: I632610dec1aa6bb59af5423e6f86164fc791aadd
Change-Id: I9873c889f943fcbd7d867d534a7857f20ef0c5dc
2021-07-15 09:12:17 +01:00
James D. Forrester
597376e12c Replace getMasterDB methods with getPrimaryDB
Bug: T254646
Change-Id: I68198bc39b174ea1920b4acc2617cb6c6ce406e9
2021-07-14 16:21:04 -07:00
jenkins-bot
599f39015c Merge "filerepo: Make $wgUploadThumbnailRenderMap work with multipage files" 2021-07-01 00:21:57 +00:00
Tim Starling
e5993ea2db In recordOldUpload, use source path when computing properties
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
2021-06-29 18:29:43 +00:00
jenkins-bot
1ffb4ae93a Merge "Manual and automatic image metadata reserialization" 2021-06-29 13:12:35 +00:00
jenkins-bot
6eb8c5a6da Merge "Use IEC prefixes instead of SI prefixes for byte sizes (docs+backend)" 2021-06-29 10:34:41 +00:00
Tim Starling
1a7bfba0bd filerepo: Make $wgUploadThumbnailRenderMap work with multipage files
To replace the nonfunctional PdfHandler feature
$wgPdfCreateThumbnailsInJobQueue.

Bug: T284416
Change-Id: I225f33144ed4a89fa7ea2c03008317c72ce8c6f9
2021-06-29 01:20:35 +00:00
Fomafix
356f1b72ef Use IEC prefixes instead of SI prefixes for byte sizes (docs+backend)
This change doesn't change any UI messages.

Bug: T54687
Change-Id: Ia62899a2a6fe8910618c35cd667291e397ddb055
2021-06-28 11:59:09 +01:00
DannyS712
b45ddb2ab3 Use WikiPage::doUserEditContent() instead of ::doEditContent()
Results in passing a user where previously the fallback
to $wgUser was being used, mostly in tests.

Bug: T255507
Change-Id: Iabe24315b23c0ad1272353186425e71974528d23
2021-06-28 00:11:30 -07:00
Tim Starling
9251f3c9e3 Manual and automatic image metadata reserialization
* 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 b814245d9f. 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
2021-06-26 22:50:17 +00:00
jenkins-bot
2739509d38 Merge "Optionally split out parts of file metadata to BlobStore" 2021-06-26 20:32:04 +00:00
DannyS712
47d70dbfba Post Revision-removal cleanup
Updates for the removal of the Revision class itself
and the various methods/hooks/variables removed in the
process, including:

- Update some documentation removing most references
to the Revision class and updating the MCR migration
notes to reflect the past tense for Revision methods.

- Change some capitalization from "Revision" to "revision"
to make it clear comments are about revisions in general,
not the Revision class in particular.

- Minor code tweaks including removing unused variables that
were around for the old hooks that were removed, and
removing the use of DeprecatablePropertyArray where no
longer needed for anything.

- Fix incorrect documentation for PageUpdater::getStatus(),
the status value changed a while ago to have revision-record
in addition to revision, and recently to only have the
revision-record, but ironically PageUpdater was never updated.

- Removed Parser::$mRevisionObject, used to be a Revision object
and was deprecated in 1.35, missed earlier because it was no
longer being set to Revision objects, always null.

- Add RevisionRecord typehints in DummyLinker to match those
in the corresponding Linker methods

This should be a no-op in terms of functionality.

Bug: T247143
Change-Id: I03bbb94fc29085855448780b1a5ad9063911ecc4
2021-06-24 00:32:39 +00:00
Thiemo Kreuz
2ba01c7ee7 Remove some more comments that literally repeat the code
… 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
2021-06-18 21:23:56 +00:00
jenkins-bot
f93e78f7fe Merge "filerepo: Fix parsing metadata in ForeignAPIFile" 2021-06-18 11:28:21 +00:00
Amir Sarabadani
5d1badae5d Deprecate LocalFile::getHistory hook
This undocumented hook which is only used in FlaggedRevs (and it's being
removed in If5a56a8fd5fc568) doesn't serve much purpose and can break
the file class.

Bug: T284777
Change-Id: I7ed8c01f0d0485f40307a24cc33cf3536f70c417
2021-06-17 08:33:31 +02:00
Amir Sarabadani
65e875acbb filerepo: Fix parsing metadata in ForeignAPIFile
ForeignAPIFile::parseMetadata is a recursive function trying to parse the
metadata tree. We want to emit _error as value if the metadata returned
by API is not an array but at the same time, we broke when the function
reaches the leaves and tries to parse them making parseMetadata return _error
for all leaves instead.

This broke beta cluster. I tested this change on beta cluster and this
patch fixes it.

Bug: T275268
Change-Id: I2befa92a8f9619ba6eb990d461f0a6f0fa7a4677
2021-06-15 11:14:56 +02:00
DannyS712
a95838c1f6 Remove LocalFile::recordUpload2
Hard deprecated, no remaining uses

Bug: T262708
Change-Id: I9f6f9197db105618e87c927503dee9011899d6a8
2021-06-15 07:04:33 +00:00
Tim Starling
68ebdfc77f Optionally split out parts of file metadata to BlobStore
* Optionally store metadata in the database in JSON format instead of
  PHP serialization. The new JSON format has a top-level "envelope"
  array which gives us a place to store things that are not part of the
  handler metadata.
* Optionally split metadata items, putting items above a threshold into
  the text table. The FileRepo and MediaHandler must both opt in.
* For staged deployment, the read side of these changes is always
  active. Only the write side is configurable.

Bug: T275268
Change-Id: I876ea5c9d3a1881e278f689d2f8a3ae20240c703
2021-06-11 08:01:26 +10:00
Timo Tijhof
5c1385f55a filerepo: Update outdated LocalFile comment about cache size
Follows-up b4849e03b7.

Change-Id: Id54004703b0b127002be54b5842ca273d5e12988
2021-06-09 20:16:57 +01:00
Tim Starling
b4849e03b7 Use the unserialized form of image metadata internally
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
2021-06-08 17:04:01 +10:00
jenkins-bot
ab94819309 Merge "Stop requiring full User to upload a File." 2021-06-07 20:34:01 +00:00
Petr Pchelko
2a94694185 Stop requiring full User to upload a File.
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
2021-06-07 12:48:48 -07:00
DannyS712
a84ad7bd40 Add some missing __METHOD__ parameters to database calls
Plus fix a typo

Change-Id: I8ca326990559ea80254ce0cef2ed204590716679
2021-06-07 19:28:51 +00:00
Tim Starling
7f8adc13bf Reapply "LocalFile: don't use dynamic property assignment when loading from 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 9e8ff12a59.

Change-Id: Ia3c14c51541e06264891a51763a8dadde83fbab7
2021-06-07 15:01:30 +10:00
Petr Pchelko
3e2259be93 ArchivedFile: replace ::getUser methods with ::getUploader
Change-Id: I43ea7be80e8546e217d6aa371bb48f0699129cc4
2021-06-04 12:07:07 -07:00
jenkins-bot
ec79d285d9 Merge "OldLocalFile::uploadOld() accept UserIdentity" 2021-06-03 13:48:12 +00:00
DannyS712
b631cd932a OldLocalFile::uploadOld() accept UserIdentity
Only used to pass the user to recordOldUpload(), which
already only needs a UserIdentity

Change-Id: I73dcd62f01cf7a03e25ac6d4edb6d0309a7fcd77
2021-06-03 05:32:54 +00:00
Petr Pchelko
eed864e311 Hard-deprecate File::getUser
Depends-On: Ia944ba04880b20d6da71ebccfc0cb7ecd9b37904
Depends-On: Ie9978d2ee692952b73832a859ea30e3f5457a743
Change-Id: I6885be24237cf222a2bd87156b64c784590b6efb
2021-06-02 13:49:00 -07:00
Petr Pchelko
5455e58967 Deprecate File::getUser in favor of File::getUploader
Change-Id: I8a45a8fdfa827f203e6bc123cb685d02c3612bb0
2021-06-02 09:06:09 -07:00
Ppchelko
9e8ff12a59 Revert "LocalFile: don't use dynamic property assignment when loading from the DB"
This reverts commit 29cd484c86.

Reason for revert: subclasses of LocalFile broke, cause they were relying on dynamic property assignment. For example OldLocalFile was loading oi_deleted this way. We could override loadFromDB, but since LocalFile is @stable to override, this becomes a breaking change. I'll leave it to Tim to re-revert in a way he thinks it's best.

Change-Id: I81e06c13128d3330972a39fb2628a1dd5f8c4658
2021-06-02 14:35:19 +00:00
Tim Starling
29cd484c86 LocalFile: don't use dynamic property assignment when loading from the DB
Merge LocalFile::decodeRow() with its only caller loadFromRow(), and
replace dynamic assignment $this->$field with plain assignment. This
makes the data flow more obvious.

The point of dynamic assignment was defeated by the fact that almost
every field required some kind of normalization after loading it from
the database. There's no point looping over all fields when you need to
do something different for each field.

Dynamic assignment is retained in loadFromCache() and setProps(), where
there is less normalization.

Change-Id: Ie103884c4436ab63c29652edf3bab331a34081c9
2021-06-02 11:32:42 +10:00
jenkins-bot
e20a0d7c29 Merge "FileRepo::findFile - support Authority" 2021-06-01 15:24:39 +00:00
ZabeMath
1ee6279cf7 Hard deprecate RepoGroup methods
RepoGroup::singleton(), ::destroySingletons() and ::setSingleton()
are all deprecated since 1.34.

Bug: T249020
Change-Id: Ie6c7db6331681ec96da646f945958ed8675e6b78
2021-05-27 23:08:24 +02:00
Tim Starling
f5d86ec75e Replace usage of custom File properties
Some MediaHandler subclasses were setting custom properties on the File
object in order to cache file-associated state. So:

* Add File::getHandlerState() and File::setHandlerState().
* Put them in an interface, which will be used in a subsequent commit in
  MediaHandler::getSizeAndMetadata().
* Use them in DjvuHandler.
* Provide a trivial implementation of the interface, for use in testing
  and in the subsequent commit.

Change-Id: Ic365384ff13f7898c1203da38c4405abf03d7563
2021-05-27 18:48:06 +10:00
Petr Pchelko
fb6529e653 FileRepo::findFile - support Authority
Change-Id: Ib42b7f7d5aa88447b4fb363f52062b08a1af30c3
2021-05-26 19:01:12 -07:00
James D. Forrester
f2f9345e39 Replace uses of DB_MASTER with DB_PRIMARY in documentation and local variables
This is just a start.

Bug: T254646
Change-Id: I9213aad4660e27afe7ff9e5d2e730cbf03911068
2021-05-14 12:40:34 -07:00
Thiemo Kreuz
6805f39a30 Remove unused default values from class properties
In all these cases the property is unconditionally set in
the constructor. The extra initialisation is effectively
dead code and an extra source of errors and confusion.

Change-Id: Icae13390d5ca5c14e2754f3be4eb956dd7f54ac4
2021-05-12 13:44:28 +02:00
Petr Pchelko
99ca273aa7 Convert UploadStash to UserIdentity
Change-Id: I7e0a0824bc9924f40e68119aa3d8cf0687446c79
2021-05-10 11:33:02 -07:00
Petr Pchelko
7b882b2e51 Convert File to Authority/UserIdentity
None of the changed methods actually are overridden
according to codesearch, so I guess it is ok
to change signatures.

Change-Id: I35bafb303163dfc1584a13b29675b5e10cd055fd
2021-05-10 10:57:06 -07:00
DannyS712
7bd7d2a6c1 Remove hooks that use Revision objects
All hooks were previously hard deprecated
in 1.35. Affected hooks:
* ArticleRevisionUndeleted - use RevisionUndeleted
* ArticleRollbackComplete - use RollbackComplete
* DiffRevisionTools - use DiffTools
* DiffViewHeader - use DifferenceEngineViewHeader
* HistoryRevisionTools - use HistoryTools
* NewRevisionFromEditComplete - use RevisionFromEditComplete
* PageContentInsertComplete - use PageSaveComplete
* PageContentSaveComplete - use PageSaveComplete
* ParserFetchTemplate - use BeforeParserFetchTemplateRevisionRecord
* RevisionInsertComplete - use RevisionRecordInserted
* TitleMoveComplete - use PageMoveComplete
* TitleMoveCompleting - use PageMoveCompleting
* UndeleteShowRevision - no replacement

Includes a fix for setting the associated rev id
of page protections, which previously was only done
using $nullRevision which was a Revision object created
if any hooks needed it; those hooks were hard deprecated
and so for WMF prod the rev id was not being set.

Bug: T247143
Depends-On: Idfa345193ae99fb2f1c9a8f8d28d8d540a6e3d62
Change-Id: I519167f76a5a3c1f5410415b2721462a3dcc3ec8
2021-04-30 17:28:20 +00:00
James D. Forrester
64898405cb build: Upgrade mediawiki-codesniffer from v35.0.0 to v36.0.0
Change-Id: I8905d0d69738a1cd6997c104080fdf128d315e8b
2021-04-29 13:00:15 -07:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Umherirrender
8971719867 UploadBase::getSha1Base36FromPath can return false
Bug: T187491
Change-Id: Ie91d87f3a0aeab0344f8af6d1e0906dacf8a8e38
2021-04-27 22:48:53 +02:00
Tim Starling
a3b7ea6732 Stop using legacy ActorMigration fields img_user/oi_user/fa_user
Bug: T278917
Change-Id: If7dd7d2198bd79636fdfb8b5644fb7cd8ae2901f
2021-04-26 12:23:59 +10:00
daniel
4eebc3491a FileRepo: replace Title in method signatures
NOTE: FileRepo is extended (via LocalRepo) by a couple of extensions,
even though it is not stable to extend. Hwever, none of these extensions
overrides any of the methods changed here.
https://codesearch.wmcloud.org/extensions/?q=extends%20%5Cw%2BRepo%5Cb&i=nope&files=&excludeFiles=&repos=

Bug: T278459
Change-Id: I0c236bfa354b01b03f864dd343371e4ae323b56f
2021-04-16 11:01:48 +00:00
daniel
e0000ce176 RepoGroup: replace Title in method signatures
Bug: T278459
Change-Id: Icee70d3743b321b25c046429e8738fffa6a657de
2021-04-16 11:01:33 +00:00
jenkins-bot
46efdb6e35 Merge "LocalFile: Move "supportsSha1URLs" in purgeThumbList() out of the loop" 2021-03-27 03:39:47 +00:00
Reedy
135c3d2887 LocalFile: Move "supportsSha1URLs" in purgeThumbList() out of the loop
The assignments are not connected to the loop, and don't need calling
repeatedly.

Change-Id: I952bdbb8a2c8212363223ca22361bbaa38d34b56
2021-03-27 02:41:45 +00:00
jenkins-bot
9015e4fdc1 Merge "Deprecate UserIdentity::getActorId()" 2021-03-13 21:30:22 +00:00
daniel
4dce6dd0c3 Deprecate UserIdentity::getActorId()
Note: User::getActorId() is not (yet) deprecated.

Bug: T274179
Change-Id: Ic2ca6d489db821fc2334e53bf2496c7b0d3ea5b1
2021-03-13 19:45:57 +01:00