Commit graph

119 commits

Author SHA1 Message Date
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
Erik Bernhardson
d55fedfba8 Introduce Message::plaintextParam
I have run into numerous issues trying to utilize unsafe user
provided content as an argument to a Message instance.  Specific
cases are enumerated in MessageTest.php

Typically the solution to using user provided text is to use
Message::rawParam, but this pushes escaping of the parameter to
the caller.  This patch introduces Message::plaintextParams which
handles escaping of the string parameter to match the requested
output format.

The functionality is:
* plain and text: exactly like rawParams()
* escaped, parse and parseAsBlock: escape it but don't do brace expansion

Additionaly, similar to Message::rawParam, plaintext parameters are not
valid parser function arguments.

Change-Id: I320645cd23c98fea4bfc32ab22b7ef8d320957cb
2014-09-30 12:51:29 -07:00
Erik Bernhardson
c9a3ecef59 Message: Correct output of wfMessage( 'non-existent-msg' )->text()
The output of Message::text() should always be acceptable to pass into
external html escaping, such as when the response is returned over an
API request and escaped by the client side code. Calling ->text() on a
non-existent key was returning the entity encoded value which leads to
double encoding down the line, this patch fixes that oversight.

Bug: 66199
Change-Id: Ieec94d4e4c7e5c36e5e68bbf01792e96368e54e0
2014-09-23 21:06:22 +00:00
daniel
cff86194ff Consistent handling of multiple keys in Message
Message objects may be constructed with a list of keys as a
simple fallback mechanism. This patch assures consistent
handling of this case.

Change-Id: I458c0af3114754ddf3d721f6c374e249f482e4cf
2014-08-06 12:29:28 +01:00
umherirrender
1c68a1ee86 Cleanup some docs (includes/*.php)
- Swap "$variable type" to "type $variable"
- Added missing types
- Fixed spacing inside docs
- Makes beginning of @param/@return/@var/@throws in capital
- Changed some types to match the more common spelling

Change-Id: I783e4dbfe5f6f98b32b9a03ccf6439e13e132bcc
2014-07-24 19:42:24 +02:00
Alexandre Emsenhuber
b025e69891 Don't use isset() to check for null
Those two member variables are always defined.

Change-Id: I7d1b9319bb1ce212f730a0568961eefb963fc7df
2014-07-01 19:17:02 +02:00
Bartosz Dziewoński
c3aa5ef597 Create Parser::stripOuterParagraph to avoid code duplication
We've had the logic for stripping the outer <p/> element in three
separate places. The version in OutputPage was missing the '$' at the
end of the regex, that was most likely a mistake caused by the
duplication.

Also, extend the logic in order not to generate invalid HTML if the
input contains more than one <p/> tag. Added tests for this and the
previous behaviour.

https://www.mail-archive.com/mediawiki-api@lists.wikimedia.org/msg03188.html

Change-Id: I6bb3597898324556df912a23a7ffc9ff250b8f58
2014-05-15 12:20:19 -04:00
Siebrand Mazeland
c0c39640e4 Make phpcs-strict pass on includes/ (5/~10)
Change-Id: I259f3f11cfc22f3ed1693f9ebd5bd80491b8a6e8
2014-05-11 19:35:32 +00:00
Siebrand Mazeland
e9eb00b203 Make phpcs-strict pass on includes/ (1/~10)
Change-Id: Ib51381a2261d064988ba2f39b71c0252f2458faf
2014-05-11 19:14:17 +00:00
umherirrender
a3983418d5 Fixed some @params documentation (includes/*)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I0056b4a8df243cfc0c5f25378de48f7a35170aca
2014-04-22 13:07:02 +02:00
daniel
c95bc7fe90 Changing a message's lang must reset cached text.
Without this patch, it's not possible to get text in different
languages from the same Message object.

Change-Id: I0bb915b0d9205e78ac4599ced5efacacf2cf0240
2014-04-16 12:17:47 +02:00
aude
78937428b6 Add getLanguage method to Message
This allows to more easily test code where language is set,
Message::inLanguage() is called, etc.

Change-Id: If8f9697480f5d084f755990fdc0f2a1e18f056bc
2014-03-28 18:04:12 +01:00
aude
3df8366e9a Allow to optionally set language in Message constructor
This helps with testability to not have to rely on $wgLang
and setting globals in tests.

This also provides convenience, so one does not necessarily
need to call Message::inLanguage() if language is known
at time of constructing the message object.

Also added tests to cover this change.

Change-Id: I14ee98972c7be954e04398ece9e6103f96ab60dd
2014-03-28 17:59:48 +01:00
Thiemo Mättig
6806400129 Added and updated Doxygen comments in content handler and diff namespaces
Reasons for touching this are:
* "@param type $var" were mixed in a lot of places. Both works but the
  MediaWiki coding conventions suggest that specific order.
* Things like String and Bool aren't objects and shouldn't be uppercase.
* Tried to fill missing types in "@param $var".
* Tried to fill missing descriptions in "@return type" when I could.
* Removed duplicate descriptions if a @see is sufficend.
* Removed useless descriptions ("isUsefull returns true if usefull").
* Removed useless @return void.
* Replaces mixed[] with array (does have the exact same meaning).
* Tried to find better replacements for "varargs", phpDocumentor
  suggest $var,...
* Order should be @since, @param, @throws, @return, @see. This is the
  order Doxygen renders this.

There is always more to do but I think this is already much better
than before. Please feel free to put more change sets on top of mine
or request more changes by adding comments.

Change-Id: I05262ce06caabf79f68772302524ac91bbead1c6
2014-03-06 11:17:41 +01:00
Yuri Astrakhan
5b4c232ab2 Add logging for "Invalid message parameter"
Records a full stacktrace for this warning

Bug: 58676
Change-Id: I234b525b04168eee6085d44fbf0e0d8ac3d0af91
2013-12-21 11:42:05 +00:00
Yuri Astrakhan
cee9fbc39a Better warning for Message object
Trying to track down the source of the production warnings

Change-Id: Iba666af3e84651fde338764d0f9d47a38b6b54e9
2013-12-11 21:23:39 -05:00
Brad Jorsch
58a161fa35 Status::getHTML should actually return HTML
Currently it only returns wikitext with templates expanded (like
Message's text() method).

Bug: 45844
Change-Id: I24b5b098f15d0a4194817f31f63e37be1179aae6
2013-12-09 12:14:06 -05:00
Tyler Anthony Romeo
96a9a3e101 Fix double-parsing of account creation messages.
Account creation messages don't need to be parsed. This is
a temporary fix to follow up when double-parsing was accidentally
added in 69ea440003 (I402c6bebcfe).

Bug: 44718
Bug: 52191
Change-Id: I333d5468820994625348316ebf6c57d4df025284
2013-10-24 10:16:19 +00:00
parent5446
0f88ab3d4e Added more Message parameter functions
Similar to numParams(), added functions for other parameters
that can be formatted by the Language class. Adds functions for
expiry, size, timePeriod, duration, and bitrate parameters so
that the formatting doesn't have to be done at the caller.

Change-Id: I7b435fcc11824ead55e4c0f5512418187eae9a6f
2013-10-19 14:34:14 +02:00
MatmaRex
df8ec1e216 No spaces after (casts)
Also removed some unnecessary ones. I think I've caught them all.

The spaceless version already appears in core ~300 times (after
accounting for false positives when grepping). Some consistency would
be nice.

Change-Id: I607655b5f4366e66dc78730d5fd2f57ed8776cae
2013-09-04 20:05:43 +02:00
daniel
b8c3140723 Return messages in a consistent form from Status objects
Also fixes Message::getKey() to always return a string.

Rationale:

Some code, like RollbackAction, assumes that Status::getErrorArray will 
return an array of the form ( messagekey, param... ), but this was not
the case when a Message object was passed to the Status.

This change makes sure Status::getErrorArray will always return arrays
of the expected form. This is especially important since the messages in
the Status object may be provided by extensions.

In order to convert Message objects to arrays of message keys and parameters,
Message::getKey() needed to be fixed to return a single key always.

Bug: 49338
Change-Id: I0deaa9888e9d86726a8e41ca606c571f56190c91
2013-07-30 02:11:48 +00:00
umherirrender
15ff79312d Fixed spacing and removed unneeded parenthesis
Added spaces after/before parenthesis
Removed unneeded parenthesis around some statements
Broke a long line

Change-Id: I7fbe129f7bbf524dd0598ece2a9708643f08453b
2013-05-17 16:12:08 +00:00
umherirrender
ef2f507d23 Fixed spacing in files direct in includes folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: Ibb8dd102db045522d12ff939075ba7420d95ab6b
2013-04-21 06:38:49 +00:00
Yuri Astrakhan
9506e3d812 Spellchecked /includes directory
* Ran spell-checker over code comments in /includes/
* A few spellchecking fixes for wfDebug() calls

Found one very strange (NOOP?) line in Linker.php - see "TODO: BUG?"

Change-Id: Ibb86b51073b980eda9ecce2cf0b8dd33f058adbf
2013-03-13 03:42:41 -04:00
Tyler Anthony Romeo
4dcc7961df Fixed @param tags to conform with Doxygen format.
Doxygen expects parameter types to come before the
parameter name in @param tags. Used a quick regex
to switch everything around where possible. This
only fixes cases where a primitve variable (or a
primitive followed by other types) is the variable
type. Other cases will need to be fixed manually.

Change-Id: Ic59fd20856eb0489d70f3469a56ebce0efb3db13
2013-03-11 13:15:01 -04:00
Reedy
9f4d498beb Few more message parameter type hints
Change-Id: I9017170a434b8924692e04410acc88831237ef8d
2013-03-06 21:10:59 +00:00
daniel
c0f47c445a Add getters to Message object.
Being able to get the message key and parameters from a Message object
is needed to be able to report errors from the API in an abstract,
language neutral way.

Change-Id: I8ee9da4005db7cb0a487457127f1e24fb11dbd66
2013-02-19 20:30:36 +01:00
umherirrender
1044b0b8df fix some spacing
Change-Id: I8f976013f33c5818e4402604fe8610aa3f43b0c6
2013-02-04 20:18:33 +00:00
Tyler Anthony Romeo
5f38cc2dbe Changed Message::content() to pass $this to MessageContent.
MessageContent can take either a Message or a message key in
the constructor. Since Message::content() is an instance method,
it makes sense to pass the instance itself rather than just
the key. This fixes cases where RawMessage::content() is called,
since passing RawMessage's key to MessageContent will not work
properly.

Change-Id: Ic3b935e5ac997df07eea40b438445ebd5024e306
2013-01-27 23:20:57 -05:00
umherirrender
6fbbbd17ca fix some spacing
Change-Id: Ie7bb35871cc99237f3a655f7db22ca1f0646df5e
2013-01-27 14:21:50 +01:00
daniel
185e4eee10 Catch excpt to avoid fatal in Message::__toString
PHP doesn't allow __toString to throw exceptions and will
trigger a fatal error if it does. So, catch any exceptions
and try to report them using wfWarn.

Change-Id: I52d38e9a927da4db18f4733fd207f9396adedf94
2013-01-08 17:55:31 +01:00
parent5446
69ea440003 Changed LoginForm::addNewaccountInternal() to return Status.
Rather than calling mainLoginForm() and returning false,
the addNewaccountInternal() function now returns a Status
on failure. mainLoginForm() is then called in addNewAccount()
and addNewAccountMailPassword() instead. This allows for
processing of the account creation form without submitting
anything to $wgOut.

Change-Id: I402c6bebcfe276233cc1f9e16efbe55a034b2181
2012-12-13 19:00:53 +00:00
Kevin Israel
7f9fe1b29d Remove the throw from Message::extractParam()
Per Tim Starling's comment on bug 41400, I replaced the throw (when a
message parameter is invalid) with a call to trigger_error().

The string [INVALID] is used as a placeholder to make it clear from
the output that an error has occurred.

Change-Id: I974d55d44d392c956e7de6d243da9d8dc07d8833
2012-11-29 22:33:57 +00:00
Aaron Schulz
e882babdbe Fixed MessageCache::parseText() and fixed docs for MessageCache::parse()
Change-Id: Ia297d9d0f893451a611051f9df7db3870b4c2333
2012-11-01 10:28:52 -07:00
Niklas Laxström
3f68a44535 More informative debugging messages
Change-Id: Ib83dde07e8935e9ae3d864a12af7f93b68ee8f85
2012-10-23 15:23:22 +00:00
Siebrand Mazeland
d4b046a893 Update docs for return and exception info
* Removed some inline tabs in the process.
* IDE fixed some incorrect leading spaces, too.

Change-Id: Ic9303eff6db4424ac3f1fa2816839692b43e6190
2012-10-09 09:41:58 +00:00