Commit graph

113 commits

Author SHA1 Message Date
Lucas Werkmeister
3983e1af46 Highlight internal modules in API help and sandbox
This mostly mirrors the existing handling for deprecated modules. In
lists, internal modules are ordered after deprecated ones, with
deprecated internal modules at the very end.

action=paraminfo gains an array of internalvalues analogous to
deprecatedvalues. Help messages for internal modules are prefixed with
the text “Internal”. The help page and API sandbox styles color internal
values in red, just like deprecated values (and matching the existing
style for the “this module is internal or unstable” warning in the help
page), but do not add a strikethrough.

Bug: T185508
Change-Id: I5dfc3bacbc070d74f467eb1a4042cab159aa28ec
2019-10-11 16:30:16 +02:00
Brad Jorsch
bba1a0f2f9 API: Warn about POST without Content-Type
HHVM sniffs the content type and so probably correctly guesses
application/x-www-form-urlencoded and fills in $_POST, while PHP 7 does
not sniff and so doesn't fill in $_POST.

Since there are clients that have been expecting the HHVM behavior, give
a warning both to let them know and so we can have some idea of how many
such clients there are.

This also adds any warnings and errors as an HTML comment at the top of
the auto-generated help page, to hopefully make it easier for people
getting that unexpectedly to find out why.

Bug: T230735
Change-Id: I017b7afe808844d74d376f6436894a5a2f525a9f
2019-08-19 13:00:37 -04:00
Timo Tijhof
30565e2491 API: Create a module bundle for 'apipretty' and 'apihelp'
These are both fairly small modules used in related low-traffic
scenarios. The cost of registering both globally on all page views
as a top-level entry point does not seem worth the marginal gain
of loading only one of these two in the contexts where they are
needed.

Change-Id: I42458ebec3f8d6e14e52e44d62fb914fcbeda5db
2019-07-30 01:17:35 +01:00
Kunal Mehta
01541db36b Remove usage of deprecated SkinFactory::getDefaultInstance()
Change-Id: I3bd50f8ca5baabd34dbc0e3bbc2f97e94650a17a
2019-06-02 21:08:07 -04:00
Aryeh Gregor
2e1ac38485 Mass conversion to NamespaceInfo
Change-Id: I2fef157ceec772f304c0923a1cd8c0eef2e82a0f
2019-05-07 22:44:56 +02:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
jenkins-bot
93350da7f1 Merge "Remove loading of module 'mediawiki.toc' in special pages" 2018-12-13 01:57:34 +00:00
Brad Jorsch
46875ad861 API: Set robots noindex,nofollow on HTML output
There's probably not much benefit in search engines indexing the API
auto-generated help or various random "format=jsonfm" outputs.

On Wikimedia wikis we already have a robots.txt entry denying indexing
of everything under /w/, which includes api.php.

Bug: T207818
Change-Id: I196d401eeb5fcf49844265df41ad3cce83ffdcdf
2018-10-25 09:37:30 -04:00
Fomafix
81e773f2f2 Remove loading of module 'mediawiki.toc' in special pages
The module 'mediawiki.toc' is not needed anymore because it is
superseded by the style module 'mediawiki.toc.styles'.

In the skin the module 'mediawiki.toc' may be used by self-build TOCs
from the content.

Change-Id: I53cd6f222c77a1902b89913fe45c92c105dec022
2018-10-20 18:24:04 +02:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
jenkins-bot
56d45558b1 Merge "Hide TOC with CSS instead of JavaScript" 2018-07-11 20:36:22 +00:00
Fomafix
68527cf479 Hide TOC with CSS instead of JavaScript
Changes in the behavior:
* The toggle button generate no FOUC on loading.
* On keyboard navigation the toggle key is the space key and not the
  return key.
* Animation on hide and show is missing. Maybe a new animation with CSS
  can added.
* The state of the button is not saved in a cookie.
* Self-build TOCs can not get hidden.

Browser support:
* The new implementation does not need JavaScript and therefor it works
  on browser with disabled JavaScript and on Grade C browser.
* The new implementation requires the CSS pseudo-class selector
  :checked. Therefor IE8 and lower are not supported.

Risks:
* The new implementation needs additional HTML elements. These elements
  also get cached and crawled. The elements have no content so they get
  hopefully ignored by crawler.
* The new CSS code imitates some styles (link, focus). This must kept
  up to date.
* Multiple TOCs on one page would generate the same id attribute.
  This can avoided by appending a counter or better and easier a random
  string to the id attribute.

Bug: T195053
Change-Id: I82db33d656b3795d7134a91d20ed9d93a3471086
2018-07-09 08:07:52 +02: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
Brad Jorsch
78d1b8ebba API: Introduce "templated parameters"
With MCR coming up, ApiEditPage is going to need to be able to take
"text" and "contentmodel" parameters for each slot-role, and enumerating
such parameters for every possible slot would probably get rather
confusing as to what is required when, or at least long-winded in
repeating the exact same thing for every possible role.

So let's abstract it: we'll have an "editroles" parameter to specify which
slots are being edited, and ApiEditPage will just declare that
"text-{role}" and "contentmodel-{role}" parameters should exist for each
value of "editroles" in the submission.

Note this patch doesn't introduce anything that uses templated
parameters, just the functionality itself. For testing purposes you
might cherry pick I2d658e9a.

Bug: T174032
Change-Id: Ia19a1617b73067bfb1f0f16ccc57d471778b7361
2018-05-16 16:19:31 -04: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
jenkins-bot
9f3bc1fe59 Merge "Add string length limits" 2017-11-21 15:21:26 +00:00
Gergő Tisza
17d001b73a Add string length limits
Adds two new ApiBase::getAllowedParams() keys:
PARAM_MAX_BYTES and PARAM_MAX_CHARS, to set a length
limit for a (string-like) parameter.

This makes it easy to document and enforce database
field length limits (where relying on the database
would either result in unfriendly error messages or
silent truncation, depending on DB settings) and
also exposes them in structured form so API clients
can verify the length without doing roundtrips.

Change-Id: I2e784972d7e11cad79fdef887bbcde297dbd9ce0
2017-11-21 10:24:11 +00:00
Brad Jorsch
c75f0e95c9 SECURITY: API: Avoid some silliness with browser-guessed filenames
If someone is both dumb enough to blindly save an API response and to
then execute the resulting file, this can be used to attack their
computer.

We can mitigate this by disallowing PATH_INFO in api.php URLs (because
we don't make any use of them anyway) and by setting a sensible filename
using a Content-Disposition header so the browser won't go guessing at
the filename based on what is in the URL.

Issue reported by: Abdullah Hussam

Bug: T128209
Change-Id: I8526f5cc506c551edb6138d68450b6acea065e93
2017-11-15 00:58:44 +00:00
Gergő Tisza
5e76403387 Make API multivalue limits configurable
Adds two new parameter settings, ApiBase::PARAM_ISMULTI_LIMIT1
and PARAM_ISMULTI_LIMIT2 for configuring the maximum number of values
that can be contained in a multivalue field (for unprivileged and
apihighlimits users, respectively). When present, these replace the
default 50/500.

Change-Id: Ic1b1bcc7ff556b7762c8d2375d910cc4fcb43087
2017-08-24 02:08:50 +00:00
jenkins-bot
8ddf721b6f Merge "Remove "@author Bryan Davis" and "Brad Jorsch" annotations" 2017-06-27 06:02:23 +00:00
Bryan Davis
aaf1e17088 Remove "@author Bryan Davis" and "Brad Jorsch" annotations
Undo traces of a practice we carried over from past projects and
existing examples that is neither universal nor actively encouraged in
the MediaWiki codebase.

Bug: T139301
Change-Id: I5c9c89b72a45a44aa4264a5e57b003c1a86cdf6e
Co-Authored-By: Brad Jorsch <bjorsch@wikimedia.org>
2017-06-26 15:25:46 -06:00
Brad Jorsch
d4392eaaea API: Display message-per-value style help for submodule parameters
The module's summary will be used as the description of the value.

Since these are often very long lists, this also changes ApiSandbox to
collapse <dl> lists in parameter descriptions by default.

Bug: T123930
Change-Id: I205b68a52a94cae4c1cdf7ec9fd3e8a04d565919
2017-06-20 17:35:51 +00: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
Kunal Mehta
42c91fe7fa ApiHelp: Avoid deprecated ObjectCache::getMainWANInstance()
And switch wfMemcKey() to $cache->makeKey() while we're at it.

Change-Id: I4e37fbe1ddd49cc7583dd0f2f950eaf21c9ef050
2017-05-22 21:37:33 -07: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
Brad Jorsch
47e2bec361 API: Allow finding log events and links to special pages
Log events are sometimes attributed to a special page; it should be
allowed to use rcnamespace or lenamespace to filter for these.

It's also possible for special pages to be the targets of redirects, so
list=allredirects and prop=redirects should find them.

Maybe someday we'll record links to and transclusions of special pages
too (see T19597), so we may as well make it possible to query for those
as well via list=alllinks, list=alltransclusions, list=backlinks,
list=embeddedin, prop=linkshere, prop=transcludedin, prop=links, and
prop=templates.

NS_MEDIA has similar considerations: although we currently "normalize"
page links to the corresponding File and I don't think anything logs the
Media title rather than the File, transclusions and redirects do show
up in those tables.

Bug: T154319
Change-Id: I00348f83855c6c703b6bd6015f6d3bedc5bfd1c5
2017-01-06 13:07:29 -05:00
Max Semenik
d4f3e554d7 Decrease the number of 'function says it should return something' errors
Change-Id: Ib5115fe5bbaa67d8a6e54cc3ba1ba7020e239e11
2016-12-15 16:05:52 -08:00
Andrew H
03d3a5c062 Add PARAM_ALL setting for multi-option API parameters
Adds support for specifying an asterisk '*' instead of a pipe seperated list
of all the allowed options for a multi-option param.

Adds a line to the api help for these parameters.
Adds a "allspecifier" key to ApiParamInfo parameter responses
Enables the default ('*') for parameters of type 'namespace'.

Bug: T124009
Change-Id: I3905bb2516dc1ff982f1beeac3deed6b69446a77
2016-11-22 04:10:38 +00:00
Brad Jorsch
12d7b7a4d7 ApiHelp: Add directionality to various things that are likely English-like
This follows up I28e8e0cb with the other things identified during review
of that patch.

Added dir="ltr" to:
* Module names in the linktrail
* Non-internationalized extension names
* SPDX license tags
* Help URLs
* Parameter names
* Module names in the list of values for a submodule-type parameter
* Value names when using message-per-value documentation
* Example URLs

Added dir="auto" to:
* List of values for enumerated-type parameters
* Default value for parameters

Change-Id: Ie3c08ec604e1796629912fa16e6db4ae3fdce72e
2016-07-26 12:59:17 -04:00
Prateek Saxena
8f9643d8f9 Pass addModuleStyles an array instead of calling it multiple times
Change-Id: Ia359c441714c039c505acd4bd37dd1b52c60b8ea
2016-07-07 10:54:43 +05:30
Amir E. Aharoni
7b76fbfeed Set explicit direction to ApiHelp headers with module names
Bug: T112364
Change-Id: I28e8e0cbbeb0ff0a41a06cb28fbda26d72725e59
2016-04-29 18:06:38 +03:00
Max Semenik
ff4a3287db Switch to external HtmlFormatter
wikimedia/html-formatter is already present in mediawiki/vendor
as of 3954ca36ce3cbedc76c1763ad2694320c1327ce6.

Bug: T125001
Change-Id: Ie98096e5e3d325cde583bc66b21b8b41f2bba8b2
2016-04-13 02:37:59 +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
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
jenkins-bot
74174fca25 Merge "Add logic for "tags" in ApiBase" 2016-02-04 22:01:33 +00:00
victorbarbu
4044a49374 Add logic for "tags" in ApiBase
Bug: T97720
Change-Id: I275c516b4744e243333ec0818d2be1e5508e54a3
2016-02-04 22:30:50 +02:00
Brad Jorsch
f0207e8ca6 Add Special:ApiSandbox
Like Extension:ApiSandbox, but rewritten to use OOJS-UI and to add many
long-requested features.

Bug: T89386
Bug: T92893
Bug: T98457
Bug: T98083
Bug: T89229
Bug: T66008
Bug: T50607
Bug: T47811
Bug: T38875
Bug: T36962
Bug: T34740
Change-Id: Ic42a6c5ef54b811cd63cfef2132942b27a626fe5
Depends-On: I85c0eedcd31a0e419d8055eca0d9cb1ba872ae62
Depends-On: Ic85ff4abbbcd2076ebf5cdfaa0e95e98878e2308
2016-02-03 11:13:59 -05:00
Brad Jorsch
ede1d19076 API: Add support for documenting dynamic parameters
This will be used by AuthManager's API modules to document the fact that
AuthenticationRequest fields are accepted by the module, and to inform
the user reading the documentation how to determine what those are at
any particular time.

Change-Id: Ic7351de0f9bd239db17d584196e52a77112ed978
2016-01-21 10:31:19 -05:00
Kunal Mehta
e0ec23d313 API: Avoid FOUC on help pages
Loading CSS with OutputPage::addModules() causes a FOUC because the
styles are loaded through JavaScript, using addModuleStyles() fixes
this. But it doesn't load module dependencies, so load the
mediawiki.hlist styles explicitly in ApiHelp.

Bug: T117901
Change-Id: I1dfd194d686c05573eefc85d5dfd7ee2731bf286
2016-01-10 22:41:48 -08:00
Reedy
32ff1f4c47 Remove various unused variables
Change-Id: I4b1b20b4126735cb32a80e473fe48d523bcb24d1
2015-11-07 21:22:17 +00:00
Reedy
9335469cf3 Fix casing of function calls in API
Change-Id: I44b343568e5713118c41f29a73e112162dd3e635
2015-11-07 21:10:23 +00:00
Brad Jorsch
eea7d4ff1b ApiHelp: Fix undefined variable warning
Change-Id: I5b2790af9182dd76cd52be284f56e4833ac464c6
2015-11-07 12:55:01 -05:00
S Page
87496302f5 Add example of help for all query submodules
It's useful and shows difference from recursivesubmodules.

Change-Id: I85cb5c89fde0063bbd9dfc86d00c14553035f053
2015-11-04 18:38:28 -08:00
Aaron Schulz
4f781c7bf9 Convert some users to WANObjectCache for consistency
These callers don't need to do purges, but can still perfectly
take advantage of this instance over a plain BagOStuff. Namely:
* Replication and snapshot lag awareness
* Preemptive regeneration
* Easy process cache support

The idea is for there to only be one caching class/factory
to use, instead of having rules for picking which one to use.

Change-Id: I8e362df451c0c28731fc853c044c4c4b8e097f01
2015-10-19 16:46:52 +00:00
Siebrand Mazeland
0fdb0ce284 Fix most PHP CodeSniffer warnings in includes/api
Change-Id: I01bb3e4c96d6034a5b6c18728bb0574c710ea9db
2015-09-28 14:24:52 +02:00
Ricordisamoa
f3874a4a91 Fix rel="copyright" for ApiHelp
Bug: T94038
Bug: T93995
Change-Id: I06e9bb6797c4e4ee00e5d72eda1e273800b2c7f4
2015-06-13 01:53:40 +02:00
Brad Jorsch
df80f1ead5 API: Add more parameter types and improve info
New types 'text' and 'password' for where a <textarea> or
<input type="password"> would be preferred over <input type="text">.

Some timestamp parameters get actually tagged as 'timestamp'.

'submodule' types change the 'submodules' output property from a boolean
to an object indicating the mapping from values to module paths. And
they get an indication of the submodule parameter prefix (e.g.
generator's "g"), if applicable. "generator" actually gets reported as a
submodule type, using this new mechanism.

action=paraminfo will now indicate ApiBase::PARAM_RANGE_ENFORCE status,
and return better-formatted defaults for timestamps and booleans.

Change-Id: Ic862d6f8fe13f7eb6b4298683514d33af5823e47
2015-05-29 19:26:44 +00:00
Brad Jorsch
fcb2e7a336 ApiHelp: Fix undefined array index reference
Follows up I0219689.

Change-Id: I833d8eab49a7093872a66c3bb0d314f6c7adb98c
2015-05-07 12:21:27 -04:00
Brad Jorsch
dc15ea106a ApiHelp: Make 'toc' parameter work
Bug: T98378
Change-Id: I0219689f621e325fc22f0eab6e4c000e1b2fa06f
2015-05-06 13:37:41 -04:00
Brad Jorsch
c4ba6f9ecf API: Document parameter types
Two things here:
* Identify the parameter types when they're not simple strings (or
  already identified).
* Add a section to the 'main' module documentation that describes
  booleans and timestamp formats.

Bug: T93982
Bug: T47652
Change-Id: I67da4f4c026616eed5669256b208b03350e756c0
2015-04-16 23:29:00 +00:00