Commit graph

246 commits

Author SHA1 Message Date
Volker E
2c1729e4e9 HTML: Remove self-closing XHTML syntax from core
Syntactical leftover with no significance in modern web.

Bug: T309150
Depends-On: I3a029ca950db42b938962b2452ad136ae8ddea6f
Depends-On: Id0557ac19583de36d7226b14a4c06933da47fe97
Depends-On: I17580a72e4a9384d7d774866e610197e950900cb
Change-Id: I4bbfa47fbf6e30fb90d920d6d02cdf6e0b1cdb46
2023-05-03 10:44:41 +02:00
C. Scott Ananian
0448851e92 Add ParserOutputFlags::NO_TOC
Rather than suppress the TOCData in ParserOutput when __NOTOC__ is used,
set a new parser output flag, NO_TOC, since some clients want to know
whether there are sections present on the page irrespective of whether
the UX for the Table Of Contents should be displayed/suppressed.

Added OutputPage::getOutputFlag() as an @internal method for the
moment; eventually we should use the same object to represent
metadata in ParserOutput and OutputPage (T301020).

Bug: T332243
Followup-To: Ife2126ace95ac4d9ec44f6374c63d8fc995cf034
Followup-To: Iea6426336f93c053a5977768f0785cdb46daf5bf
Change-Id: Ib41e6e4926cb752826ad75d10e8692125fc0b064
2023-04-28 10:56:57 -04:00
Tim Starling
be3018b268 Just another 80 or so PHPStorm inspection fixes (#4)
* Unnecessary regex modifier. I agree with this inspection which flags
  /s modifiers on regexes that don't use a dot.
* Property declared dynamically.
* Unused local variable. But it's acceptable for an unused local
  variable to take the return value of a method under test, when it is
  being tested for its side-effects. And it's acceptable for an unused
  local variable to document unused list expansion elements, or the
  nature of array keys in a foreach.

Change-Id: I067b5b45dd1138c00e7269b66d3d1385f202fe7f
2023-03-25 00:39:06 +00: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
C. Scott Ananian
29853113f7 Deprecate ParserOutput::{get,set}TOCHTML()
No uses in deployed code outside mediawiki-core:

 https://codesearch.wmcloud.org/deployed/?q=%5Bgs%5DetTOCHTML%5C%28&i=nope&files=&excludeFiles=&repos=

Bug: T293513
Change-Id: I3fd82150ac581afbeb94f401672702063586fff0
2023-03-10 20:34:33 -05:00
Timo Tijhof
19d11ae2a3 OutputPage: Remove unused $IP override in test case
Follows-up I61e947fb17cf64 (ef2a622e49).

Change-Id: I76a07206b4eb9993a65ae1529940b74ba8352a83
2023-03-08 20:58:19 +00:00
daniel
ef2a622e49 OutputPageTest: override config consistently
This patch makes OutputPageTest independent of local configuration.

Change-Id: I61e947fb17cf64ba1d448ce68b84b74f38b7a7da
2023-03-07 21:06:23 +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
Winston Sung
b0e2b38d33 OutputPage: Fix the behavior for canonical URL and alternate URLs
This fix is for the behavior of language variants, including:

* Fix the language variant behavior in meta alternate hreflang URLs.
  meta alternate URLs should point to respective canonical URLs.
  meta alternate URLs should be kept even in current page view language
* Make meta canonical URL language-variant-aware.
  This only take effect when there's variant or uselang specified in
   URL, so it doesn't affect variant-non-specified (variant-auto-
   detected) URLs.
  See `LanguageConverter::getURLVariant()` .

Bug: T54429
Bug: T108443
Bug: T305540
Change-Id: I5e6c8c3f7671d27aecdb52be271b34ba524fadf7
Co-Authored-by: Func <Funcer@outlook.com>
Co-Authored-by: Jdlrobson <jrobson@wikimedia.org>
2023-03-01 18:11:31 +00:00
Jon Robson
c6138e880d OutputPage: Reduce line complexity of getHeadLinksArray
Split this into multiple functions with multiple concerns for
easier maintenance and code review.

Bug: T330777
Change-Id: I80d93ec09be2df5c8b94a16140ba11da4827a42d
2023-03-01 03:48:47 +00:00
Timo Tijhof
bf34238252 objectcache,rdbms: Widen needlessly narrow @covers test annotations
We'd lose more useful coverage and spend more effort keeping these
accurate through refactors etc than is worth the theoretically "bad"
accidental coverage. Plus, even then we still very often forget to
update these and waste time digging into seemingly uncovered code
and either write duplicate test or discover they are already covered.

Especially for private methods this can be a flawed endavour as
we tend to trust tests when changing those and thus feel we shouldn't
update tests, except it's riddled with private method mentions for
coverage purposes (not in terms of actual called code).

I think the best practice is to write good narrow unit tests,
not to write bad tests and then hide their coverage. Generally
that's what we do. Maybe these are useful when invoking a huge
legacy class, but generally we don't need these I think, at least
in the libs our team maintains.

Change-Id: I4c7d826c7ec654b9efa20778c46c498784661f1c
2023-02-21 21:27:40 +00:00
Amir Sarabadani
7d8768e931 Reorg: Move HTML-related classes out of includes/ to Html/
Bug: T321882
Change-Id: I5dc1f7e9c303cd3f5b9dd7010d6bb470d8400a18
2023-02-16 20:40:01 +01:00
Amir Sarabadani
bfedab2eb8 Reorg: Move CSP class to Request/
Bug: T321882
Change-Id: Ic809656a31e08626d0e5a1172da02b2397096e14
2023-02-16 13:36:41 +01:00
Umherirrender
ed33ab1bbf tests: Replace deprecated Language::(has|get)Variants
Bug: T252095
Change-Id: Ie95c1343edf980b62693752c82b6009e744edaea
2023-01-31 21:19:21 +00:00
jenkins-bot
cc4d4d17ee Merge "Make sure hreflang Tags' alternate URLs are fully-qualified" 2023-01-17 19:43:29 +00:00
Bartosz Dziewoński
0945f6976c OutputPage: Call setSections() from addParserOutputMetadata()
Remove calls elsewhere which now became redundant.

Bug: T325562
Bug: T325600
Change-Id: I1611f3bdea46a729ecf9daf699d761b018d49b55
2022-12-20 01:08:23 +01:00
Reedy
116b71452c tests: Simplify some nested ->will( $this->return assertions
Change-Id: Ic861ce5604784b7fa600844d81387b84230bc0e1
2022-11-12 11:57:12 -07:00
daniel
8c1c1ae35a Enable pig-latin variant for testing
Having pig-latin enabled per default in dev environments is convenient
for manual testing. More importantly, it will allow us to write
end-to-end tests for variant conversion.

Depends-On: I9dc2f743ac487b0f7cfb667150c0f6950d5e7fce
Depends-On: I85b66c85be3959d48a048733af17197bc4cf70af
Change-Id: Ia80ad33cbf5e311fa8b84bd765a8df8d156f4c38
2022-11-08 17:45:51 +05:30
Amir Sarabadani
bbe704b5c1 Reorg: Move some of request related classes to MediaWiki/Request
Redoing I5ea70120d74 but without moving WebRequest that caused issues
with phan-taint-plugin.

Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequestUpload

Bug: T321882
Change-Id: I832b133aaf61ee9f6190b0227d2f3de99bd1717b
2022-10-28 10:15:31 +00:00
Zabe
f6b9381d7f Revert "Reorg: Move some of request related classes to MediaWiki/Request"
This reverts commit 2bdc0b2b72.

Reason for revert: T166010#8349431

Bug: T166010
Change-Id: Idcd3025647aec99532f5d69b9c1718c531761283
2022-10-27 13:14:16 +00:00
Amir Sarabadani
2bdc0b2b72 Reorg: Move some of request related classes to MediaWiki/Request
Moving:
 - DerivativeRequest
 - FauxRequest
 - FauxRequestUpload
 - PathRouter
 - WebRequest
 - WebRequestUpload

Bug: T166010
Change-Id: I5ea70120d745f2876ae31d039f3f8a51e49e9ad8
2022-10-26 16:49:10 +02:00
Func
33cf6197be OutputPageTest: Adjust testAddBodyClasses
The class change in 76d1135 which triggered this test failure sounds
like a valid good practice, and the test should not assume no other
body class is set.

Bug: T321021
Change-Id: Iaee1881f37b3e24a89b3c1f1b05a19c6260184aa
2022-10-18 09:46:07 +08:00
Daimona Eaytoy
ee672592d8 tests: Replace assertRegExp with assertMatchesRegularExpression
And also assertNotRegExp -> assertDoesNotMatchRegularExpression. The
methods were renamed in PHPUnit 9.

Done automatically with:
  grep -rl assertRegExp tests/ | xargs sed -r -i "s/>assertRegExp\(/>assertMatchesRegularExpression\(/"
  grep -rl assertNotRegExp tests/ | xargs sed -r -i "s/>assertNotRegExp\(/>assertDoesNotMatchRegularExpression\(/"

Split out from Ifdba0f9e98eb6bce4590b7eb73170c51a697d7c6 so that it
remains smaller and easier to review.

Also make a test use MediaWikiUnitTestCase (it's already in the unit/
dir) so that it can access the forward-compat method.

Bug: T243600
Change-Id: Ifa279d5f201d7abeebece292141ebface8278046
2022-10-07 14:13:16 -04:00
Moh'd Khier Abualruz
3c04f0fd82 Allow large image previews by adding max image preview tag
- This is across all skins
- Adjusted unit tests to check for value

Bug: T310267
Change-Id: If61b8bb3bbbe990c8babb0742f747372004dc10c
2022-10-05 15:22:15 +02:00
Alexander Vorwerk
22dca3ab89 BadTitleError: Enable 1 hour CDN cache for this error response
Varnish is unable to cache these currently. However since pages with an
invalid title will never have any variable/editable content, we can
cache them unconditionally.

Also, undeprecate OutputPage::enableClientCache for this since it
is clearly useful here, but the parameter is being removed since
OutputPage::disableClientCache should be used to disable client side
caching instead.

Bug: T316932
Change-Id: Ib98fd165bffd9ca3dcbbcb8c6f06964dba7c90b7
2022-09-26 20:27:24 +00:00
Umherirrender
89b2d11a0d tests: Use Title::makeTitle instead of Title::newFromText
Avoid parsing known titles in tests to improve performance

Change-Id: Ie240eb42479d19714e64cc4606e26073fadc2e13
2022-09-23 21:53:11 +02:00
jenkins-bot
94fa3912e8 Merge "Use ParserOutputFlags::SHOW_TOC in OutputPage" 2022-09-12 23:27:44 +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
C. Scott Ananian
00bfaa757a Use ParserOutputFlags::SHOW_TOC in OutputPage
Parser output flags are intended to be "set only".  That means that
extensions can *set* the SHOW_TOC flag, but once set SHOW_TOC can't be
reset, and the TOC will be shown in the result if *any* of the merged
ParserOutputs on the OutputPage contain the SHOW_TOC flag set.  That's
consistent with prior merge behavior.

There's a possibility extensions are playing other games with the
Table Of Contents (TOC) in the OutputPageParserOutput hook; be
compatible with prior behavior for now but we may need to provide
additional functionality (perhaps a way to merge new section data) if
needed.

Bug: T310083
Change-Id: I0909ac85c6c785d9089b077a16923c61d6a09996
2022-08-18 10:11:36 -04: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
Thiemo Kreuz
77a3b3f1a0 Make use of PHPUnit fail() shortcut
Change-Id: Id8474e8531fcb526b72511c969728433a9bda9a2
2022-07-14 14:48:15 +02:00
Umherirrender
e00a52e6f5 Clean up line indent with mixed tabs and whitespaces
Change-Id: Ifcd15ecc4212d4ebfc26b2e18d6f1da47abf2a86
2022-07-09 22:21:53 +02:00
Junyin Chen
ae85a7cd67 Make sure hreflang Tags' alternate URLs are fully-qualified
Currently, the hreflang Tags' alternate URLs are not fully-qualified,
resulting these tags useless in SEO stand point.

This change makes sure hreflang Tags' alternate URLs are fully-qualified,
with testcase coverage.

Bug: T294716
Change-Id: I1dd3453c44f5c80adfbd7309860563d3bb9a7f86
2022-06-30 20:13:07 +08:00
Derk-Jan Hartman
fdbd6cff57 parse: Wrap indicators with a div.mw-parser-output element
Alternative to having this in the skin, is to do it for each separate
indicator. A counter argument against this was inline vs block mode
elements, specifically the reason why we stripped the p element. But
the p element has a margin in each and every skin. It's rather
unlikely that div's have such a standard layout. The wrapping div
around each indicator at the skin level is already inline-block, so
interactions between the indicators are already decoupled via that
skin element.

In this patch the wrapping is done in OutputPage when a ParserOutput
is added.  OutputPage::addHelpLink() also adds indicators, which would
not be wrapped by this patch; this is reasonable since the content of
::addHelpLink() is not parsed wikitext.  It's possible external users
may also call OutputPage::setIndicators() directly, which would also
add unwrapped indicators; the caller of OutputPage::setIndicators() is
responsible for wrapping any indicators which might come from parsed
wikitext.

Bug: T188443
Co-Authored-By: C. Scott Ananian <cananian@wikimedia.org>
Change-Id: I42be893101f7d7887480fe635143bea535ee5634
2022-06-17 21:17:31 +00:00
DannyS712
69cd8a1126 tests: Remove some unneeded PHPUnit return callbacks
Use willReturnArgument() and willReturn() with a value instead

Change-Id: I878d411a5c6891352cfd16d68cb83254adf3b38b
2022-06-06 02:09:52 +00:00
Reedy
41c42d5435 Tests: Cleanup some unnecessary nested function calls
Replace ->will( ->return with ->willReturn(

Change-Id: Ia2dfafa03cac8169d86d6fa5a30b73bfad1fe9fa
2022-06-06 01:02:34 +01:00
Umherirrender
f01a391f0d tests: Fix types in documentation by adding use statements
Some types used in @param/@return are not correct,
because the class is not used with namespace

Change-Id: Ic2643687378a6addabc2c9cd402224e442257f86
2022-05-29 07:11:15 +00:00
Umherirrender
770f905900 tests: Use namespaced IDatabase class
Change-Id: I7171ff26faee00d9eaabc33c2f3d91049ea0b40d
2022-05-28 00:09:55 +02:00
Tim Starling
3e2653f83b ResourceLoader namespace (attempt 2)
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader itself.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Revert of a241d83e0a.

Bug: T308718
Change-Id: Id08a220e1d6085e2b33f3f6c9d0e3935a4204659
2022-05-24 15:41:46 +00:00
Lucas Werkmeister (WMDE)
a241d83e0a Revert "ResourceLoader namespace"
This reverts commit e08ea8ccb9.

Reason for revert: Breaks Phan in extensions, and as far as I’m aware,
this change isn’t urgently needed for anything, so the simplest fix is
to revert it again for now. After PHP 7.4 it should be safer to try this
again (we hopefully won’t need the two “hack” classes by then).

Bug: T308443
Change-Id: Iff3318cbf97a67f821f78e60da62a583f63e389e
2022-05-16 14:43:33 +00:00
Tim Starling
e08ea8ccb9 ResourceLoader namespace
Move ResourceLoader classes to their own namespace. Strip the
"ResourceLoader" prefix from all except ResourceLoader and
ResourceLoaderContext.

Move the tests by analogy.

I used a namespace alias "RL" in some callers since RL\Module is less
ambiguous at the call site than just "Module".

I did not address DependencyStore which continues to have a non-standard
location and namespace.

Change-Id: I92998ae6a82e0b935c13e02a183e7c324fa410a3
2022-05-16 14:41:27 +10:00
Func
fbe6443942 Apply logo variant override in ResourceLoaderSkinModule
Logo variant override is available for 'wordmark' and 'tagline' in
the new Vector skin and has been used for a while, but the 'logo'
feature built in the core didn't take variants into account.
The logic should be pushed down to ResourceLoaderSkinModule so that
behavior can be consistent between skins and core.

Also, old code use $title->getPageViewLanguage() to determine the
variant of logo, which is a wrong behavior. Logos should be in the
interface language instead of the content variant.

Bug: T273578
Change-Id: Ifb3cc45600d57cf9c72757016148684cd7ab1400
2022-03-28 13:22:07 +08:00
Clare Ming
47612020b5 Add option to amend robots meta tag
- Add private var, helper methods to format and set robots options.
- Add reference to new method in OutputPage::getHeadLinksArray().

Bug: T301584
Change-Id: I2652f20c9fe5f2d3e28e329d4eddc2a2ff88cf76
2022-03-14 23:03:41 +00:00
daniel
cf581bb2ca Define MW_INSTALL_PATH constant and BaseDirectory config.
Application logic should use the BaseDirectory config variable.
Framework code should use MW_INSTALL_PATH to locate files should.

NOTE: Update https://www.mediawiki.org/wiki/Manual:$IP

Bug: T300301
Depends-On: I7142af16d692f26e90673b058029f572c1ea3991
Change-Id: Ib4caa80bb7007c4c7960a2fd370cf5da7d9ba344
2022-03-04 14:18:27 +01:00
Ammarpad
4df73a4a0a tests: Remove redundant fake time reset in individual tests
Fake time is automatically reset by MediaWikiTestCaseTrait
after each test. Individual tests need not duplicate that.

Change-Id: I926bf21d915208ea33ae0be2ef00eeba0160c9c8
2022-03-01 18:04:37 +00: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
C. Scott Ananian
ff81baa8b5 Use MediaWikiTestCaseTrait::hideDeprecated() instead of \suppressWarnings()
Followup-To: I3a8a0897ed36dac5927dc7fb3d533cdb12e5136f
Change-Id: Ic684dcff32ba01cceacdc93c8f14b203624c26c1
2022-02-17 14:29:53 -05:00
C. Scott Ananian
6859304afc Hard-deprecate OutputPage::enableClientCache()
Code search:
https://codesearch.wmcloud.org/deployed/?q=enableClientCache&i=nope&files=&excludeFiles=&repos=

Depends-On: I91d0b8e8f69a2d309b6fc61e13bfb5d86dc0218d
Depends-On: I0b0cc58f18a47766a174af7f25be51d7630ecb37
Depends-On: I4aff8ceeae7e28a869c8cb60b69f59a4dac48b5d
Depends-On: I70c4b719346b737c801257c37c26997fbbecd27f
Depends-On: Ib195336a8f6bb9f7d4a1344e9dcf3c01dfd5d114
Depends-On: Idf1cf2fac3311f50ed3cbc420f7772b5c71b1992
Depends-On: I7c89e20528a0d91173f0edcb997dcae631935ee5
Change-Id: I3a8a0897ed36dac5927dc7fb3d533cdb12e5136f
2022-02-04 15:51:53 -05:00