Commit graph

1314 commits

Author SHA1 Message Date
Arlo Breault
0a82cbf301 Set alt in galleries, despite caption being visible
Similar to e7004a6 for tooltips.

Matches Parsoid commit I9d82c8003fd67cd984a8f4523e4993ed1f22b5d2

Bug: T297443
Bug: T162360
Bug: T63566
Change-Id: Ia3b13424d9f77586d334a477822e6e918d3b65c3
2022-06-07 18:20:26 -04:00
Arlo Breault
e7004a62d4 Set tooltips in galleries, despite caption being visible
Matches Parsoid commit Icbc36b6e9aa1b9f4f27c23f4833c626a725cc154

Bug: T297443
Bug: T108380
Change-Id: Ib6606dcbe8cf9476aaf694c4f86d5dc4768b9dd2
2022-05-16 19:25:49 -04:00
Arlo Breault
e2752a0dcf Clarify tooltips are set if captions aren't visible
Matches Parsoid commit Icbc36b6e9aa1b9f4f27c23f4833c626a725cc154

Bug: T297443
Bug: T108380
Depends-On: I896e2af2e8a712a36eb23a25cad08f53574fc044
Change-Id: I30eba0fb226971ddeda4eb240929e89ef7e5f45f
2022-05-16 19:25:27 -04:00
Arlo Breault
2cff882c79 Support unlinked media |link=| in gallery
Change-Id: Ie142752f9af9af622b9ba8175fe4c8f155199bcb
2022-05-11 12:11:44 -04:00
Arlo Breault
2cd940e1f3 Remove redundant calls to add(External)Link
parseLinkParameter already calls these.

Follow up to 1c9664d

Change-Id: If4cbcc4608ac732710f8d9a7b833d900064f1bf9
2022-05-11 12:11:44 -04:00
Arlo Breault
6289e1919d Use Linker::getImageLinkMTOParams() for galleries
This assures that nofollow's are added where necessary and sets the
title attribute on links where appropriate, matching file links outside
of galleries.

Change-Id: I999a294bbcb921fe53823503e8009ab678411bb2
2022-05-11 12:11:43 -04:00
Matěj Suchánek
e47c441078 Fix many typos in comments
Found using IntelliJ's "Typo" code inspection.

Change-Id: I746220ebe6e1e39f6cb503390ec9053e6518cf16
2022-05-10 12:46:11 +00:00
Aryeh Gregor
b85391120b Use UrlUtils in Parser
Change-Id: I65f851ea29efe482ee225565a200d623fa85bc20
2022-04-28 17:14:51 +03:00
jenkins-bot
b978acab5a Merge "Fix output encoding of language converter display title" 2022-04-27 15:43:34 +00:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
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
2022-04-26 19:03:37 +03:00
Tim Starling
d6a3b6cfa8 TempUser EditPage and permissions
* Allow EditPage to create a user on page save. This has to be enabled
  in config and then activated by the UI/API caller.
* Add an autocreate source for temporary users.
* Allow editing by anonymous users via automatic account creation when
  $wgGroupPermisions['*']['edit'] = false. On an edit GET request, use
  an unsaved placeholder user to stand in for post-create permissions.
* On preview or aborted save, the username to be created is stashed in a
  session and restored on subsequent requests.
* On a (likely) successful page save, create the account.
* Put regular non-temporary users in a "named" group so that they can be
  given additional permissions.
* Use a different "~~~" signature for temporary users
* Show account creation warnings on edit and preview.

Change-Id: I67b23abf73cc371280bfb2b6c43b3ce0e077bfe5
2022-04-26 14:10:53 +10:00
Fomafix
02de34c039 Fix output encoding of language converter display title
The change eed3121a8f added
unintentionally an HTML encoding to the language converter display
title with the syntax
  -{T|lang:Foo <i>italic</i> Bar}-
which shows raw HTML in the title. This change restores the previous
behavior for the language converter display title and applies the HTML
encoding only to the converted normal title.

This change also ensures that & is encoded to &amp; and that HTML
entities are supported like in the {{DISPLAYTITLE:}}.

Bug: T294612
Change-Id: Idc55e5756513808907be5ea95855d964a2fa704c
2022-04-17 20:29:21 +00:00
tacsipacsi
025ff0f4a4 Parser: Remove outdated warning of setHook
extract() is not used since 3d560be, so random variables cannot be
inadvertantly (or intentionally) modified by setting array keys anymore.

Change-Id: I4d72b52d59f66bca227c5ccafa8ce504d22f17f5
2022-04-17 19:13:16 +02:00
jenkins-bot
aecf21c0bc Merge "Manualthumb is a format, like the others" 2022-04-14 23:17:22 +00:00
Arlo Breault
4ffe6cd630 Manualthumb is a format, like the others
Previously "manualthumb" had a higher precedent than all the other
formats, because of its specialized handling.  However, it's mutually
exclusive to the other formats, so that doesn't seem justifiable.

Bug: T305641
Change-Id: I603f98e6315f04d518ff14f6b000a1c0c6f96d37
2022-04-14 21:49:40 +00:00
jenkins-bot
5b73bebe80 Merge "Percent decode titles in media link option" 2022-04-14 13:51:56 +00:00
Arlo Breault
58b4a45ad5 Percent decode titles in media link option
This matches expectations with wikilinks.

Bug: T216003
Change-Id: Ie7344dcf35b8036a0970c04c9b66d12112065bb5
2022-04-13 16:51:10 -04:00
Tim Starling
13c1839735 Fix SignatureValidatorFactory circular dependency
Parser is using the service container to get a SignatureValidator
because, as noted in Gerrit comments on the relevant commit, there is a
circular dependency Parser -> SignatureValidatorFactory -> Parser.

So, have SignatureValidatorFactory::__construct() take a closure which
returns a Parser, instead of an actual Parser or ParserFactory.

Change-Id: I7bf4660f84ec8c8fb1d5b3b8581fe5d82bc3156e
2022-04-13 12:38:00 +10:00
Aryeh Gregor
747bc81ac0 Use MainConfigNames instead of string literals
Part 1, proof of concept. Hundreds of files left to go. These changes
brought to you in large part by vim macros.

Bug: T305805
Change-Id: I44789091e9f6394c800a11b29f22528c8dcacf71
2022-04-11 17:53:27 +03:00
Arlo Breault
5b8fbe6ad7 Remove unrecognized frame parameter
"frame" is an alias "framed" and not a recognized internal parameter.

This was introduced in 05978d7

Change-Id: Ida9d4c81116769b63887022c68b4e1905aa2afe2
2022-04-07 12:13:01 +00:00
C. Scott Ananian
c1a326f44e Emit warnings when accessing deprecated public properties of Parser
Code search:
 https://codesearch.wmcloud.org/deployed/?q=-%3E%28mLinkID%7CmIncludeSizes%7CmDoubleUnderscores%7CmShowToc%7CmRevisionId%7CmRevisionTimestamp%7CmRevisionUser%7CmRevisionSize%7CmInputSize%7CmInParse%7CmFirstCall%7CmGeneratedPPNodeCount%29&i=nope&files=&excludeFiles=&repos=

The following @deprecated properties are not included in this patch in
order to keep it conservative:

* Hard to code search because of generic name:
  $mTitle, $ot, $mOptions
* Should be @internal, not @deprecated, because they are used internally:
  $mPPNodeCount, $mHighestExpansionDepth
* Used by SyntaxHighlight_GeSHi and TemplateStyles extensions (even though
  they could/should use their own independent unique ID):
  $mMarkerIndex
* Used by test cases for Wikibase:
  $mExpensiveFunctionCount

Change-Id: I1dadff934ead767cbd25615c08768e8e935d6b2e
2022-03-31 19:25:33 -04:00
jenkins-bot
232353c19b Merge "phan: Remove PhanPossiblyUndeclaredVariable suppression" 2022-03-31 14:36:57 +00:00
jenkins-bot
b2ae571c95 Merge "parser: Set init value for some variables in Parser" 2022-03-31 14:32:54 +00:00
jenkins-bot
c46c358cf9 Merge "Parser: allow Q tag in table of content items" 2022-03-31 14:26:59 +00:00
Umherirrender
6caf78c2c8 phan: Remove PhanPossiblyUndeclaredVariable suppression
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
2022-03-30 19:47:15 +00:00
Umherirrender
0bbb64d8b8 parser: Set init value for some variables in Parser
The variable are declared under conditions, which makes it hard for phan
to see there are already defined when used.

Found by phan (T259172)

Bug: T259172
Change-Id: Id4a9c7ca0e2fd88a454a7b72afcf4d293488d136
2022-03-30 19:39:33 +00:00
Umherirrender
7aa0884029 phan: Remove PhanTypePossiblyInvalidDimOffset suppression
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
2022-03-28 23:26:49 +02:00
Pols12
e8dcc61666 Parser: allow Q tag in table of content items
Parser::finalizeHeadings() strips out HTML for TOC line content.
This commit adds an exception to allow `<q>` HTML tags; useful when
the heading contain a quotation.

Bug: T251672
Change-Id: Ic1a4c7716fdcd5b0de9ac764aa472e898501fb12
2022-03-23 23:03:19 +01:00
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
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
2022-03-21 18:25:07 +00:00
jenkins-bot
2876074562 Merge "phan: Disable scalar_implicit_cast setting" 2022-03-20 15:55:45 +00:00
Umherirrender
6dd8a2bb32 phan: Disable scalar_implicit_cast setting
Make phan stricter about scalar types by setting scalar_implicit_cast to
false (the default in mediawiki-phan-config)

Bug: T242536
Bug: T301991
Change-Id: Ia2fe30b17804186571722e728578121c8b75d455
2022-03-18 18:52:24 +00:00
Alexander Vorwerk
82739980fd parser: change 'level' in parse api back to string
We changed to operate on an int internally in I92daeb0f7be8a0.
Let's cast it back to a string for the api in order to prevent
a breaking change, which is not really necessary.

Bug: T304171
Change-Id: I5f5a9203b4dd085cb5defba72c6650532bc9e8d1
2022-03-18 19:52:24 +01:00
jenkins-bot
7e5a2477ff Merge "Pass a ConvertibleTimestamp to CoreMagicVariables" 2022-03-15 22:26:32 +00:00
C. Scott Ananian
b72fa830d6 Pass a ConvertibleTimestamp to CoreMagicVariables
This avoids a type mismatch found by phan strict checks
(Ifc7fc64ac26a756f181b7d0155f13a6500114f5e) -- the passed timestamp
from Parser was a string in unix format (ie, an integer as a string)
but was declared as an integer.  It was then passed to
MWTimestamp::getInstance() which expected a string.

However, the 'simple' fix for this issue still caused unnecessary
conversions to/from timestamp format.  We took the string (nominally
in TS_MW format), ran a regexp against it to convert it to an
MWTimestamp instance, then converted that MWTimestamp to UNIX format
and exported that as a string, just to take that string and run four
different regexps against it *again* to convert it back to an
MWTimestamp instance so we can format it.

Better to just pass the MWTimestamp directly.  Only two wrinkles:

1. the ParserGetVariableValueTs hook expects to be passed a string
in TS_UNIX format and then to be able to mutate it. Nothing in production
uses that hook, so only do this conversion if the hook is registered.

2. Parsoid would like to use the definitions in CoreMagicVariables
in the future as well.  So pass the timestamp as the not-MW-@internal
ConvertibleTimestamp class instead of directly as a MWTimestamp.

Change-Id: Ib2c5fa45630c54c2716897370a0580ed48d27242
2022-03-14 17:30:15 -04:00
jenkins-bot
920b15ede9 Merge "Hard deprecate Parser::{get,set}DefaultSort() and ::getCustomDefaultSort()" 2022-03-12 01:25:44 +00:00
jenkins-bot
0200221a93 Merge "Fix various documentation related to null types (part II)" 2022-03-09 22:42:42 +00:00
jenkins-bot
fc8b8e77fe Merge "Fix various documentation related to scalar types" 2022-03-09 21:58:03 +00:00
Umherirrender
d30b3d8926 Fix various documentation related to scalar types
Found by phan strict checks

Change-Id: If41d16b473baddd92cc4261cdc2bfbe65fedcb19
2022-03-09 20:49:51 +00:00
C. Scott Ananian
dc3d489156 Hard deprecate Parser::{get,set}DefaultSort() and ::getCustomDefaultSort()
Code search:
https://codesearch.wmcloud.org/deployed/?q=-%3E%28get%7Cset%29%28Custom%29%3FDefaultSort%5C%28&i=nope&files=&excludeFiles=&repos=

Change-Id: I582f13b104a6c7bb9e98427a260b191d94866fa9
Depends-On: I603051d75b551d398233c607d73403584dc75852
2022-03-09 12:06:58 -05:00
jenkins-bot
a9900325fa Merge "Ensure that ToC is converted into the proper target language" 2022-03-09 05:34:10 +00:00
C. Scott Ananian
0955046ca5 Ensure that ToC is converted into the proper target language
This patch exports the necessary information from the Parser into the
ParserOutput to ensure that the Table of Contents can be properly
language-converted: both ensuring that the target language is correct
(in cases where it differs from the content language) and that various
conversion-suppression mechanisms are functional.  When the
ParserCache does not (yet) have the new properties from Parser, the
behavior is unchanged from before (the content language is used, and
its "preferred variant").

This is a follow up to the "quick fix" deployed in
Ic14b3a49a8ee7ed600485d4f8a363a206035a847 to fix an UBN regression.

Parser tests have also been added to verify that ToC conversion
is correctly done (T299973).

Task T303329 has been opened to (eventually) rename the
'core:target-lang' and 'core:target-lang-variant' properties added to
the ParserOutput in this patch.

Bug: T303235
Bug: T295187
Bug: T299973
Followup-To: Ic14b3a49a8ee7ed600485d4f8a363a206035a847
Followup-To: Ib273f88531c340b561072ee9f616aa60725091e6
Change-Id: Ie0f1d7b6daffc8ff47228f6f086a257518f72717
2022-03-09 00:08:57 -05:00
Umherirrender
d7248d63fb Fix various documentation related to null types (part II)
The functions returning null or the class property is set explict null.
Some function should not accept null or return null.

Found by phan strict checks

Change-Id: Ie50f23249282cdb18caa332f562a3945a58d86ff
2022-03-08 23:45:31 +00:00
jenkins-bot
4140d7eaad Merge "Deprecate Parser::getDefaultSort(), ::setDefaultSort(), ::getCustomDefaultSort()" 2022-03-08 21:08:53 +00:00
C. Scott Ananian
822020da6f Deprecate Parser::getDefaultSort(), ::setDefaultSort(), ::getCustomDefaultSort()
In modern mediawiki these methods are just wrappers for the 'defaultsort'
page property, and don't need a parser property of their own.

Change-Id: I18bdffd4d6565733fb52cbff409cc25d49a76b65
2022-03-08 15:08:02 -05:00
jenkins-bot
c268687d46 Merge "Hard deprecate Sanitizer::removeHTMLtags()" 2022-03-08 19:29:55 +00:00
Umherirrender
6ea3d6ac2c Add explicit casts between scalar types
php internal functions like floor/round/ceil documented to return
float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: I92daeb0f7be8a0566fd9258f66ed3aced9a7b792
2022-03-08 16:59:01 +00:00
C. Scott Ananian
d6576e5dc6 Hard deprecate Sanitizer::removeHTMLtags()
Rename Sanitizer::removeHTMLtags() into an @internal method named
::internalRemoveHtmlTags() so that we can deprecate external use.

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

Followup-To: Ic864c01471c292f11799c4fbdac4d7d30b8bc50f
Depends-On: Iaca83ed06e9c61d8366579cd2283cba653c82319
Depends-On: I1963bfe9a99198ea02ca482a5769467ce806cd58
Depends-On: I83923d8b38d33f3638cd53958dd10f257ec21f7c
Depends-On: I018b34bb5f6e113056da9b04cc72d4318422adce
Change-Id: I202826f8b27519f7be89643e24eda47a6e3fc9f6
2022-03-07 22:04:56 -05:00
Umherirrender
86fc7aaf9e parser: Improve line indent in Parser::expandMagicVariable
Also break some line on other hookrunner

Change-Id: Ia4077b7f0240abd7e5b731739f2c9801fe3b5096
2022-03-01 23:42:44 +01:00
Umherirrender
9efd9ca45e Add explicit casts between scalar types
* Some functions accept only string, cast ints and floats to string
* After preg_matches or explode() casts numbers to int to do maths
* Cast unix timestamps to int to do maths
* Cast return values from timestamp format function to int
* Cast bitwise operator to bool when needed as bool

* php internal functions like floor/round/ceil documented to return
  float, most cases the result is used as int, added casts

Found by phan strict checks

Change-Id: Icb2de32107f43817acc45fe296fb77acf65c1786
2022-03-01 18:19:33 +01:00
Arlo Breault
c5c7d5c9bb Fallback to parser-extlink-target instead of setting link-target
This makes the call to getImageLinkMTOParams consistent between thumbs
and not thumbs by now passing the parser in the former.  The result
being that the nofollow relationship is now added for external thumb
links as well.

Linker::getImageLinkMTOParams sets the parser-extlink-target based on
the same getExternalLinkTarget call.  This also makes it clearer when
parser-extlink-rel is modified by the target in getExternalLinkAttribs.

custom-target-link does have a higher precedence but it looks like this
was added in 1a4957e as a fallback to respect the global config so the
change seems fine.

A few parserTests cover this with the wgExternalLinkTarget config but a
case for thumbs with external links was added.

The phan annotations look like a false positive similar to
https://github.com/phan/phan/issues/3645
from the use of `$params[$type][$paramName] = $value;`

Change-Id: Icf887b13d046b0f610b1984d641f248d1dec5226
2022-02-18 23:06:43 +00:00