Commit graph

171 commits

Author SHA1 Message Date
Amir Sarabadani
728321e113 Make autopatrol third option in rc_patrolled and use it in API
Bug: T184791
Change-Id: If64ba8b845b122a87f20646dddf72ef257b793cb
2018-04-03 18:44:37 +02: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
Umherirrender
46942c2536 Add edit tags to list=watchlist
It is using the same query as list=recentchanges by left joining
tag_summary

Bug: T181975
Change-Id: I9e9ab9753ec0f813e9e555106cc81fd15ad9fb4a
2018-01-09 20:02:14 +00:00
Kunal Mehta
5ec4dd50a0 ApiQueryWatchlist: Document type of $commentStore property
Change-Id: I884bdd347aeddadfd4a7de89261e5ab1a0d8f6f2
2017-09-11 14:24:09 +00:00
Kunal Mehta
996587e228 ApiQueryWatchlist: Don't reinvent Title::newFromLinkTarget()
Change-Id: I1591c517ad8325e7c249197e6601fcc3d3efcc99
2017-09-10 15:13:07 -07: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
WMDE-Fisch
6df9ed1ad6 update mediawiki-codesniffer to 0.11.0 and fix issues
- mostly auto fixes
- some too long lines fixed
- ignore amp space in one case  passing by reference

Change-Id: I6472f83bc3cbf4bd629d83050cc3319b19ec465c
2017-08-11 22:27:51 +02:00
Brad Jorsch
4d38a489b0 SECURITY: API: Don't log "sensitive" parameters
Stuff like passwords and CSRF tokens shouldn't be in the logs.

The fact of being sensitive is intentionally separated from the need to
be in the POST body because, for example, the wltoken parameter to
ApiQueryWatchlist needs to be in the query string to serve its purpose
but still shouldn't be logged.

Bug: T125177
Change-Id: I1d61f4dcf792d77401ee2e2988b1afcb2a2ad58f
2017-04-06 13:42:48 -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
83ead540ae ApiQueryWatchlist: Handle empty wltypes
The pre-WatchedItemQueryService code used ApiQueyrBase::addWhereFld()
which filters out empty arrays. WatchedItemQueryService doesn't do that.

Bug: T153733
Change-Id: I3416b5a05c9751303b5c28a8b6d9cb746a101f73
2016-12-20 14:40:03 -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
715cbe468b Add hooks for WatchedItemQueryService / ApiQueryWatchlist
In order for an extension to add data to ApiQueryWatchlist, we need to
provide a way to allow it to manipulate the database query made by
WatchedItemQueryService. We also need some hooks in ApiQueryWatchlist to
handle the marshalling of data to and from WatchedItemQueryService.

To better handle hooking, this also moves some of the continuation logic
from ApiQueryWatchlist to WatchedItemQueryService.

Bug: T147939
Change-Id: Ie45376980f92da964a579887b28175c00fd8f57e
2016-11-03 11:41:40 +00:00
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
Leszek Manicki
1a9460308e Refactor database-related code in ApiQueryWatchlist
This moves generating of a complex Watchlist and RecentChanges
related query to a WatchedItemQueryService class.
ApiQueryWatchlist class no longer contains any database-related
code.

Bug: T132565
Change-Id: I5a5cda13f8091baa430ac1a8e2176e0efd1ae192
2016-06-29 10:21:17 +02:00
Brad Jorsch
027658bd87 ApiQueryWatchlist: wlshow=unread should filter revisions, not pages
It's currently showing all relevant revisions from pages with at least
one unread revision, where it would be more sensible for it to show just
the unread revisions. Something similar applies to wlshow=!unread.

Bug: T125729
Change-Id: I552901efb98081af9a1a677f4403a2a1a73bd94f
2016-02-17 15:50:35 +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
aude
aedbb34dfe Fix undefined property notice in ChangesList
This comes from ApiQueryWatchlist, which calls
ChangesList::isUnpatrolled with recent change row entries.

Since If71af587, rc_log_type is now needed along with rc_patrolled.

Bug: T123542
Change-Id: If6507121e59c53df925998f383c9bdf8f2936e37
2016-01-13 16:58:42 -05:00
addshore
d40cd42b9f Enable users to watch category membership changes #2
This is part of a chain that reverts:
e412ff5ecc.

NOTE:
- The feature is disabled by default
- User settings default to hiding changes
- T109707 Touching a file on wikisource adds and
      removes it from a category... Even when page
      has no changes.... WTF? See linked issue,
      marked as stalled with a possible way forward
      for this patch.
      @see https://gerrit.wikimedia.org/r/#/c/235467/

Changes since version 1:
- T109604 - Page names in comment are no longer
      url encoded / have _'s
- T109638 & T110338 - Reserved username now used
      when we can't determine a username for the change
      (we could perhaps set the user and id to be blank
      in the RC table, but who knows what this might do)
- T109688 - History links are now disabled in RC....
      (could be fine for the introduction and worked
      on more in the future)
- Categorization changes are now always patrolled
- Touching on T109672 in this change emails will never
      be sent regarding categorization changes. (this
      can of course be changed in a followup)
- Added $wgRCWatchCategoryMembership defaulting to true
      for enabling / disabling the feature
- T109700 - for cases when no revision was retrieved
      for a category change set the bot flag to true.
      This means all changes caused by parser functions
      & Lua will be marked as bot, as will changes that
      cant find their revision due to slave lag..

Bug: T9148
Bug: T109604
Bug: T109638
Bug: T109688
Bug: T109700
Bug: T110338
Bug: T110340
Change-Id: I51c2c1254de862f24a26ef9dbbf027c6c83e9063
2015-10-20 14:23:48 -07:00
CSteipp
e412ff5ecc Revert "Enable users to watch category membership changes"
This reverts commit f6879ea16e.

Bug: T109638
Change-Id: I770d8d33a4cff3829bdea9a4df24de209cbe691b
2015-08-20 10:35:56 -07:00
Kai_WMDE
f6879ea16e Enable users to watch category membership changes
Bug: T9148
Change-Id: I5a89d8f19804b1120f4c755d834e2da6ca12ceae
2015-08-13 17:58:06 +02:00
Kunal Mehta
96092399c1 API: Use ApiBase::PARAM_HELP_MSG_PER_VALUE for 'prop' in query+watchlist
Change-Id: I5e956f4b4dccb2b109d514332e4347252ce846c4
2015-07-06 13:10:22 -07: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
61233fc847 API: Move parameter formatting into LogFormatter
This allows for extensions to format their log entry parameters, and
keeps the code for formatting API log entry parameters in the same place
as for other formatting.

This also takes the opportunity to rearrange the output format slightly
to avoid conflicts like what's happening in T73020.

Bug: T35235
Bug: T73020
Bug: T91466
Change-Id: I6846ce09322eb404c506b5a51780a44ce9279fe2
2015-04-17 04:59:41 +00: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
Chad Horohoe
cc2eb92668 Pass if log entry is legacy to ApiQueryLogEvents::addLogParams()
Querying via ApiQueryRecentChanges and ApiQueryWatchlist did not
pass if a particular log entry was a legacy log entry.

Ultimately CheckUser should stop writing legacy style log entries
too but we can at least behave properly when we hit them.

Bug: T91466
Change-Id: I1564ec7e599e2f9d78775e63e06eca84db497a43
2015-03-12 11:57:03 -07:00
jenkins-bot
b3b50d7294 Merge "Add default type param for recentchanges and watchlist query api modules" 2015-02-23 13:32:12 +00:00
umherirrender
b7a2503bda Give objects to DatabaseLogEntry::newFromRow
No need to cast to array, because the called function will recast to
object.

Change-Id: I0eaa62450a0ebcc9ab8458b225dfadb71197a2ad
2015-02-22 11:36:00 +01:00
aude
81a6394395 Add default type param for recentchanges and watchlist query api modules
Set the type param for ApiQueryRecentChanges and ApiQueryWatchlist
to 'edit|new|log', thus excluding 'external' type.

In most cases, api users probably don't want external changes and
they might be confusing, unless explicitly requested.

Bug: T88254
Change-Id: I74bab5d4719f4e17118fa89a0ceb3e63c0246a1f
2015-02-02 15:04:17 -05:00
Aaron Schulz
6921770414 Updated some try-catch statements: MWException -> Exception
Change-Id: I76601a86e30f4984e3b1a8c8ec5ef5a0f652433a
2015-01-09 17:20:22 -08: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
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
Reedy
e48ecbc524 Switch API to use Config classes
Only done where globals are config (so not $wgParser, $wgContLang etc)

Change-Id: Ic39cdd858cfb9096a2bc09618f97e64270d76f13
2014-06-15 23:56:38 +01:00
Brad Jorsch
ad0ac845cc API: Add show=unread to ApiQueryWatchlist
This allows for retrieving only those pages that have changes since the
last visit.

Bug: 65246
Change-Id: I81d2fae39178708efc0f57e5acea93b50463bc7a
2014-06-09 14:14:04 -04:00
jenkins-bot
e0dfd13037 Merge "Move ApiQueryRecentChanges::parseRCType to static method on RecentChange" 2014-05-19 18:57:25 +00:00
kishanio
b7cc86cdc0 Move ApiQueryRecentChanges::parseRCType to static method on RecentChange
Prior parseRCType was an private method in includes/api/ApiQueryRecentChanges and also
duplicated in includes/api/ApiQueryWatchList. This method has been made static and moved
to includes/changes/RecentChange.php.

Bug: 65071
Change-Id: Ic911fbcf9411c782685c4f956f8522051f2517f0
2014-05-17 15:07:01 +00: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
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
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
addshore
719d7a2f03 Add final period to API module descriptions
Change-Id: Icae68c1ab1fd0006e00a3a9a56ae8f831d3d0d45
2014-03-10 09:04:08 +00: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
Siebrand Mazeland
aeb358f0c3 Throw exception on invalid RecentChange types
Change-Id: I39279a13a2eb5891991e1c3b4bee0fafe844f1f2
2014-01-02 22:36:47 +00:00
Siebrand Mazeland
aabbbce707 Update documentation for ApiQueryWatchlist::parseRCType()
Change-Id: I41be0aafd86f49e4b36fa91147dc41ebdeb8779c
2013-12-27 17:06:06 +00:00
Siebrand Mazeland
fc50d150db Fix CodeSniffer errors and warnings on some API classes
Change-Id: Id5fd7180f3a1d62663f79b27ad5108062607596a
2013-11-15 17:50:05 +00:00
Siebrand Mazeland
dadbe23810 I'm in your API classes updating your formatting
Change-Id: I6087573dfdc6edcd63062508056ebcf3502e03f2
2013-11-14 18:28:26 +00:00
kaligula
d797477d7b (bug 47219) Allow specifying change type of Wikipedia feed items
It exposes field /rc_type/ as ApiQueryRecentChanges does thus allowing
user to define which (edit, external, new, log) changes to show in feed.

Bug: 47219
Change-Id: If22827129b04d423711f921307dc820d4840d9d1
2013-04-30 18:52:56 +02: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