Commit graph

1584 commits

Author SHA1 Message Date
Gergő Tisza
f6aae4d126 Login-related messages should get the URL as a parameter
System messages along the lines of "you can't view this page,
please log in" get the login link (with returnto parameters) as a
HTML string, but sometimes one might want to customize the link
on one page without affecting all the other pages so it's nice
to have the raw link available as well.

Change-Id: Ib71791ea28718455d2925e4424147e87ef901f33
2018-12-07 02:38:16 +00:00
jenkins-bot
5466734477 Merge "doc: Modernise parameter names and documentation for 'replica' DBs" 2018-11-13 21:39:14 +00:00
jenkins-bot
0098688a00 Merge "Hard deprecate OutputPage::parse() and OutputPage::parseInline()" 2018-11-05 18:07:29 +00:00
C. Scott Ananian
9dc7826f2d Update deprecations after OutputPage::parse*As*() backport to 1.32
Originally landed in 1.33 in a3f63785ee.

Backported to 1.32 in cff9ab4b5c26dc87137aa2c04efd5d1f31226fe8.

Change-Id: I402c31b57904f6a6fd0b3a2c32a1c0a73c553254
2018-11-02 17:00:42 +00:00
C. Scott Ananian
4d596861e5 Hard deprecate OutputPage::parse() and OutputPage::parseInline()
Depends-On: I2cc3a4631bcb45b7f8cd913e9b6dba14349e5e9e
Depends-On: Ieaac7a198cacec406a8240ed07b2d9f32ef9e56a
Depends-On: Ia4b63715380d97ccb3133bf39a260834c20b4f5a
Depends-On: I88fb74c3007360e2301c8bca7db6a940e966a735
Change-Id: If5c619cdd3e7f786687cfc2ca166074d9197ca11
2018-11-01 21:32:56 +00:00
James D. Forrester
903e8b63de doc: Modernise parameter names and documentation for 'replica' DBs
Non-breaking change. Remaining uses are public interfaces (a constant, two
globals, a config sub-parameter, SQL queries, storage function names), one i18n
message key, and a whole lot of maintenance scripts with calls to the deprecated
function wfWaitForSlaves().

Change-Id: I6ee5ca92ccf6a80c08f53d9efe38ebb4b05064d7
2018-10-31 10:36:48 -07:00
C. Scott Ananian
a3f63785ee Deprecate OutputPage::parse() and OutputPage::parseInline()
The OutputPage::parse() and OutputPage::parseInline() methods behave
misleadingly different from the OutputPage::addWikitext*() methods:
they don't tidy their output, they have different defaults for
interface/content language selection, and they (sometimes) add
wrapper divs.  Deprecate these and add new methods with tidy output,
clear language selection, and consistent defaults:
OutputPage::parseAsContent(), OutputPage::parseAsInterface(),
and OutputPage::parseInlineAsInterface().

Unify the implementation of the parse* methods with the addWikiText*
methods, to reduce the likelihood that the behavior will diverge again
in the future.

Bug: T198214
Change-Id: Ica79c2acbc542ef37f971c0be2582ae771a23bd0
2018-10-29 15:34:40 -04:00
C. Scott Ananian
db4fa6fb9f Fix OutputPage::parseInternal() by stripping <div> wrapper
We should probably strip the <div> wrapper in OutputPage::parse() as
well: this behavior was added in 1.30, but it only applies when
$interface is false.  However, that requires a more careful audit
(a lot more places call parse() than parseInline()) and so I'll defer
that for now.

Change-Id: Iad5412f03af29c04deb653969dd71f6c86f0ae50
2018-10-26 11:20:26 -04:00
jenkins-bot
23b8bd2ad0 Merge "Hard deprecate non-tidy OutputPage::addWikiText() method" 2018-10-24 22:13:00 +00:00
jenkins-bot
13dba84b6f Merge "Fix PHPDoc type for instance variables and methods" 2018-10-24 21:17:02 +00:00
C. Scott Ananian
45305de579 Hard deprecate non-tidy OutputPage::addWikiText() method
Tidy will always be enabled with our future parsers.  Hard-deprecate
this method which doesn't tidy the output.

Users of `OutputPage::addWikiText()` will be converted one-by-one to
`OutputPage::addWikiTextAsInterface()` so that any unexpected issues
(deliberately untidy wikitext added, which should be rare) can be
addressed.

Bug: T198214
Depends-On: I778ba9e6efed576605f492c9a073c7203b6c0477
Depends-On: I16529879a3b3aed960c5dc006e2af513d7e91fcd
Change-Id: If8353c37245d9d233d589f82c198668ccb3fce05
2018-10-24 20:05:58 +00:00
jenkins-bot
72e5b5af65 Merge "Use OutputPage::addWikiTextAsInterface() instead of untidy addWikiText()" 2018-10-22 01:49:58 +00:00
Alangi Derick
b4ecf374fe Fix PHPDoc type for instance variables and methods
Should be "string" not "String" and "array" not "Array" in
@param, @return and @var use cases. Also, minor typo fixes.

Change-Id: I9d5ebc5b741c6560907b95f7c0c4039da2861f4a
2018-10-21 13:00:25 +01:00
C. Scott Ananian
d63684a064 Deprecate $wgUseESI
This was an experimental Squid 3 feature which is now defunct.

Change-Id: I799d87309b0dc77100900b75040fa9b85a35fc9a
2018-10-19 11:44:17 -04:00
C. Scott Ananian
c0ed262053 Use OutputPage::addWikiTextAsInterface() instead of untidy addWikiText()
This change ensures that the output is tidy, and is necessary to support
future parsers which will not be able to produce untidy output.

Bug: T198214
Change-Id: I743f4185a03403f8d9b9db010ff1ee4e9342e062
2018-10-17 10:35:28 -04:00
C. Scott Ananian
d404b76510 Add OutputPage::wrapWikiTextAsInterface() to safely wrap wikitext
This patch introduces a new method,
OutputPage::wrapWikiTextAsInterface(), which wraps the result of
OutputPage::addWikiTextAsInterface() in a tidy and robust way that
won't break if the wrapped message contains double newlines, extra
</div>, or other nasties.

This replaces a common unsafe pattern:
  $output->addWikiText( '<div class="..."' .... '</div>' );

Bug: T205624
Change-Id: I1040c7cf0ec1f5c4bef7c06d4486f50d85f2dc0f
2018-10-16 23:39:43 -04:00
C. Scott Ananian
6258e5e55c Deprecate $wgUseKeyHeader and OutputPage::getKeyHeader()
The `Key` header was a draft IETF specification which expired without
becoming a standard.  It does not appear to be in active use anywhere.

Change-Id: I3924a1b5ff428b107573d2827c40e4af8adaaeb1
2018-10-12 13:29:06 -04:00
Aryeh Gregor
ff7c3c9f03 Increase OutputPage test coverage to >45%
Also stop returning a value from OutputPage::adaptCdnTTL().  There are
no users and the value doesn't seem very helpful: one would probably
expect it to return the new value of mCdnMaxage, but instead it
returns the new value of mCdnMaxageLimit. Better to have no return
value than one that's easily misunderstood (*and* which nobody uses).

Change-Id: Ia9dab86923b839334eab9f6fde17c4aed52130ec
2018-10-11 18:59:42 -04:00
C. Scott Ananian
2837fe8556 Hard deprecate OutputPage::addWikiText*Tidy() methods
These have been replaced with OutputPage::addWikiTextAsContent().
There is only one apparent use outside core, in the ProofreadPage
extension.

Bug: T198214
Depends-On: I826e463c1623481c11156a55a5b7e1da0aa27b8b
Change-Id: I4b1a9429029bfbbf70b2d5da1b290319ecbbdf3a
2018-10-10 14:54:27 -04:00
C. Scott Ananian
f2b325002b Hard deprecate unused OutputPage::addWikiText* methods
Codesearch shows no users of `OutputPage::addWikiTextWithTitle()`,
and no users of `OutputPage::addWikiTextTitle()` (other than the
implicit uses by the other `OutputPage::addWikiText*()` methods).

These methods produce untidy output, which future parsers won't
support.

Bug: T198214
Change-Id: Id5ee3bdfa6c464e3a92af82af7bc7317ca9d07a9
2018-10-10 14:54:27 -04:00
C. Scott Ananian
7af52285f7 Deprecate and rename OutputPage::addWikiText* methods
Tidy will always be enabled with our future parsers, and it is fast
and pure PHP now with the Remex implementation, so deprecate all the
untidy variants of 'OutputPage::addWikiText*()' and add new methods
which tidy by default.  Clarify the content language/interface
language distinction while we're at it by adding 'AsInterface' to the
name of methods which use the "interface language" by default,
and renaming the 'addWikiText*Tidy' methods to
'addWikiTextAsContent'.

The 'OutputPage::addWikiTextTitle' method has been deprecated, but it
is still used internally as the implementation for the newly-added
methods.  It is expected that the shared implementation will move in
the future to a new private method.  Setting the `$tidy` parameter of
`OutputPage::addWikiTextTitle` to false is independently deprecated;
for backwards-compatibility with old MW releases you may wish to
continue to invoke OutputPage::addWikiTextTitle() but set $tidy=true;
this will result in the same tidied output that the newly added
methods would produce.

Bug: T198214
Change-Id: Ia58910164baaca608cea3b24333b7d13ed773339
2018-10-10 14:54:27 -04:00
Stephane Bisson
8ebdf02421 Show copyright based on $output->hasCopyright()
Introducing setCopyright/hasCopyright in OutputPage to
make the showing of the copyright message controllable
by pages other than articles.

hasCopyright defaults to isArticle() to preserve the rule
that all article should show the copyright.

This is used by Flow to show the copyright
on various pages that contain user-generated
content.

Bug: T184960
Change-Id: I3a50dbcedc6b119b9262c50cb3a84b0dd230fb3d
2018-10-03 11:54:16 -04:00
C. Scott Ananian
300b91a1ec Don't wrap output added by OutputPage::addWikiText*()
There are three methods affected: `OutputPage::addWikiTextTidy()`,
`OutputPage::addWikiTextTitleTidy()`, and
`OutputPage::addWikiTextWithTitle()`.

There's a special case in Parser.php which adds the wrapper class from
ParserOptions to the ParserOutput only if "interface mode" is off; the
affected methods default to adding output in "content language" mode
(not "interface language" mode), but they seem to be used for
"interface messages in the content language" (rare) and so should also
be unwrapped.  This would make all the `OutputPage::addWikiText*()`
methods consistent.

The `OutputPage::addWikiTextTidy()` method is only used once in the WMF
repositories, where it is used to insert an interface message in the
content language:

91cd2a928f/SpecialProofreadPages.php (40)

The `OutputPage::addWikiTextWithTitle()` method is used by no one:

https://codesearch.wmflabs.org/search/?q=addWikiTextWithTitle%5C(

The `OutputPage::addWikiTextTitleTidy()` method is used only in core:

3888c001a1/includes/EditPage.php (2669)

It seems clear that the output in this case is intended to be
unwrapped as well (the codepath adds its own explicit wrapper).

Ia58910164baaca608cea3b24333b7d13ed773339 will add additional
documentation to clarify the distinction between the different
OutputPage::addWikiText*() methods, but I felt it safer to make
this particular change first as a standalone patch, just in case
it had unexpected side effects or merited further discussion.

Change-Id: I3e5b598d358819191562b56d40ebf1cb6f3cda41
2018-09-25 14:43:20 -04:00
Niklas Laxström
d89704bc4c Improve page display title handling for category pages
One use case of display title is to localise page names with Translate
extension or without. While the page title changes, the subheadings still
say something like "Pages in category Foo/de".

Also converted one raw HTML message to be a parsed message.

First version of this patch caused an issue when previewing
because page title in h1 is not the same as page display title.

This issue is fixed by promoting page display title as it's own member
in OutputPage. Also added getUnprefixedDisplayTitle that attempts to
strip away the namespace prefix to mimic Title::getText() but which
works with display title instead.

Bug: T43720
Bug: T46197
Change-Id: I6097a873297eb57759252fc56ad6d02c44e4c366
2018-09-10 08:29:48 +02:00
Timo Tijhof
2ec27eb038 resourceloader: Refuse to preview content with </script>
Bug: T200506
Change-Id: I4ab5fbb0f5413aad24360169ba635672ce8d9c8e
2018-08-29 23:11:35 +00:00
Timo Tijhof
5d0b5a402e resourceloader: Move logo preload from OutputPage to SkinModule
This was introduced in OutputPage before support for getPreloadLinks()
was added to ResourceLoader. The introduction in ResourceLoader was
actually inspired by this original implementation.

Now that we have it, we should make use of it for this module
as well. Doing so has several benefits:

* Makes the code cleaner by not requiring every skin to implement
  the extra boolean method. Instead, it naturally works. If
  the skin loads the SkinModule, it gets the preload as well.
  If not (such as Minerva, which has a different logo config),
  then it also doesn't get the preload link.
  Naturally, automatic.

* Makes code cleaner by not having static methods, and by not
  having OutputPage call into a Module class.

* Fixes the problem where, if a site's logo is changed, all cached
  HTML is preloading the old logo whilst the stylesheet fetches
  the newer one. Causing both to be downloaded.

* Still preloads the logo well before it can render.

Change-Id: I11b390f2e4f5e7db8b4506ab547839152888005c
2018-08-27 23:05:51 +00:00
Umherirrender
40d3ce8d17 Reduce calls to MediaWikiServices::getInstance()
In some functions MediaWikiServices::getInstance() was called twices or
in loops. Extract the variable to reduce calls.

Change-Id: I2705db11d7a9ea73efb9b5a5c40747ab0b3ea36f
2018-08-18 06:02:39 +02:00
Aryeh Gregor
e68fdb4065 Mass conversion to SpecialPageFactory service
Change-Id: Ia6e1e819ec6cbe8bf75b820109f51d47863e31fc
2018-08-17 12:03:12 -07:00
jenkins-bot
fe25fde55b Merge "Add type hint for ParserOutput" 2018-08-12 07:03:19 +00:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
jenkins-bot
34392825d0 Merge "Comments and code cleanup in OutputPage" 2018-08-09 18:06:05 +00:00
Brian Wolff
146e9c96ea resourceloader: Give module eval the ContentSecurityPolicy nonce
Previously domEval didn't have CSP nonces, causing it to violate
the policy.

Also removes the meta tag scheme, as I could not make it compatible
with how RL storage works using domEval instead of real eval() and
it didn't provide much protection anyways.

Bug: T196923
Change-Id: I3cd2d7cc295c39b498d0bf37915d4ba167fdd48c
2018-08-07 16:54:40 +00:00
Aryeh Gregor
7f0c305c33 Comments and code cleanup in OutputPage
Change-Id: I8c44f30801792e8b84ab3d556cb5b1b5feb9baf3
2018-08-03 10:52:34 +03:00
jenkins-bot
d9327f9a57 Merge "Improve OutputPage test coverage more" 2018-08-02 03:03:22 +00:00
Aryeh Gregor
5daf4022a2 Improve OutputPage test coverage more
Improved locally from 26.81% to 37.18%.

Depends-On: Ib564624c644ee6620ac06872f5684831acaaaadb
Change-Id: Icdc0288c04b8c4ba841f9fbb3e05a0cdc8a20fa5
2018-08-01 16:08:46 +03:00
Aryeh Gregor
a5853433da Remove long-dead OutputPage methods set/getPageTitleActionText()
They were accidentally made non-functional in April 2009 by commit
e4d21170.  Subsequent commits 2d045fa1, 9e230f30, e275ea28, ae45908c
removed all callers by October 2011.  Needless to say, I found no
callers in core or extensions.

It seems we have the functionality in some other way, probably just by
directly calling setHTMLTitle(), so there's no need to revive this
feature.

Bug: T200643
Change-Id: Ifa2537b97cf19e7e91ee33d4ea4c131f7a38ee89
2018-08-01 10:14:42 +00:00
jenkins-bot
b1289408df Merge "Improve test coverage for OutputPage" 2018-07-30 12:48:49 +00:00
Aryeh Gregor
243e0f5d6c Improve test coverage for OutputPage
Raises coverage locally from 16.10% to 26.81%.

Change-Id: Ib564624c644ee6620ac06872f5684831acaaaadb
Depends-On: I79c4e37092958c63a693194b27a9eafae70cb2f8
2018-07-30 05:08:54 -07:00
Fomafix
6a022c8d20 Add type hint for ParserOutput
EditPage::getPreviewLimitReport is called by EditPage::showEditForm
with $output = null. Specify this in the @param tag and allow this by a
default value.

Change-Id: Iec8905aab736a1f254a57853c7cab935d008653e
2018-07-30 09:23:59 +02:00
jenkins-bot
e8efad4669 Merge "Use array_merge() for OutputPage::$mLanguageLinks, not +" 2018-07-30 03:14:34 +00:00
Aryeh Gregor
8a1bc59d11 Use array_merge() for OutputPage::$mLanguageLinks, not +
Based on documentation together with inspection of some callers, the
intent seems to be that this is an indexed array, not associative.  +
will therefore do totally the wrong thing, ignoring any new values that
have the same key as an existing item (e.g., '0' or '1').  Even if it
was an associative array, + keeps the values on the left-hand side,
which means you normally want to do $foo = $bar + $foo instead of $foo
+= $bar if you want to overwrite old values with the new ones.

Before this change, calling addLanguageLinks() or
addParserOutputMetadata() would generally not add all of the links it
was supposed to if there were already links defined.  (It could still
work if the arrays' keys didn't conflict for some reason, e.g.,
something passed an associative array or an indexed array with a hole.)
I don't know if anything actually hits this bug, because it's likely
that callers usually add all their links at once.  I find no uses of
addLanguageLinks() at all.

I found this bug while working on adding more tests for OutputPage, and
the tests for this change will be submitted later in
Icdc0288c04b8c4ba841f9fbb3e05a0cdc8a20fa5.

Change-Id: I53f6e7ea94417b0034371e56e733e8c86af21658
2018-07-29 14:21:10 +03:00
Aryeh Gregor
62eea350d7 Remove two unused OutputPage methods
addMetadataLink and getMetadataAttribute were added in 2004 (22f8c4ce)
for functionality that was moved to extensions in 2011 (27c3b22b).
Those extensions, CreateCommonsRdf and DublinCoreRdf, now use
addHeadItem() directly.  There are no other callers in core or
extensions.

Change-Id: I4bc21fdaefc8f56969a2950eb53b340bf4aac399
2018-07-26 14:02:20 +03:00
Aryeh Gregor
dcb721dca4 Make OutputPage::mPagetitle private
Code search revealed only one outside access, which I've submitted a patch for.

Depends-On: I001deecad241b091070483d882088d2d6361ed5a
Change-Id: I0f7e565f4eacc1074c619772b2d11a47a05e3584
2018-07-24 16:40:37 +03:00
Jack Phoenix
0ed71cb0e0 New 'OutputPageAfterGetHeadLinksArray' hook, allowing extensions to modify the return value of OutputPage#getHeadLinksArray
Code from wikiHow codebase, where this hook is used by the following extensions:
* AlternateDomain -- used to remove certain links altogether and change the contents of other elements (e.g. <meta description="..." />)
* hooks (PageHooks) -- used to hide certain links for anons on noindexed pages to avoid leaking article info to Googlebot
* QADomain -- used to remove certain elements and correct <meta keywords="..." /> tags not to mention "wikiHow" if that string is present
* search (LSearch) -- used to remove canonical URL on Special:LSearch for SEO

Change-Id: I4a9ceb343bb5c0b4eb79e4589d36c3790938f8a9
2018-07-15 02:08:16 +03:00
Brian Wolff
cb57179a01 Deprecate specialized file errors in OutputPage and fix escaping
OutputPage has a number of specialized error reporting methods
related to file handling. With exception of showFileDeleteError,
they are all unused. In my opinion such specialized error handling
does not belong in OutputPage, but in whatever class is generating
the error.

Futhermore, these functions do not appropriately escape their
arguments or their i18n messages. I replaced the one usage
in SpecialUpload with an equivalent that does escape properly.
This is not exploitable as the attacker is not in control of
the temporary file name, but it is very bad practice.

This deprecates the following methods:
* OutputPage::showFileDeleteError()
* OutputPage::showFileNotFoundError()
* OutputPage::showFileRenameError()
* OutputPage::showFileCopyError()
* OutputPage::showUnexpectedValueError()

[Discovered with the help of an experimental phan plugin]

Change-Id: I9e7aaa59ded66f32c78cfdfed1e59e073ffd5051
2018-07-11 18:57:24 +00:00
Brian Wolff
53a18d1294 CSP: Allow an option of disabling nonces
The current rollout plan calls for initial rollout to only
disallow external JS, and leave removing unsafe inline stuff
to a later date. Thus this adds a useNonces option to the CSP
config to allow that.

Renamed ContentSecurityPolicy::isEnabled() to isNonceRequired
for clarity. The old name has never been in a released version
of MediaWiki, so is removed immediately.

Change-Id: I756d8e97b77c6f97dbbf040a20c8750fecb157c5
2018-07-10 00:12:32 +00:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Umherirrender
ae2f5d6232 Add missing use statements
Swap some ResultWrapper/Database to interface IResultWrapper/IDatabase

Change-Id: I312cb3cca5742f72efdb0965ba35362f2eb1129d
2018-06-27 20:49:23 +02:00
jenkins-bot
84fa176c9c Merge "Avoid deprecated LinkCache::singleton()" 2018-06-14 23:48:54 +00:00
Fomafix
0f1858321c Use PHP 7 '??' operator instead of if-then-else
Change-Id: I790b86e2e9e3e41386144637659516a4bfca1cfe
2018-06-12 23:14:18 +02:00