Commit graph

197 commits

Author SHA1 Message Date
Gergő Tisza
1bb5b58eb1
Unwrap HTML loaded from parser cache
Partially and temporarily reverts I1641b7995 to deal with cached
HTML the same way the old code did.

Bug: T203716
Change-Id: I29846a6513f6b580b429c0bfe6c310ada50b28bb
2018-09-07 18:49:34 +02:00
Brian Wolff
13e5700b23 Use annotations for taint in Parser & ParserOutput.
This replaces the builtin taints that are removed in
Ic1e1983a51c. Additionally, parse will no longer warn about
double escaping - there's many situations where such warnings
are wrong (e.g. Using Html::rawElement()). However this also
means that Parser::parse( wfMessage( 'foo' )->parse() ); will
no longer give a double escaping warning, which is unfortunate.

Bug: T202380
Change-Id: Ia52d37411beb62b112c6ff102438063c3d750769
2018-08-31 15:55:44 +00:00
daniel
d8c409dd16 Make HTML generation in RenderedRevision optional
This allows optimization for situations in which a caller
needs the meta-data of a ParserOutput, and the respective
ContentHandler can provide that meta-data without generating
HTML output.

Bug: T194048
Change-Id: I786d294d18a6a2e3cea61577313e21b578c44f1e
2018-08-31 10:48:41 +00:00
daniel
e9f71517f7 [MCR] Introduce RevisionRenderer
RevisionRenderer is the MCR replacement for Content::getParserOutput,
as outlined in <https://www.mediawiki.org/wiki/User:Daniel_Kinzler_(WMDE)/MCR-PageUpdater>.

Note: This change also introduces quite a bit of code for
merging ParserOutput objects.

Bug: T194048
Change-Id: I871978bf79f67c9e7954fb3fc8528d6e365f2cc1
2018-08-30 19:15:12 +02:00
daniel
0dc7ba02b4 Apply content wrapping in ParserOutput::getText()
Instead of applying wrapping the the parser and unwrapping in
ParserOutput::getText(), turn this around and apply wrapping in getText(),
and only if desired.

This avoids search&replace logic for unwrapping, and it also makes it a lot
easier to merge the output of multiple slots for MCR output.

This changes behavior in two hopefully irrelevant ways:
1) the limit report comments will be inside the wrapper div, instead of
following it.
2) if HTML with a wrapper div is explicitly injected into a ParserOutput
object, it will not be possible to unwrap the text.

Bug: T174035
Change-Id: I1641b7995af9bd297f1acd610d583fbf874f34e0
2018-08-29 16:46:25 +02:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Legoktm
cddd1a7e75 Revert "Use type Language instead of string for $lang of doEditSectionLink"
This reverts commit 531e71acda.

Was a breaking change that did not following the deprecation
policy.

Change-Id: Idefd38e1f42ee849a09da0fc5793fb7f051b2a4c
2018-06-18 23:11:17 +00:00
Fomafix
531e71acda Use type Language instead of string for $lang of doEditSectionLink
The call of wfGetLangObj( $lang ) is not necessary anymore.

Keep $lang as optional parameter to avoid the coding style check error
 Required argument follows optional

Depends-On: Ibe295e7020e995eea52e319feaf59c635f8bb4dc
Change-Id: Id49201957e716ef8a2ea930b3616ca4fe6e35633
2018-06-17 22:36:35 +02:00
Max Semenik
6e956d55aa Replace call_user_func_array(), part 2
Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.

In one occurrence, a simple conditional instead of trickery was much more readable.

This patch finishes all the easy stuf in the core, the remainder is either unobvious
or would result in smaller readability gains. It will be carefully dealt with in
further commits.

Change-Id: I79a16c48bfb98b75e5b99f2f6f4fa07b3ae02c5b
2018-06-07 20:19:26 -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
Kunal Mehta
230958d97c Autofix MediaWiki.Commenting.FunctionComment.SpacingDoc* errors
Change-Id: I63761ebce04c03b9b13237919c27cc10180f198f
2018-05-19 14:07:03 -07:00
Timo Tijhof
a63088d496 resourceloader: Deprecate OutputPage::addModuleScripts()
And the counter-part in ParserOutput as well.

This follows-up on 80e5b160e0, which removed the last use of this
method. It also deprecated ResourceLoaderClientHtml::setModuleScripts()
but that isn't usually used directly. The public interfaces are
mainly in OutputPage/ParserOutput, which are now deprecated as well.

Bug: T188689
Change-Id: I90baafdfc089ac03c4c3abc12065c0b60d43994e
2018-05-07 14:26:56 +01:00
Thiemo Kreuz
e6b6920cff Fix PHPDoc type hints in CacheTime, ParserOptions, and related
I'm intentionally not touching any code in this patch, only
documentation.

Change-Id: I6975194c218760031789d5335dfbb330017dc6fc
2018-04-18 15:10:31 +00:00
Brad Jorsch
2791fb0861 Hard-deprecate ParserOutput stateful transform methods
This also removes all the in-core calls that had been kept for the
benefit of extensions, and causes them to not have any effect since
anything that had been calling them was already either a no-op or will
probably be broken now that nothing in core is setting or checking the
flags.

Change-Id: Id22c1a5a6d6a249debb14063ae3f8838d105b634
2018-02-13 12:28:36 -05:00
Brad Jorsch
9b2b375fce ParserOutput: Add 'deduplicateStyles' post-cache transformation
This transformation will find <style> tag with a "data-mw-deduplicate"
attribute. For each value of the attribute, the first instance will be
kept as-is, while any subsequent tags with the same value will be
replaced by a <link rel="mw-deduplicated-inline-style"> with its href
referring to the "data-mw-deduplicate" value using a custom scheme.

This also adds an $attribs parameter to Html::inlineStyle() so the
data-mw-deduplicate attribute can be added.

Note this doesn't actually depend on Ib931e25c, but action=mobileview
will break if it starts being used without that patch.

Bug: T160563
Change-Id: I055abdf4d73ec65771eaa4fe0999ec907c831568
Depends-On: Ib931e25ce85072000e62c486bbe5907f03372494
2018-02-11 05:55:56 +00:00
Gergő Tisza
5859eff1b0
Fix ParserOutput::getText 'unwrap' flag for end-of-doc comment
The closing div might be followed by debug information in HTML comments.

Bug: T186927
Change-Id: I72d4079dfe9ca9b3a14476ace1364eb5efdee846
2018-02-09 14:17:22 -08:00
jenkins-bot
74426f3cf7 Merge "Warn if stateful ParserOutput transforms are used" 2018-02-02 02:45:27 +00:00
Brad Jorsch
d511626236
Add 'unwrap' ParserOutput post-cache transform
And deprecate passing false for ParserOptions::setWrapOutputClass().

There are three cases for the Parser wrapper: the default
mw-parser-output, a custom wrapper, or no wrapper. As things currently
stand, we have to fragment the parser cache on each of these options,
which uses a nontrival amount of storage space (T167784).

Ideally we'd do all the wrapping as a post-cache transform, but
TemplateStyles needs to know the wrapper in use in order to properly
prefix its CSS rules (that's why we added the wrapper in the first
place). So, second best option is to make *un*wrapping be a post-cache
transform and make "custom wrapper" be uncacheable.

This patch does the first bit (unwrapping as a post-cache transform),
and a followup will do the second part once the deprecation process is
satisfied.

Bug: T181846
Change-Id: Iba16e78c41be992467101e7d83e9c3134765b101
2018-02-01 14:24:27 -08:00
mainframe98
70e92cdad5 Fix additional usage of incorrect case
Courtesy of the PhpStorm inspection Case mismatch in method call or
class usage.

Bug: T166759
Change-Id: I27c53658b99048fa0dd8f9d6ef1398620386e1cc
2017-12-15 11:58:11 +01:00
Brad Jorsch
c8e4823714 Warn if stateful ParserOutput transforms are used
This should help clean up any missed uses.

Change-Id: I371f3b27d245d6927c74ea52f1df9fd5c675b94a
Depends-On: I30f162aa43c7f513df1153e0884a4339e4279aeb
Depends-On: Iff28b00638c15de7307a130196bbb91cda91c3d1
Depends-On: I432da8c0686c279b3c2e770f7f9e20248589d6db
Depends-On: I404f064b93573e80b61a228e3cf2b5d2add65c39
Depends-On: Ia54a9e3d11c9ab28975947148d0841819f3a8e3c
Depends-On: I2cd7519186f2319f32cf6288655ddb873337a638
Depends-On: I28b46cf4da66cc6e1f04045939a243faa30bc9bf
Depends-On: I3565868af824a08235ab5ce4a34145895ed0e74d
Depends-On: I0d05ce2f565778a4bf39d3d25d26acd0b8043788
Depends-On: I100fae755ae7e729d11163377fbddaebeaa020a6
Depends-On: I38e56d04f7ffbe8796dbda6500106a028a459980
Depends-On: Id6ad08a0b1f8575e7ee98916217a84c09e72dd3b
Depends-On: I2794430f6bc076f073e79e662701403f7e063c35
Depends-On: I39b599246759baad2164a29244150c99f0920684
Depends-On: Ic7aa606b7d697e06c74c1e9207efc77442f5b0c3
Depends-On: I140ff32373430b61b92226689ef9b58cca317450
Depends-On: I9b082e37f19c8baa182b0583c7d70d692fafc16e
2017-11-30 14:27:49 -05:00
Brad Jorsch
e74ba29aa6 Use ParserOutput stateless transforms
We still set the state in many cases for benefit of extensions, but all
calls within core should no longer be using non-default state.

Change-Id: I78b62ec33fcb8273acb9b3b4e9012215442be94c
Depends-On: I140ff32373430b61b92226689ef9b58cca317450
2017-11-30 14:27:49 -05:00
Brad Jorsch
92cf49df5c ParserOutput: Add stateless transforms to getText()
The stateful transforms are deprecated.

Inspired by Krinkle's If2fb32fc.

Bug: T171797
Change-Id: Ied5fe1a6159c2d4fa48170042b44d735ce7b6f9b
2017-11-30 14:27:46 -05:00
Fomafix
396f2684b8 Move call of Sanitizer::decodeCharReferences from Skin to Parser
Supporting HTML entities in Wikitext is part of the parser not of the
skin.

Change-Id: Ib30ff08f4f4ce585f31211aa24b719783f06456e
2017-09-13 13:51:35 +02:00
Umherirrender
86463f3df6 build: Updating mediawiki/mediawiki-codesniffer to 0.12.0
Change-Id: Iefaae5043fa77d5d556c31079549dab8f61bd3ef
2017-09-10 21:11:37 +02:00
Umherirrender
f739a8f368 Improve some parameter docs
Add missing @return and @param to function docs and fixed some @param

Change-Id: I810727961057cfdcc274428b239af5975c57468d
2017-09-10 20:32:31 +02:00
Umherirrender
3f1a52805e Use short type bool/int in param documentation
Enable the phpcs sniffs for this and used phpcbf

Change-Id: Iaa36687154ddd2bf663b9dd519f5c99409d37925
2017-08-20 13:20:59 +02:00
Kunal Mehta
d1cf48a397 build: Update mediawiki/mediawiki-codesniffer to 0.10.1
And auto-fix all errors.

The `<exclude-pattern>` stanzas are now included in the default ruleset
and don't need to be repeated.

Change-Id: I928af549dc88ac2c6cb82058f64c7c7f3111598a
2017-07-22 18:24:09 -07:00
Fomafix
5c41b29993 Use isSpecialPage() where possible
Change-Id: Ie4d0838acf96a7ed4a1fe4cfdc901c77d3312174
2017-04-29 22:31:42 +02:00
Brian Wolff
17e7bc0235 SECURITY: Always normalize link url before adding to ParserOutput
Move link normalization directly into addExternalLink() method,
since you always need to do it - having it separate is just
inviting people to forget to normalize a link.

Additionally, links weren't properly registered for <gallery>.
This was somewhat unnoticed, as the call to recursiveTagParse()
would register free links, but it wouldn't work for example with
protocol relative links.

Issue originally reported by MZMcBride.

Bug: T48143
Change-Id: I557fb3b433ef9d618097b6ba4eacc6bada250ca2
2017-04-06 13:44:44 -07: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
Max Semenik
13054a4c70 refreshLinks.php: allow refreshing by categories, tracking or not
Needed for selective updates of pages using a particular feature.
Intended to be run in production, so needs to scale.

Bug: T149723
Change-Id: If20fb1f91de8d4227def5b07d6d52b91161ed3fd
2017-01-23 14:30:16 -08:00
Aaron Schulz
b03b387e5a Include JS variable for NewPP report
Adapted from reverted commit b7c4c8717f.

Bug: T110763
Change-Id: If249b679c534879bfac622592a1d2fa913a0cf9d
2017-01-05 19:11:38 -08:00
jenkins-bot
dfaa26a7b1 Merge "Add dotall modifier to EDITSECTION_REGEX" 2016-12-18 02:53:47 +00:00
Thiemo Mättig
00c3f09566 Remove empty lines from PHP and JavaScript comment blocks
This is a pure documentation change. It mostly removes empty lines from
comments (and entirely empty comments), as well as adds a few missing
documentation blocks and fixes a minor mistake. I hope it's ok to have
this in one patch. I can split it, please tell me.

Change-Id: I9668338602ac77b903ab6b02ff56bd52743c37c4
2016-12-09 09:01:06 +00:00
Bartosz Dziewoński
0e15a6068a Revert "Move NewPP limit report HTML comments to JS variables" and followups
This change resulted in unreasonable feature loss (human-readable
limit report was gone). Three months and multiple followups later,
the functionality is still not completely restored. Given lack
of response from the original author, I think it is time to revert
and reconsider, especially since the 1.28 release is soon.

A machine-readable limit report would be a very useful feature,
but not at the cost of losing human-readable limit report.

This reverts the following commits:

* Move NewPP limit report HTML comments to JS variables
  b7c4c8717f
* Only pretty-print the parser report JS vars
  28adc4d7ee
* Show wgPageParseReport on page previews too
  1255654ed5
* Re-add human readable parser limit report
  0051f108b9
* Restore hooks.txt for ParserLimitReportFormat
  4663e7a737

Resolved minor merge conflicts in OutputPage (with 80e5b160)
and release notes.

Bug: T110763
Bug: T142210
Change-Id: Id88c8066fae3f369e8977b4b7488f67071bdeeb7
2016-11-08 22:35:15 +01:00
Tim Starling
a31b2153b3 Add dotall modifier to EDITSECTION_REGEX
The regex failed to match for input text like

==<nowiki>
</nowiki>==

resulting in <mw:editsection> tags being leaked into the output.

Change-Id: I3daade920d2de8cd3fc31fcaabf46ffe14b047d5
2016-10-18 12:23:48 -07:00
Aaron Schulz
97f004694c Adapt the ParserOutput cache TTL when including special pages
For simple pages that transclude special pages, like user pages
including Special:PrefixIndex, the TTL is allowed to drop to 15
seconds if the page parses fast enough.

Bug: T139893
Change-Id: If41885ded648d68352fe3d06336d98aa0ab53966
2016-08-31 17:17:38 +00: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
Timo Tijhof
9093af0a28 Remove modulemessages from ApiParse and Output (deprecated in 1.26)
No uses of 'modulemessages', getModuleMessages() or addModuleMessages()
anywhere in Wikimedia Git.

Change-Id: I59420880f3545d1aabf9bcbea1e34b1475697d26
2016-07-26 00:13:04 +01: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
Aaron Schulz
af349f79c8 Fix timestamp check in ApiStashEdit::checkCache
* The wrong time method was used, and it also was not set.
* Bumped the threshold a bit while at it, which was basically
  0-5 minutes before.

Bug: T133332
Change-Id: Ide3e66f551aa6e50410c562e5c917141d59b7f64
2016-04-28 22:01:03 +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
Tim Starling
914f6a62a6 Introduce ParserOutput::getRawText()
Avoid polluting the parser cache with skin-dependent output from
Skin::doEditSectionLink() by introducing getRawText(), which provides
access to the uncooked text. Use this in
WikitextContent::fillParserOutput() which is the primary offender
judging by the debug logs (see referenced bug).

Bug: T124356
Change-Id: Ia9e1e4a6dc3a26f88eeebc64eed023ff20c53d58
2016-01-25 14:50:27 +11:00
IoannisKydonis
44f16d2fb8 Remove Deprecated methods from ParserOutput.php
Remove ParserOutput::getSecondaryDataUpdates and
ParserOutput::addSecondaryDataUpdate
Deprecated since 1.25, slated for removal in 1.26 but not done.

Change-Id: Id5e41003fe47b55f493f636c69c9b31932cde9b8
2016-01-18 17:22:58 +00:00
IoannisKydonis
27769e3fe4 Remove ParserOutput::hasCustomDataUpdates()
Deprecated since 1.25, slated for removal in 1.26 but not done.

Change-Id: Ia198c3b5a55c794cfdd8a5e93521aff85468ff88
2016-01-17 12:58:57 +00:00
Timo Tijhof
afcfc3290c resourceloader: Consistently refer to the framework as ResourceLoader
Change-Id: Ia59e4eac9662723e80d62f7cfcb9e4292e3ee4de
2015-10-28 03:24:40 +00:00
daniel
d034329764 Clarify that ParserOutput::getDisplayTitle() returns HTML.
This change only improves documentation, it does not touch code.

For reference:
* CoreParserFunctions::displaytitle generates HTML, with &, < and so on
property escaped. OutputPage::setPageTitle() treats the input as wikitext,
which works for both plain text and HTML.

* Wikibase calls ParserOutput::setDisplayTitle() with HTML including <span>
structures.

In the API action=query&prop=pageprops returns HTML. There doesn't seem to
be a good place to document that fact, though.

Change-Id: I043b26b82f066abe2830a81d3bc073543b3748d8
2015-10-16 20:03:33 +02:00
Amir E. Aharoni
4841ede9c3 Rewrite comments on member variables of ParserOutput as proper variables documentation
This also makes lines short enough to pass phpcs.

Bug: T102614
Change-Id: I11597bc052e8a8c2eaf4d60f7913e4186d0eb8e2
2015-09-28 11:22:23 +00:00
daniel
053e968f3c Add comments clarifying how calling getters on ParserOutput affects the parser cache.
Change-Id: Ie6a4a8989df218f88cfc7c1cf1d4b68cf871abbb
2015-08-28 07:59:33 +00: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