Commit graph

827 commits

Author SHA1 Message Date
Amir Sarabadani
6b221fa96a Clean up array() syntax in docs, part IV
Change-Id: If626409a93d31bf90c054c9bf7ba44a78ea9a621
2016-08-26 16:06:58 +04:30
Kunal Mehta
85034abca5 content: Refactor normalization of line endings code
The code that normalizes line endings ("\r\n" and "\r" to "\n") and
trims trailing whitespace is buried in Parser::preSaveTransform(), and
was duplicated to TextContent in 96b6afb31d, as non-wikitext content
models should still be normalizing line endings.

This splits the duplicated code into
TextContent::normalizeLineEndings(), and utilize it in the Parser.
Additionally, expand the documentation of
TextContent::preSaveTransform() to document that subclasses should make
sure they normalize line endings during the PST stage.

And remove a useless rtrim() call from WikitextContent that did nothing.

Change-Id: I9094c671d4bbd23d75436f8f1d682d6dd6e6d2fc
2016-08-23 11:09:59 -07:00
Brian Wolff
e2a6fe5711 SECURITY: XSS in unclosed internal links
rawurldecode was being run on unclosed internal links
which could allow an attacker to insert arbitrary
html into the page.

See also related: r13302

Bug: T137264
Change-Id: I4e112a9e918df9fe78b62c311939239b483a21f5
2016-08-23 03:39:36 +00:00
Brad Jorsch
96b6afb31d TextContent: Normalize newlines in preSaveTransform()
This does the same normalization of newlines that
Parser::preSaveTransform() does. This should be appropriate for any text
content type, especially considering that EditPage uses
WebRequest::getText() which does a less-strict version of this same
transformation.

This also cleans up the code for doing that newline replacement
to be a bit less verbose.

Bug: T142805
Change-Id: I462afcda502f031a8b0360d982ce2398a0383a96
2016-08-16 10:21:32 -04:00
Florian
794bb8bb25 Fix comment of get/setLinkRenderer in doxygen
Doxygen requires the full qualified name of the class in a comment
or in the @aram/@return annotation, otherwise the class isn't linked
in the resulting output[1]. This commit changes the LinkRenderer
annotations in SpecialPage and Parser to \MediaWiki\Linker\LinkRenderer.

[1] https://doc.wikimedia.org/mediawiki-core/master/php/classSpecialPage.html#a3560214f63fc2f20c63b4025db5cd81d

Change-Id: I74cedcd764a6053cc5a0c6d2eedbedb72651f57c
2016-08-09 17:23:00 +02:00
Tim Starling
134f8c4513 Don't run the non-Tidy "bug 2702" hack unless Tidy is really missing
We have two hacks which are used when Tidy is not available: one in
Sanitizer::removeHTMLtags(), and the second here as a late Parser pass
equivalent to Tidy itself. But the Sanitizer one was enabled only if
MWTidy::isEnabled() returned false, whereas the Parser one was enabled
also when tidy was disabled in ParserOptions. This patch makes them both
consistent, it enables the bug 2702 hack only when MWTidy::isEnabled()
returns false, and when Tidy is disabled in parser options, the output
is simply passed through.

This allows tidying to be done separately on the ParserOutput, as is
required by the proposed ParserMigration extension (I24d0776a933fa3f).

Eventually the bug 2702 hack will be removed in favour of a pure-PHP
HTML 5 parser, but it looks like it is too early for that.

Change-Id: I94be6c9dec531c23ef80cb36732243bd6858bf22
2016-07-27 14:47:36 +10:00
Aaron Schulz
b7c4c8717f Move NewPP limit report HTML comments to JS variables
* Instead of having messy code to create a hidden HTML
  comment of English strings at the bottom of the page,
  expose the structured data of the parse information
  to JS so tools can use it.
* Make makeConfigSetScript() use pretty output so these
  variables are also easy to read in "view source".
* Remove ParserLimitReportFormat hook, since the data
  is not formatted to HTML anymore.

Bug: T110763
Change-Id: I2783c46c6d80f828f9ecf5e71fc8f35910454582
2016-07-26 11:31:20 -07:00
Tim Starling
d3d682fb45 Hide marked empty elements by default (stage 1)
We originally imagined rolling out the display of empty elements
simultaneously with the Html5Depurate, but now we have added support for
marking empty elements to Html5Depurate and plan on having some sort of
longer migration period. So, move the relevant CSS to content.css, and
remove the concept of CSS dependant on tidy driver.

Add a body class which will allow the effect to be toggled in a gadget or
extension. Actual toggling in the CSS will be in the stage 2 patch, to be
deployed after the varnish cache and parser cache have expired.

I originally imagined that there would be a gadget that overrides the
rule with an !important selector, but that method does not allow you to
recover the original display property, which is often overridden by the
style attribute or site CSS to be "inline".

Also, in RaggettWrapper, switch to the new class mw-empty-elt, following
Html5Depurate, instead of mw-empty-li. The old class will be removed in
the stage 2 patch.

Change-Id: Ic0f432c43a006629ca5a1a7c2dda3552ceb4dc4f
2016-07-14 14:24:27 -07:00
C. Scott Ananian
6cdae80513 Add tracking category when editors use the deprecated self-closed tag hack.
Some pages use constructs like `<b/>` or `<span/>` to protect spaces or
special characters at the beginning/end of templates.  This syntax is
incompatible with HTML5 parsing rules, which dictate that these should
be treated as open tags, and instead rely on an unusual quirk of the
`tidy` program that removes invalid constructs.

This syntax is deprecated as part of the process of reconciling `tidy`
with modern HTML5 parsing semantics.  Authors can use `&#32;` or `<nowiki/>`
as valid replacements.

In order to provide time to transition existing content, pages using
self-closing tags in violation of the HTML5 parsing specification
will have their templates/pages added to a new tracking category.
After these uses are fixed, we will change the sanitizer to treat these
as normal open tags, to be consistent with the HTML5 parsing spec.

Note that this construct is already disallowed if tidy is disabled; it
is rendered as `&lt;b/>`.  We add a tracking category in the no-tidy
case as well, in preparation for eventually making the no-tidy and
with-tidy behaviors consistent.

Bug: T134423
Change-Id: Ie1cf3aa40d5483bf395ece539f0240b694ff04ab
2016-07-12 14:18:04 +10:00
Aaron Schulz
005b4d6fff Try to predict the rev_id when preparing edits
During both the edit stash and first parse in on page save,
guess what the rev_id will be and use that instead of null.
Only reparse if it turns out to be wrong. This avoids extra
parsing on wikis that have low-medium traffic, and does not
cost much. The parsing that can be avoided is:
a) in doEditContent() by using the stash
b) in doEditUpdates() by using the doEditContent() result,
   whether that was able to use the stash or not itself

Also improved the parse operation logging in save paths.

Bug: T137900
Change-Id: Ic6faae70a78b4e223e4d3585cefd482c0fa00677
2016-06-29 05:39:33 -07:00
Kunal Mehta
fb04b0ce28 Parser: Use LinkRenderer for building ISBN magic links
Instead of manually building the <a> tag, use LinkRenderer to create it.

Change-Id: Iaefe85527307a8399e9f52dde58fb2c24c4753c2
2016-06-23 14:11:24 +00:00
Kunal Mehta
8a6326c211 Add SpecialPage::getLinkRenderer()
And SpecialPage::setLinkRenderer(), so the Parser can pass on its
LinkRenderer instance for when special pages are being included in a
page.

Change-Id: If9a9c648ab670b824ce534e7cf0d20d41e1bfd12
2016-06-22 23:32:00 +02:00
Jackmcbarn
d05dde4329 Render bad images in wikitext as links
In galleries, bad images are rendered as links. This causes the same behavior
to occur in wikitext, rather than the current behavior of not rendering
anything.

Change-Id: I1a074bff7cb661b5b4e6db9503eb6a5de702ee2f
2016-06-19 03:24:57 +00:00
Aaron Schulz
7d42e96748 Deprecate Parser::disableCache
Few maintained extensions still rely on this and it is
bad practice to use this for handling cache correctness.

Change-Id: I2de481198bbff5c4f3dd81fc6d1b137e4c37b93f
2016-06-18 19:55:43 +00:00
Brian Wolff
7730dee63b Make transcluded special pages not disable cache in miser mode.
Previously {{Special:Foo}} would cause parser cache to be disabled,
now have a method in SpecialPage to control this behaviour and set
arbitrary caching times.

Note: This does not affect caching of direct views to the special page

The new default is now disabling cache if not in miser mode,
otherwise setting to 1 hour, except for Special:Recentchanges
and Special:Newpages which set to 5 minutes. These values are
possibly really low, but for now I think best to be close to the
old behaviour. We had 0 caching for these things for years, and
afaik it hasn't caused any big issues. Part of me wonders if
Special:Recentchanges should stay at 0, but that sounds crazy.

This change also causes transcluded special pages to not be
"per-user" if they are being cached (Specificly $wgUser et al
become 127.0.0.1).

Bug: 60561
Change-Id: Id9ce987adeaa69d886eb1c5cd74c01072583e84d
2016-06-14 20:46:32 -07:00
Aaron Schulz
879ebfb18a Use a low TTL for parser output when special pages are included
Previously, no TTL at all was used, which is quite harsh on
performance and had downstream effects like disabling edit
stashing for affected pages.

Bug: T136678
Change-Id: I2462057aa189cfb05fe65d0b3c081a9fd10066a2
2016-06-14 17:48:04 -07:00
Aaron Schulz
147f79eedd Improvements to {{REVISIONUSER}} handling
* Do not change the result to a null editing user anymore.
* Use a new vary-user flag instead of vary-revision. This
  will only cause a reparse on null edits. Normal edits
  can still use the prepared output now.
* Edit stashing now applies for pages with this magic word.
* Fixed bug where the second prepareContentForEdit() call
  (due to vary-X flags) would still check the edit stash.

Bug: T135261
Bug: T136678
Change-Id: Id1733443ac3bf053ca61e5ae25db3fbf4499e9f9
2016-06-14 19:28:09 +00:00
Timo Tijhof
8eca3b5027 parser: Remove redundant comment about revisionsize cache vary
Follows-up 457431b.

Change-Id: Iac3e4d6c11de3737155e7f7ff35ec7a6a3873865
2016-06-14 01:26:37 +02:00
Aaron Schulz
457431b57b Avoid setting vary-revision for {{REVISIONSIZE}}
Just always use the input size for new revisions. If they are
saved, then that should be the revision size. If they are just
null edits, then the size must have matched the current revision.

This also enables edit stashing for this case.

Change-Id: I428c0cc87750eeddd1d7dcebd1a2b03817cec441
2016-06-13 23:00:05 +00:00
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