Commit graph

241 commits

Author SHA1 Message Date
Kunal Mehta
2912873a61 parser: Simplify code for {{#int:}} if the message doesn't exist
Ever since 184658eb32, the output of a non-existing message will be
HTML safe, regardless of output format, so we can treat non-existing messages
exactly the same as messages that do exist.

The pre-existing "int keyword - non-existing message" parser test verifies
that no change in output has ocurred in this patch.

Change-Id: I0e32be14f1b420d7f222ac3c76e1cc266f912b69
2018-08-25 01:20:43 -07:00
Aryeh Gregor
e68fdb4065 Mass conversion to SpecialPageFactory service
Change-Id: Ia6e1e819ec6cbe8bf75b820109f51d47863e31fc
2018-08-17 12:03:12 -07:00
Aryeh Gregor
81c60356ff Update CoreParserFunctions to use ContentLanguage
Bug: T200246
Change-Id: I4e32195b46967d70e69eeccf3ecd1887e8ae7da8
2018-08-11 07:25:59 +00:00
Aryeh Gregor
5a16d92e04 Update MagicWordArray to use MagicWordFactory
Bug: T200247
Change-Id: Ie5a60b81382d7299beadc691fe4d27e931ebe0ed
2018-07-31 21:40:21 +03:00
Aryeh Gregor
72ab013be0 Update CoreParserFunctions to use MagicWordFactory
Bug: T200247
Change-Id: I122d8acf601581b18756a5b8d65e50953b28c21d
2018-07-31 15:36:57 +03:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
jenkins-bot
84fa176c9c Merge "Avoid deprecated LinkCache::singleton()" 2018-06-14 23:48:54 +00:00
C. Scott Ananian
dbda7cdfb0 Remove unnecessary Parser::getConverterLanguage() indirection
The getConverterLanguage() method was added in March 2012 in commit
561424c266 as a workaround for a regression
in mediawiki 1.19.  It was an indirection which checked the global variable
$wgBug34832TransitionalRollback to return a different converter language
for Chinese wikis.

When this temporary bugfix was reverted in January 2013 in commit
a3fbdaaa2c, the temporary global variable
was removed, but not the getConverterLanguage() indirection.  Since then,
new code in the parser seems to have faithfully used getConverterLanguage()
instead of getTargetLanguage(), even though they are identical and the
need for getConverterLanguage() has long since passed.

Strike a small blow for elegant minimalism by removing the completely
unnecessary Parser::getConverterLanguage() indirection.  Well, sort
of: since this blight has been slowly growing inside Parser.php for
so long, we need to deprecate getConverterLanguage() first just in
case any external dependency has been infected.  Next release we
can finally excise the unnecessary method.

Change-Id: I567c29c9c7699020955699b76cbe8578d02e2fe6
2018-06-12 23:33:03 +00:00
Kunal Mehta
c4e5a9dd97 Avoid deprecated LinkCache::singleton()
Change-Id: Ie0e5c4ef0fe6ec896378bb2433af0898655dd907
2018-06-10 23:55:11 -07:00
Kunal Mehta
dc96f656af parser: Validate $length in padleft/padright parser functions
$length is user input, so cast it to an int before passing it to min().
If there is nothing to add at that point, return immediately.

In PHP 7.1+ this raised a warning of "A non-numeric value encountered"
because min() will return the junk value, returning a string. Then we
try and subtract an int from it (return value of mb_strlen()),
triggering the warning.

Added a parser test to verify the behavior, and confirmed that it
triggers warnings without the patch.

Bug: T180403
Change-Id: I614750962104f6251a864519035366ac9798fc0f
2018-06-10 11:20:13 -07:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Fomafix
d59af4c341 Use PHP's implode() with the suggested order of arguments
https://secure.php.net/manual/en/function.implode.php defines the order
of arguments as

 string implode ( string $glue , array $pieces )
 string implode ( array $pieces )

Note:
  implode() can, for historical reasons, accept its parameters in
  either order. For consistency with explode(), however, it may be less
  confusing to use the documented order of arguments.

Change-Id: I03bf5712204e283f52d3ede54af9b9ec117d4280
2018-02-22 20:24:00 +01:00
Prateek Saxena
60a64e8912 Gallery: Use Parser::parseWidthParam() for gallery dimensions
Used by the `setWidths` and `setHeights` methods to make sure we are
using correct values.

Makes `parseWidthParam` static to be used in the gallery class.

Bug: T129372
Change-Id: I38b9ef0ea26e3748ad5d5458fadd2545f677ef93
2018-01-25 17:35:40 -05:00
Brian Wolff
5fd1e1abe0 Make Gender normalize usernames
This ensures that if GENDER is fed wfEscapeWikitext()'d version
of a username, it will normalize it.

See discussion on T182800.

Note, we do not need to worry about the case of a user named
"Project:*foo" as such namespace prefixes are illegal in
usernames.

Change-Id: Ic5a8fc76c28dca43ce8e334ef1874c2673433f00
2018-01-22 23:12:01 +00:00
Max Semenik
f9d4f53105 {{anchorencode:}} output should be always usable in links
Bug: T179544

Change-Id: If8098e3e839e8ba1cf27b6053017e818c556a733
2017-11-21 16:42:35 -05:00
jenkins-bot
a7f7bc7981 Merge "Refactor global function wfBCP47 to static function LanguageCode::bcp47" 2017-10-05 17:55:50 +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
Fomafix
ea0bd74a94 Refactor global function wfBCP47 to static function LanguageCode::bcp47
Deprecate global function wfBCP47.

Change-Id: Ie6bb061b5d6ca67289bb18bc468a87421f38fc94
2017-10-05 09:54:45 +02: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
Kunal Mehta
844d724621 Avoid using deprecated Title::canTalk()
Change-Id: Ibd224f9de595435524e683262882c9ebf2761abf
2017-08-29 12:36:33 -07:00
Umherirrender
b5cddfb27b Remove empty lines at begin of function, if, foreach, switch
Organize phpcs.xml a bit

Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
2017-07-01 11:34:16 +00:00
James D. Forrester
9635dda73a includes: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I6f59febaf8fc96e80f8cfc11f4356283f461142a
2017-02-21 18:13:24 +00:00
Niklas Laxström
c9d638d6c7 CoreParserFunctions: Use Title::inNamespace instead of manual comparison
Change-Id: I60c02bc68ef0d48b1dc66ba0961275feec5789fb
2016-12-21 10:55:14 +01:00
Nikerabbit
63bb3852a5 Parser functions now format numbers according to page language (2nd attempt)
Bug: T62604
Change-Id: I1c60d828891b82a8122e7030d843018fccaf72e4
2016-12-19 10:17:11 +01:00
addshore
7dd1600e9c Get GenderCache from MediaWikiServices
Change-Id: I752a65d93ec49ea6c44306eb18a6641ef86f7b5c
2016-11-22 23:14:43 +00:00
Legoktm
962b945538 Revert "Parser functions now format numbers according to page language"
This reverts commit 4290f686c0.

Bug: T149840
Change-Id: I7e2dfe14813b510a1a974ae0007390bb2879f804
2016-11-02 20:23:18 +00:00
Niklas Laxström
4290f686c0 Parser functions now format numbers according to page language
Also fixed incorrect return value documentation.

Bug: T62604
Change-Id: I1e16f20ca79436afe17eba711981b2ae43fed9e1
2016-10-25 19:13:25 +03:00
Legoktm
3172dfe21e Revert "Move wfEscapeWikiText() to Parser::escapeWikitext()"
Apparently it is possible for Parser::mParserOptions 
to not be set in some cases. I'll try again later.

This reverts commit bda74bff6e.

Bug: T146433
Change-Id: Idb6d1b20995d5f86b712abb386ab987356c4f560
2016-09-23 00:29:21 +00:00
Kunal Mehta
bda74bff6e Move wfEscapeWikiText() to Parser::escapeWikitext()
wfEscapeWikiText() used $wgEnableMagicLinks, but that could result in an
inconsistency when something modifies the magic link related
ParserOptions.

In general, most uses of wfEscapeWikiText() are in parser functions or
when message parsing, so the Parser is a logical place for it.

A future patch will make it easy to use Parser::escapeWikitext() in
message parameters.

Change-Id: I0fd4d5c135541971b1384a20328f1302b03d715f
2016-09-13 22:34:24 -07:00
jenkins-bot
089612544d Merge "Show ParserOutput warning instead of on the actual page output for ignored display titles" 2016-06-02 21:23:04 +00:00
jenkins-bot
408e9de28c Merge "Add pages with ignored restricted {{DISPLAYTITLE}}s to a tracking category" 2016-05-22 21:17:10 +00:00
Bartosz Dziewoński
06b9d0af42 CoreParserFunctions: Return 0 from {{PAGESIZE:}} when length is unknown
Revision::getSize() might return null when the revision.rev_len field
is null. That should never happen normally (the field should get
backfilled as part of the update process), but we've also had a bug
where rev_len was not being recorded for empty pages (see T135414 for
details). It's saner to return a number here rather than empty string,
and 0 should actually be correct for all pages affected by that issue.

Bug: T20998
Change-Id: Ie12f0be24f00aaf8b90b25c4921a97df3b789369
2016-05-22 18:39:11 +00:00
Glaisher
bacd87e494 Show ParserOutput warning instead of on the actual page output for ignored display titles
Ignored restricted DISPLAYTITLE warning isn't really relevant for the casual reader
so don't show it in the page output. Instead show it above the edit box.

Bug: T135949
Change-Id: I009dd865bec7b6e3a7492c49db97074483f93ee4
2016-05-22 22:45:56 +05:00
Glaisher
8af59afa0d Add pages with ignored restricted {{DISPLAYTITLE}}s to a tracking category
Added to "Pages with ignored display titles" category
(message key: "restricted-displaytitle-ignored")

Follow up to I6ae6d5d0e567ba9c86e46c32240ee51a2ca5d8d1

Bug: T135949
Change-Id: I9e0f8b1e3d39a62c13191bea6734fb136e976e0c
2016-05-22 17:19:46 +00:00
Jackmcbarn
b34d4e2cf3 Warn when a restricted displaytitle is ignored
If a page contains a call to DISPLAYTITLE that is ignored because of
$wgRestrictDisplayTitle, output a warning.

Bug: 26546
Change-Id: I6ae6d5d0e567ba9c86e46c32240ee51a2ca5d8d1
2016-05-08 03:01:22 +00:00
Reedy
b5656b6953 Many more function case mismatches
Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
2016-03-19 00:20:58 +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
Jackmcbarn
bcb6429372 Fix protectionexpiry using the wrong page
Change-Id: I0d8cfd68a735fbcdd32a000ef47e6922a816968e
2016-01-14 12:10:33 -05:00
cenarium
a042808b91 Add magic word for protection expiry
This adds a magic word to get the protection expiry for a page for a
given action.
Usage is {{PROTECTIONEXPIRY:action}}.

Bug: T19354
Change-Id: Ia1a20e313781789480dc082bdc7f585c4f0e28df
2015-12-07 10:02:12 +00:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Amir E. Aharoni
bd30ccd795 Make lines shorter to pass phpcs in some files under includes/parser
This doesn't fix all the files under includes/parser -
some of them deserve their own patches.

Bug: T102614
Change-Id: I2fcbc19ee337e1b7db4635b5e5f324c651b4d144
2015-09-26 18:19:11 +00:00
umherirrender
87c1ca1ac1 Escape return of {{int:}} if message not exists
This avoids returning possible html tags like <var> for {{int:var}}.

Bug: T44914
Change-Id: Ibcba9129d88510e6a84282c774ebe2dbfa548462
2015-07-24 22:02:54 +02:00
Arlo Breault
baddcab658 T105242: U is for urlencode
* Urlencode and extension tags don't play nice. The current behaviour
   is pretty broken. For example,

      {{urlencode:<pre id="one">two</pre>}}

   outputs

       <pre id="one">two</pre>

   which isn't exactly urlencoded.

 * Just drop the unexpanded content; anything more seems unsafe. There's
   precedent for this already in anchorencode.

 * Noticed in the infobox caption for enwiki/%22F%22_Is_for_Fugitive

Change-Id: I0ec5d2fdeb71f762036464f65029afd029e8b4a1
2015-07-08 15:28:21 -07:00
David Chan
f5c88ef8e5 Add {{bidi:}} syntax for directionality-safe arguments
In parallel with jquery.i18n version:
https://github.com/wikimedia/jquery.i18n/pull/76

Bug: T104472
Change-Id: I25afa50ab1e0521bd0b3779cbd16b6c190d72722
2015-07-01 11:06:45 -07:00
Max Semenik
08762b02de Minor cleanups
* Declare undeclared variables
* Kill unused variables
* Fix comments including PHPDoc

Change-Id: I60015f6b6740aa9088bda3745f4dc4e65e29fcb1
2015-04-02 16:22:42 +00:00
Chad Horohoe
aa21e125a3 Remove obvious function-level profiling
Xhprof generates this data now. Custom profiling of various
sub-function units are kept.

Calls to profiler represented about 3% of page execution
time on Special:BlankPage (1.5% in/out); after this change
it's down to about 0.98% of page execution time.

Change-Id: Id9a1dc9d8f80bbd52e42226b724a1e1213d07af7
2015-01-07 11:14:24 -08:00
Jackmcbarn
c05b4c9bc4 Re-emit unknown tags from #tag
When #tag is given a tag that it doesn't recognize, re-emit it as a
regular tag instead of giving an error. This allows for it to be used with
transparent tags and HTML tags.

Change-Id: I0ceee8a4fdaf2d3142054a108f445ff06597c31a
2014-12-18 23:06:22 -05:00
Ricordisamoa
12dec5d85d Fix some stuttering in comments and documentation
Change-Id: I9c0088b9aab37335203cad45a1d6fa8ac3f43321
2014-12-17 19:44:10 +00:00
umherirrender
91f26d50ee Use Parser::SFH_NO_HASH/SFH_OBJECT_ARGS class const
Instead of the global const
Add hint to Defines, that they should not be used.

Change-Id: I3e1dcf46fe18a97a05e3406c209815adb7e0e083
2014-11-18 21:19:22 +01:00
jenkins-bot
cf93d76c03 Merge "Remove hitcounters and associated code" 2014-10-20 21:12:54 +00:00