Commit graph

1112 commits

Author SHA1 Message Date
DannyS712
a2b20b63d7 Emit deprecation warnings reading from $wgUser
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
2021-09-15 20:17:04 -07:00
Amir Sarabadani
64752c0fc4 Drop $wgDjvuToXML
The software behind this is abandoned and we are migrating djvu metadata
to json instead.

This doesn't affect production as we already use djvudump

Bug: T275268
Change-Id: If45ae5746ba91ba305f93603dc1e3aafba80a369
2021-09-10 23:40:31 +02:00
Umherirrender
2e4ee47c3d Cleanup mixed space/tab line indent
Change-Id: I833052a656b1ce419c0929f6f0514f2a33c2c4cc
2021-09-04 00:52:31 +02:00
jenkins-bot
40c423d441 Merge "Simplify if-then-else-return statements with explicit true/false" 2021-08-24 11:44:23 +00:00
Umherirrender
220fd020c4 Simplify if-then-else-return statements with explicit true/false
When both branches returns a bool, use the condition as return value

Change-Id: I59416aa021d0ada77d84fda4aaf7def0eea54009
2021-08-17 23:19:04 +02:00
vladshapik
1091f7753f Hard-deprecate Parser::mUser public access, Parser::getUser and ParserOptions::getUser
Bug: T285713
Depends-On: Ie75c9cd66d296ce7cf15432e2093817e18004443
Change-Id: I4297aea3489bb66c98c664da2332584c27793bfa
2021-08-17 15:42:05 +00:00
Alexander Vorwerk
60c3deaba1 RepoGroup: inject MimeAnalyzer
Change-Id: Ic3009b368b38d307d00dc3bec5c8d46b2dc97f83
2021-08-13 17:02:42 +02:00
Alexander Vorwerk
135595a818 Remove unnecessary use statement
I10d2b32bd95316e1331b5eb88ef57de55c3ca1a1 removed the last usage of MediaWikiTestCaseTrait, thus the use statement can be removed.

Change-Id: I05b3b56abc8079abd294e453c78128858ef8ea7d
2021-08-04 00:54:08 +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
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
Arlo Breault
ce7df5f6ea Copy changes from legacyMediaParserTests to mediaParserTests after syncing
From I41eb89f9a4caddce7f90f8c8b92b4fcb29eb4539

Change-Id: I24835feed2b17c2091729657c6c0c34f3ee31b78
2021-06-25 11:01:27 -04:00
Arlo Breault
354a366f31 Sync up with Parsoid legacyMediaParserTests.txt
This now aligns with Parsoid commit 356629d62ad930d67798c54aa8c11f45f328d030

Change-Id: I41eb89f9a4caddce7f90f8c8b92b4fcb29eb4539
2021-06-25 10:55:22 -04:00
Arlo Breault
9c854614a3 Sync up with Parsoid parserTests.txt
This now aligns with Parsoid commit 356629d62ad930d67798c54aa8c11f45f328d030

Change-Id: I5179a5f6fc4fdb221f1b4fd92fe0bfb3fa4442e5
2021-06-25 10:55:22 -04:00
Arlo Breault
fdd8f864b8 Emit media structure as piloted in Parsoid
Gated behind the flag $wgParserEnableLegacyMediaDOM.  The scattershot
usage of it is a little unfortunate but isn't expected to live very long
so maybe that's acceptable.

Further details can be found at,
https://www.mediawiki.org/wiki/Parsing/Media_structure

Bug: T51097
Bug: T266148
Bug: T271129
Change-Id: I978187f9f6e9e0a105521ab3e26821e36a96b911
2021-06-24 23:32:40 +00:00
Tim Starling
9c3c0b704b Use array_fill_keys() instead of array_flip() if that reflects the developer's intention
array_fill_keys() was introduced in PHP 5.2.0 and works like
array_flip() except that it does only one thing (copying keys) instead
of two things (copying keys and values). That makes it faster and more
obvious.

When array_flip() calls were paired, I left them as is, because that
pattern is too cute. I couldn't kill something so cute.

Sometimes it was hard to figure out whether the values in array_flip()
result were used. That's the point of this change. If you use
array_fill_keys(), the intention is obvious.

Change-Id: If8d340a8bc816a15afec37e64f00106ae45e10ed
2021-06-15 00:11:10 +00: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
ZabeMath
947cba5dee ParserTestRunner: use HookContainer instead of Hooks class
Hooks::register and Hooks::clear are deprecated (the second one is
hard deprecated, leading to deprecation warnings). Use
HookContainer::register and HookContainer::clear instead.

Bug: T281613
Change-Id: I10d2b32bd95316e1331b5eb88ef57de55c3ca1a1
2021-05-02 05:12:08 +00: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
Arlo Breault
c32e539bcd Sync up with Parsoid parserTests.txt
This now aligns with Parsoid commit 760eb7ea841efff29a9e740662985c330501601b

Change-Id: I06928d461e2948db2b23806e64adb2de4ef2c724
2021-04-26 15:09:39 -04:00
jenkins-bot
ee3e2a572d Merge "Don't p-wrap <aside> tags in extension HTML" 2021-04-26 18:50:46 +00:00
Amir Aharoni
c8caf26ffd Remove RLM/LRM from Names.php
This character is no longer required here.

It was added to ensure correct display of parentheses in mixed
LTR/RTL environment, for example an interlanguage link from
an RTL wiki to an LTR language with parentheses in its name.
However, the Unicode bidirectional algorithm was updated
to handle parentheses more cleverly and automatically,
making manual adjustment with RTL/LRM unnecessary.
This update was implemented years ago in all browsers and
operating systems. I've tested this in Firefox, Chrome, Edge,
and Internet Explorer 11, and it works correctly without
the RLM/LRM characters.

Parser tests are updated accordingly.

Bug: T280435
Change-Id: I63107f623ade3b8367eae579a8e96d7e2c18b747
2021-04-22 08:27:41 +00:00
jenkins-bot
24c72c6079 Merge "MediaHandlerFactory: inject a logger" 2021-04-14 15:17:28 +00:00
Máté Szabó
377c53ae51 Don't p-wrap <aside> tags in extension HTML
Our PortableInfobox extension uses the HTML5 <aside> tag in its generated HTML.
This tag isn't recognized as a block element (in the way e.g. <div> is) by the
legacy parser, resulting in some spurious empty paragraphs in the output.

As a fix, make the legacy parser aware of <aside> tags to avoid unnecessary
p-wrapping. Also add <aside> to the Sanitizer's internal attribute check.
I3e57f55ac69d2c1ee8a1d41c21b692e56fc7e628 takes care of updating Parsoid-PHP
accordingly.

Bug: T278565
Change-Id: I89dbdf7770e13e1b62320228a366c64e64217b0b
2021-04-06 16:26:12 +02:00
Umherirrender
dc7cfa0434 Add parser test for {{safesubst:self}}
This fails without the follow-up patch with the same exception as on the
task

Bug: T276476
Follow-Up: I014da3a333f8ee6ca623b98c415b8d9f9d1be084
Change-Id: Ib61e9ea44a6fdc31e10b89c3504cecec5b9fd208
2021-04-04 22:22:29 +02:00
DannyS712
6fb338ae40 MediaHandlerFactory: inject a logger
Instead of using wfDebug
Also normalize the entries

Change-Id: Ie539233c8b95eaae370732f97681989821157299
2021-03-31 17:45:51 +00:00
James D. Forrester
7c74fc35e2 parserTests: Avoid problematic language in comments
Bug: T277986
Change-Id: I1e079d670ecfb5338223a26df507427b45e28121
2021-03-28 21:23:37 -07:00
C. Scott Ananian
ff20e86a4c Make Parser::$mFunctionHooks private
This property was deprecated in 1.35.

Code search:
https://codesearch.wmcloud.org/search/?q=mFunctionHooks&i=nope&files=&excludeFiles=&repos=

No dependencies in WMF-deployed code.  One use in non-WMF-deployed code:
* I5ae19465561b150ee1c74a1fe03fa359964e81c4

Bug: T275160
Change-Id: I96ca88048c5a1cc8032ebcd502015819958680fb
2021-03-16 19:42:25 +00:00
C. Scott Ananian
1c6e24a1a2 Make Parser::$mTagHooks private
This property was deprecated in 1.35.

Code search:
https://codesearch.wmcloud.org/search/?q=mTagHooks&i=nope&files=&excludeFiles=&repos=

Dependencies below are for WMF-deployed code.  Other uses in
non-WMF-deployed code have been patched in:
* I435b0d1ccae9d9bf6fff85dc3e79d3c4b447eb37
* I85ef0e6ce3f0c818df85809d39259d13b56d966c
* Idab6c9475f78ff4040061f2f317560bbe41666d8

Bug: T275160
Depends-On: Ic5445471d770e396421a4fb2bcfbe1490a77e1bf
Depends-On: Ib708e3f84aa871de84aa56561c875f4a85bb000c
Change-Id: I42e23b101e870b66d169cbb731a0359e90f46265
2021-03-16 19:42:12 +00:00
C. Scott Ananian
3f990d5b4c Inline Parser::firstCallInit() into ::__construct()
This has effectively been the case since 1.35; this just cleans up the
remaining code which assumed it still needed to explicitly call
Parser::firstCallInit() on a newly-constructed Parser.

Bug: T250444
Change-Id: I340947c721172f12ff413322b4283627c0b0b3a4
2021-03-16 19:41:56 +00:00
James D. Forrester
bdddfb92ba Drop wgContLang, deprecated in 1.32
Bug: T245940
Depends-On: Ib7fe7318100c0aadc3aa759416bf787913a9b788
Change-Id: I75c3b6715abd5eaf3619337cab8b1844e9a8349a
2021-03-08 13:27:28 -06:00
jenkins-bot
800e1f8cea Merge "Don't worry about something before when armoring french spaces" 2021-03-02 01:28:03 +00:00
Arlo Breault
6222a1aee8 Don't worry about something before when armoring french spaces
We lost some insight in c44a395 because we're no longer analysing the
entire dom as a serialized string, but instead running our regexp on
individual text nodes.

This patch as written here just allows for the space to be at the start
of the text node.  However, some git spelunking shows that in 9dc65ef,
the condition for there being a non-whitespace character previous to the
space was only because armoring French spacing happened before
doBlockLevels and wanted to protect indent pre's.

That's certainly not the case anymore, so we can probably get away with
dropping the condition altogether now.

Bug: T275918
Change-Id: I654a09b0f98937379b9fad3f325134ead7f2d8a6
2021-03-01 11:52:27 -05:00
Arlo Breault
ed543be03b Sync up with Parsoid parserTests.txt
This now aligns with Parsoid commit 241a08fb80cd5b4b16146eb99054b25c0261998c

Change-Id: I8d176b76891e10de096247f6ad3ed52ec6f5735e
2021-02-18 11:23:19 -05:00
Arlo Breault
c44a3958a3 Don't apply French spacing in raw text elements
This also means we don't need to take special care for French spacing in
attributes, since it's no longer applied there.

Adds a test that captures this change.

Note that the test "Nowiki and french spacing" wonders whether this
escaping should be applied to nowiki content.

Bug: T255007
Change-Id: Ic8965e81882d7cf024bdced437f684064a30ac86
2021-02-16 19:26:29 -05:00
Umherirrender
a1de8b8700 Tests: Mark more more closures as static
Result of a new sniff I25a17fb22b6b669e817317a0f45051ae9c608208

Bug: T274036
Change-Id: I695873737167a75f0d94901fa40383a33984ca55
2021-02-09 02:55:57 +00:00
Reedy
729f20afc8 Tests: Mark more closures as static
Bug: T274036
Change-Id: I911d3041cebe417d162934223b46ea295c6d20e3
2021-02-07 13:26:56 +01:00
Umherirrender
205f141bb8 Improve some class properties documentation in tests
Change-Id: Id9c9e56865cf9a6bb112be37a5674ec753604fb1
2021-02-02 16:48:15 +00:00
jenkins-bot
eb4b304ed8 Merge "Add missing @param and @return to documentation in tests" 2021-01-30 15:22:33 +00:00
jenkins-bot
7b2a853019 Merge "Parser test for Balinese language conversion" 2021-01-30 15:22:25 +00:00
Arlo Breault
21dfb00fa3 Sync up with Parsoid parserTests.txt
This now aligns with Parsoid commit 4dd80737783737621bf1fc0e0b7e954f3d1bbf3c

Change-Id: Ib780af2f1e71aa6df8369d17cebf66d3bc85686b
2021-01-29 17:28:43 -05:00
jenkins-bot
03e2d471c4 Merge "Rewrite <langconvert> to support BCP 47 tags" 2021-01-28 16:30:31 +00:00
Tim Starling
0384793a2e Parser test for Balinese language conversion
Bug: T263082
Change-Id: I0a51656c54fbd547a6283dd23a7ee571dfb43d08
2021-01-28 03:43:07 +00:00
Umherirrender
47cc4da6d7 Remove unneeded @return documentation
Change-Id: If79d2126cc1b6a6e9876a972c9560d045de42ff6
2021-01-25 19:44:27 +01:00
Subramanya Sastry
0f86da8d4f ParserTests: Update error message to point to the failing test file
Change-Id: Idd5963aedffb2520153a6d99a1661c0471686008
2021-01-22 14:59:21 -06:00
Umherirrender
7691dbeca9 Add missing @param and @return to documentation in tests
Change-Id: Ic663e81cca0bf007804a70772250914a85f1fef4
2021-01-22 19:57:25 +01:00
jenkins-bot
e845067ab6 Merge "Adopt pipe trick with Arabic comma" 2021-01-16 03:29:36 +00:00
Arlo Breault
96d9eaa8c7 Sync up with Parsoid parserTests.txt
This now aligns with Parsoid commit ebf0a41507ec09a17f247acd2fdbb72555cbf2af

Change-Id: Ic3f59b93ae7b3132e1f410d0dfd35b1a4f6852be
2021-01-14 10:21:57 -05:00
David Kamholz
cdbd2e791d Rewrite <langconvert> to support BCP 47 tags
This validates langconvert's "from" and "to" arguments as valid BCP 47 tags. For example, it will accept "sr-Cyrl" and "sr-cyrl" and reject the non-standard internal MediaWiki code "sr-ec". I made the BCP 47 matching case insensitive as that seems to conform with how MediaWiki handles it elsewhere and case sensitive matching would probably be a headache for users.

Bug: T271758
Change-Id: I9f765fe650279820d61c3a7e499ca99468df3d14
2021-01-13 19:00:47 -08:00
Arlo Breault
78e85ab9e5 Split out media parser tests
Bug: T111604
Bug: T271129
Change-Id: I9893d11d50b8e5884239da2bb41262e093afc47f
2021-01-13 15:53:33 -05:00