Commit graph

1815 commits

Author SHA1 Message Date
Lucas Werkmeister
c1a0f9ecb8 Use SelectQueryBuilder in OutputPage
This makes the LEFT JOIN and the WHERE conditions somewhat more
readable, IMHO.

Bug: T311866
Change-Id: I76ef805530187ae9958b5a0fd8e5cda20eb969c6
2022-07-05 13:59:51 +02:00
Tim Starling
f270881ca2 Deprecate Parser::getFreshParser()
Following up on the comment I made at Ibbc1423166f4804a5122, make Parser
instance management a ParserFactory responsibility. It is weird for
Parser to have a ParserFactory proxy aspect.

* Add ParserFactory::getMainInstance(), which is equivalent to the old
  MediaWikiServices::getParser() and $wgParser.
* Add ParserFactory::getInstance(), which is equivalent to
  $wgParser->getFreshInstance(), returning the main instance if it is
  free, or a new instance otherwise. The naming is supposed to encourage
  it as the default way to get a parser, which will help with the linked
  bug.
* Deprecate Parser::getFreshParser() and migrate all core callers.

I left the entry in ServiceWiring.php so that it's not immediately
necessary to migrate ObjectFactory specs that ask for Parser.

Bug: T310948
Change-Id: I762b191e978c2d1bbc9f332c9cfa047888ce2e67
2022-07-05 14:09:36 +10: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
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
jenkins-bot
14bce5492d Merge "OutputPage: Handle language variants in getUnprefixedDisplayTitle" 2022-05-10 09:07:25 +00:00
bhsd
12e7f45215 OutputPage: Handle language variants in getUnprefixedDisplayTitle
When the namespace prefix is converted to a specific language variant,
the function getUnprefixedDisplayTitle() takes no effect.

This issue is visible on category pages, where the unprefixed display
title is used for subheadings.

Bug: T302161
Change-Id: I94684ca0760aafb7c41470210652abfffb7e0d51
2022-05-10 08:39:34 +00:00
jenkins-bot
0c478a5b0b Merge "Prepare for deprecation of Skin::bottomScripts" 2022-04-18 18:05:50 +00:00
Jon Robson
95a4189814 Prepare for deprecation of Skin::bottomScripts
Bug: T62846
Change-Id: I203881d7ab035bc953d113106f21348187b51374
2022-04-18 17:15:27 +00:00
Umherirrender
e3a741661a Remove usage of protection related deprecated Title function
Bug: T306131
Change-Id: I487a12a88ae82c367d1cbb2e52083fe20b27d4ce
2022-04-14 21:42:55 +00:00
jenkins-bot
fe58a16796 Merge "actions: Add missing ->text() in RevertAction::getPageTitle()" 2022-04-14 15:39:40 +00:00
jenkins-bot
8a2a146d30 Merge "Remove usages of deprecated Title::getRestrictionTypes" 2022-04-14 05:15:06 +00:00
Timo Tijhof
c8ae6826f8 actions: Add missing ->text() in RevertAction::getPageTitle()
It currently becomes a string implicitly much later on based on the
default format. All other implementations return a string and for
messages that typically is formatted as text(). This should be done
explicitly as it is the responsibility of RevertAction to know this
message and how it is meant to be formatted to get the string that
the "getPageTitle" contract calls for.

This bug has been here since 2012 with change I2c6fad30e2c4eaebf122,
where the code changed from wfMsg (string, unlike wfMessage) to
`$this->msg` without calling a format.

Bug: T252946
Change-Id: Ibfa335952eb752515a31be6feb6749534bb2a7c4
2022-04-13 23:33:20 +01:00
Umherirrender
a7e8f87d9f Remove usages of deprecated Title::getRestrictionTypes
Bug: T306131
Change-Id: Id7b2849bb1c31dbd79acbeb607dfc4f7869e6142
2022-04-13 20:34:10 +00:00
Jon Robson
1c13772366 Drop messagebox, warningbox, errorbox classes
This can be done when relevant communities have been notified
and the classes have rolled out of cached HTML.

Bug: T270796
Change-Id: If35ebe88702bf97f2306c77b26d8b3cab4c0420d
2022-04-11 17:40:04 +00:00
daniel
552ec41814 Use name constants to access config settings.
Use name constants instead of string literals in calls to Config::get
and ServiceOptions::get, when referring to core configuration variables.
This protects against typos and makes the decumentation and schema
declaration of the config settings discoverable.

This is the first batch, only touching files directly under /includes/

Change-Id: I7252e636c7c86d950d9257b33491af492c6dd5eb
2022-04-07 13:02:28 +02:00
Umherirrender
9cc4f9b65e phan: Remove PhanCompatibleAccessMethodOnTraitDefinition suppression
* Remove the fallback code in ImagePage, it is possible to call
  getImageLimitsFromOption non-statically in this situation
* In OutputPage replace the call to trait function to one class
  implementing the trait

Bug: T289813
Change-Id: I166a53615fb2be6e3d8b48489ce342e48435dfc3
2022-03-31 19:22:34 +02:00
Timo Tijhof
3fdfef96e4 context: Add a cached RequestContext::getActionName method
This method is dependent on, and inherently must depend on, all of
Title, WikiPage, and WebRequest. And, like Title and WikiPage,
which also have getters in RequestContext, Action is also derived
from a query parameter that is widely recognised in almost all
web requests to index.php.

The status quo in core and extensions, is to obtain this value
via Action::getActionName(), which as a static method that bypasses
dependency injection and also has the problem of not being cached.
Caching it within ActionFactory seems hard and awkward, due to
varying by context.

In change I61d66211bd (22f9a32853) a cached wrapper method was added
internally to the Skin class. In change I8cbc4bba4d248d9 (235820d631)
another cached wrapper was added in the Gadgets extension.

This change takes this approach further by making it a stable public
method on RequestContext.

To facilitate testing and to offer basic confidence in this working
correctly, this commit also adopts the new method in two place that
are considered "safe" (Skin, and OutputPage). Both of these are
called relatively late in the PHP proccess and well after any Setup
code and overrides (such as in MediaWiki.php), during which it is
more complex to call this. I'll audit and update those in a subsequent
change.

Change-Id: I1e259b54dca48a32be5a8c6cbb8eb69aec2da115
2022-03-25 12:12:48 +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
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
jenkins-bot
c29d5b3ab5 Merge "Add various null checks when null is not possible to use as argument" 2022-03-14 20:06:20 +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
9d07e1333c Remove unneeded calls of TitleValue::castPageToLinkTarget
- ManualLogEntry::setTarget accepts PageReference
- LinkRenderer::makeLink accepts PageReference
- PermissionManager::isBlockedFrom accepts PageReference

Change-Id: I41901e10c3df22145e92d12de74f0382976bb598
2022-03-11 17:58:50 +00:00
jenkins-bot
057d3b6358 Merge "Deprecate the ParserOutputHook functionality" 2022-03-08 21:38:43 +00:00
jenkins-bot
277453fe78 Merge "Define MW_INSTALL_PATH constant and BaseDirectory config." 2022-03-08 17:44:09 +00:00
C. Scott Ananian
ef871db2f3 Deprecate protected and public properties of OutputPage
We plan to refactor these properties and move them into a value object
instance.  Mark them deprecated for 1.38 so we can move/remove them
in a future release.

Bug: T301020
Change-Id: I8ec2e903bd7cde8d54fe0366707cbcf625f1f1a1
2022-03-07 22:11:07 -05:00
C. Scott Ananian
773801e439 Deprecate the ParserOutputHook functionality
These hooks should be implemented in the OutputPageParserOutput hook
instead.

Bug: T292321
Change-Id: Ib6f457596ea9d193bc03e15a48f135db4f4a6b27
2022-03-07 16:56:10 -05:00
jenkins-bot
fd2c1795a9 Merge "Add Sanitizer::removeSomeTags() which uses Remex to tokenize" 2022-03-06 08:35:40 +00:00
C. Scott Ananian
9f14fbd002 Add Sanitizer::removeSomeTags() which uses Remex to tokenize
The existing Sanitizer::removeHTMLtags() method, in addition to having
dodgy capitalization, uses regular expressions to parse the HTML.
That produces corner cases like T298401 and T67747 and is not guaranteed
to yield balanced or well-formed HTML.

Instead, introduce and use a new Sanitizer::removeSomeTags() method
which is guaranteed to always return balanced and well-formed HTML.

Note that Sanitizer::removeHTMLtags()/::removeSomeTags() take a callback
argument which (as far as I can tell) is never used outside core. Mark
that argument as @internal, and clean up the version used by
::removeSomeTags().

Use the new ::removeSomeTags() method in the two places where
DISPLAYTITLE is handled (following up on T67747).  The use by the
legacy parser is more difficult to replace (and would have a
performace cost), so leave the old ::removeHTMLtags() method in place
for that call site for now: when the legacy parser is replaced by
Parsoid the need for the old ::removeHTMLtags() will go away.  In a
follow-up patch we'll rename ::removeHTMLtags() and mark it @internal
so that we can deprecate ::removeHTMLtags() for external use.

Some benchmarking code added.  On my machine, with PHP 7.4, the new
method tidies short 30-character title strings at a rate of about
6764/s while the tidy-based method being replaced here managed 6384/s.
Sanitizer::removeHTMLtags blazes through short strings 20x faster
(120,915/s); some of this difference is due to the set up cost of
creating the tag whitelist and the Remex pipeline, so further
optimizations could doubtless be done if Sanitizer::removeSomeTags()
is more widely used.

Bug: T299722
Bug: T67747
Change-Id: Ic864c01471c292f11799c4fbdac4d7d30b8bc50f
2022-03-04 14:06:02 -05: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
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
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
Reedy
86934b2fa8 Replace some more usages of Wikimedia\(suppress|restore)Warnings()
Change-Id: I2eb133a9e32116cd155f59086245bc4d15ecbfcc
2022-02-24 20:27:46 +00:00
jenkins-bot
529f223f78 Merge "Hard-deprecate OutputPage::enableClientCache()" 2022-02-15 00:17:29 +00:00
jenkins-bot
7e19c4749d Merge "Add OutputPage::disableClientCache() and deprecate ::enableClientCache(false)" 2022-02-10 07:01:21 +00:00
jenkins-bot
e75de3e0bf Merge "exception: Simplify MWExceptionRenderer to reduce influence of config" 2022-02-07 12:10:00 +00:00
jenkins-bot
c45cc5ea04 Merge "Remove OutputPage::$mContainsNewMagic" 2022-02-04 22:52:37 +00:00
jenkins-bot
7a6b209fad Merge "Support variants of page content language in live preview" 2022-02-04 22:11:59 +00: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
C. Scott Ananian
065617f93c Add OutputPage::disableClientCache() and deprecate ::enableClientCache(false)
As far as I can tell, outside of test cases, every single time we call
OutputPage::enableClientCache() we pass it `false` and actually mean to
*disable* the client cache.  Create a new less-confusingly-named method
and deprecate the old one.

Change-Id: I7c89e20528a0d91173f0edcb997dcae631935ee5
2022-02-04 15:51:50 -05:00
C. Scott Ananian
5fd3583d45 Remove OutputPage::$mContainsNewMagic
This variable has been unused since 2ca258fd03
in 2004 (it was also touched in 918d0a78c5
in 2008 but it had never been assigned any value for four years at that
point).

Change-Id: I3fab6f7a01f0aee9087ecc52a17d25c54c5134a4
2022-02-04 14:15:06 -05:00
jenkins-bot
3776cd2497 Merge "Skins can define bodyClasses at skin registration" 2022-02-04 09:00:04 +00:00
Jon Robson
ad6ac30741 Skins can define bodyClasses at skin registration
Bug: T298734
Change-Id: I55fbe6c8d90fb2c13a5661c4f328f26fa48f1245
2022-02-03 21:16:16 +00:00
Timo Tijhof
e8fefb931d exception: Simplify MWExceptionRenderer to reduce influence of config
Remove use of two configuration globals. This follows-up to
commit 47adb6d65a (I1a691f01cd82e60) which aimed to access all config
via MediaWikiServices, but that isn't safe during error handling.

These two were only used in the low-level "plain text" and
"basic HTML" error pages, which already can't have any branding,
skinning or localisation; and are not how most exceptions are rendered.
in those edge cases, we can use the name of the software instead of
(trying) to use the name of the site.

== Remove use of $wgSitename  ==

In msg() and reportHTML(), remove use of $wgSitename in favour of a
generic fallback matching DefaulSettings.php. This does not affect
the common case of runtime fatals and timeouts, as we're only
changing the fallback after wfMessage() fails in msg(), or when
OutputPage is unavailable, which is typically only if services,
localisation or DB are also down (or not yet loaded). Most exceptions
happen when and after those have initialised fine.

Test case 1:
(Clean state) Edit ViewAction::show() to add `throw new RuntimeException();`
as its first statement, then try to view the main page.
This error page is unchanged. It is skinned, localised, and still uses
the configured sitename in the doc title.

Test case 2:
Edit index.php to call foo() instead of wfIndexMain(),
then try to view the main page. Before, this "minimal HTML" error page
would have a doc title of "Internal error - MyWiki", and now
"Internal error - MediaWiki".

Test case 3:
(Clean state) Edit Message::text() to add `throw new RuntimeException();`,
then try to view the main page. This results in a "plain text" error
page that doesn't even have an HTML doc, and is also unchanged.

== Remove use of $wgMimeType ==

In output(), remove use of $wgMimeType and remove the Content-Type
header that it was used for. This was redundant because the next
statements (reportHTML) already outputs Content-type. In reportHTML,
we sometimes delegate to OutputPage (if safe) and that honours
$wgMimeType already. In other cases, it is handled inline in with a
basic HTML error page, and that branch also sets the Content-Type
header already. In one case (reportOutageHTML) a header was not yet
set. For that one, I've added the missing header call and made it
explicitly text/html.

This is technically a bugfix, because our basic HTML error page is
HTML5, whereas $wgMimeType (which exists to allow enabling XHTML)
can be XHTML which we weren't following. In OutputPage and
Html::htmlHeader that would normally result in outputting `<?xml`.

Test case:
Edit ViewAction::show(), and add `throw new RuntimeException();`
as its first statement, then try to view the main page.
In devtools>network, there is still a proper Content-Type
and charset on the error page document.

Change-Id: I03cfa2b6155fb711582164852e7cab4c325a1b92
2022-01-30 03:11:01 +00:00
Bartosz Dziewoński
59c346f7fc Normalize HTML of page titles using Tidy/Remex
This affects titles set using {{DISPLAYTITLE:…}} and some special pages.

This is a quick-and-dirty stopgap while we work on a proper fix (T299722).

Bug: T298401
Change-Id: Ib2854de808e1235a695ad03808ceac179b7c28da
2022-01-22 01:06:00 +00:00
Siddharth VP
1fa10ef036 resourceloader: Use named constants for groups
Makes the code easier to follow, in particular to identify functionality of the various groups.

Change-Id: Ib2dae5757e9325f9706ff2a9f760f311475fe615
2022-01-19 21:21:00 +00:00
Jdlrobson
07ce31850f Revert "Revert "Categories are modelled as a portlet""
This reverts commit c360439219.

Reason for revert: The issue was fixed elsewhere, see T299352.

Bug: T299352
Bug: T298302
Bug: T298801
Change-Id: I67f699e57e47b36d183e5d90ba407b48dbe5e425
2022-01-18 20:18:36 +00:00
Esanders
c360439219 Revert "Categories are modelled as a portlet"
This reverts commit 0e52aeb356.

Reason for revert: Caused T299352

Bug: T299352
Bug: T298302
Bug: T298801
Change-Id: Id1f7e7d90ca9886c403e4ceb98c3cd6409165d74
2022-01-17 18:35:47 +00:00
jdlrobson
0e52aeb356 Categories are modelled as a portlet
- Skins using SkinMustache will now be able to render
categories as a portlet instead of using html-categories
- Skin::getCategoryLinks is extended to support the
SkinAfterPortlet hook.
	```
$wgHooks['SkinAfterPortlet'][] = function ( $skin, $name, &$html ) {
	if ( $name === 'category-normal' ) {
		$html .= 'I am text after the categories';
	}
};
```
- Links can now be added to the portal via
SkinTemplateNavigation::Universal

Bug: T298302
Bug: T298801
Change-Id: Icfb8da09cd43854d1aa12e10af704047ad222aec
2022-01-11 20:07:58 -08:00