Commit graph

37 commits

Author SHA1 Message Date
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
jenkins-bot
c09ac42243 Merge "build: Use inline ignore for MediaWiki.Usage.DeprecatedGlobalVariables" 2024-10-05 15:59:19 +00:00
jenkins-bot
8f8677e2c0 Merge "Use a better bidi aware markup in CommentParser" 2024-10-04 12:21:17 +00:00
Ebrahim Byagowi
efda4cae32 Use a better bidi aware markup in CommentParser
As noted on the comments, this needed a markup that work better
in bidi scenarios and as a part of replacing bidi control codes
with HTML markup I was able to test different bidi scenarios
using <bdi> HTML tags.

Bug: T375975
Change-Id: If2af751fc9f78869acf7b7e93199fa927de2cc19
2024-10-04 10:50:02 +03:30
Ebrahim Byagowi
bc7ec83596 Remove CommentFormatter::formatStringsAsBlock
This doesn't seem to be used anywhere except the tests and the
better API is to use $formatter->createBatch() API that
doesn't expose 'ugly boolean parameters' as described by
formatInternal method above so let's remove it.

https://codesearch.wmcloud.org/search/?q=formatStringsAsBlock

Change-Id: Ia7428f5dbdf6c76b7537ae3889aef077bb26c722
2024-10-04 10:23:17 +03:30
Umherirrender
c7cd5399e7 build: Use inline ignore for MediaWiki.Usage.DeprecatedGlobalVariables
This avoids addition of new code with the deprecated global,
or at least it gives extra attention on review when new code also uses
the inline ignore

Change-Id: I5c1bc5a1685c28f153d4fbe3525959930f54b557
2024-09-26 18:15:32 +00:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
C. Scott Ananian
b855c62f66 Move Linker::makeExternalLink() to the LinkRenderer service
Move Linker::makeExternalLink to the LinkRenderer service, as has been
done with the other static methods of Linker.

In order to allow phan's SecurityCheckPlugin to perform a more accurate
analysis of taintedness, tweak the API of Linker::makeExternalLink to
clearly indicate via the type system whether the link text has already
been escaped or not: a `string` argument will always be escaped, and
if the argument is already escaped it should be passed as an HtmlArmor
object.  In refactoring, `Message` arguments were also common, and accept
them as-is to avoid the caller having to think about whether to call
Message::text() or Message::escaped().

This allows us to provide a more precise taint type to the $text argument,
avoids an opaque boolean argument, and avoids spurious errors from
SecurityCheck.

We also require the caller to explicitly pass a Title context, instead
of implicitly relying on the global $wgTitle.  This works cleanly
everywhere except for CommentParser, which has a $selfLinkTarget which
generally works as the title context for the external link, but which
is nullable.  The original Linker::makeExternalLink() used $wgTitle as
a fallback, but $wgTitle can also be null in some circumstances.  The
title context only determines how $wgNoFollowNsExceptions is handled,
so existing code basically just ignored $wgNoFollowNsExceptions when
$wgTitle was null, which isn't terrible.  A future refactor could/should
clean up CommentParser to ensure that there is always a non-null title
context that can be used.

Change-Id: I9bcf4780f388ba639a9cc882dd9dd42eda5736ae
2024-06-10 18:47:32 +00:00
Brian Wolff
36c9bdf09c SECURITY: Ensure CommentParser link processing does not lead to XSS
CVE-2024-PENDING

A malicious editor could potentially create an edit summary or log
summary with links such that a link marker is in an attribute which
will then get replaced allowing the content to break out of the
attribute leading to an XSS.

Bug: T355538
Change-Id: If20a8a95e84bb2f6e132bdda4907e3db6f133a8e
2024-03-28 22:51:59 +00:00
James D. Forrester
35b2542895 Namespace includes/cache
Bug: T353458
Change-Id: Ic3f3168ef17113f5fb3ec11e0a47f52d65eefba9
2024-02-20 10:28:03 -05:00
Subramanya Sastry
e55cc517da Move Parser to Mediawiki\Parser namespace
Bug: T166010
Co-Authored-By: Daimona Eaytoy <daimona.wiki@gmail.com>
Co-Authored-By: James Forrester <jforrester@wikimedia.org>
Co-Authored-By: Subramanya Sastry <ssastry@wikimedia.org>
Change-Id: I79b4e732c45095eedbaa80afa5eb7479b387ed8a
2024-02-16 09:18:38 -05:00
Brooke Vibber
dcd9c3ae26 Update name & email for bvibber
Updating name & email addresses for Brooke Vibber.

Re-ran updateCredits.php as well so there are some new entries in
there as well.

There are a couple of files in resources/libs that will have to
be changed upstream to keep tests happy, I will do patches
later. :D

Change-Id: I2f2e75d3fa42e8cf6de19a8fbb615bac28efcd54
2024-02-08 17:02:16 -08:00
Doğu Abaris
be736d2d13 Replace Linker qualifier with import
Change-Id: I2fa6d52871e863497459ae26156aa7bdac12f5ee
2024-01-18 23:13:00 +01:00
James D. Forrester
468e69bccc Namespace Sanitizer under \MediaWiki\Parser
Bug: T166010
Change-Id: Id13dcbf7a0372017495958dbc4f601f40c122508
2023-09-21 05:39:23 +00:00
James D. Forrester
5bc2a04b08 Namespace remaining Title-related classes under \MediaWiki\Title
Bug: T166010
Change-Id: Ia2e5a7367cc8cdbd8a7b845ae2fd5d776ff22891
2023-09-19 05:21:23 +00:00
James D. Forrester
41fb118c5c Namespace TitleParser under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4848e903b0c0a2f7c58ac19e0baeef0085a36bdc
2023-09-19 05:19:00 +00:00
James D. Forrester
a8a6cfd966 Namespace NamespaceInfo under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: Ibe103cd362535d3cb94cb8931e95fc74099d1497
2023-09-19 05:17:04 +00:00
James D. Forrester
94ece673b2 Namespace TitleValue under \MediaWiki\Title
One of the big ones, so doing this alone.

Bug: T166010
Change-Id: I4c901d5c32696d8334ec30cede7d9b6f3d8d645e
2023-09-18 18:24:39 +01:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
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
2023-03-02 08:46:53 -05:00
Amir Sarabadani
4bb2886562 Reorg: Migrate WikiMap to WikiMap/ out of includes
And WikiReference

Bug: T321882
Change-Id: I60cf4b9ef02b9d58118caa39172677ddfe03d787
2023-02-27 05:19:46 +01:00
Alexander Vorwerk
f6bd18d6c2 Split a base class out of CommentStore
so that extensions (i.e. CheckUser) can implement their own comment
store without having a lot of code duplication

basically the comment store version of I3a6486532f2ef36

Bug: T233004
Change-Id: Ib40f99e00a514d41776ce521baf113e46d37e9cd
2023-01-01 22:34:36 +00:00
Amir Sarabadani
2d60ba0c63 Reorg: Move DummyLinker and Linker to linker/
This feels like a no-brainer unless I'm missing something obvious

Bug: T321882
Change-Id: Id49c3d0dd6ea4593211048850856b5b8e05a8fb3
2022-12-08 06:38:17 +01:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Welp
7ffda2e095 Escape link markers before replacement when building comments.
Bug: T307153
Change-Id: I24b5db2f06042b2021478ece5b46d5c8bdb38a22
2022-10-05 10:13:21 -07:00
Aryeh Gregor
c435212260 Get rid of warnings on PHP 8.1
This is mostly about adding return types to methods that implement PHP
interfaces, and not passing null to core functions that want a string.
After this patch, and an update to return types in RemexHtml,
tests/phpunit/integration/ has no more errors than in PHP 8.0.

Bug: T289879
Bug: T289926
Change-Id: Ia424f5cc897070f4188ae126b5bf6a1f552db0e1
2022-06-13 04:42:20 -04: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
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
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
Umherirrender
c259c37033 Add various null checks when null is not possible to use as argument
Also check for false if needed

Found by phan strict checks

Change-Id: I298204653dfb788515a87978dd8705b6e4f9c775
2022-03-14 17:17:17 +00: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
Ammarpad
4cbda4ba6b CommentParser: Optimise operation order (cache before isAlwaysKnown)
Check the more common case (local cached title) first, before
calling isAlwaysKnown which can be expensive due to hooks.

Follows-up Ica8733fb4a890fd2d2fc37eb85657c3715805133.

Bug: T293665
Change-Id: I8eb6144a3f1de5ebf9b4bd44e4021f9b6837f442
2022-02-22 15:04:08 +00:00
Ammarpad
a078ad29d5 CommentParser: Treat known titles as always known for linking
Existence of global userpages (or similar nonlocal pages)  can only be
known if the relevant title hook is involved, but LinkBatch is caching
these pages as bad links immediately after querying the local database.

CommentParser is then relying on this information to treat them as
always bad; thus preempting any further checks that might be done by
LinkRenderer to properly account for their magical existence.

Now title always-known status will be checked, to preempt bad linking.

Bug: T293665
Change-Id: Ica8733fb4a890fd2d2fc37eb85657c3715805133
2022-02-18 10:20:51 +00:00
Tim Starling
16979ecf29 Fix pollution of LinkBatch/LinkCache with interwiki link
* In LinkBatch::addObj(), reject interwiki links with a warning.
  Otherwise the link is added to the batch by ns/title and later
  reconstructed as if it were a local link without an interwiki
  prefix.
* In CommentParser, treat interwiki links as always good, don't defer
  the existence check.
* In LinkBatch, inject a LoggerInstance instead of calling LoggerFactory
  in four places.
* Add a regression test, and some general tests for known links.

Bug: T300311
Change-Id: I0e5825eb48a6ba2932aea69a4d0fff3439c50ff5
2022-01-28 10:52:38 +11:00
Umherirrender
5c40232470 Call LinkBatch::setCaller in CommentParser
For better tracking of db queries

Change-Id: Idad72d0dabb2ff1684189bf958d14aaa8b3c08ab
2021-12-16 22:26:40 +01:00
Reedy
c054b10423 Remove or replace usages of "sane"
Bug: T254646
Change-Id: Ia660ab95353cd8f05c50e60f30d29fd22b018a43
2021-11-22 15:48:03 +00:00
Tim Starling
44bc468cc2 RowCommentIterator: Cast data coming out of the DB
Bug: T292590
Change-Id: I8f830183c6deeb8bea146f1c1b791722a384220c
2021-10-06 09:06:09 +11: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