Commit graph

90 commits

Author SHA1 Message Date
Func
4d1da6f7f8 phpunit: Update @covers annotations for namespaced classes
We renamed many classes to be namespaced, but the `@covers` and
`@coversDefaultClass` annotations weren't updated properly.

PHPUnit didn't support short cover annotations with `use` statements,
these didn't trigger any errors yet, because they are class alias.

This patch is populated by a modified version of PhpunitAnnotationsSniff.

Change-Id: I6c602290a30099239b17d2dc0d67b1488b4eaeeb
2023-05-27 17:43:12 +08:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
Just methods where adding "static" to the declaration was enough, I
didn't do anything with providers that used $this.

Initially by search and replace. There were many mistakes which I
found mostly by running the PHPStorm inspection which searches for
$this usage in a static method. Later I used the PHPStorm "make static"
action which avoids the more obvious mistakes.

Bug: T332865
Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
2023-03-24 02:53:57 +00: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
Timo Tijhof
a2e3e079d3 linker: Fix broken specialLink() when combining subpage with querystring
Follows-up 3255f37af1 (Ibcd2c5365a1f581e), which introduced support
for subpage slashes and querystrings. Due to the order of operations,
it split off the subpage (including query) before the check for the
query, which meant it was actually encoded as part of the subpage.

The original unit test did expose this issue but the bug was part of
the expected value.

For example:
<https://en.wikipedia.org/wiki/Special:Contributions/JohnDoe%3FtopOnly%3D1>
vs
<https://en.wikipedia.org/wiki/Special:Contributions/JohnDoe?topOnly=1>
of which only the latter is identical to
<https://en.wikipedia.org/?title=Special:Contributions/JohnDoe&topOnly=1>

While at it, also improve readability and future-proof stability by
making the conditional check and the substring operation share the
same result directly instead of computing it three times. This avoids
future refacting causing the three lines to go out of sync in a way
that e.g. the subsequent strpos operations might find false which
would lead to an unpredictable outcome. Phan isn't able to catch this
yet, but probably will in the future, namely that strpos() can return
false which isn't a valid param to substr().

Change-Id: Iec00a6ecbf7abf57b8944e32a6256ac9db4a653b
2022-12-09 17:57:55 +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
James D. Forrester
3255f37af1 Linker: Add ability for Special page links to parse subpage and params
Change-Id: Ibcd2c5365a1f581eda43970dd12a1708880144a1
2022-12-07 16:22:12 -05:00
James D. Forrester
c013cc7d57 Linker: Add direct tests for makeSpecial ahead of changes
Change-Id: I190d4329051244bdbb5902d8e000d7c2ac4c5401
2022-12-06 16:27:01 -05:00
Umherirrender
6555923b08 tests: Replace deprecated WikiPage::factory
Bug: T297688
Change-Id: Ic84d491c5603f3590e26cb56a305508b2b0ca109
2022-09-02 19:34:02 +00:00
Derick Alangi
b6b335b183 tests: Migrate MediaWiki settings to overrideConfig...()
Also, make use of MainConfigNames constants where necessary like in
HashConfig map.

NOTE: Since `wgConf` is not a setting, keep using `setMwGlobals()`
  in this case.

Change-Id: I8d0c718fd02043835fe122d675cce3d759b30330
2022-08-18 17:48:03 +01:00
Derick Alangi
9899846d10
tests: Use overrideConfigValue(s) where necessary
The files in `tests/phpunit/includes/` directory are now all
covered. Will do sub-directories of `/includes/` next.

Change-Id: I8d5655ce267b6d32cf3c7ee40dc5d2992631b5a6
2022-07-16 23:45:52 +01:00
Jdlrobson
4a0cbbc0f8 Revert "WatchedStore requires PageIdentity"
This reverts commit c9c6bab379.

Reason for revert: This broke VisualEditor editing.
Not sure why but will repost in different format.
(https://phabricator.wikimedia.org/F35030276)

Change-Id: I7f21a2c756d06f488766896086e5b3488a366c19
2022-03-30 16:18:10 +00:00
Jon Robson
c9c6bab379 WatchedStore requires PageIdentity
According to the function signature of WatchedItemStoreInterface
a PageIdentity must provided. Any other parameter is deprecated.

The test is updated as it's trying to watch a special page and it's
not possible to watch special pages.

Change-Id: Ia97e497fbae922e46a1098bca32ad3d8d62070fa
2022-03-29 13:44:44 -07:00
Timo Tijhof
128debb64b tests: Change use of AtEase to at operator
Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359.

Per T253461, not mass-changing source code, but the use of the native
error silencing operator (@) is especially useful in tests because:

1. It requires any/all statements to be explicitly marked. The
   suppressWarnings/restoreWarnings sections encourage developers to
   be "lazy" and thus encapsulate more than needed if there are multiple
   ones near each other, which would ignore potentially important
   warnings in a test case, which is generally exactly the time when
   it is really useful to get warnings etc.

2. It avoids leaking state, for example in LBFactoryTest the
   assertFalse call would throw a PHPUnit assertion error (not meant
   to be caught by the local catch), and thus won't reach
   AtEase::restoreWarnings. This then causes later code to end up
   in a mismatching state and creates a confusing error_reporting
   state.

See .phpcs.xml, where the at operator is allowed for all test code.

Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
2022-02-24 21:29:51 +00:00
Reedy
12aae45101 tests: Replace some usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I361fde0de7f4406bce6ed075ed397effa5be3359
2022-02-24 12:55:25 +00:00
Timo Tijhof
8d406bbcd6 phpcs: Disable Generic.Files.LineLength for test files
There is a common and reasonable need for longer lines in tests.
The nudge for shorter lines doesn't seem valuable here. The natural
breaks will likely still fall in 80-100 given the enforced practice
for non-test code, e.g. whether through habit, or 80-100 column markers
in text editors, or the finite width of diff and code review
interfaces.

Change-Id: I879479e13551789a67624ce66f0946d2f185e6ee
2022-02-18 18:32:05 +00:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01: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
vladshapik
9d13a3cb5b Drop User methods which were deprecated since 1.36
The following User methods, deprecated in 1.36, have been removed:
- ::isLoggedIn,
- ::getFirstEditTimestamp,
- ::getLatestEditTimestamp

Bug: T277511
Change-Id: I338ee9313e08bda8b22b683281dad3b0e616fd18
2021-11-19 10:56:25 +02: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
Alexander Vorwerk
04dfdc3653 Hard deprecate User::setOption()
deprecated since 1.35

Bug: T277818
Change-Id: Ic251d624e5d6fa857aa92f9c5dd3df44714ac610
2021-09-26 17:18:54 +02:00
TChin
e9d57a4e52 Add tests for comment formatting methods in Linker
Tests added:
* formatLinksInComment test case for a missed branch
* makeCommentLink
* commentBlock
* revComment

Bug: T289998
Change-Id: I3ffe7ef5a385f8c29d0d3f205130ab5b6d35e37c
2021-09-02 11:29:09 -04:00
Tim Starling
32a2be8ec4 A few extra tests for Linker::formatComment()
For better coverage of the new CommentParser.

Change-Id: I70d20c8c1d190e1edf2568b6b3d119ccbe105ae4
2021-08-26 16:54:40 +10:00
TChin
48496b8526 Support fluent interface for PageUpdater
Also refactored some calls to use it.

Bug: T287484
Change-Id: Ibb745e0131761600789dcb1a2065a981a65ec515
2021-07-29 12:09:37 -04:00
Ammarpad
a7481c029c Restore userlink for IP range.
IP range needs to be explicitly tested for as it will not be
covered by both UserNameUtils::isIP and IPUtils::isValid calls.

Bug: T274526
Change-Id: Ib3498530e5ea9589117a7037ee836557f3800abc
2021-02-11 15:32:36 +01:00
daniel
e2b732cd86 Linker: userLink() should not explode on malformed user names.
Bug: T232451
Change-Id: Ibaea91767a1882d8246254ea3edc0c41d703e678
2021-02-02 10:45:58 -08:00
James D. Forrester
2550c145bb Drop the LinkBegin and LinkEnd hooks, deprecated since 1.28
Bug: T259108
Change-Id: I05aa2decaba032a2f1ae5afa7eee860b5136a263
2020-07-29 11:25:49 +01:00
suecarmol
436d7fbf06 Display remaining watch period in watchstar
Add a new tooltip message that displays the remaining watch period of a
page, if it is being watched temporarily. The tooltip message remains
the same if it is being watched indefinitely.

Bug: T250215
Change-Id: Ic9d1301427d477de71fb6f63fe77554a33684cd1
2020-07-18 01:45:51 +00:00
Timo Tijhof
45da13803d resources: Bundle ajax patrol and ajax rollback code
Create a small "curate"-related bundle of moderation and review
enhancements. The overlap between the two is not perfect, but the
scripts are small enough that it doesn't seem worth trying to
create separate bundles for.

Change-Id: Ibd00e0eddfafc57323b147e225ee668528dc1c1c
2020-05-28 07:22:07 +00:00
WMDE-Fisch
40aba4175b Make formatLinksInComment understand and link [[Text[[Link]]
In Wikitext this will end up in [[Link]] being converted to a link.
In comments this is ignored prior to this patch.

Bug: T197958
Change-Id: I454d342a57c35c30af042349a04e3b86d778568f
2020-05-13 14:26:35 +02:00
DannyS712
4721717527 Replace uses and hard deprecate Article:: and WikiPage::getRevision
Bug: T250532
Bug: T239975
Change-Id: Ic8f2baa0ac805d5196a7107bdc7a1abb36eba139
2020-04-20 23:06:48 +00:00
DannyS712
af7f397ccc Pass RevisionRecord to Linker methods
Hard deprecation of passing Revision objects will follow soon,
but until that is ready core calls can be updated

There is some code cleanup that could be done around the calls, but
to simplify review no other changes are made.

Bug: T249561
Change-Id: Ifcfb3811650decffeaa87dc033c41fd1710b47a6
2020-04-18 01:24:54 +00:00
Petr Pchelko
a749000d39 Deprecate Title and WikiPage getFirstRevision methods
They naturally belong in RevisionLookup. They return Revision,
so should be replaced anyway.

Bug: T246284
Change-Id: Ie5c478e4667ca0e773186b9cb8a319cd09145112
2020-03-24 11:56:08 -07:00
Daimona Eaytoy
f5529400cc Stop using assertContains with string haystack
This was done automatically by replacing every assertContains with
string *needle*. Then verifying the results.

Bug: T192167
Change-Id: Id8cbbf3b01e948f80046714183cc299f86be21fd
2019-12-15 00:22:44 +00:00
jenkins-bot
2bf3cd85e6 Merge "Linker: Kill HHVM and PHP5 special case" 2019-10-07 20:57:22 +00:00
Max Semenik
4345c1e38b LinkerTest: explicitly set $wgFragmentMode
Change-Id: If59c721474fe04a639582869efe9b66746b499f1
2019-10-06 12:22:13 -07:00
Max Semenik
8835ac44ad Linker: Kill HHVM and PHP5 special case
Add another test case to be extra sure™ it won't regress.

Change-Id: Ib35a469e70ee475ea88a1f99a733ffb4ac751a45
2019-10-06 12:19:32 -07:00
Thiemo Kreuz
32a429e8c4 tests: Prefer assertSame() when comparing the integer 0
assertSame() is guaranteed to not do any type conversion. This can be
critical when acciden tially comparing, for example, 0 to 0.0.

Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
2019-09-19 15:35:23 +00:00
daniel
e9e50ad014 Make userLink() not fail too hard on false and null.
This works around an issue in Flow, which sometimes passes false
for a user name.

Bug: T224095
Change-Id: I14dc52f7199012dc35605f3170b06eb1719165a7
2019-06-05 14:51:57 +02:00
jenkins-bot
b13123c3ac Merge "Cleanup LinkerTest leakage between provider entries" 2019-05-30 18:09:09 +00:00
daniel
0c4410a623 Fix empty auto-summaries triggering a fatal error.
Aka:  Streamline Linker::formatAutocomments() and add tests

This uses the "streamlining" for the code proposed by Thiemo
in I38edc1ad7720. I have squashed the two commits, so it now
has his code in Linker, but still has my tests as well as his.

Thiemo wrote on his patch:
This also changes the output in case there is no fragment to link to.
Before an empty `/* */` in a summary this would have created a link to
the page. I would like to argue this is not what a user expects.

Bug: T222628
Change-Id: I05408ede0e20dfd976f4057fc5baab461d2ef769
2019-05-30 16:34:34 +02:00
Aaron Schulz
b589693af0 Cleanup LinkerTest leakage between provider entries
The problem was that new revisions were being added to the same page
since it is not deleted between each run.

Change-Id: I52e8db8e5ef3cde309c26f928fd44de4e6ec18e4
2019-05-30 04:42:01 +00:00
Timo Tijhof
63cf83e089 Linker: Fix fatal error for "/* */" in an edit summary
Follows-up b6e1e99bec, which switched the method from Title::makeTitleSafe
to TitleValue. The latter throws fatal on non-string $fragment.

Title::makeTitleSafe, on the other hand, uses makeName(), which casts
$fragment to a string, and ignores if it ends up as empty string
(boolean false becomes empty string and thus did "the right thing").

Bug: T222857
Change-Id: Iecc2140fabd31ef0f193740c7fab0fc698c38e51
2019-05-19 11:20:34 +00:00
Aryeh Gregor
ddd1d4b920 Log warning and show error on empty username
Historically it seems that if Linker::userLink or friends were passed an
empty username (probably due to an incorrect database entry), they would
produce bogus output, e.g., an <a> with no contents or a link to the
invalid page "User_talk:" or similar.

In b6e1e99bec we replaced an occurrence of Title::makeTitle() (no
safety checks!) with creating a TitleValue, which asserts in its
constructor that the title text is not empty. This made such pages fail
an assertion and stop displaying at all.

Now there's a proper check for the error. Such cases will log a
production error and return "(no username available)".

Bug: T222529
Change-Id: Id65bdf9666b0d16e5553b8f38c7cf8fce2e37a25
2019-05-06 14:44:23 -05:00
Tim Eulitz
341320457c Show confirmation prompt on rollback links
Bug: T215020
Change-Id: Ic831888e30808a20a04397912498fe2ca04f80ba
2019-03-21 10:13:22 +00:00
Thiemo Kreuz
b0615e1249 Remove empty and unnecessary /* @{{ … */ comments
This was the only comment I could find that uses two curly brackets
for some reason. There are a few more with one curly bracket.

Change-Id: Iaed631916064e6be4895edd4c7a3d7de491e16c2
2019-03-15 14:59:19 +01:00
Kunal Mehta
1706d353ae Don't link wikilinks in section heading autocomments
Previously, a manually constructed autocomment in the form of
/* [[Some link]] */

would create a link to the the section, and then the "Some link" page.

After T165189 was implemented, the entire autocomment is now a link to
the section, so we're creating links inside of a link...which is
problematic. In most contexts (history and watchlist particularly), the
section link is more important than the title in the section heading, so
that's what we'll favor here.

It's worth noting that this situation is a manually created edge case.
Even if the section heading is a wikilink, the edit summary will
autofill a section autocomment without the double brackets.

We'll now render the double brackets ([[...]]) and not link them. This
is what the user literally typed, and matches the existing practice of
rendering templates in section headings with their literal syntax. And
as a bonus, it's still possible for user scripts such as wikEdDiff to
turn the rendered double brackets into a real link if users want.

Bug: T165189
Change-Id: Ib10679edd76c72a60d7e1c89fc8454166e34c463
2018-12-03 12:43:03 -08:00
Kunal Mehta
0c9cf24b05 Restore old HTML structure for history section links
A follow-up to 0a8e16d7cf thanks to Anomie's code review.

The section title is now inside <span dir="auto"> and <span
class="autocomment">, as before. $wgLang->getDirMark() between the arrow
and the text was restored.

Given the comment
 /* External links */ removed bogus entries
the HTML before 0a8e16d7cf looked like:
 <a href="#External_links">→</a>‎<span dir="auto"><span
 class="autocomment">External links: </span> removed bogus entries</span>
after this change, it will look like:
 <span dir="auto"><span class="autocomment"><a
 href="#External_links">→‎External links</a>: </span> removed bogus
 entries</span>

The issue of having links be inside other links will be addressed in a
separate patch.

Bug: T165189
Change-Id: I31d87a87ccaf50de58fdd0621c46133b2881b490
2018-12-03 12:42:56 -08:00
Bjornskjald
0a8e16d7cf Make "→" link to page section on History page larger by adding section name to it
Bug: T165189
Change-Id: I1f845592bd3de342fda84b60fc412055973950fd
2018-11-24 03:22:16 +00:00
Thiemo Kreuz (WMDE)
2c58fbaa29 Linker: more consistent whitespace parsing in formatLinksInComment
Try to paste and preview this in the wikitext as well as the summary
line: [[:a]] [[ :a]]

The wikitext will show "a a", but the summary line will show "a :a".
This is only a display issue, all 4 links correctly link to the
article [[A]].

Change-Id: I08253a6d0b55b9aa3eace519bbdc1a456400bf84
2018-09-06 17:19:32 +00:00
Kunal Mehta
03e7ae45bc Remove deprecated Linker::getLinkColour()
Change-Id: I1818d9eb369c620cc436c13446a5362816e8362d
2018-06-13 01:30:04 -07:00