aboutsummaryrefslogtreecommitdiffstats
path: root/includes/language/Message.php
Commit message (Collapse)AuthorAgeFilesLines
* Replace Title in Message/MessageCachePetr Pchelko2021-06-091-12/+33
| | | | Change-Id: Ib0e36d767788edcdd8fa9ebc5de6bbde4cf50f12
* Message: Deprecate toString() with an implicit formatTimo Tijhof2021-04-221-16/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This functionality exists to enable the anti-pattern of calling a format method, without using its return value, and then subsequently calling toString() to parse the same message, the same way, a second time with the format you just called. For example: ``` $msg = new Message('laggedreplicamode'); echo $msg->plain(); // <strong>Warning:</strong> Page may not contain recent echo $msg->toString(); // <strong>Warning:</strong> Page may not contain recent echo $msg->escaped(); // &lt;strong&gt;Warning:&lt;/strong&gt; Page may not contain recent echo $msg->toString(); // &lt;strong&gt;Warning:&lt;/strong&gt; Page may not contain recent ``` Deprecate this rare anti-pattern in favour of using the return value from the formatting methods such as $msg->plain() and $msg->escaped(), or for compat we can also support $msg->toString('plain') etc. This commit also fixes an unintentional lie in the assertion message of one of the unit tests, which was claiming that toString() is unaffected by format calls, when in fact it is. (And is what we are deprecating here). This implicit formatting and the related $this->format field will be removed in 1.37. Bug: T146416 Depends-On: Ia257621fb421854bf13e2965b04009663711ba0a Change-Id: Ibb22099ff8042406e441d6c7fab87537d3ac92aa
* Add Message/MessageValue datetime parameter typesPetr Pchelko2021-03-301-0/+102
| | | | | | | | | | | This is used quite a lot in the codebase and it's a reason for a lot of usages of $wgLang. Time and date seems generic enough to put into Message library - we already have references to Wikimedia\Timestamp library there. Bug: T278482 Change-Id: If7cb5f5dcfa736b6530f731af9dc3af168812054
* Message: update docs to discourage wfMessage usageGergő Tisza2021-03-181-42/+17
| | | | | | | | | | | | | | Update the phpdoc of the Message class to encourage object creation via MessageLocalizer::msg() instead of wfMessage() as the latter results in calling to the global request context during message parsing, which leads to unintuitive errors when sessions are not available (in ResourceLoader callbacks or early hooks like LocalUserCreated). Also drop the documentation about the (long since removed) wfMsg* methods. Change-Id: Ie8c5c5e055cb8ff79d47d4c129df56f719e1cba6
* build: Enable SecurityCheck-DoubleEscaped and suppress issuesUmherirrender2020-12-301-0/+2
| | | | | | | | | | | | This issue type was globally suppressed in I849ac4f120fd15b483e8939d4db45c98dc351259 to make reviewer easier. This adds inline suppressions or @suppress directives on function docs for false positives, mostly restoring those removed in I849ac4f120fd15b483e8939d4db45c98dc351259 Bug: T231311 Change-Id: I1b1d814bd907e9d49fcc39f777982936574fc7c6
* build: Enable phan-taint-check-plugin and suppress issuesUmherirrender2020-12-301-1/+0
| | | | | | | | | | | | | | | | | | Taint check checks for possible security issues by tracking html escaping and more by using phan. This slows done the phan-job a bit and requires more ram Keep the DoubleEscaped issues out to make reviewer easier Adds suppression for false positives Adds taint-annotation to help taint-check Removes suppression for code phan now understand better by the tracking of keys in taint-check Fix some small issues by adding int cast or htmlspecialchars calls Bug: T216348 Bug: T268920 Change-Id: I849ac4f120fd15b483e8939d4db45c98dc351259
* taint-check: Set raw taints on Message::rawParamUmherirrender2020-12-131-0/+1
| | | | | | | | Also add taint for LogFormatter::makePageLink similiar to LogFormatter::makeUserLink to avoid false positives as the return of this function is mostly wrapped in Message::rawParam Change-Id: Iab770702fd3a1d20f25f54057770dc03e28f1b0e
* Add taint hints for message creation methodUmherirrender2020-12-101-0/+2
| | | | | | | | | Some function using union type string|Message where string is a message key and not html. This can be marked as tainted to avoid double escape issues from taint-check Bug: T216348 Change-Id: I40a305b5e49d67b3f6d7737c0846b93a80b78fa9
* Drop Message->getFormat(), hard deprecated since 1.29James D. Forrester2020-09-201-13/+0
| | | | Change-Id: I02955f93b773868e067c577e9d497dd0bb428d5c
* Replace "@stable for calling" by "@stable to call"daniel2020-07-131-1/+1
| | | | | | | | | | | For compliance with the new version of the table interface policy (T255803). This patch was created by an automated search & replace operation on the includes/ directory. Bug: T257789 Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
* Annotate newable classesdaniel2020-07-071-0/+2
| | | | | | | | This annotates classes that can safely be instantiated by extensions, per the Stable Interface Policy. Bug: T247862 Change-Id: Ia280f559874fc0750265ddeb7f831e65fd7d7d6a
* Remove is_scalar check on arrayUmherirrender2020-06-191-4/+1
| | | | | | is_array is called before is_scalar and arrays are not scalar Change-Id: I73e65ac8bce95e31a2c5da7a48a212ce35fb4f40
* Fix more PSR12.Properties.ConstantVisibility.NotFoundReedy2020-05-151-5/+5
| | | | Change-Id: I94520b10d78a17ea8e965633dd475ea711f25c99
* Remove reference to wfMsgHtml()Kosta Harlan2020-05-111-2/+2
| | | | | | It was removed in MediaWiki 1.27 Change-Id: I9d84d16371ee466064813b24ea855da82ff1e267
* Use MediaWikiServices::getMessageCacheUmherirrender2020-03-141-3/+3
| | | | Change-Id: I07fcc9529991adc634c10e5ed8498ac138a1c2b7
* language: Avoid title parsing cost for serialised Message objectsTimo Tijhof2020-03-061-5/+11
| | | | | | | | | | | | | | | | | | | | | | There is currently notable overhead from having to call Title::getPrefixedText/TitleFormatter upon serialisation, and Title::newFromText/TitleParser upon unserialisation. An unscientific benchmark: > $start = microtime(true); $a = new RawMessage('some content'); > $a->title( Title::makeTitle( NS_SPECIAL, 'Badtitle/MessageCache' ) ); > $s = serialize($a); $b = unserialize($s); > $duration = microtime(true) - $start; > echo 'time: ' . round($duration * 1000, 1) . ' ms'; Run on mediawiki-docker-dev on PHP 7.2.28, via eval.php: * Before: 129.7 ms, 118.6 ms * After: 6.6 ms, 4.7 ms Bug: T247035 Change-Id: I999db53e2f6189fb4319fefc2fbd8e5e5a228df0
* language: Clean up file headers and class-level docsTimo Tijhof2020-02-121-5/+3
| | | | | | | | | | | | | | | | | | | This follows-up d83fcce5cb6, which did something similar for includes/profiler/. * Ensure presence of license header. * Merge any file-level descriptions with the class block, where it gets seen in generated docs about that class. * Add any missing `@ingroup` tags to class blocks. * Remove remaining `@ingroup` from file blocks. These clutter the Doxygen pages with duplicate entries. * Fix some misspelled words from 61e0908fa29 and f136c2953c62. Change-Id: I5d21ec159766b799ba519da951d4f0716bae5f9f
* Allow injecting a message localizer into StatusGergő Tisza2019-10-301-1/+1
| | | | | | | | | | | | The coupling of Status with the global request context for Message object creation is a common pain point in unit tests and in no-session code. As a short term solution (until Status is properly deprecated) allow injecting a different localizer. Also refactor the code a bit to get rid if the explicit need for the context language (which is already implicit in the localizer). Change-Id: I82a2e4a83743546a934fb938b94e877a2471a3d2
* Remove Language::factory and getParentLanguage useAryeh Gregor2019-10-271-2/+6
| | | | Change-Id: I11f8801ef47ec1a1f63d840116e69667e6f3ae3c
* Use real variargs for variadic methodsDaimona Eaytoy2019-10-061-38/+22
| | | | | | | These were all checked via codesearch to ensure that nothing is overriding these methods. Change-Id: Ie2d8c1fd01478f46f3d0d1259417182b0d955a12
* Unsuppress more phan issues (part 3)Daimona Eaytoy2019-08-311-0/+1
| | | | | | Bug: T231636 Depends-On: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd Change-Id: I58e67c2b38389df874438deada4239510d21654f
* Unsuppress other phan issues with low countDaimona Eaytoy2019-08-301-0/+2
| | | | | | | | | And also update approximated counts, which for the most part are lower than reported (hooray!) Bug: T231636 Depends-On: Ica50297ec7c71a81ba2204f9763499da925067bd Change-Id: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
* Import the PSR logger classes in MessageAaron Schulz2019-07-041-2/+4
| | | | Change-Id: If05db9b55275246174b6f1fd0ca8437f271f5eea
* language: Move some language-related classes to includes/language/Timo Tijhof2019-06-181-0/+1396
Bug: T225756 Change-Id: Ica351483d83a3a912d58ebb194b30828541fbcf3