Commit graph

127 commits

Author SHA1 Message Date
MusikAnimal
6a898faed2 Add watchlist expiry support to applicable APIs
This introduces an ApiWatchlistTrait that refactors out common code
across APIs that allow you to watch pages. Some methods have been
migrated from ApiBase and changed completely, but codesearch suggests
they aren't being used outside the API modules in this patch.

Bug: T248512
Bug: T248514
Change-Id: Ia18627b9824dca81f44f0571e8420d89b7626cf6
2020-07-13 18:18:15 -04:00
Tim Starling
a06e3d06b1 Fix some PHPStorm inspection warnings in includes/api
Notably:
* In ApiManageTags, I used a switch instead of a dynamic function name,
  so that the call graph will be correct.
* In ApiImageRotate, checkTitleUserPermissions() has always returned
  void, this was an error introduced in 4e6810e4a2

Change-Id: Iea22616b8e7e2e0cc804619a54f8690898b2cb82
2020-02-18 14:17:37 -05:00
Umherirrender
6b8a2a75ee Avoid multiply calls to MediaWikiServices::getInstance() in one function
RepoGroup::singleton() results in
MediaWikiServices::getInstance()->getRepoGroup()

Also avoid getting the service in loops, doing it once before the loop
is cheaper

Change-Id: I29e0c7487e3e498559ff16a567e2fad0c0f8bb69
2019-09-01 20:49:19 +02:00
Derick Alangi
52a21ace03 Fix method/function names case mismatch in core files
PHP doesn't care much but I think we humans do because we should
call methods by the name we give them. Method fixed are;

- isOk() -> isOK()
- setOk() -> setOK()
- teardown() -> tearDown()

Change-Id: I6b3f0cf3902887058efa426968da380803869e0b
2019-08-31 23:17:51 +00:00
jenkins-bot
36fdf484e9 Merge "Replace User::isAllowed with PermissionManager." 2019-08-21 08:00:33 +00:00
Petr Pchelko
1d286560d2 Replace User::isAllowed with PermissionManager.
Covers root includes, actions, api, block, changes,
changetags, diff and PermissionManager itself.

Bug: T220191
Change-Id: Ic027d32f5dd8f4c74865df0c8a9fcf91123c889c
2019-08-20 14:43:51 -07:00
Aryeh Gregor
8ec24b607a Introduce MovePageFactory
This will help make MovePage more testable.

In the course of abstracting the logic out of ParserFactoryTest to
FactoryArgTestTrait so it could be used in MovePageFactoryTest, I made
them all unit tests instead of integration. This required some
modification to the Parser constructor so that it didn't access
MediaWikiServices unnecessarily.

Change-Id: Idaa1633f32dfedfa37516bb9180cfcfbe7ca31aa
2019-08-19 20:25:31 +03:00
Derick Alangi
21e2d71560 Replace some uses of deprecated wfFindFile() and wfLocalFile()
These global functions were deprecated in 1.34 and services made
available to replace them. See services below;

* wfFindFile() - MediaWikiServices::getInstance()->getRepoGroup()->findFile()
* wfLocalFind() - MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->newFile()

NOTES:

* wfFindFile() and wfLocalFind() usages in tests have been ignored
  in this change per @Timo's comments about state of objects.

* includes/upload/UploadBase.php also maintained for now as it causes
  some failures I don't fully understand, will investigate and handle
  it in a follow up patch.

* Also, includes/MovePage.php

Change-Id: I9437494de003f40fbe591321da7b42d16bb732d6
2019-06-11 13:26:37 +00:00
Aryeh Gregor
9510dbc4ce Introduce MovePage::moveSubpages(IfAllowed)
Title::moveSubpages() is now deprecated, and the one caller in core and
extensions was ported.

Change-Id: Ic1dc5a6f1a1bef89a35c13f0a72f6740c6a01c50
2019-05-22 14:44:27 -05:00
Brad Jorsch
c073e531cf API: Spread autoblocks from action=edit and action=move
The code in EditPage and SpecialMovepage does this primarily in web UI
code paths that aren't called by the API. EditPage also has a check in
the internal code path used by the API, but ApiEditPage runs its own
permissions check first and won't reach that code path.

Bug: T216245
Change-Id: I6263c8b60a24f3195dba583463f1ce4b004f82f5
2019-02-19 17:34:48 -05:00
Aryeh Gregor
80c7158f06 Test ApiMove
One bug caught: the watch and unwatch params were not being honored.
They have now been removed.

Depends-On: Ia21a974f2b463afc9324182137b95c80db86a6aa
Change-Id: I0e214339c9ae3f0fb5a40c88a84190bc32503151
2018-04-15 14:13:08 +03: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
Kunal Mehta
844d724621 Avoid using deprecated Title::canTalk()
Change-Id: Ibd224f9de595435524e683262882c9ebf2761abf
2017-08-29 12:36: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
James D. Forrester
50e796e948 includes/api: Replace implicitly-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: I49e2a10350a328a8572fcedd44012751a29e1068
2017-02-24 16:41:47 +00:00
This, that and the other
f3f2df07ec Add parameter to API modules to apply change tags to log entries
Adds support for tagging log entries for the block, import,
managetags, and move API modules, using a 'tags' parameter.

Bug: T97720
Change-Id: I9d75d2cece317a7704c4bc6d734ad3cafe24544e
2017-01-12 16:30:17 -06:00
Brad Jorsch
4900ff27c0 ApiMove: Fix fatal when attempting to move to a namespace with no talkpages
The move will probably error out anyway, but we want it to do so
properly instead of by throwing a PHP fatal.

Bug: T153693
Change-Id: I19334a28a3f539e0f3d3866353093711f68786ee
2016-12-19 19:21:09 +00: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
8a00ddbf35 SECURITY: Rate limit moves via the API
While rate limiting has been applied to moves via the web UI since rate
limiting was first added, it appears that it was overlooked when ApiMove
was created.

This follows the same model as is followed by the web UI: each
submission to ApiMove is one "hit" for the rate limiter, even though
that submission might result in multiple pages being moved (e.g. the
page, its talk page, and its subpages) depending on the options and user
rights.

Bug: T132874
Change-Id: I564d8bfcc7dd3ad6d92dbbc33519a589697c0d4e

Signed-off-by: Chad Horohoe <chadh@wikimedia.org>
2016-05-20 09:49:33 -07: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
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
Aaron Schulz
9bba2d169e Added wfTransactionalTimeLimit() method and applied it
* Potentially long running POST requests often use multiple transactions,
  talk to multiple services, or defer updates. Try to make sure they have
  a chance to complete all of the work. WMF already sets ignore_user_abort()
  across the board in config, but this applies it to key spots for all
  installs, in addition to bumping the time limit. 
* Eventually this can lower the need for high overall time limits.

Bug: T102890
Change-Id: I893ddd773064dcd63b5b24c84c6391974f4b5aee
2015-08-12 22:09:40 +00:00
Brad Jorsch
beab6b009e Change API result data structure to be cleaner in new formats
Nothing in this patch should result in changed output for format=json or
format=php except as noted in RELEASE-NOTES-1.25, and changed output for
format=xml should be similar or cosmetic. However, other code accessing
the result data directly may need to be updated.

Bug: T87053
Bug: T12887
Change-Id: I3500708965cb8869b5aed1543381aad208dadd13
2015-04-20 17:49:37 -04:00
Brad Jorsch
1c57794e37 API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.

ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.

So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
  arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
  Formatters are responsible for stripping it if necessary. "raw mode"
  is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
  question, and so on.
* New class for formatting warnings and errors using i18n messages, and
  support for multiple errors and a more machine-readable format for
  warnings. For the moment, though, the actual output will not be changing
  yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
  between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
  modules currently returning booleans will need to use
  ApiResult::META_BC_BOOLS to preserve their current output.

Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.

Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2015-04-10 16:57:15 -04:00
Brad Jorsch
56a12f8b57 API: Check suppressredirect right in ApiMove
Change Ic5026384 accidentally lost the check when changing from
Title::moveTo (which does the check itself) to MovePage::move (which
doesn't).

Bug: T75985
Change-Id: Ia64a233936c639a6748488e4d25816e87658ffe1
2014-11-26 14:43:58 -05:00
jenkins-bot
a75e07ccf5 Merge "Fully replace Title::moveTo() with MovePage" 2014-10-30 20:06:27 +00:00
Brad Jorsch
f62bc7536e API: Fix access on getExamplesMessages
ApiBase declares it protected, but for some reason I had made it public
in all subclasses.

Change-Id: I8a50d4f47e66c7f09137968d3941dc5cdc1d28e4
2014-10-29 11:15:27 -04:00
Kunal Mehta
ac53e45035 Fully replace Title::moveTo() with MovePage
* AbortMove hook is removed in favor of two more specificly focused
  hooks: MovePageCheckPermissions and MovePageIsValidMove.
** MovePageIsValidMove is for extensions to specify whether a page
   cannot be moved for technical reasons, and should not be
   overridden.
** MovePageCheckPermissions is for checking whether the given user
   is allowed to make the move.

* Title::moveNoAuth() deprecated
* Title::moveTo() deprecated
* Title::isValidMoveOperation() broken down into
  MovePage::isValidMove() and MovePage::checkPermissions().

* Title::getTitleProtection() is now public, and returns
  unprefixed fields

Change-Id: Ic5026384b92a0d68d628397ffe1de6e5b6183f02
2014-10-28 12:52:36 -07:00
Brad Jorsch
ad225f501c API: Internationalize all remaining core API modules
This also adds some new ApiBase::PARAM_* constants to generate more
helpful help, and a method to override the default description message
for the use of ApiDisabled and ApiQueryDisabled.

Bug: 71638
Change-Id: Ic0c3d232e0498d58a043037e2e0c6f0b1c3edad3
2014-10-20 16:56:35 -04:00
Brad Jorsch
fdddf94570 API: Overhaul token handling
The current token handling is a mess. This simplifies things greatly:
* *All* tokens are obtained from action=query&meta=tokens, rather than
  being spread over action=tokens, action=query&prop=info,
  action=query&prop=revisions, action=query&prop=recentchanges, and
  action=query&prop=users. All these old methods are deprecated.
* Similarly, there is only one hook to register new token types. All old
  hooks are deprecated.
* All tokens are cacheable.
* Most token types are dropped in favor of a 'csrf' token. They already
  were returning the same token anyway.
* All token-using modules will document the required token type in a
  standard manner in action=help and are documented in machine-readable
  fashion in action=paraminfo.

Note this will require updates to all extensions using tokens.

Change-Id: I2793a3f2dd64a4bebb0b4d065e09af1e9f63fb89
2014-08-26 14:53:45 -04:00
Brad Jorsch
b5cd9e2f6b API: Log usage of various deprecated features
This will let us know how aggressively we can finally remove these.

Change-Id: I03fab36e921807e74fbabfa878756af254d89a1b
2014-08-14 16:51:14 -07:00
Brad Jorsch
f0a6435f3b API: Remove action=paraminfo 'props' and 'errors' result properties
The format for 'props' was never specified and the list for 'errors' is
impossible to keep updated when considering that many errors come from
MediaWiki backend code and extension hook functions. And since there
doesn't seem to be any real use case for either of these, let's just
kill both of them instead of wasting effort on trying to fix them.

Note that neither getResultProperties nor getPossibleErrors are called
from any extensions in gerrit, and none of the other deprecated methods
are called outside of the implementations of those two methods. Removing
the obsolete methods is left to the maintainers of the extensions, as
keeping them hurts nothing and is needed to maintain compatibility with
earlier versions of MediaWiki.

Change-Id: Ie11a401d60c834059fbf1b5625ca8ea093b3337c
2014-08-07 16:51:19 +01:00
umherirrender
e63299d208 Fixed some @params documentation (includes/api)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I758fa4ad80ac95e2ddd3770bcb9b7d2e57ec34ea
2014-04-18 13:55:36 +00:00
umherirrender
23fab68274 Fix spacing after @param and friends in comments
Searched for:
\@(param|return|throws|since|deprecated|access|todo|var)[ \t]{2,}

Change-Id: Icce22ba9fe0635455691ca58d9872d618151f346
2014-04-05 20:02:29 +00:00
addshore
719d7a2f03 Add final period to API module descriptions
Change-Id: Icae68c1ab1fd0006e00a3a9a56ae8f831d3d0d45
2014-03-10 09:04:08 +00:00
Siebrand Mazeland
ca209473d1 Remove unneeded uses of else{} in api/
Fixed a little documentation issue, removed a line of unreachable code
and fixed up two formatting issues in the process.

Change-Id: If29391ee1a0daf19973437f36c3216b8716debd0
2013-11-18 21:34:43 +01:00
Siebrand Mazeland
d026e1a403 Address errors and warnings in CodeSniffer in api/
Change-Id: I06de371393d50eada33154626874b106d814642b
2013-11-17 16:52:24 +01:00
Siebrand Mazeland
a60643422b Update formatting on more API classes
Change-Id: I1e6325b628359a557ceaa1e1ae30043aa5fc1402
2013-11-14 18:11:13 +00:00
umherirrender
a35cce4be0 Fixed spacing in api folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: Id7779dca4d1185245cf5764102b8de8b232c34b6
2013-04-20 07:47:36 +00:00
Yuri Astrakhan
9506e3d812 Spellchecked /includes directory
* Ran spell-checker over code comments in /includes/
* A few spellchecking fixes for wfDebug() calls

Found one very strange (NOOP?) line in Linker.php - see "TODO: BUG?"

Change-Id: Ibb86b51073b980eda9ecce2cf0b8dd33f058adbf
2013-03-13 03:42:41 -04:00
umherirrender
5880f89707 API: Throw error when interwiki is given for various title param
See bug 44341 for action=parse, but the problem with interwiki
processing can also be happen in other modules.

This gives clearer error message on some modules
For example action=move:
Bad title "*title*"
instead of:
Unknown error: "immobile-target-namespace-iw"

Change-Id: I86524533dfd778a169b39968999918a1f531efeb
2013-03-01 16:01:26 +01:00
Antoine Musso
b2fba3f27f api: remove duplicate __contruct calls
For historical reasons, all our API class had a dummy __construct which
simply calls their parent constructor.  This patch removes all such
occurences to save out some bytes.

Change-Id: I667955d7821f780fc5ce23823d74dedb1729b9fa
2013-01-29 09:38:17 +01:00
Yuri Astrakhan
503cd2f4ae (bug 35885) remove api version string and parameter
API was using SVN's version keyword which GIT does not support.
All related methods were either removed, or for those that
could have been used from extensions, emptied out.
api.php?version now shows unrecognized param warning.

Change-Id: I910ca1448ed2ed697ac19b17c486d130aa1d7e03
2013-01-18 12:41:18 -05:00
Yuri Astrakhan
32fd68f81c Minor cleanup
Fixed spacing, eol chars, "string" --> 'string'

Change-Id: I630247c6c5b469efb67ec9de32e8533ae88e59fb
2013-01-12 01:50:48 -05:00
daniel
277ca9ac4e (bug 42915) make MovePage aware of whether redirects are supported.
Special:Movepage and ApiMovePage should be aware whether the present content
model supports redirects, and only offer to keep a redirect on moving
of it's supported.

Change-Id: I2d02b2668ea8ebe39387b79d165f6cf1037303b9
2012-12-20 19:00:35 +01:00
umherirrender
7a427c2be8 add moveoverredirect to result of api move
Change-Id: I5047d94d75112c1390c42a7eb3bb4f16b5249539
2012-08-31 16:15:13 +02:00
umherirrender
06166e334a (bug 38190) Add "required" flag to some token params
action=block/action=unblock can not have the token required because when
using the gettoken param, the token param can not set.

Change-Id: I15317f16c06f150d29c1b17de76f41a6cfa84820
2012-07-20 15:45:51 -07:00
Aaron Schulz
e6faa2fd76 Merge "escape HTML elements in docblock with double quotes" 2012-07-18 19:17:46 +00:00
Antoine Musso
4f5d2386f3 escape HTML elements in docblock with double quotes
Doxygen choke on text enclosed by '<' and '>' since it tries to
interpret them as HTML or XML elements. This patch adds double quotes
in includes/api/*.php files around the two following strings:

 <Firstname>.<Lastname>@gmail.com
 <Firstname><Lastname>@gmail.com

Which becomes:

 "<Firstname>.<Lastname>@gmail.com"
 "<Firstname><Lastname>@gmail.com"

Tested locally, it prevents doxygen 1.8.0 related warnings.

Change-Id: I36d82eb3fd4989ee3ffc65b0b527b83711d1ba69
2012-07-15 22:15:45 +02:00