Commit graph

283 commits

Author SHA1 Message Date
James D. Forrester
9be9e77b51 build: Upgrade mediawiki-codesniffer from 26.0.0 to 28.0.0
Newly-disabled general rules:
* MediaWiki.Commenting.FunctionComment.MissingSplatVariadicArg
* MediaWiki.Commenting.FunctionComment.SuperfluousVariadicArgComment
* MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedException
* MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedExceptionMessage
* MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedExceptionMessageRegExp
* MediaWiki.Usage.NullableType.PHP71NullableStyle
* MediaWiki.Usage.PHPUnitTypeHints.MissingTypehint
* PSR12.Files.ImportStatement.LeadingSlash
* PSR12.Properties.ConstantVisibility.NotFound

Change-Id: Ifcf8c6d5fecc47a32741114b5a5b746a41510045
2019-10-11 10:05:43 -07:00
Umherirrender
f74400487f phan: Disable enable_class_alias_support
It is enabled for b/c in extensions, but not needed in core

Change-Id: I51dca12be9c77049f77563d9bf0edd07928c2300
2019-09-15 08:26:52 +00:00
Daimona Eaytoy
c659bc6308 Unsuppress another phan issue (part 7)
Bug: T231636
Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9
Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0
Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8
2019-09-03 17:19:21 +00:00
Derick Alangi
339211a1ea Avoid usage of deprecated Revision::* constants, use RevisionRecord
Change-Id: I872fc89e5c02dd6a3ae9cd7e76640b95dc33f514
2019-07-21 15:03:03 +01:00
Aryeh Gregor
e6df285854 Remove all $wgParser use from core
Bug: T160811

Change-Id: I0556c04d33386d0339e02e2bf7a1ee74d97c2abd
2019-04-17 15:16:50 +03:00
Thiemo Kreuz
d1a497a9f4 Avoid a few overly complicated is_null() checks
We can use the ?? syntax introduced with PHP 7.0 because it is already
supported by HHVM, even when HHVM is set to be compatible with PHP 5.6.

This was inspired by Ib117e05.

Change-Id: If980839fe6f86f2b4e86bbe99905a796e4708c7c
2019-03-11 10:29:20 +01:00
Timo Tijhof
c6f3440832 resourceloader: Remove addModuleScripts, and deprecate getModuleScripts.
The addModuleScripts() methods were deprecated in 1.31 and 1.32,
these are now removed.

The getModuleScripts() are now deprecated as well, always returning
an empty array. To be removed in 1.34.

Depends on commits for bundled/wmf-deployed extensions that
remove the last few remaining callers to the deprecated functions
in: 3D, Collection, Flow, GlobalUserPage, and Wikibase.

Bug: T188689
Depends-On: If9f0bc6aef85117587fa1929f34f8861c8d80314
Depends-On: Ia8d41b97fbf6822f5f8f7ac889408acce1ac9a3a
Depends-On: I503b919739ea474ff33726815b0da55e2f7e2724
Depends-On: I236ef637fd03b810a46eb361e25067a037e9d183
Depends-On: I62e17779753b977a452cc0c9694947941e999cc3
Change-Id: I5a19b8f164ccf666485d2971202194b747f882df
2019-03-05 16:54:08 +00:00
Reedy
4691389fa4 Use (int) rather than intval()
Bug: T216969
Change-Id: I4c06716c83b69d128f26fa7f68736808aa2d3d64
2019-02-25 00:38:33 +00:00
Bill Pirkle
d993f499ee Refactor calls to deprecated function Content::getNativeData()
Function Content::getNativeData() was deprecated.  Replace with
calls to new function TextContent::getText() in most places.

Bug: T155582
Change-Id: I2bd508c72aac4faf474ba45ab1f92e2e8d2eb9be
2019-02-15 17:48:01 +00:00
Alangi Derick
b4ecf374fe Fix PHPDoc type for instance variables and methods
Should be "string" not "String" and "array" not "Array" in
@param, @return and @var use cases. Also, minor typo fixes.

Change-Id: I9d5ebc5b741c6560907b95f7c0c4039da2861f4a
2018-10-21 13:00:25 +01:00
C. Scott Ananian
eb351597e4 Deprecate the 'disabletidy' parameter for ApiParse
This will be unsupported by future wikitext parsers, which always
construct well-formed HTML.

Bug: T198214
Change-Id: Ic189cd1b38bca5b9ec0ef9810555fe0cbd8b733d
2018-09-24 17:40:51 -04: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
Kunal Mehta
c4e5a9dd97 Avoid deprecated LinkCache::singleton()
Change-Id: Ie0e5c4ef0fe6ec896378bb2433af0898655dd907
2018-06-10 23:55:11 -07:00
jdlrobson
a01d8be82c Skins: getDefaultStyles can now define render blocking CSS
This optimisation attempts to minimise loading the styles in places
they are not needed.

The logic is kept inside Skin::getDefaultModules to avoid fragmentation
of where modules get defined.

Update ApiParse to avoid repetition of code.

Bug: T42792
Bug: T42812
Change-Id: I59f02a7bab3baa9d43f6bc2ef1f549d9d31d8456
2018-04-26 13:00:19 -07:00
Brad Jorsch
3f1142045f Generalize ResourceLoader 'excludepage' functionality
There has long been a hack for previewing edits to user JS/CSS, where
OutputPage would pass an 'excludepage' parameter to
ResourceLoaderUserModule to tell it not to load one particular page and
would instead embed that page statically. That's nice, but there are
other places where we could use the same thing.

This patch generalizes it:
* DerivativeResourceLoaderContext may now contain a callback for mapping
  titles to replacement Content objects.
* ResourceLoaderWikiModule::getContent() uses the overrides, and
  requests embedding when they're used. All subclasses in Gerrit should
  pick it up automatically.
* OutputPage gains methods for callers to add to the override mapping,
  which it passes on to RL. It loses a bunch of the special casing it
  had for the 'user' and 'user.styles' modules.
* EditPage sets the overrides on OutputPage when doing the preview, as
  does ApiParse for prop=headhtml. TemplateSandbox does too in I83fa0856.
* OutputPage::userCanPreview() gets less specific to editing user CSS
  and JS, since RL now handles the embedding based on the actual
  modules' dependencies and EditPage only requests it on preview.

ApiParse also gets a new hook to support TemplateSandbox's API
integration (used in I83fa0856).

Bug: T112474
Change-Id: Ib9d2ce42931c1de8372e231314a1f672d7e2ac0e
2018-04-25 00:37:08 +00:00
Aryeh Gregor
84db63aa6f Improve test coverage for ApiParse
Also removed a sketchy-looking usage of ?: with a string in
ApiParse.php.  In this case I think it was fine, because it would only
cause a bug if a page's display title was '0' but its actual title was
not '0', which is only possible if $wgRestrictDisplayTitle is false,
which is broken by design anyway and I don't think is worth testing.
But ?: used for something that should be interpreted as a string is
generally not a good idea.

One bug fixed: an error message that used an undefined variable.

Depends-On: Id0e6184aff8f9d7e8f32558e1de14faa0168cc1d
Change-Id: I0904bff0f9d80892d0db2ebb590c24fb862f2418
2018-04-12 15:59:54 +03: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
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
Umherirrender
c9d303d39e Remove "Created on" from file header comments
It is the job of git and svn to provide this information/metadata.
The form was different, some with short, some with long month name
some with leading zero at the day, some without.
The year is also present in the Copyright clause

Change-Id: If006907b82b9e45f13cfa2e45d41107a95570e1a
2018-01-26 23:12:40 +00: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
Timo Tijhof
d5ed2785fb API: Include setupSkinUserCss in prop=modules for useskin mode
Follows-up 90c95fc7f2, which included result of Skin::getDefaultModules
in the prop=modules list. All hardcoded modules in OutputPage and Parser
were also subsequently moved into Skin::getDefaultModules.

However, a number of modules cannot be moved there because fundamentally
Skin::getDefaultModules can only load modules via OutputPage::addModules().

For style modules, addModuleStyles() must be used.

Fortunately, there is already a centralised place for that, namely
Skin::setupSkinUserCss(). Include that in the ApiParse return as well.
That should resolve the last bit of inconsistency between ApiParse
and OutputPage when it comes to the module queue.

Bug: T140664
Change-Id: I35e2e3bbdccdd1aa2a259b8e624daa80c609ba8c
2017-10-25 02:16:01 +01:00
Arlo Breault
af3bd08fb8 API: Pass revid when parsing text
* Provides consistency with expandtemplates
 * Necessary for properly rendering `text` with {{REVISIONID}}

Change-Id: I310d0778d74c46f15385cd411d2462b541ed339a
2017-09-18 14:33:47 -04:00
Brad Jorsch
e2c949677e API: Add the ability to flag parameter values as deprecated
This has a number of implications:
* A deprecation warning is automatically generated if the value is used.
* action=paraminfo can list it in a machine-readable manner.
* It is automatically flagged in the help when message-per-value mode is
  used.
* In values lists in the help, it's specially marked (currently
  strike-through).
* ApiSandbox will mark it in the widgets (currently strike-through).

Deprecation of submodules is not automatically detected here, that's
left for a later patch.

Bug: T123931
Change-Id: Idad6377063e457f9352a99df5c7cc15b1563579e
2017-06-20 11:41:26 -04:00
Brad Jorsch
2775de01c8 ApiParse: Fetch content with parsetree
I0079e10a assumed callers were correctly passing $getContent to
getParsedContent(). Apparently they weren't.

Bug: T167826
Change-Id: I85cbdfb5d0580252c1df23a0f27c8052f1d65dc3
2017-06-13 15:42:21 -04:00
Brad Jorsch
1e2b3fb37f ApiParse: Clean up parsing code
Now that ParserOptions->isSafeToCache() exists, use it where necessary.
This also moves the use inside the makeParserOptions() method so other
callers can pick it up as well.

Then pass the flag as $forceParse into WikiPage::getParserOutput()
instead of duplicating the logic in several cases, and generally clean
up the logic in the module to let WikiPage decide when to use the cache
in more cases.

Change-Id: I0079e10a40997e4a3b59ac21ef6c92246a147736
2017-06-12 12:34:17 -04:00
Brad Jorsch
5ad73b8aab ApiParse: Use existing OutputPage for prop=categorieshtml
Follows up Iaa85ac49.

This also ensures that the Skin correctly refers back to the constructed
OutputPage even when 'useskin' isn't specified.

Change-Id: I983e907c05acd753733e88904953f355e26f393d
2017-05-25 11:29:04 -04:00
Timo Tijhof
90c95fc7f2 ApiParse: Add Skin::getDefaultModules() in useskin mode
Bug: T130632
Change-Id: Idc41934eb89ec8f928bbea3b2135c3f246fe3925
2017-05-21 19:06:43 +02:00
Timo Tijhof
df5b122641 ApiParse: Add 'useskin' param for general OutputPage/Skin support
Required for Idc41934eb89.

* If 'useskin' is set, run ParserOutput through OutputPage (with proper
  Skin set up). Specifically call addParserOutputMetadata().

  Then use OutputPage isntead of ParserOutput to retrieve that subset
  of meta data. Such as modules, lang links and config vars.

* Deprecate 'effectivelanglinks' in favour of 'useskin'.

* Simplify 'headhtml' support and re-use this new code.

Change-Id: Iaa85ac49f6e0cbdf7f1bb0f50a8f7730d119f0a2
2017-05-21 19:06:42 +02:00
Brad Jorsch
1aac0a2992 Wrap parser output in <div class="mw-parser-output">
This will allow CSS to target just the parser output, without also
accidentally targeting the edit form, diff tables, and so on.

Bug: T37247
Change-Id: If4eb5bf71f94fa366ec4eddb6964e8f4df6b824a
Depends-On: I330c6aa4aaee045614b1801ed34bc9e03be69650
Depends-On: I52a518fa44e017841fe78474012cd69823e0a41d
2017-05-08 05:32:03 +00:00
Baha
036b9c4167 Make API documentation links language aware
Links generated by the API are now aware of the user's preferred
language and will show documents in that language if available.

To test, log in to mediawiki.org and set your language preference to 'es',
then on an MediaWiki installation with this patch view the generated
expanded API help at `api.php?action=help&recursivesubmodules=1&modules=main`.
Each link to documentation on mediawiki.org should take you to its
translated /es subpage, if one exists.

Bug: T104518
Change-Id: I339a1f3ae1bce9d759cf251899d57c32b1def91e
2017-04-05 11:08:25 -04:00
Baha
2326d420c7 API: Allow returning parse warnings for action=parse
Passing in the 'parsewarnings' property will return warnings related
to parsing content.

Bug: T92634
Change-Id: I7e54765ee9a24ffb78e7763f73a520151023baf6
2017-03-31 13:07:31 -07:00
Brad Jorsch
a90bbf1a48 Add ILocalizedException interface
We already throw around some exceptions that are localized
(ErrorPageError and its subclasses, MalformedTitleException), but
there's no standard way to recognize them. Let's change that.

Then let's use them in the API to be able to have internationalized
errors when such exceptions are caught, instead of wrapping the
English-language version.

Change-Id: Iac7c90f92a889f8de9dae373547c07b884addaea
2016-12-08 13:53:24 -05:00
Brad Jorsch
4e6810e4a2 API: i18n for warnings and errors
API warnings and error messages are currently hard-coded English
strings. This patch changes that.

With a few exceptions, this patch should be compatible with non-updated
extensions:
* The change to ApiBase::$messageMap will blow up anything trying to
  mess with it.
* The changes to the 'ApiCheckCanExecute' hook will cause a wrong
  (probably unparsed) error message to be emitted for extensions not
  already using an ApiMessage. Unless they're currently broken like
  Wikibase.

Bug: T37074
Bug: T47843
Depends-On: Ia2b66b57cd4eaddc30b3ffdd7b97d6ca3e02d898
Depends-On: I2e1bb975bb0045476c03ebe6cdec00259bae22ec
Depends-On: I53987bf87c48f6c00deec17a8e957d24fcc3eaa6
Depends-On: Ibf93a459eb62d30f7c70d20e91ec9faeb80d10ed
Depends-On: I3cf889811f44a15935e454dd42f081164d4a098c
Depends-On: Ieae527de86735ddcba34724730e8730fb277b99b
Depends-On: I535344c29d51521147c2a26c341dae38cec3e931
Change-Id: Iae0e2ce3bd42dd4776a9779664086119ac188412
2016-12-06 10:20:48 -05:00
Brad Jorsch
7c49c10d80 API: Add a 'known' property when missing-but-known titles are output
For example file pages from foreign repos, MediaWiki-namespace messages
that haven't been locally customized, and titles manipulated with the
'TitleIsAlwaysKnown' hook.

This allows clients to be able to display such titles as bluelinks
rather than redlinks.

This also has ApiPageSet populate LinkCache to make later checks of
->exists() and ->isKnown() more efficient.

Bug: T141963
Change-Id: Idbdfd2896c0ce9425ededd7cb4b60eda89ba7ef5
2016-10-11 12:18:08 -04:00
Daniel Kinzler
c18cb7ed15 SECURITY: Check read permission when loading page content in ApiParse.
Prevents leaking page contents for extensions that deny read rights
to certain pages via a userCan hook, but still allow the user to
have read rights in general.

Issue originally reported by Tobias

Bug: T115333
Change-Id: I19f5c2583393794cff802a70af7ccf43c2fed85c
2016-08-22 18:13:01 -07:00
Timo Tijhof
f19050377c ApiParse: Deprecate prop=headitems
This code has been rotting for a while. It is important missing stylesheets
and critical inline scripts. Consuming these items is quite risky.
One can't safely use it to update an existing document (as some parts are
duplicative or conflicting). One also can't use it to build a new document as
several critical pieces are missing.

* Since ResourceLoader was introduced in 2011, buildCssLinksArray() doesn't have any stylesheets.

For most pages, this will produce an empty array for headitems.

Mark it as deprecated since in favour of 'prop=headhtml' or 'prop=modules'.

Change-Id: I6084e4454e245f59bf3c82d6db830977725f71e5
2016-07-28 18:23:26 +01: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
Brad Jorsch
2ecba36c4f API: Generate head items in the context of the given title
$context->getOutput() returns an OutputPage tied to the main
RequestContext at the root of the chain, not to the modified context
we're actually using.

Bug: T139565
Change-Id: Ie086d7f2ad3f7b5f50e3a2f83b1680e760b85e5e
2016-07-07 09:44:45 -04:00
Brad Jorsch
7762a0cab6 Add 'ApiMakeParserOptions' hook
This allows extensions (e.g. TemplateSandbox in I77a9aa5a) to better
interact with the ApiParse and ApiExpandTemplates modules.

Change-Id: I72d5cf8e0b86e4250af1459219dc3b42d7adbbb8
2016-06-20 14:22:53 -04:00
jenkins-bot
2aff530dfb Merge "Use single quotes in API where possible" 2016-03-08 17:03:24 +00:00
Siebrand Mazeland
bc0ae710e3 Use single quotes in API where possible
Change-Id: I972e296f4820f78f5dfcecc27bc4912ca84a3178
2016-03-08 17:27:00 +01:00
Siebrand Mazeland
33ba3bea02 Use Elvis operator where possible in API
Change-Id: I0a26c04cf2ded2c1bd74d8dabd131ae8e20117f3
2016-03-08 16:10:23 +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
addshore
9992e6adb3 Cast numeric cat names back to string in api output
This could be considered a breaking change even
though it unifies behaviour.

Change-Id: Ib6bc7386f689cc6c2812e9e9406f18b20caa8fee
2015-12-03 15:15:59 +01:00
Reedy
32ff1f4c47 Remove various unused variables
Change-Id: I4b1b20b4126735cb32a80e473fe48d523bcb24d1
2015-11-07 21:22:17 +00:00
Brad Jorsch
05ff357a42 API: Log all deprecated parameter uses to api-feature-usage.log
Some were being logged, and some weren't. Let's log them all
automatically when PARAM_DEPRECATED is processed, instead of requiring
each module to manually log them.

Bug: T117569
Change-Id: Ia38aeeccd0b9857b12b28914f509284483fbcca8
2015-11-03 12:23:00 -05:00
Vivek Ghaisas
c54766586a Fix issues identified by SpaceBeforeSingleLineComment sniff
Change-Id: I048ccb1fa260e4b7152ca5f09b053defdd72d8f9
2015-09-26 23:06:52 +00:00
Brad Jorsch
1f12006151 Add @todo comment for I4b0e55fe
In the interest of not blocking other work, I4b0e55fe worked around an
issue locally in ApiParse while filing T110269 for the larger task that
would be needed to properly fix the problem.

This adds a @todo comment referring to that task to make the situation a
bit more clear, since I4b0e55fe was merged too hastily to get the
comment included there.

Change-Id: I5be690aa5316cba1d498358635d497aa465a9972
2015-08-26 09:42:41 -04:00
Tim Starling
3d94c63b90 API: Rename disablepp and introduce disabletidy
* Rename disablepp to disablelimitreport, since it does not disable the
  preprocessor (which is what PP stands for in "NewPP").
* Introduce new option "disabletidy" for T89331
* Suppress the use of the parser cache when options are specified that
  affect the output but are not in ParserOptions::optionsHash(). This
  was already broken, but the damage was fairly limited since the
  options rarely caused user-visible changes. It would break very badly
  if I use the disabletidy option for what I am intending.

Change-Id: I4b0e55fe34e237a68450f583bf59bab7dd703a29
2015-08-26 04:38:34 +00:00