Commit graph

143 commits

Author SHA1 Message Date
Daimona Eaytoy
e2e543f7c2 Unsuppress more phan issues (part 5)
Bug: T231636
Depends-On: I6e5fba7bd273219b1206559420b5bdb78734aa84
Change-Id: I50377746f01749b058c39fd8229f9d566224cc43
2019-09-01 09:48:31 +00:00
Petr Pchelko
fd130247c2 Deprecate and replace usages of User:isAllowed{All,Any}
Bug: T220191
Change-Id: I197b8fadaa93e7b320fc19c10e3e09387fe09ad2
2019-08-21 18:36:16 -07: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
Derick Alangi
339211a1ea Avoid usage of deprecated Revision::* constants, use RevisionRecord
Change-Id: I872fc89e5c02dd6a3ae9cd7e76640b95dc33f514
2019-07-21 15:03:03 +01:00
Bill Pirkle
d2edb58930 Remove references to db field ar_text_id
Field ar_text_id is being removed as part of MCR schema changes.
Remove references to this field. These references were already
unnecessary due to commit 07842be3.

Bug: T198341
Change-Id: I3dbf12abf3f67fa0ea07c535e830c9d40b46fdc3
2019-07-09 16:14:48 -05:00
Derick Alangi
e6e5ea4791 API: Removed unused local variable $p from ApiQueryDeletedrevs
This local var was introduced in fdddf94 and usage of it removed in
4e6810e. This is no longer used so cleaned up.

Change-Id: I2acf28b3a027284adbda70f50bee3c4a6b4a68b2
2019-07-02 15:12:32 +00:00
Aaron Schulz
cb15755e92 Normalize use of "INNER JOIN" to "JOIN" in database queries
The ANSI SQL default join type is INNER and this might save
some line breaks here and there.

Change-Id: Ibd39976f46ca3f9b71190d3b60b76ca085787a00
2019-03-06 09:17:30 -08:00
Reedy
4691389fa4 Use (int) rather than intval()
Bug: T216969
Change-Id: I4c06716c83b69d128f26fa7f68736808aa2d3d64
2019-02-25 00:38:33 +00:00
jenkins-bot
85fa38d0b7 Merge "Migrate Api modules from tag_summary table to change_tag" 2018-11-30 19:13:46 +00:00
Amir Sarabadani
02a930d7fb Drop $wgChangeTagsSchemaMigrationStage
Bug: T194163
Change-Id: Ieb6cc60cacf9dd0d86641b1be817249cdce42112
2018-11-28 23:03:41 +01:00
Amir Sarabadani
c91cc078bf Migrate Api modules from tag_summary table to change_tag
Bug: T209525
Change-Id: I7624d86bbff675eab7fee97adf3b7e2e6753f81d
2018-11-27 18:12:06 +01:00
Amir Sarabadani
0841a0f79e API: Use ct_tag_id in queries when applicable
Bug: T194162
Change-Id: I2146cd1f72b546277723102ab64c79567549ff5b
2018-09-04 22:22:29 +02:00
Brad Jorsch
21c6ae1163 Drop archive.ar_text and ar_flags
This should have been done long ago. Now it is being done.

This also changes ar_text_id to NOT NULL, since it should never be null
anymore, and DEFAULT 0 in preparation for MCR stopping writing it.

Bug: T33223
Change-Id: I18f1c740b7537c7dc3cfeba9b241d0a9f31caa34
2018-04-03 12:54:27 -04:00
Brad Jorsch
27c61fb1e9 Add actor table and code to start using it
Storing the user name or IP in every row in large tables like revision
and logging takes up space and makes operations on these tables slower.
This patch begins the process of moving those into one "actor" table
which other tables can reference with a single integer field.

A subsequent patch will remove the old columns.

Bug: T167246
Depends-On: I9293fd6e0f958d87e52965de925046f1bb8f8a50
Change-Id: I8d825eb02c69cc66d90bd41325133fd3f99f0226
2018-02-23 10:06:20 -08:00
addshore
e5879da149 Pass $key into CommentStore methods and use MediawikiServices
This allows CommentStore to be added to MediaWikiServices
without the need of an aditional Factory.

This change includes a compatability layer to allow the behaviour
from 1.30 to continue to be used while deprecated.

CommentStore::newKey has been deprecated.
Keys are now passed into the public methods of CommentStore
where needed.
The following CommentStore methods have had their signatures changed
to introduced a $key parameter, but when used in conjunction with
CommentStore::newKey behaviour will remain unchanged:
  * CommentStore::getFields
  * CommentStore::getJoin
  * CommentStore::getComment
  * CommentStore::getCommentLegacy
  * CommentStore::insert
  * CommentStore::insertWithTemplate

Change-Id: I3abb62a5cfb0dcd456da9f4eb35583476ae41cfb
2018-02-05 15:34:12 +00: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
11cf01dd9a Add comment table and code to start using it
A subsequent patch will remove the old columns.

Bug: T166732
Change-Id: Ic3a434c061ed6e443ea072bc62dda09acbeeed7f
2017-08-30 15:05:00 +10:00
Reedy
26bec934a0 Add ar_ prefix back to usertext_timestamp USE INDEX
This is the correct/canonical index name. For usages on mysql it will
map to the unprefixed version.

Bug: T154872
Change-Id: Ie2daf7b33428855ac59c85bf04a99a9bca7feba1
2017-04-05 23:40: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
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
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
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
Reedy
00c426e3c2 Replace wfBaseConvert with Wikimedia\base_convert
Change-Id: Iadab3d018c3559daf79be90edb23d131729bdb68
2015-11-24 22:51:42 +00:00
Brad Jorsch
a90cbb48f8 Cast various things that are supposed to be ints
Mysqli is returning SELECTed ints as strings rather than as ints, I'm
guessing to avoid problems with 64-bit int types on 32-bit systems. PHP
mostly doesn't care, but it causes API JSON output to have strings
instead of ints all over the place.

This also fixes ForeignAPIFile::getUser( 'id' ) returning the user
*name*.

Bug: T98276
Change-Id: Ie6591d72b3ac40172f8176a8ca8b6fad8e9275a5
2015-05-06 11:40:41 -04: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
Ricordisamoa
693ec8b76a New convenience method ApiBase::lacksSameOriginSecurity()
For consistent handling of API requests with the 'callback' argument.

Change-Id: Ic6e3483f5e8819498c693650a11728efc1bafcc0
2015-02-27 09:48:37 -05:00
Brad Jorsch
991de897e4 API: Split list=deletedrevs into prop=deletedrevisions and list=alldeletedrevisions
list=deletedrevs has always been an odd one: it pretends to be a prop
module sometimes in taking titles from ApiPageSet, but when the pageset
supplies no titles it acts like a list module. This causes problems
such as bug 71389, and makes the whole thing unnecessarily confusing.

The solution is to split the "prop" and "list" aspects into separate
modules: prop=deletedrevisions when input should come from ApiPageSet
and list=alldeletedrevisions when not.

At the same time, let's take advantage of the situation to clear up some
other bugs. And let's share the revision-formatting code with
ApiQueryRevisions instead of partially reimplementing it.

Bug: 23489
Bug: 27193
Bug: 44190
Bug: 71396
Bug: 71389
Change-Id: I3e960d5c655bc57885d6d4ee227e67104808add7
2014-11-04 15:02:03 -05: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
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
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
eikes
2f002458d5 Split "suppressrevision" into two user rights
In this change, a new passive user right named "viewsuppressed"
which can be used in order to view suppressed page content was added
to MediaWiki core.
Furthermore, this right was also added to the list of available rights,
to qqq.json and to en.json where also the description of the
"suppressrevision" right was adjusted in order to reflect reality.

Bug: 20476
Change-Id: Id1baacb9c782763db5e05ef8b5c1b761997efcc9
2014-07-19 18:11:15 +02:00
Brad Jorsch
e3ba5956e0 API: Fix list=deletedrevs with pre-1.5 revisions
In pre-1.5, deleted revisions have the text in the ar_text field of the
archive table with empty ar_text_id. Adjust the JOIN used for
drprop=content to take this situation into account, and the logic for
extracting the revision content to match.

Bug: 67699
Change-Id: I3672435ac97fa1eff2bdf80b24c470525c93ab27
2014-07-09 10:26:39 -04:00
Thiemo Mättig
23632a4ecd Use precise ApiMain/ApiQuery type hints in all API modules
Which type is used depends on the ApiModuleManager responsible for
the API module. There are two managers, one in ApiMain and one in
ApiQuery. Both contain a list of API modules they instantiate.
Both use $this as the first parameter in the constructors of the
individual modules. There is no other regular way to instantiate the
modules, so we know the type must either be ApiMain or ApiQuery.

The lists don't intersect.

I would have prefered the naming scheme $mainModule for ApiMain
modules and $queryModule for ApiQuery modules but since this
doesn't add much I left the shorter variable names untouched.

Change-Id: Ie6bf19150f1c9b619655a06a8e051412665e54db
2014-05-16 11:07:23 -04:00
Brad Jorsch
d9534a5d56 API: Make more continuations unique
API queries must be completely ordered for proper behavior; otherwise
you may get into a situation where a query returns the same continuation
value that was provided. Various modules that have been using timestamps
in/as their continuation parameter can easily run into this problem.

Normally we'd have to add additional fields to the relevant indexes to
be able to make this work without having filesorting queries (which
MySQL really doesn't do well, it fetches all matching rows and only
applies the limit after[1]). But InnoDB has a "feature" where it
effectively appends the table's primary key to all other indexes,[2]
which makes these queries be properly indexed in that situation.
Apparently we're ok with this, since Icc43b62f was merged depending on
this feature.

Also, this change fixes some MySQLisms and other oddities done to
ApiQueryRecentChanges in Icc43b62f.

 [1]: https://dev.mysql.com/doc/refman/5.5/en/limit-optimization.html
 [2]: https://dev.mysql.com/doc/refman/5.5/en/innodb-table-and-index.html

Bug: 24782
Change-Id: I4c9f8c0c2bfd831755d4fa20a18f93fef1effd28
2014-04-11 10:50:16 -04:00
Bartosz Dziewoński
e745f30e4e ApiQueryDeletedrevs: Fix getDescription() docs
Strings were incorrectly quoted.

Change-Id: I5b7aa4709a9bfde36b4e81ba8ea3e15efde003b1
2014-04-07 16:10:55 +02:00
addshore
719d7a2f03 Add final period to API module descriptions
Change-Id: Icae68c1ab1fd0006e00a3a9a56ae8f831d3d0d45
2014-03-10 09:04:08 +00:00
Siebrand Mazeland
0cef781886 Fix CodeSniffer errors and warnings
Change-Id: Idc74e34634d88625773fb8f73315f61edfa67e28
2014-02-05 11:20:17 +01:00
Brad Jorsch
48de797fbd Improve API query RevDel handling
* ApiQueryDeletedrevs, ApiQueryFilearchive, ApiQueryRecentChanges, and
  ApiQueryWatchlist will now return entires where fields have been
  revision-deleted. "Hidden" indicators will be provided as appropriate.
* ApiQueryImageInfo, ApiQueryLogEvents, ApiQueryRevisions,
  ApiQueryContributions will now return field values in addition to the
  "hidden" indicators when the requesting user has the necessary rights.
* Modules that return "hidden" indicators will now also return a
  "suppressed" indicator.
* ApiQueryImageInfo will now return info for DELETED_FILE file revisions
  if the requesting user has the 'deletedtext' right.
* ApiQueryLogEvents, when searching by user or title, will now return
  entries where the user or action are revision-deleted if the
  requesting user has the 'deletedhistory' right.
* ApiQueryContributions now uses the correct user rights rather than
  'hideuser' to determine when to show contributions where the username
  was revision-deleted.
* ApiQueryContributions will now indicate when the revision text is
  hidden.
* Fix a bug in ApiQueryDeletedrevs found during testing where specifying
  the "content" prop along with the "tags" prop or "drtag" parameter
  would cause an SQL error.
* Fix various PHP warnings in ApiQueryFilearchive caused by the lack of
  ArchivedFile::selectFields() fields.
* ApiQueryImageInfo::getInfo's $metadataOpts parameter has been renamed
  $opts, and now may have an option to indicate the user to use for
  RevDel visibility checks.
* ApiQueryWatchlist now properly uses the actual user's rights for
  checking whether wlprop=patrol is allowed, rather than using the
  wlowner's rights.

Bug: 27747
Bug: 27748
Bug: 28261
Bug: 34926
Bug: 48966
Change-Id: Idec2199976f460e1c73a26d0717e9fc4ab8042bb
2014-01-17 11:43:22 -05:00
btongminh
1f47c9b9ae Fix capitalization in ApiQueryBase::titlePartToKey()
ApiQueryBase::titlePartToKey now allows an extra parameter that
indicates the namespace in order to properly capitalize the title part.

This allows list=allcategories, list=allimages, list=alllinks,
list=allpages, list=deletedrevs and list=filearchive to
handle case-sensitivity properly for all parameters.

Bug: 25702
Change-Id: Iaa5a71ec536f3716f54bc84b39f645545dfd8660
2013-12-23 12:53:43 -05:00
Jackmcbarn
855e3626e3 Show tags on deleted edits through the API
Add support for viewing and filtering by tags in list=deletedrevs in the
API. This code is mostly copied from the prop=revisions code. To avoid
bug #45619 reoccuring here, no index is specified.

Change-Id: I53a1e0479bc6bafe2a1115de875548519e5b3b59
2013-12-04 17:38:24 -05:00
Siebrand Mazeland
b9b699cd1f Fix CodeSniffer errors and warnings on a number of ApiQuery classes
Change-Id: I763f79c66cd8ed2ca19586323d5b3ee8b60ffd18
2013-11-15 10:33:50 -08:00
Siebrand Mazeland
d45bb99e8c Yet more formatting updates for yet more API classes
Change-Id: Iaa1cfaaffc7c55bb7670dfbff3f063cf22434f09
2013-11-14 18:15:00 +00:00
Brad Jorsch
43f3ab65cf SECURITY: Prevent tokens in jsonp mode
Add checks to token-returning functions to prevent returning tokens in
jsonp mode. This affects action=tokens, action=login,
action=createaccount, and action=query&list=deletedrevs.

Also, remove the "gettoken" parameter to action=block and
action=unblock, which has been deprecated since 1.20.

Bug: 49090
Change-Id: Ibeaa5c72d8084585092b15935a3f5709104bf7f7
2013-09-03 15:04:47 -07:00
umherirrender
da39005596 Removed space after isset
While at it, added/removed some other spaces in the same files

Change-Id: Iabb23a448f6f53eb6020155f9c744f74f8b11786
2013-04-26 14:18:06 +02: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
umherirrender
d63121016d fix some spacing
Added/removed spaces around logical/arithmetic operator
Reduced multiple empty lines to one empty line
Removed wrong tabs before comments at end of line
Removed too many spaces in assigments

Change-Id: I2bba4e72f9b5f88c53324d7b70e6042f1aad8f6b
2013-03-07 17:53:21 +01:00
Brad Jorsch
154a0a03aa Fix API list=deletedrevs continuation in mode 1
r86782 introduced validation of parameter combinations for
list=deletedrevs, but screwed up in that it disallowed drcontinue in
"mode 1" (list all deleted revisions for the specified titles).

Apparently no one uses this much, because it doesn't seem to have been
reported as a bug despite being broken since April 2011.

Change-Id: I30691d04fab759ee56fb4156d475fbb21b81ab45
2013-03-06 03:32:15 +00:00
umherirrender
ca31ebad3f fix some spacing
Added/removed spaces after opening/before closing parentheses

Added a space after a comma

Removed unneeded parentheses in condition

Change-Id: I306091347ccaaf11dee0cdfda3019cb0c12be51b
2013-02-09 23:03:53 +01:00