Commit graph

983 commits

Author SHA1 Message Date
Arlo Breault
2a23988766 The targetlang is a handler parameter
Follow up to I348840ef405e1370cc0c17d69051bce30153c9c0

Change-Id: Ia09c7ebf1dec605600ff0974e26c22ac601218fd
2022-03-14 18:51:23 -04:00
jenkins-bot
0200221a93 Merge "Fix various documentation related to null types (part II)" 2022-03-09 22:42:42 +00: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
Umherirrender
9ed1ed185f Fix various documentation related to false
Some function already document "False on failure", but does not document
it on the used type

Found by phan strict checks

Change-Id: I12eb8bbc99179833ee3e42c1a7d1dc1443682ca6
2022-03-03 21:33:31 +01:00
Thiemo Kreuz
88eefdae1a Trivial replacements of "-" comparisons with isDisabled()
This is split from I1d267ae, as well as a follow-up to Ie70d849.

Custom code like this exists because some messages do something
like {{#if: … | … | - }} to get dynamically disabled. This is not
something isDisabled() supports. That acts on the unparsed message
before any {{…}} was expaned.

The few cases in this patch are not affected because they use plain(),
which does not do any {{…}} expansion anyway.

Change-Id: I70541cf28c6fff14422e202f774b86086c2a850c
2022-03-03 16:13:45 +00:00
Jon Robson
350ea6686e Should be possible to use Linker static functions without global context
The methods Linker::tooltipAndAccesskeyAttribs, Linker::titleAttrib
and Linker::accesskey are not true static methods as they use classes
outside the ones passed in parameters. This blocks writing unit tests
in certain parts of the skin code, so these are now added as optional
parameters

Change-Id: I01e956084e8163f07afe2308d670d6efa3bea656
2022-02-23 21:50:12 +00:00
jenkins-bot
31afa269a6 Merge "Linker: Compact rollback edit count related code" 2022-02-22 18:46:04 +00:00
Arlo Breault
4ae0758db2 Revert "Add "resource" attribute to img tags"
This reverts commit 5809ef7caa.

Bug: T292657
Bug: T297984
Depends-On: I261887a3b2d15130894b947d18a2e85537d50a1f
Change-Id: Id4e8d16344ce0f420bfd3e0d5833c67d1cf85fd8
2022-02-18 20:14:20 -05: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
Arlo Breault
bb36c0609b Check if link-title-query is set
Follow up to I968dbb72731b9588fad0fa1e7770c799c0e451a5

Change-Id: Ieb1cdf2c7fa48d6059a6774a89ef8735068dc4c4
2022-02-18 17:50:52 -05:00
Arlo Breault
e4150464f9 Use link-title for manualthumb
link-url for external links, which this isn't and which gain rel
attributes in the follow up.

Change-Id: I968dbb72731b9588fad0fa1e7770c799c0e451a5
2022-02-18 22:26:40 +00:00
Tim Starling
a72c58e276 Reduce WANObjectCache hits on page view
When a nonexistent message is requested, a WAN cache request results,
because nonexistent keys are suppressed in the main cache by
isMainCacheable(). There is some performance degradation when such
keys are requested on every page view.

So:

* Make it so that keys prefixed with accesskey-, tooltip- and nstab-
  use Message::isDisabled() instead of Message::exists(), so that they
  can be blank instead of missing by default.
* Add blank messages for several such keys.

Change-Id: Ie70d849a8ecbf9ab70e58f582b9ba89afe9f2829
2022-02-10 11:04:54 +11:00
Thiemo Kreuz
b2ded2c7e9 Linker: Compact rollback edit count related code
This (hopefully) makes the code more readable.

Change-Id: Ia167a9a44277ae678464b9dcfb21611aabd22f97
2022-02-04 18:06:54 +01:00
jenkins-bot
7c2187f48c Merge "PHP 8.1: add ENT_COMPAT to some htmlspecialchars() calls" 2022-01-27 21:46:38 +00:00
Tim Starling
c5ef6e3091 PHP 8.1: add ENT_COMPAT to some htmlspecialchars() calls
In PHP 8.1 the default $flags argument to htmlspecialchars() has changed
from ENT_COMPAT to ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401. This
breaks some tests.

I changed all the calls that break unit tests, and some others
based on a quick code review. A lot of callers just use the default for
convenience, and were already over-quoting, so the default should still
be good enough for them.

Change-Id: Ie9fbeae6f0417c6cf29dceaf429243a135f9fecb
2022-01-25 16:30:44 +11:00
Umherirrender
c80faaeb39 Linker::getRollbackEditCount confused on revisions with same timestamp
When revisions have the same timestamp the rollback could be confused
about the order of both revisions.
Add additional order by rev_id as used in
RevisionStore::getRelativeRevision to fix this situation

mysql is ordering by the primary key in case of same values of an index,
using the same order, but postgres fails in this situation.

Bug: T195807
Bug: T218400
Change-Id: Id40f8351992de0fb747f09821de4e8463c8986d2
2022-01-22 17:26:09 +00:00
jenkins-bot
27187c26e3 Merge "Fallback to generic rollback message when editcount is unclear" 2022-01-21 09:35:47 +00:00
DannyS712
7f33d268f9 Linker: cleanup and reduce duplication around MediaWikiServices
No-op in terms of functionality.

Change-Id: Ia95a3e25437a268efad9d3a95b864639e27d0d10
2022-01-18 23:56:42 +00:00
Umherirrender
9dcf6fcb77 Fallback to generic rollback message when editcount is unclear
Linker::getRollbackEditCount can return 0 on replica lag

In this code the function does not return false or null, because
- false only when $verify is set (which is false here)
- null only when $wgShowRollbackEditCount is not set, but that is
already checked

Bug: T89780
Change-Id: I2d8108b1be5d25c33a68c40731a127deb3f45819
2022-01-11 20:18:12 +01:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
jenkins-bot
7d62f16f77 Merge "Add "resource" attribute to img tags" 2022-01-07 19:23:48 +00:00
Arlo Breault
ad0746110c Match output for broken thumbnails
Follow up to the FIXME added in I6d03037af1b5c90e6d57fd048506da2b4e4bc704

The output isn't great but at least it matches Parsoid's.

Change-Id: I5660b8ccdb8bd0c89b94669a1c6ab260d57183df
2021-12-16 21:23:20 -05:00
Arlo Breault
5809ef7caa Add "resource" attribute to img tags
This is spec'd out at https://www.mediawiki.org/wiki/Specs/HTML#Media

It's also useful in the bug to determine when the link is pointing at
the resource, and hence MediaViewer should open.

Previously that was distinguished with .image class on the link but
that's now omitted in getDescLinkAttribs.

FIXME: Should the "resource" contain querystrings?  Maybe this needs to
be done on the Parsoid side as well.

Bug: T292657
Depends-On: Idb60e418f79dcb6a121de2a11e6e0ed0b31fd3ff
Change-Id: Ia94138383ebdbfc2feef75fdf651b969085a72b1
2021-12-15 19:16:44 -05:00
Arlo Breault
28062181f9 Add content-media print styles
* Magnify clip isn't present in print styling
* Print and screen thumbborder are different
* Print thumbinner and thumbimage borders are absent

Bug: T287965
Change-Id: Ie1dac57412da7da3e73eb39ef20a6077923860d6
2021-12-09 11:42:05 -05:00
Amir Sarabadani
3cacc7f9c3 Fix local rendering of link in diff view with action=render
We probably should move Linker::expandLocalLinks( $text ) somewhere
better.

Bug: T263581
Change-Id: Iac446e761a709b6ceff5bd83dfa9a80db50a08d5
2021-12-01 17:18:53 +01:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
jenkins-bot
6a2f059dda Merge "Improve nullable documentation in Linker class about args" 2021-11-04 11:14:18 +00:00
Umherirrender
b9e8cd219f Improve nullable documentation in Linker class about args
Change documentation to null or false where the type is allowed
Also use int on Linker::tocLine, because an int is passed most

Change-Id: I9591ac91586aa9a28f38f80e0ab576b66b303d8d
2021-11-02 11:43:56 +01:00
jdlrobson
24949480eb Give skins more flexibility over table of contents render
* Do not store table of contents in parser output
* Instead inject table of contents via strpos where needed
  inside Article based on Skin "toc" option
* Use <mw:tocplace> as a TOC placeholder; for Parsoid compatibility
  this will be replaced with a <meta> tag in a followup patch.

Bug: T287767
Change-Id: I44045b3b9e78e7ab793da3f37e3c0dbc91cd7d39
2021-10-25 22:26:41 +00:00
Tim Starling
f7f84dddb3 Introduce CommentFormatter
CommentParser:

* Move comment formatting backend from Linker to a CommentParser service.
  Allow link existence and file existence to be batched.
* Rename $local to $samePage since I think that is clearer.
* Rename $title to $selfLinkTarget since it was unclear what the title
  was used for.
* Rename the "autocomment" concept to "section link" in public
  interfaces, although the old term remains in CSS classes.
* Keep unsafe HTML pass-through in separate "unsafe" methods, for easier
  static analysis and code review.

CommentFormatter:

* Add CommentFormatter and RowCommentFormatter services as a usable
  frontend for comment batches, and to replace the Linker static methods.
* Provide fluent and parametric interfaces.

Linker:

* Remove Linker::makeCommentLink() without deprecation -- nothing calls
  it and it is obviously an internal helper.
* Soft-deprecate Linker methods formatComment(), formatLinksInComment(),
  commentBlock() and revComment().

Caller migration:

* CommentFormatter single: Linker, RollbackAction, ApiComparePages,
  ApiParse
* CommentFormatter parametric batch: ImageHistoryPseudoPager
* CommentFormatter fluent batch: ApiQueryFilearchive
* RowCommentFormatter sequential: History feed, BlocklistPager,
  ProtectedPagesPager, ApiQueryProtectedTitles
* RowCommentFormatter with index: ChangesFeed, ChangesList,
  ApiQueryDeletedrevs, ApiQueryLogEvents, ApiQueryRecentChanges
* RevisionCommentBatch: HistoryPager, ContribsPager

Bug: T285917
Change-Id: Ia3fd50a4a13138ba5003d884962da24746d562d0
2021-09-28 11:13:03 -07:00
Petr Pchelko
5afc62f258 Remove stub threshold feature
Bug: T284917
Change-Id: I5c9ea04a9deca136bb7210f07200d18f97fd6686
2021-09-13 09:26:38 -07:00
Umherirrender
864068d000 Remove unneeded explicit true/false inside conditions
The non-strict conditions in if/while are true/false without the check.

In some situation the true/false is removed, because it is known to be a
bool (by is_bool check or type hint)

Change-Id: I5ca4c4771af25d2e785e82732df204a73653886e
2021-08-17 21:52:34 +02:00
mainframe98
3bab2cc853 EditPage: load mediawiki.interface.helpers.styles
This module provides styling for span.comment, produced by
Linker::commentBlock, which EditPage calls when generating the
HTML for the edit summary.

Add a notice for that to Linker::commentBlock, like was done
in ddbf011257, and update the
comment in the stylesheet.

Bug: T288907
Change-Id: I3d929eaae54754bd3e41a9add419f1098a7f8e3a
2021-08-15 16:01:07 +02:00
Kunal Mehta
a85f569dd1 Revert "Use CsrfTokenSet as CSRF token source"
This reverts commit 0d75fdb4f7.

Bug: T287542
Change-Id: Iedd3461869f973f8d621a39e6ad4674cbb577551
2021-08-05 15:48:26 -07:00
libraryupgrader
5357695270 build: Updating dependencies
composer:
* mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0
  The following sniffs now pass and were enabled:
  * Generic.ControlStructures.InlineControlStructure
  * MediaWiki.PHPUnit.AssertCount.NotUsed

npm:
* svgo: 2.3.0 → 2.3.1
  * https://npmjs.com/advisories/1754 (CVE-2021-33587)

Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
2021-07-22 03:36:05 +00:00
jdlrobson
d030d86357 Revise FIXME comments relating to use of '-' character as an access key
Introduced in 2008, and would involve a lot of unnecessary complexity
and potential software confusion, so revising comment to explain
the constraint that access key cannot be a "-" character.

Bug: T284139
Change-Id: I25f5b1943c58f76df9e3a7830d0d4c377494b280
2021-07-14 00:15:54 +00:00
Petr Pchelko
0d75fdb4f7 Use CsrfTokenSet as CSRF token source
Change-Id: I079d2c802d9b48d6abf7f37fa9ef7dafac631345
2021-07-12 14:19:15 -07: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
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
DannyS712
a4673c7ee7 Linker: remove support for Revision parameters
- Linker::buildRollbackLink
- Linker::generateRollback
- Linker::getRevDeleteLink
- Linker::getRollbackEditCount
- Linker::revComment
- Linker::revUserLink
- Linker::revUserTools

Bug: T247143
Change-Id: I600b690788dedeb4c9f7bd92da4f24b7dae2c4d2
2021-05-04 19:20:12 +00:00
Ammarpad
168ac52a58 Prepare for renaming page_timestamp revision index
Bug: T270033
Change-Id: I28ab091cf741e080c88ac7209edf3652b0f12fc1
2021-04-29 22:58:02 +01:00
Amir Sarabadani
b6f148bec6 Add classes to when a linked change is suppressed
This also tries to centralize adding logic of adding history-deleted
class as well. To make future changes easier.

This doesn't affect history deletion on files, recentchanges, and logs yet

Bug: T23272
Change-Id: I08f14f712479e1b170c606e2b64857f8386acd76
2021-04-29 15:28:06 +00:00
mainframe98
ddbf011257 Move most remaining legacy styles to interface.helpers.styles
This module is used almost everywhere these elements are found.
Methods in Linker that produce these elements list that this module
is required for proper styling.

Where possible, the module is added to retain the styles.

Bug: T278576
Change-Id: I7dedebd3bce3b4aec127738edc81b180325f0836
2021-04-20 07:15:25 +00:00
ZabeMath
60606a2986 Avoid using User::getBoolOption()
User::getBoolOption() is deprecated and should be replaced with UserOptionsLookup::getBoolOption()

Bug: T277600
Change-Id: Ife3c721237258d50852bbf764def74657cc70428
2021-03-27 22:51:03 +01:00
Peter Ovchyn
45140daa29 Avoid using User ::getDefaultOption, ::getDefaultOptions
This patch hard-deprecates the methods above

Bug: T276035
Change-Id: Ic36b0702f7547acce0d162d6e0b54bbd4ecf4d81
2021-03-16 17:24:17 +02:00
Petr Pchelko
c4f28d017b Replace some usages of User with Authority/UserIdentity
Change-Id: I7dfbf9bbd1709f5e67de7f6680a5a5ad156994fa
2021-03-04 17:20:40 -07:00
Petr Pchelko
782a46f661 Use Authority for revision audience where possible
Depends-On: I963a79d94b9e39086940a43945def7c8eff1536d
Change-Id: If99d428b391c0eaf61396565af7f38740bef6c4a
2021-02-24 10:56:50 -07:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
diwanshu885
9f2dc47bc3 Add data attribute to the elements with class "history-size"
Bug: T147908
Change-Id: I9a27ff029e86c705271ef1c2289daa95eb927315
2020-12-23 19:44:54 +05:30
Arlo Breault
c2cef6cb58 Consistent label escaping in makeBrokenImageLinkObj
Html::element is more lenient about which characters it escapes.

But really this is just factored out of the next patch for ease of
review.

Change-Id: I9abb4d866a624df7bf4628ab9cc581967e715160
2020-12-18 11:41:09 -05:00