Commit graph

154 commits

Author SHA1 Message Date
Brad Jorsch
f4b9ac7710 Message: Don't include Title objects in the serialization (part 2)
Stringify the title instead. This will help avoid running into the
PHP/HHVM serialization incompatibility described in T210528.

This is part 2: Once all servers have part 1 (and rollback is unlikely)
we can stop storing the Title objects.

Bug: T210528
Change-Id: If3acfeb42788bd675c3022cc1b49dccc9ac1ecbe
2018-12-14 14:20:41 +00:00
jenkins-bot
801f046b71 Merge "Message: Throw if given invalid serialized data" 2018-12-01 10:50:18 +00:00
Brad Jorsch
508ee26e5e Message: Don't include Title objects in the serialization (part 1)
Stringify the title instead. This will help avoid running into the
PHP/HHVM serialization incompatibility described in T210528.

This is part 1: start stringifying and using the string, but continue
storing the Title object for the benefit of mixed environments where
some servers still only handle a Title object.

Bug: T210528
Change-Id: I07aac3aab2d4e27a7203f4e4fb3ce1b5d86c517c
2018-11-28 13:43:00 -05:00
Brad Jorsch
e2f2da74f2 Message: Throw if given invalid serialized data
Instead of silently winding up with a bogus Message object having most
fields invalidly set to null, just throw an exception.

Bug: T210528
Change-Id: I79313f8acf3ebb1ef12dac30c362aa10c715f40b
2018-11-28 10:28:34 -05:00
Fomafix
68ddb83f62 Message: Fix error on getTitle() without language
Steps to reproduce:

Old:
> $msg = new Message( 'brackets' )
> print $msg->getTitle()
Error from line 478 of /.../includes/Message.php: Call to a member function equals() on boolean

New:
> $msg = new Message( 'brackets' )
> print $msg->getTitle()
MediaWiki:Brackets

This got broken in 796d62d0.

Change-Id: I52cde36787e348378c4df18d90aa577a5600e06b
2018-08-17 18:09:44 +02: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
Brian Wolff
89b21847e1 Start working on phan-taint-check warnings. Fix minor escaping issues.
This fixes 26 of the phan-taint-check warnings on MW core. Some
are outright fixed, others are false positives that were suppressed.

This really only covers some of the easy ones. There are still
314 warnings to go.

Change-Id: I30463bc3a09fd4324d190de8533f51784764dd3a
2018-07-12 03:26:59 +00:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Erik Bernhardson
aa7612e030 Resolve required parameter after optional in Message
It looks like this parameter has had a default since it was first
created, and somehow kept it even after a new parameter was added
to the end. codesearch.wmflabs.org suggests, and I could not find,
and calls to this function from any other code that would need
the defaulted param (probably because they fail due to the later
required parameter).

Change-Id: Iae6e736c5c957d9fccb6ab5813a3b5b02eeb3f6f
2018-06-08 21:48:51 +00:00
Fomafix
174f0d28df Message: Only clear message cache when set language is different
Change-Id: Ic0d810b9017b2cc693282807540ddf3e4d952b9d
2018-05-30 13:58:23 +00:00
Umherirrender
63d96c15fd build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
Change-Id: I59b59f79bbf3ce4feff3b3a20c1c31bc16370531
2018-02-17 13:29:13 +01:00
Brad Jorsch
d511626236
Add 'unwrap' ParserOutput post-cache transform
And deprecate passing false for ParserOptions::setWrapOutputClass().

There are three cases for the Parser wrapper: the default
mw-parser-output, a custom wrapper, or no wrapper. As things currently
stand, we have to fragment the parser cache on each of these options,
which uses a nontrival amount of storage space (T167784).

Ideally we'd do all the wrapping as a post-cache transform, but
TemplateStyles needs to know the wrapper in use in order to properly
prefix its CSS rules (that's why we added the wrapper in the first
place). So, second best option is to make *un*wrapping be a post-cache
transform and make "custom wrapper" be uncacheable.

This patch does the first bit (unwrapping as a post-cache transform),
and a followup will do the second part once the deprecation process is
satisfied.

Bug: T181846
Change-Id: Iba16e78c41be992467101e7d83e9c3134765b101
2018-02-01 14:24:27 -08:00
Huji Lee
e74bfe13f6 Require indentation of CASE statements in PHP code
Bug: T182546
Change-Id: I91a9555893a08e4ec58da97c6cc4d1e70000ff6b
2017-12-10 22:07:50 -05:00
Brad Jorsch
e74ba29aa6 Use ParserOutput stateless transforms
We still set the state in many cases for benefit of extensions, but all
calls within core should no longer be using non-default state.

Change-Id: I78b62ec33fcb8273acb9b3b4e9012215442be94c
Depends-On: I140ff32373430b61b92226689ef9b58cca317450
2017-11-30 14:27:49 -05:00
Brian Wolff
410c00a9ae SECURITY: Ensure Message::rawParams can't lead to XSS
If you used wfMessage( 'foo' )->rawParams( 'bar"baz' )
there's a possibility of leading to xss, if the foo
message has a $1 in an attribute, as the quote characters
may end the attribute.

To prevent that, we convert $1 to $'"1 for after parameters,
so if any of them end up in attributes, the attribute escaping
will break the parameter name, preventing substitution.

This would of course break if someone intentionally inserted
a raw parameter into an attribute, but that's silly and I
don't think we should allow that.

This is similar to the parser strip marker issue.

Bug: T176247
Change-Id: If83aec01b20e414f9c92be894f145d7df2974866
2017-11-15 02:36:48 +00:00
Chad Horohoe
2dd06563cd Clean up "bad parameter" error messages in Message handler
Change-Id: I64b54b1991d17ae97a8dd9414d6807daab982a3a
2017-11-01 22:10:38 +00:00
Addshore
c02d643d86 Revert "Stop stubbing StubUserLang"
This reverts commit 7ab57ba290.

Bug: T177478
Change-Id: I28ac95ebcb64231a12c178165a0cb174e70f4e18
2017-10-05 16:52:49 +00:00
Chad Horohoe
7ab57ba290 Stop stubbing StubUserLang
Stub objects are confusing as heck and are a performance optimization
that really aren't fit for the modern era. They were designed to avoid
loading the actual code from the disk back in the days when bytecode
caching wasn't always gonna be there.

It's 2017. If you're using HHVM, you've got a bytecode cache. If you're
using any reasonably recent version of PHP then you've got the opcode
caching enabled by default in basically every distro-related build.

Nothing actually relies on this object being a stub (that'd be silly),
so only references are basically things force unstubbing (also kind of
silly) the object. Once remaining code referencing this in extensions
are all cleaned up then we can remove the class itself.

Change-Id: I15df24aeeb729e8e764792daa933377f35042fab
2017-10-03 21:54:34 +00:00
Florian Schmidt
499f643bef Move RawMessage out of Message.php to its own file
Change-Id: Idae9617dafa3c314085eb097f78f1c8d38672f31
2017-08-14 17:33:52 +00:00
Umherirrender
ace44e2064 Use correct variable name in @param documentation
For some varargs a variable name is added with suffix ,... as seen for
many other varargs

Some @param are swapped, because there are in the wrong order

Enable Sniff MediaWiki.Commenting.FunctionComment.ParamNameNoMatch

Change-Id: I60fec6025bce824d5c67563ab7b65ad6cd628ad8
2017-08-11 19:27:19 +02:00
Umherirrender
9cd5a3fccf clone keyword must not be used as a function
Also changed a require_once

Change-Id: Ib8030ea5320a62ee4f114d8d506382c5665e3e02
2017-06-28 16:29:33 +02:00
Brad Jorsch
773556d635 More properly fix error message
I2b686228 was a quick bandaid, but resulted in the error message not
actually reporting the incorrect list type.

Change-Id: I2b2bd6ee66a78fadb31b3524dfe04bf9e1f45535
2016-12-16 09:34:43 -05:00
Reedy
31177024a2 Fix undefined $param
Change-Id: I2b6862284b80c27f1f6189a261428324295699ae
2016-12-15 22:43:07 +00:00
Leszek Manicki
95b9d82a3a Fix parameter type docs
Changes:
 - uses int instead of number as param and return value type,
 - uses stdClass instead of stdObject
 - fixes ResourceLoaderClientHtml constructor's $target param type:
   it is string|null, not an array (previously misspelled as "aray")
 - changes the type of references to XML parser in XMP lib to resource
   instead of not existing XMLParser

Change-Id: I98c363ebc6658d1f4dcabad97a9a92f3fcd7ea8c
2016-12-14 17:01:47 +01:00
Brad Jorsch
7f2663fb91 Message: Fix buggy parameter handling in Message::params()
Message::params() wants to take parameters either varargs-style or as a
single array. But it also detects "special" parameters like those
returned from Message::numParam() as an array of parameters instead of
as a single "special" parameter.

Bug: T152603
Change-Id: Idef2437470eee843a17ff23f4cefe8f3132988bd
2016-12-07 10:48:52 -05:00
Brad Jorsch
3041b5c038 Add Message::listParam()
This allows for passing a list of values that will be turned into a list
in the context of the language for which the Message is being processed.

For example, currently you'd have to do

 $msg = new Message( 'something', [ $language->commaList( $list ) ] );

which isn't going to give correct results if the message is later
changed to a different language with a different value for
'comma-separator'.

Now, you can do this instead

 $msg = new Message( 'something', [ Message::listParam( $list, 'comma' ) ] );

and it will be listified properly no matter what language is later used to
parse $msg.

Change-Id: I66868c61832260870449998fef14c842f17753ee
2016-11-30 15:54:17 +00:00
Brad Jorsch
79274e1f44 Better handling of Message objects as Message parameters
If a Message object is a parameter of another Message object, it should
use the same language, use-database flag, and so on as the outer Message
when it's being stringified.

Change-Id: I92762a1a63c90a16e8581edc96bd1da699880157
2016-11-14 13:25:14 -05:00
jenkins-bot
507024c9d0 Merge "mw.Message: Match behavior when key does not exist to PHP" 2016-11-14 16:54:02 +00:00
Bartosz Dziewoński
e681e5d8c9 mw.Message: Match behavior when key does not exist to PHP
See 184658eb32.

Change-Id: I3dba16bcb137ca2f52203bce95f8c044870af3fd
2016-11-14 15:26:20 +00:00
Gergő Tisza
b0784a8e96 Deprecate Message::$format (mostly)
Message::__toString() used the same formatting mode that the last
explicit transformation used:

    $msg = new Message( 'foo' );
    echo $msg; // escaped
    echo $msg->plain();
    echo $msg; // not escaped

This is not particularly useful and makes code review hard, so let's
get rid of it.

The same behavior with $msg->toString() is left intact (and logged)
for now.

Bug: T146416
Change-Id: Ia9b2a1dcf09d52348b2c6d8299fd849b809f6e74
2016-11-10 09:06:26 +00:00
Gergő Tisza
695f5f66d2 Log when Message::__toString has an unexpected format
Message formatting methods have a side effect on how string conversion
will work, which is a security problem waiting to happen:

    $msg = new Message( 'foo' );
    echo $msg; // parsed
    echo $msg->plain();
    echo $msg; // not parsed

This change logs Message -> string transformations which are
affected by a prior call in this way. The behavior will be removed
in a later patch (possibly replaced by something more explicit
if it turns out that something depends on it).

Bug: T146416
Change-Id: Id51cf6a5a937bc41a914f317e980ef42e4d385fb
2016-09-22 21:35:40 +00:00
Amir Sarabadani
6b221fa96a Clean up array() syntax in docs, part IV
Change-Id: If626409a93d31bf90c054c9bf7ba44a78ea9a621
2016-08-26 16:06:58 +04:30
Brian Wolff
184658eb32 Make non-existent messages be html safe regardless of output format
If you have a non-existent message in the output, chances are its
user-controlled. If the message has the ->plain() or ->text()
format, the output used to be not safe for html. Obviously people
should not be using those format types where html is being outputted,
but sometimes that happens. I think we should prioritize always being
safe over the fallback content not potentially being double escaped.

Additionally switch the enclosing brackets to be fancy unicode
characters, to sidestep the escaping issue on the enclosing brackets.

So previously, wfMessage( 'script>alert(1)</script' )->text() would
have outputted <script>alert(1)</script>. Now it outputs
⧼script&gt;alert(1)&lt;/script⧽. No sane message key will include
< or >, so this would really only come up if the user can control
the message key name.

This goes somewhat against T68199.

Change-Id: Ic8a60892b8e847e6021494c10968814aac391731
2016-06-29 18:59:30 -04:00
Brad Jorsch
5f01cbb3ad Allow Message::newFromSpecifier to handle ApiMessages
Instead of constructing a new Message from the Message as
a MessageSpecifier, just clone the existing Message which will preserve
subclass data.

Also, make use of this to simplify the logic in ApiBase::parseMsg().

Change-Id: I9545acb8da752c0c21e16d8b1d37d8802fcb329d
2016-06-28 12:15:27 -04:00
Gergő Tisza
b6516e11f1 Fix Message::newFromSpecifier for nested RawMessage
This can happen e.g. when something processes Status contents
and expects [$key, $param1, ...] and instead gets [$messageObject]

Change-Id: I346b35e08bd38ce231e16d0616438ea408b55bff
2016-06-07 22:30:54 +00:00
Fomafix
796d62d034 Language: Introduce new method equals( Language $lang )
Use

 $lang->equals( $wgContLang )

instead of

 $lang->getCode() === $wgContLang->getCode()

Change-Id: Id7ed6a21ce5e2ea2887ec98c7bd9d3eba83d733b
2016-05-16 22:33:33 +00:00
Gergő Tisza
687dadfb70 Add @since for Message::newFromSpecifier
Adds doctag missing from I2e6195b.

Change-Id: I3a0918c48b49a85498f856896575d6c69e5547e1
2016-05-04 19:40:56 +02:00
Gergő Tisza
dab874cc22 Unify HTMLForm message handling
Improves Ida647973a which unified message handling for form fields
but did not make the functionality available to HTMLForm itself.

Change-Id: I2e6195ba13afbd8b993acb47409fab1be91c547e
2016-05-02 19:48:28 +00:00
Timo Tijhof
0beb5ca992 Message: Use RequestContext instead of $wgLang
This cuts the $wgLang and StubUserLang which is a bit cleaner.
It also makes it more reliable when load.php sets its
RequestContext user interface language.

Bug: T127920
Change-Id: I05302feb9b3ce9e4c29541e07a4260effc4b55b2
2016-03-18 23:31:32 +00:00
Fomafix
3871bee9a2 Message.php: Update comment to current implementation
Change-Id: I04f6b42380e6b8eeb5bf0d679e8fb65cb4696d1a
2016-02-24 19:41:50 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Brad Jorsch
471637c571 When serializing Message, don't try to unstub StubUserLang
If the serialization is happening during PHP shutdown due to a Session
save, it can fatal because $wgLang is already gone.

Change-Id: I7d877be15ef8639f3b94b74bba763053ec289358
2016-01-29 21:26:24 -05:00
Aaron Schulz
0df249d3d3 Various WikiPage code cleanups
* Break numerous long lines
* Clean up style in a few methods
* Fix some IntelliJ IDEA errors

Change-Id: If8e58906031d4080c28ac33b0c9b5efe95b15854
2015-10-08 04:42:25 +00:00
jenkins-bot
012248fc5a Merge "Allow constructing a Message from a MessageSpecifier" 2015-07-20 23:05:26 +00:00
Brad Jorsch
7782819d64 Improve serialization of Message, Title
This allows them to be stored in the session, for example.

Note that properly serializing a Message requires that all its
parameters be serializable as well; we don't attempt to account for that
here.

Change-Id: I3a42a2a883e8eef900eeb02355fc3b064411f642
2015-07-07 15:56:47 -04:00
umherirrender
e51eaf619f Fix edit link for messages in $wgForceUIMsgAsContentMsg
Some special pages or actions have a link for users with editinterface
rights to edit the message used in scroll down menu.
When the message is parsed for the scroll down menu the config
$wgForceUIMsgAsContentMsg is used, but that was not used for the edit
link.

Add a new function Message::getTitle and use it in all places in core.

Most benefit will have the edit link for MediaWiki:Licenses on
Special:Upload, because commons.wikimedia.org has that message in
$wgForceUIMsgAsContentMsg.

Change-Id: Ib800b9adcc9ae88ef53228b66838bf61d2065f0f
2015-05-15 20:38:32 +02:00
Brad Jorsch
3a878b81be Allow constructing a Message from a MessageSpecifier
Bug: T91986
Change-Id: Id6a9862d23c2b71da2c8b34acdd19b8247ac5301
2015-04-21 11:48:39 -04:00
Brad Jorsch
351dc9e11f Message::inLanguage() shouldn't unstub StubUserLang
When a string is passed to Message::inLanguage(), it first checks
whether the message's current language's code is equal to the string, to
avoid a call to Language::factory(). But if the message's current
language is an instance of StubUserLang, it's probably less expensive to
just call Language::factory() than it is to unstub.

This also avoids a possible recursion warning from T56193, particularly
if inLanguage() is being used intentionally in an attempt to avoid that
warning.

Change-Id: Ia09adec05cfbb09c09e07c6be1e2d613435664d9
2015-04-13 11:40:30 -04:00
Timo Tijhof
86a771beff Message: Clean up unit tests and improve code coverage
* Remove unnecessary use of ReflectionClass. It was testing
  internal properties that aren't part of the API. Using the
  getters instead.

* Remove need for func_get_args that was making the test more
  complex and the data provider hard to read. Simply maintain
  it as array of expected params and array of variadic arguments.

* Rename tests to more closely match tested methods.

* Rename data providers to provide*, and make them static.

* Reorder tests to more closely match logical order of the class.

* Improve line coverage from 31% to 67%.

Also:
* Remove testParams (dupes testConstructorParams).
* Add tests for RawMessage class.
* Add tests for transformation and parsing.
* Add tests for wfMessage().
* Add tests for Message::newFrom*.
* Add tests for "$*" replacement.
* Add tests for __toString.

Change-Id: I2b183a66f9e9f51bd800088e174b1ae4d3284d8d
2015-04-02 08:36:19 +01:00
Aaron Schulz
c15caa6d53 Split StatusValue out of Status class and put it in /libs
* Deprecated useless FileRepoStatus class

Change-Id: I015635a9bf080ef6d98b2cff49b949c4378a859f
2015-02-10 00:39:05 +00:00