Commit graph

808 commits

Author SHA1 Message Date
Kunal Mehta
d671429e41 Parser: Pass Title onto Linker::makeExternalLink()
Otherwise $wgNoFollowNsExceptions functionality won't work.

Change-Id: I2e1c5ad41f94568bff7f24a400d555b604cfe22e
2016-05-31 22:47:51 -07:00
Kunal Mehta
b07eb85267 Make $url parameter to Parser::getExternalLinkAttribs() required
All callers in Gerrit pass $url in.

Change-Id: I36246f6510db414dcc7023f8779796c060c3eba5
2016-05-31 21:25:18 -07:00
Kunal Mehta
96e15c9bd2 Parser: Make makeKnownLinkHolder() protected, and remove $query handling
Extensions shouldn't be calling this, just the Parser, so make it
protected. And since the only caller passes an empty array for $query,
we can just remove it entirely.

Change-Id: I3adbcaabbb40870eb3df1495c3c2743ff21f0c64
2016-05-26 15:00:49 -07:00
Kunal Mehta
9d867e3c7a Parser: Replace Linker::link() with LinkRenderer
Replaces usage of Linker::link() in Parser and LinkHolderArray with the
new LinkRenderer.

Change-Id: Icb796ef08d70926728732ab5468940c09ba5eaf8
2016-05-26 14:05:47 -07:00
Brian Wolff
13ece3550e Add rel="noreferrer noopener" when target attribute would open window
noreferrer is used as support for noopener is very limited.
This is to prevent the attack detailed at
https://mathiasbynens.github.io/rel-noopener/ where you can
navigate the parent window, even if the new window is a cross-origin.

Bug: T133507
Change-Id: I6e4ab938861e246ff44048077b94847e303f1859

Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
2016-05-20 09:49:41 -07:00
Brian Wolff
7e4a134f49 SECURITY: Include quote characters in strip markers so esc in attr
Strip markers get substituted for general html, which means the
substitution text general does not escape quote characters. If
someone can convince MW to put a strip marker in an attribute,
you can get around escaping requirements that way. This patch
adds the characters `"' to the strip marker text. At least one
of these characters should be escaped inside attributes (regardless
of what quote character you use for attributes), thus normal html
escaping will deactivate the strip markers, preventing the
vulnrability.

This will break any extension that escapes input with htmlspecialchars,
to add to html/half parsed html output, but assumes that strip markers
are unmangled. I don't think its very common to do this. The primary
example I found was some core usages of Xml::escapeTagsOnly(). (And
even in that case, it only affected the corner case of being called
via {{#tag:..}})

Based on MatmaRex's suggestion.

Change-Id: If887065e12026530f36e5f35dd7ab0831d313561

Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
2016-05-20 09:25:49 -07:00
Tim Starling
2e3c1f87e2 Split out doBlockLevels() into its own class
It's independent of the rest of the Parser, but quite intrusive, with
its own instance variables and several private functions. It's also
pretty big (500 lines).

I removed a few functions from Parser here which were always marked
@private in the doc comment, but were inappropriately marked
"public" in the function declaration after migration to PHP 5. I grepped
core and deployed extensions and found no callers.

The helper functions are now all private, and the constructor is
private, with just a single public static entry point, reflecting
the self-contained nature of the module and its lack of hooks.

Change-Id: I1693ed48a9194719611b4afd9d989d44f0610f8d
2016-05-06 14:40:20 +10:00
Kunal Mehta
5b97211a9b Parser: Don't use deprecated Title::setFragment()
Change-Id: I2b9ea95af288cfe5abc9a1116884a7701f7c36a0
2016-04-23 23:28:23 -07:00
jenkins-bot
220e11d651 Merge "Adding param documentation for Parser::internalParse()" 2016-04-18 07:30:53 +00:00
Kaldari
a0c648a154 Adding param documentation for Parser::internalParse()
Change-Id: Id0adeff2c2fa940205f4b7692d27b45e3466be79
2016-04-14 14:01:08 -06:00
Arlo Breault
9b510882d7 Don't replace !! in elements
* 55313f4e almost got it right, but missed the str_replacing table
   headings.

 * Thankfully, this was doubly broken before that patch since the
   StringUtils::explodeMarkup would have skipped the || which would
   go on to be explode by table cell attribute parsing. The test case
   provided would look like,

   <table>
   <tr>
   <th class="">|">ha</div> ho
   </th></tr></table>

   Suffice it to say, noone is using this in production.

 * Note that we can't just entity encode the ! since that would break
   style attributes with !important.

 * Also note, Parsoid already gets this right.

 * Adds a StringUtils::replaceMarkup

Change-Id: Iab3ae4518fcb307b795d57eece420ba48af0a3bf
2016-04-06 06:23:48 +00:00
Reedy
b5656b6953 Many more function case mismatches
Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
2016-03-19 00:20:58 +00:00
Siebrand Mazeland
5b119a0e44 Replace uses of join() by implode()
All of core uses implode() consistently now.

Change-Id: Iba50898c64c43f356d1caf8869f484e90d9ff651
2016-03-08 18:24:16 +00:00
Bartosz Dziewoński
c161c46d26 Improve code suffering from PHP 5.3's lack of support for foo()[]
I searched for /\$(\S+) = (.+?\(.*?\);)\n.*?\$\1\[/, ignored
everything involving isset(), unset() or array assigments, then
skimmed through the remaining results and changed things where they
made sense. These changes were not automated, so please review them.

Change-Id: Ib37b4c66fc57648470f151ad412210b3629c2538
2016-02-28 22:49:20 +01:00
umherirrender
74534f9ba6 Fix unmatched @codingStandardsIgnore in parser folder
Fix outstanding phpcs errors

Change-Id: I7b857be88354f2ffa27d76406253ec9e9710b91d
2016-02-17 21:26:30 +01: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
Ricordisamoa
c138dc4ee3 Stop doing $that = $this in includes/parser
Closures support $this as of PHP 5.4

Change-Id: Iace7ef43b17e8100f6bd71b4e23bad39cba87c0d
2016-02-11 09:40:54 +01:00
Arlo Breault
55313f4eaf Remove use of explodeMarkup
* At that point, element attributes are already escaped so it serves no
   purpose. Before `doTableStuff` is called, `Sanitizer::removeHTMLtags`
   has been invoked which calls `Sanitizer::fixTagAttributes` which
   calls `Sanitizer::safeEncodeTagAttributes` and finally gets down to
   `Sanitizer::safeEncodeAttribute`, with the goal of "extra armoring
   against further wiki processing."

Change-Id: Ieeb9b21148c2909eb839d13195d7d10012b48e3b
2016-01-29 11:15:29 -08:00
Arlo Breault
63aeabeff1 Last caption wins in gallery
* Currently, for images:

   [[File:Foobar.jpg|hi|alt=100|ho]]

   caption: ho

   but for galleries:

   <gallery>
   File:Foobar.jpg|hi|alt=100|ho
   </gallery>

   caption: hi|ho

 * This patch brings some consistency to them.

Change-Id: I3b73189b27cc35fade4809477cf18779b953aa3b
2016-01-22 11:22:06 -08:00
Reedy
13815fc4ff Linker::makeLinkObj() was removed
Change-Id: Id0fe255fd65403d02498f5a98292c560d39dd95a
2016-01-03 00:08:43 +00:00
umherirrender
54c1e18eec Remove various double empty newlines
The double empty newline is not needed between functions, variable or at
end of file

Change-Id: Ib866a95084c4601ac150a2b402cfa184ebc18afa
2015-12-27 18:55:12 +00:00
Tim Starling
eb40eb0f18 Client-side migration for empty li preservation
It is desirable in terms of user-friendly syntax to display an empty
list item if the user adds one to the source. However, we suspect that
this change will break the rendering of existing templates. So, preserve
the empty <li> element, but style it with display:none so that there is
no user-visible change. Changes can then be observed with a user script,
then eventually the CSS can be removed so that the desired behaviour will
be user visible.

This is imagined as a staged deployment of T89331, i.e. it is better to
resolve differences with Html5Depurate one at a time instead of
deploying it all at once.

The CSS module is specified in parser/MWTidy.php since the tidy driver
hierarchy is not meant to be so closely tied to the MW environment.

Bug: T49673
Change-Id: Ifb44b782c617240e3de73dcdf76c8737c7307d94
2015-10-28 23:35:18 +00:00
Aaron Schulz
0fc6c8b592 Remove buggy b/c logic in Parser::disableCache()/updateCacheExpiry()
* Setting mCacheTime to -1 is for old callers that
  only check getCacheTime() instead of getCacheExpiry().
  Most of them are already broken (WikiLog/SemanticForms) as
  they check for -1 which is in fact never returned
  due to the TS_MW conversion in Parser::getCacheTime.
* By using -1, the value of page_links_updated can end up
  as 1969, which is confusing and broken.

Change-Id: I8809a4258eacff05992a2c27ade7f6a0c1731c51
2015-10-23 12:35:43 -07:00
Amir E. Aharoni
c37d6549fd Fix Generic.Files.LineLength phpcs failure in 11 files under includes/
Bug: T102614
Change-Id: I0d759be6ef568c2c6f28606d3002484ad77a1830
2015-10-03 17:08:26 +00:00
Brian Wolff
e4c016a208 Do not split parser cache if limitation is reached.
The warnings are only shown during preview. It seems silly to
split the parser cache for this. There should be no parser cache
pollution to just using the user language without registering it
for use.

See also: 889e988cce

Change-Id: Ib42e8885e23a3c8bef8cf72948359d71254064c3
2015-09-28 16:39:31 -06: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
jenkins-bot
f244389571 Merge "Load module mediawiki.page.gallery.styles for all ImageGalleries" 2015-09-24 18:22:29 +00:00
umherirrender
27700d276f Load module mediawiki.page.gallery.styles for all ImageGalleries
Move the added module from Parser.php to TraditionalImageGallery,
because there the gallerybox class is added to the html and at the
moment all core image galleries are extending the traditional one.

That brings the styles back for special pages like Special:NewFiles,
Special:MostImages and also on category pages with media files.

Follows Ib1aef04dc4fece78e6615386ecaef6a9f368f49e

Bug: T113511
Change-Id: I32697c2c65824d7622c1840330d6074ebb68b488
2015-09-24 16:46:47 +02:00
jenkins-bot
889283b16e Merge "Add MWTimestamp::getTimezoneString(), use it in file revert message" 2015-09-23 20:53:50 +00:00
gladoscc
90e1b22166 Add MWTimestamp::getTimezoneString(), use it in file revert message
MWTimestamp::getTimezoneString() returns the timezone name as a message,
that supports wiki localization. The code is moved from Parser::pstPass2.

The default file revert message is currently always in UTC.

This patch sets the default timestamp to be in the wiki timezone (similar
to ~~~~). The timezone is passed as a new parameter to the message, with
the date / time parameters being merged and handled by
$wgContentLang->timeanddate

Bug: T36948
Change-Id: I48772f5f3b1635d33b6185776cedfc4ee1882494
2015-09-23 13:38:16 -07:00
C. Scott Ananian
a05971dfc7 Terminate free external link on &nbsp; (and numeric versions of <>)
Bug: T84937
Change-Id: Ic74d8d069e08c0597c7b26755e0d942bf3a510cc
2015-09-23 16:00:52 -04:00
Tim Starling
2c6c954e23 Abstract and refactor Tidy support
* Split tidy implementations into a class hierarchy
* Bring all tidy configuration into a single associative array and
  deprecate the old configuration.
* Remove $wgAlwaysUseTidy

This is preparatory to replacement of Tidy (T89331). I used the name
"Raggett" for things relating to Dave Raggett's Tidy, since if we use
"tidy" to mean the new abstract system as well as Raggett's tidy, it
gets confusing.

Change-Id: I77af1a16cbbb47fc226d05fb9aad56c58e8910b5
2015-09-10 20:18:52 -07:00
Ori Livneh
a7056e3c69 Measure string length once in Parser::replaceVariables
Change-Id: I5b1e3f3fa06cb4e2982f3c0d24222ba2ee59ea47
2015-09-09 23:52:32 +00:00
Kunal Mehta
7a1b87e543 Really actually fix the typo in Parser.php
Change-Id: I9d9c6f13095087ac2c2c6693c6bd1613219bf658
2015-08-28 21:39:15 -07:00
Aaron Schulz
868d11684b Fixed parser report typo
Change-Id: Ia549f4e1932bc1196e840e154b8d6fb0b608d10d
2015-08-28 17:06:45 -07:00
Ori Livneh
26ff3e2946 Add ParserOutput cache and expiry times to NewPP report
The labels are not localized, because I think this ought to be outputted as a
JSON blob, with uniform field names. But not doing that in this patch.

Change-Id: I235839b276632308ddeac7afe763d355b73c2a25
2015-08-27 19:07:35 -07:00
jenkins-bot
d5564b17b5 Merge "Only load gallery styling rules when galleries are on the page" 2015-08-26 22:06:18 +00:00
jdlrobson
c845586dc7 Only load gallery styling rules when galleries are on the page
* Double load styling rules in legacy modules so we have time for
cached pages to catch up
** Double loading styles is acceptable for 30 days. There is no better way.
* Load gallery css when gallery tag invoked.

To test:
* Visit a page with a gallery tag and purge it, note styles are present.
* Visit a page without a gallery tag and purge it, note styles are not present

Bug: T98878
Change-Id: Ib1aef04dc4fece78e6615386ecaef6a9f368f49e
2015-08-26 13:20:15 -07:00
jenkins-bot
8baba70fb4 Merge "Tiny clean up of Parser::doQuotes()" 2015-08-21 21:31:01 +00:00
Pavel Astakhov
78c66e6467 Tiny clean up of Parser::doQuotes()
$firstsingleletterword always is -1 here
because we leave the loop when it's set

Change-Id: I73a430b7ac650bc5919ab95867eec09f723395f2
2015-08-19 21:27:20 +00:00
C. Scott Ananian
87eebf8dd5 Support IPv6 URLs in bracketed and auto links.
The corresponding patch for Parsoid is
Ibb33188cdfe2004e469c3f6ee6f30d34d1923283.

Task: T23261
Change-Id: Iff077bf31168b431febb243e2e62f2c6502616bc
2015-08-18 22:50:58 +00:00
jenkins-bot
9331443546 Merge "Allow to enable OOUI via a parser tag extension" 2015-08-06 08:39:41 +00:00
Bartosz Dziewoński
bd7e02f39f Parser: Don't generate an external link on "http://)" and similar
Bug: T105697
Change-Id: I6cd14b9c4a541af8d0bb50b925aa0b015e97c3fe
2015-08-04 12:23:07 -04:00
Florian
2d50e28975 Allow to enable OOUI via a parser tag extension
This change adds the possibility to enable OOUI out of the parser,
which enabled parser tag functions to easily enable OOUI, if they
need it, for every page view out of the function that handles the
parser tag.

Bug: T106949
Change-Id: If1e139d4f07be98e418e11470794ea42e8a9b2eb
2015-07-25 17:36:33 +02:00
Arlo Breault
0b4208e645 Allow whitespace between indent and table start tag
* \s matches the trim on the line.

 * Since leading space is ok for table start tags, and you can use them
   in ":" context, you should be able to compose the two together.

Bug: T105238
Change-Id: Id08e24e5dd2bb8ca09453adec87b21225df4a840
2015-07-18 20:41:33 +00:00
Chad Horohoe
b8ced862bb Protect against non-text output from StripState going into Title::newFromText()
Non-string input shouldn't be fed into newFromText(). We currently handle this
indirectly with relying on Title to do it. Instead just return earlier and not
try to construct a title from bad input.

Bug: T102321
Change-Id: I9bc96111378d9d4ed5981bffc6f150cbd0c1e331
2015-07-10 20:05:06 +00:00
Arlo Breault
ba00a957fb Cleanup in doTableStuff
Change-Id: I75c0a943b24f96a30c6ee1efc3f0b11388f892b7
2015-07-09 04:57:52 +00:00
Brad Jorsch
359e77d7c9 Parser: Avoid producing <span></span> in the TOC
If someone renames a section but wants old targeted links to still work,
<span id="old-anchor"></span> is the usual solution. And sometimes
people put it inside the section header markup, like

 == <span id="old-anchor"></span>New name ==

since putting it before makes it be considered part of the previous section
while putting it after causes the browser to scroll the section header
off the screen.

But this has the unfortunate side effect that the TOC text for that
section will be "<span></span>New name". We should strip that useless
empty span.

Bug: T96153
Change-Id: I47a33ceb79d48f6d0c38fa3b3814a378feb5e31e
2015-07-08 17:11:21 +00:00
Bartosz Dziewoński
e688bea6a5 Parser: Correct setHook() documentation
Change-Id: Iaeaac9ea79b696dfa39adb6608ed68edd3754516
2015-06-30 19:02:42 +00:00
umherirrender
70f3afd548 Remove unneeded empty lines at begin of if/else/foreach body
An if body must not begin with an empty line

Change-Id: I62b058be337fcc85a120fcd3dadce564db59a271
2015-06-19 20:05:45 +02:00