Commit graph

556 commits

Author SHA1 Message Date
Brad Jorsch
e1b2dd4720 API: Filter lists of IDs before sending them to the database
People apparently have a tendency to typo the IDs somehow, and if you
hand MySQL a stringified integer in a list that is out of range it
decides it can't use sensible indexes.

Bug: T140302
Change-Id: Ic1975220e55cb9daa16127ec0540e7ad16aad44e
2018-12-04 08:57:57 +00:00
jenkins-bot
d2b7662bba Merge "Add stats for block errors on create/edit actions" 2018-11-29 01:04:38 +00:00
Dayllan Maza
b89342ffdd Add stats for block errors on create/edit actions
Monitoring block errors is behind $wgEnableBlockNoticeStats
and it is disabled by default.

The reason behind this metric is to get an idea on how
frequently blocked users attempt to edit a page. Similar tracking
is being added to MobileFrontend and VisualEditor.

Depends-On: I6bd1c95548616677e1f72ba6bcfc6f2b551c1ca6
Bug: T201717
Change-Id: I18bdb5ce61509ba3c2cea9aa6247656b9bd388e0
2018-11-28 06:34:35 +00:00
James D. Forrester
903e8b63de doc: Modernise parameter names and documentation for 'replica' DBs
Non-breaking change. Remaining uses are public interfaces (a constant, two
globals, a config sub-parameter, SQL queries, storage function names), one i18n
message key, and a whole lot of maintenance scripts with calls to the deprecated
function wfWaitForSlaves().

Change-Id: I6ee5ca92ccf6a80c08f53d9efe38ebb4b05064d7
2018-10-31 10:36:48 -07:00
Brad Jorsch
afe9a0fa5b Remove use of old API doc methods
The following deprecated methods, intended for overriding by extensions,
are no longer called and are hard deprecated.

* ApiBase::getDescription() (deprecated in 1.25)
* ApiBase::getParamDescription() (deprecated in 1.25)
* ApiBase::getExamples() (deprecated in 1.25)
* ApiBase::getDescriptionMessage() (deprecated in 1.30)

Also, the 'APIGetDescription' and 'APIGetParamDescription' hooks have
been removed, as their only use was to allow extensions to override
values returned by getDescription() and getParamDescription(),
respectively.

Change-Id: I486c4ccab4eca6a85cb17c30dbb2439876123ba1
2018-10-29 14:58:19 -07:00
Dayllan Maza
d67121f6d3 Enforce partial blocks
Enforce partial blocks and display a slightly different block
notice depending on if the block is sitewide or not

Bug: T197117
Depends-On: I675316dddf272fd0d6172ecad3882160752bf780
Change-Id: I8a3635a4a04a33912eb139b7b13c4bd874183d31
2018-10-24 00:57:48 +00:00
Brad Jorsch
6ff65e57bb API: Remove long-deprecated methods (and one class)
* ApiBase::profileIn() (deprecated in 1.25)
* ApiBase::profileOut() (deprecated in 1.25)
* ApiBase::safeProfileOut() (deprecated in 1.25)
* ApiBase::profileDBIn() (deprecated in 1.25)
* ApiBase::profileDBOut() (deprecated in 1.25)
* ApiBase::dieUsage() (deprecated in 1.29)
* ApiBase::dieUsageMsg() (deprecated in 1.29)
* ApiBase::dieUsageMsgOrDebug() (deprecated in 1.29)
* ApiBase::getErrorFromStatus() (deprecated in 1.29)
* ApiBase::parseMsg() (deprecated in 1.29)
* ApiBase::setWarning() (deprecated in 1.29)
* ApiPageSet::getInvalidTitles() (deprecated in 1.26)
* ApiQueryLogEvents::addLogParams() (deprecated in 1.25)
* ApiUsageException::getCodeString() (deprecated in 1.29)
* ApiUsageException::getMessageArray() (deprecated in 1.29)
* UsageException (deprecated in 1.29)

Change-Id: Iabb2589a29cc3b46624d31358f3a6bf7b3ccbd57
2018-10-15 16:37:04 -04:00
Brad Jorsch
0fdbc9890f Hard-deprecate hooks APIGetDescription and APIGetParamDescription
Deprecated since MW 1.25.

Change-Id: Idf376b64490eaf8cf5a1b5c3a807fe74b3c2852c
Depends-On: I0bc394f11fda5f0118904756b99f1681897cd6fd
2018-10-10 13:59:27 -04: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
Brad Jorsch
c72a5e5ef4 ApiBase: Use prefixed parameter name for 'missingparam' error
Similar errors use the prefixed parameter name, this one should too.

Bug: T200155
Change-Id: Ia14d6a9c457af06e72428c1eae14bd3849b4595a
2018-07-23 11:44:09 -04:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Max Semenik
b6e13c7e6e Hard-deprecate ApiBase::profile{In|Out}()
The only remaining calls are getting removed in I37641dee50a.

Change-Id: I3ee698781a4698d1ef8e74209b82fb1f984fb8e9
2018-06-28 13:57:46 -07:00
Max Semenik
8085c58a4b Replace call_user_func_array(), part 1
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.

Change-Id: Idcec077ef3fdf029b632cceafd0150851ad723e3
2018-06-04 23:39:04 -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
Brad Jorsch
24be43b9aa API: ApiBase::getParameter() shouldn't throw on other params' errors
This regression was introduced in Ia19a1617b7.

Bug: T195777
Change-Id: I1e1eb3861ced83f79e56d2325ab693ef4e393999
2018-05-28 18:45:24 -04:00
Brad Jorsch
a1cec32953 API: Raise an error when too many values are passed
Since 2008 the API has truncated with a warning when too many values are
passed to a multi-valued parameter. It's long past time to make this an
error.

Bug: T41936
Change-Id: I0f9efbdf9230373fa0c175a7fcacbca68225cf40
2018-05-21 18:46:43 -04:00
Brad Jorsch
91c385e138 API: Use User::getCanonicalName() when validating user names
This is a bit more interoperable than trying to roll our own by using
Title::makeTitleSafe().

We still need to handle IP addresses separately, of course.

Bug: T194916
Change-Id: Ie3900d768cbe15aef079b97d91f7fd23dc7c3e26
2018-05-18 11:59:04 +02: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
jenkins-bot
e9edf8e6ac Merge "Improve test coverage for ApiBase.php" 2018-04-10 18:46:34 +00:00
jenkins-bot
579319d960 Merge "Improve test coverage for ApiMain.php" 2018-04-10 17:03:47 +00:00
Aryeh Gregor
be391449ae Improve test coverage for ApiMain.php
One bug fixed: if ApiCheckCanExecute returned false but didn't set
$message, we would try to output a message of false, which would throw
an exception.

Change-Id: Ib06970e280d750ff57d81672f1b365167b93aa3e
2018-04-08 21:15:37 +03:00
Aryeh Gregor
d3da5e08d3 Improve test coverage for ApiBase.php
One bug fixed: a timestamp of '00' or similar would get interpreted as
'now' by mistake instead of Unix timestamp 0, without throwing the
warning for using 0 instead of 'now'.  This is because it called
wfTimestamp() once to parse the input date, got a Unix timestamp of 0
back, and then tried passing that 0 back to wfTimestamp again to
reformat as a wiki date, but it got reinterpreted as 'now'.

Also fixed parameters with type "user" to validate usernames more
correctly.  This might be risky, though, if I missed any valid
usernames, or if API clients were for some reason relying on passing in
invalid usernames.  If we don't actually want to do this, we should add
a comment explaining why we're allowing any title without a fragment
rather than validating properly.

Still lots more work to do here.

Change-Id: I56b4290263df8698efdbddda71a7eabd9e303abc
2018-04-08 15:51:42 +03:00
Jayprakash12345
64b146e55a Remove deprecated function ApiBase::getProfileTime
Bug: T189330
Change-Id: I404766b53ad33d615557faa693a513914d959a63
2018-04-06 17:53:38 -07:00
Jayprakash12345
80f787fba3 Remove deprecated function ApiBase::getModuleProfileName
Bug: T189330
Change-Id: Ifa30d115b97e8109d11cb932a924d63afc6f81d9
2018-04-06 17:53:38 -07:00
Jayprakash12345
3f1230e9ec Remove deprecated function ApiBase::getProfileDBTime
Bug: T189330
Change-Id: I7584024dff54608b138a7fbaced216ff9133ac2c
2018-04-06 17:53:38 -07:00
Kunal Mehta
2d5c742db3 Use SPDX 3.0 license identifier
SPDX released version 3 of their license list (<https://spdx.org/licenses/>),
which changed the FSF licenses to explicitly end in -only or -or-later
instead of relying on an easy to miss + symbol.

Bug: T183858
Change-Id: I4cbb98ea2bbacf46a57401dbba2bdb076fca1d3a
2018-03-18 18:08:22 +00:00
Brad Jorsch
4c7b35105c Allow querying contributions of interwiki usernames
Both for Special:Contributions and ApiQueryUserContributions.

Bug: T187079
Change-Id: I4398e473b90172851e875b3f219f7076dceda66c
2018-03-06 13:28:30 -05:00
Umherirrender
63d96c15fd build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
Change-Id: I59b59f79bbf3ce4feff3b3a20c1c31bc16370531
2018-02-17 13:29:13 +01:00
jenkins-bot
4eff5204d9 Merge "API: Allow to pass whitespaces in MultiValue" 2018-01-29 15:31:43 +00:00
Fomafix
b8f97035ce API: Allow to pass whitespaces in MultiValue
This allows to response with an invalidreason instead silently ignore
the parameter.

Example request: api.php?format=json&action=query&titles=%20

Response before this change:
{
  "batchcomplete": ""
}

Response with this change:
{
  "batchcomplete": "",
  "query": {
    "pages": {
      "-1": {
        "title": " ",
        "invalidreason": "The requested page title is empty or contains only the name of a namespace.",
        "invalid": ""
      }
    }
  }
}

Bug: T185846
Change-Id: I6fdaf32792a0e6e37b08176f975c10607093351b
2018-01-28 19:05:07 +01: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
a18476eab3 Merge "Remove @param comments that literally repeat what the code says" 2018-01-11 23:48:03 +00:00
Lucas Werkmeister
0fe95a7d55 Improve PARAM_HELP_MSG_PER_VALUE documentation
Per-value documentation is only generated if this option is specified,
even if it is only set to an empty array (i. e., when using the default
key for all values). Attempt to make this more clear.

Change-Id: I844df226271aadb1f06b3cc00ba32cc6c06ec76a
2018-01-11 18:07:26 +01:00
Thiemo Mättig
ef470ebf7f Remove @param comments that literally repeat what the code says
These comments do not add anything. I argue they are worse than having
no comments, because I have to read them first to understand they
actually don't explain anything. Removing them makes room for actual
improvements in the future (if needed).

Change-Id: Iee70aad681b3385e9af282d5581c10addbb91ac4
2018-01-10 14:14:26 +01: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
59ce3456a8 SECURITY: Fix rebase error in 4d38a489
The fix for T125177 from F4932228 was incorrectly rebased when it was
applied to master as 4d38a489, causing the bug to not actually be fixed.

Bug: T180488
Change-Id: Ie6b87ef2373369987c112c19903c99afb789c1ff
2017-11-15 03:21:54 +00:00
Addshore
2781a0c1e0 Revert "Remove some remaining mentions of unstubbing from core"
This reverts commit 0f91e75c20.

Bug: T177478
Change-Id: I1937bd116d22479c38a9a34714c2090e2a4c0d7e
2017-10-05 17:27:08 +00:00
Chad Horohoe
0f91e75c20 Remove some remaining mentions of unstubbing from core
Change-Id: Ife34335db7afd9bd4f0936cb90be227d7c4c9651
2017-10-03 23:01:43 +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
Umherirrender
ace44e2064 Use correct variable name in @param documentation
For some varargs a variable name is added with suffix ,... as seen for
many other varargs

Some @param are swapped, because there are in the wrong order

Enable Sniff MediaWiki.Commenting.FunctionComment.ParamNameNoMatch

Change-Id: I60fec6025bce824d5c67563ab7b65ad6cd628ad8
2017-08-11 19:27:19 +02:00
Umherirrender
a9007e8baf Add missing & to @param documentation to match functon call
Change-Id: I81e68310abcbc59964b22e0e74842d509f6b1fb9
2017-08-11 18:47:46 +02:00
jenkins-bot
fb79f30319 Merge "Fix and make some types in PHPDoc and JSDoc tags more specific" 2017-08-05 22:08:00 +00:00
Thiemo Mättig
c785efd25e Fix and make some types in PHPDoc and JSDoc tags more specific
Change-Id: I7c109067579f570ecccaabc75b0b4db7eac4e6c2
2017-08-05 18:46:44 +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
jenkins-bot
f4a53c5406 Merge "API: Add deprecation warnings for Iae0e2ce3" 2017-07-21 21:12:10 +00:00
Matthew Flaschen
27b14fb898 Clarify what $params is for ApiBase methods to get Title/WikiPage
Change-Id: I1bfae270072ba08db967a02a8e30047bc607e3a2
2017-07-06 20:01:54 -04:00
Umherirrender
b5cddfb27b Remove empty lines at begin of function, if, foreach, switch
Organize phpcs.xml a bit

Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
2017-07-01 11:34:16 +00:00
Brad Jorsch
efaaa2c1d6 API: Add deprecation warnings for Iae0e2ce3
Change-Id: Ib0c9d5a18803b406a1266eb24238536d122ff6e7
2017-06-22 13:21:08 -04: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