Commit graph

223 commits

Author SHA1 Message Date
jenkins-bot
39705eb311 Merge "Replace "@stable for subclassing" with "@stable to extend"" 2020-07-13 09:31:38 +00:00
jenkins-bot
0270990f0b Merge "Replace "@stable for calling" by "@stable to call"" 2020-07-13 09:27:04 +00:00
daniel
3c50afa46b Replace "@stable for subclassing" with "@stable to extend"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: Ie32c1b11b3d16ddfc0c83a757327d449ff80b2e4
2020-07-13 11:00:30 +02:00
daniel
f7116bb3a2 Replace "@stable for overriding" with "@stable to override"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: I5ffbb91882ecce2019ab644839eab5e8fb8a1c5f
2020-07-13 10:57:12 +02:00
daniel
272db6afde Replace "@stable for calling" by "@stable to call"
For compliance with the new version of the table interface policy
(T255803).

This patch was created by an automated search & replace operation
on the includes/ directory.

Bug: T257789
Change-Id: If560596f5e1e0a3da91afc36e656e7c27f040968
2020-07-13 08:55:28 +00:00
daniel
948123e589 Mark API base classes as extensible
This marks API base classes as stable for extending per the
Stable Interface Policy.

Bug: T247862
Change-Id: I164192ba3d013d8bc98a8b9c6db10e3dd1e58b23
2020-07-08 14:14:54 +00:00
Tim Starling
68c433bd23 Hooks::run() call site migration
Migrate all callers of Hooks::run() to use the new
HookContainer/HookRunner system.

General principles:
* Use DI if it is already used. We're not changing the way state is
  managed in this patch.
* HookContainer is always injected, not HookRunner. HookContainer
  is a service, it's a more generic interface, it is the only
  thing that provides isRegistered() which is needed in some cases,
  and a HookRunner can be efficiently constructed from it
  (confirmed by benchmark). Because HookContainer is needed
  for object construction, it is also needed by all factories.
* "Ask your friendly local base class". Big hierarchies like
  SpecialPage and ApiBase have getHookContainer() and getHookRunner()
  methods in the base class, and classes that extend that base class
  are not expected to know or care where the base class gets its
  HookContainer from.
* ProtectedHookAccessorTrait provides protected getHookContainer() and
  getHookRunner() methods, getting them from the global service
  container. The point of this is to ease migration to DI by ensuring
  that call sites ask their local friendly base class rather than
  getting a HookRunner from the service container directly.
* Private $this->hookRunner. In some smaller classes where accessor
  methods did not seem warranted, there is a private HookRunner property
  which is accessed directly. Very rarely (two cases), there is a
  protected property, for consistency with code that conventionally
  assumes protected=private, but in cases where the class might actually
  be overridden, a protected accessor is preferred over a protected
  property.
* The last resort: Hooks::runner(). Mostly for static, file-scope and
  global code. In a few cases it was used for objects with broken
  construction schemes, out of horror or laziness.

Constructors with new required arguments:
* AuthManager
* BadFileLookup
* BlockManager
* ClassicInterwikiLookup
* ContentHandlerFactory
* ContentSecurityPolicy
* DefaultOptionsManager
* DerivedPageDataUpdater
* FullSearchResultWidget
* HtmlCacheUpdater
* LanguageFactory
* LanguageNameUtils
* LinkRenderer
* LinkRendererFactory
* LocalisationCache
* MagicWordFactory
* MessageCache
* NamespaceInfo
* PageEditStash
* PageHandlerFactory
* PageUpdater
* ParserFactory
* PermissionManager
* RevisionStore
* RevisionStoreFactory
* SearchEngineConfig
* SearchEngineFactory
* SearchFormWidget
* SearchNearMatcher
* SessionBackend
* SpecialPageFactory
* UserNameUtils
* UserOptionsManager
* WatchedItemQueryService
* WatchedItemStore

Constructors with new optional arguments:
* DefaultPreferencesFactory
* Language
* LinkHolderArray
* MovePage
* Parser
* ParserCache
* PasswordReset
* Router

setHookContainer() now required after construction:
* AuthenticationProvider
* ResourceLoaderModule
* SearchEngine

Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
2020-05-30 14:23:28 +00:00
Tim Starling
28b7f0b3f2 In ApiQueryBase, use a SelectQueryBuilder to store query information
Bug: T243051
Change-Id: I5bc99ee4b0674a5bc02ff31e3f7182fd7564b848
2020-05-18 14:42:42 +10:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08:00
Umherirrender
3ec00a7405 Allow null on ApiQueryBase::addTimestampWhereRange
Also add null to the underlying functions used here

Change-Id: I2e45fa449cf4c82d9a0e4323c4ac3ac2155bcadc
2019-12-28 22:20:48 +01:00
Brad Jorsch
bba047c7ec API: Update docs on addWhere() and related methods
Change-Id: I189f0949e20b4e4ee130e3c7961635169853aeb4
2019-12-17 13:13:45 -05:00
Daimona Eaytoy
ce0856b12f Fix more scalar types in docblocks
Change-Id: I574d4e261ab986e028c3ce26c4f0ec648b88a2ac
2019-12-08 17:59:08 +00:00
daniel
e98094956a Don't fail hard on bad titles in the database.
This updates some code that has been constructing TitleValue directly
to use TitleValue::tryNew or TitleParser::makeTitleValueSafe.

Bug: T200055
Change-Id: If781fe62213413c8fb847fd9e90f079e2f9ffc9d
2019-11-25 22:15:38 +01:00
jenkins-bot
1876680167 Merge "Run GenderCache for api query modules using ApiQueryBase::addTitleInfo" 2019-11-05 21:07:15 +00:00
Max Semenik
f1c9cf8879 Minor cleanups
* Identifier case
* Returning a void function result
* Unused variable
* Missing documentation

Change-Id: Ibfd2fc5ae1d91c7c9c6a34bcd4523384d3bca576
2019-11-03 17:10:23 -08:00
Umherirrender
731d9f748e Run GenderCache for api query modules using ApiQueryBase::addTitleInfo
When converting a Title object into a string for user or user talk
namespace the gender information are needed.

This patch set improves performance on wikis with gender distinction
like dewiki or ruwiki by combining the fetch of the information into one
query and avoids a query per unique user name.
It also avoids false results for request with apihighlimit, because the
apihighlimit with 5000 is higher than the query max limit of the
GenderCache with 1000

Bug: T200238
Change-Id: Ibe0561b210dbeb654117dad777e839640f51b4e4
2019-11-02 22:23:23 +01:00
Umherirrender
a8525d7201 Fill GenderCache for used pages in action=query&prop=fileusage
Add an utility function
ApiQueryBase::executeGenderCacheFromResultWrapper

GenderCache stops working when there are more than 1000 cache missed
and returning the default value (T200238)
Fill the cache with all needed users avoids this behaviour
and it saves one query per user page.

Change-Id: I911dcb160a7b169091b9e8f66fb3908d0f2a1ba4
2019-09-25 21:41:34 +02:00
Brad Jorsch
02d6dc2e4f API: Use ApiBlockInfoTrait in ApiQueryUsers and AllUsers
For efficient bulk querying, this means that
ApiQueryBase::showHiddenUsersAddBlockInfo() needs to return everything
needed by DatabaseBlock::newFromRow().

Since we're rewriting it anyway, we may as well also move
ApiQueryBase::showHiddenUsersAddBlockInfo() out into a trait of its own.

Bug: T232021
Change-Id: I9c5b17a232ecbfbffefc7e40608cf5684ce8a644
2019-09-18 19:44:01 +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
Umherirrender
2664eeb632 Clean up spacing of doc comments
Align the doc stars and normalize start and end tokens

Change-Id: Ib0d92e128e7b882bb5b838bd00c74fc16ef14303
2019-08-05 22:29:50 +00:00
Umherirrender
121734c347 Type hint against IResultWrapper in api classes
Change-Id: If3870e6b8d343dd12390f5155d97edbbe080ac77
2019-06-19 21:43:51 +02:00
Fomafix
110a5877e9 Use [...] instead of array(...) in PHP comments and documentation
Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
2019-06-17 21:15:09 +02:00
Umherirrender
7cc76abc36 Change array type on ApiQueryBase::addTables
This function results in passing its value to IDatabase::select as first
parameter $table.
The first parameter is documented as string|array, because it can take
more complex arrays:
	 * Joins using parentheses for grouping (since MediaWiki 1.31) may be
	 * constructed using nested arrays. For example,
	 *
	 *    [ 'tableA', 'nestedB' => [ 'tableB', 'b2' => 'tableB2' ] ]

Update the type to allow also passing such complex arrays to this
function
ApiQueryBase::showHiddenUsersAddBlockInfo() is using this format

Change-Id: I8038243545bc1c79a1106ccc3bec7738e63c2e2e
2019-06-07 17:19:48 +02:00
Umherirrender
5aa6d533de Fix doc for $item of ApiQueryBase::addPageSubItem
ApiResult::addValue defines mixed for $value

Change-Id: I31881426ce7cb81f6430cccd4252881a154cd161
2019-05-26 00:14:02 +02:00
Derick Alangi
170c973e09 api: Remove deprecated prepareUrlQuerySearchString() from core
This method was deprecated in 1.33 and is no longer used.

Usage
=====

https://codesearch.wmflabs.org/search/?q=%5CbprepareUrlQuerySearchString%5Cb&i=nope&files=&repos=

Bug: T220656
Change-Id: I15a476438f3a579db41a43658e13b6ddc4fc62d4
2019-05-11 15:58:21 +01:00
Reedy
c13fee87d4 Collapse some nested if statements
Change-Id: I9a97325d738d09370d29d35d5254bc0dadc57ff4
2019-04-04 19:02:22 +00:00
Reedy
4691389fa4 Use (int) rather than intval()
Bug: T216969
Change-Id: I4c06716c83b69d128f26fa7f68736808aa2d3d64
2019-02-25 00:38:33 +00:00
Thiemo Kreuz
734a969d55 Safe replacement of a lot of !count() with === []
This was originally a global search and replace. I manually checked all
replacements and reverted them if (due to the lack of type hints) either
null (that would be 0 when counted) or a Countable object can end in the
variable or property in question.

Now this patch only touches places where I'm sure nothing can break.

For the sanity of the honorable reviewers this patch is exclusively touching
negated counts. You should not find a single `!== []` in this patch, that
would be a mistake.

Change-Id: I5eafd4d8fccdb53a668be8e6f25a566f9c3a0a95
2019-01-15 17:28:49 +01:00
Brad Jorsch
a793faa88d API: Use parenthesized join in ApiQueryBase::showHiddenUsersAddBlockInfo
The query is LEFT JOINing ipblocks, so we need to properly scope the new
JOINs with the comment and actor tables to get the block reason and
by-actor.

Bug: T210937
Change-Id: I230a4ab78e3ba6e83008b0466eeca8d40013ba3d
2018-12-12 01:57:13 +00:00
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
Brad Jorsch
d65e96b763 Use new externallinks.el_index_60 field
This adds a method to LinkFilter to build the query conditions necessary
to properly use it, and adjusts code to use it.

This also takes the opportunity to clean up the calculation of el_index:
IPs are handled more sensibly and IDNs are canonicalized.

Also weird edge cases for invalid hosts like "http://.example.com" and
corresponding searches like "http://*..example.com" are now handled more
regularly instead of being treated as if the extra dot were omitted,
while explicit specification of the DNS root like "http://example.com./"
is canonicalized to the usual implicit specification.

Note that this patch will break link searches for links where the host
is an IP or IDN until refreshExternallinksIndex.php is run.

Bug: T59176
Bug: T130482
Change-Id: I84d224ef23de22dfe179009ec3a11fd0e4b5f56d
2018-11-12 22:33:18 +00:00
Brad Jorsch
377c76edbc API: Ignore expired blocks in ApiQueryBase::showHiddenUsersAddBlockInfo()
This probably went unnoticed for so long because expired blocks are
regularly cleared as long as new blocks continue being issued, so people
found that the problem "fixed" itself.

Bug: T206944
Change-Id: I6559e1ec23f4469d19684b4d931913acbccb56d4
2018-10-15 11:21:44 -04:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00: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
jenkins-bot
bbedc24556 Merge "Pass $key into CommentStore methods and use MediawikiServices" 2018-02-06 15:31:59 +00:00
Fomafix
73a514b574 Remove superfluous spaces and semicolons in comments
Change-Id: Ib4b452f1843ec250c8c1fcc2a738d80726b6135d
2018-02-05 19:05:57 +00: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
f938f15bea ApiQueryBase: Fix addWhereFld for PHP 7.2
Idfe23a07d didn't go far enough with this method, it can be passed
arbitrary other scalars in addition to null and arrays.

Bug: T182377
Change-Id: I63ec23f70d6d7ad638aa382b740ec44d0ca47f85
2017-12-08 17:44:19 +00:00
Brad Jorsch
9f86261000 API: Account for PHP 7.2 change
PHP 7.2 broke existing functionality in making count( null ) raise a
warning. So add tests for null all over the place, or change tests where
we know the value is null or an array (but not false, empty-string, or
0) to just cast to boolean.

Bug: T182004
Change-Id: Idfe23a07daa9f60eee72f2daf04304be87057a29
2017-12-04 13:46:33 -05:00
Kunal Mehta
ae98cdde0c ApiQuery: Fix type docs for $groups in ApiQueryBase::selectNamedDB() call chain
Change-Id: Iaa2ed914347fc4a1b477406cc8b83d7f21adf1a7
2017-09-11 17:46:24 +00:00
Umherirrender
f739a8f368 Improve some parameter docs
Add missing @return and @param to function docs and fixed some @param

Change-Id: I810727961057cfdcc274428b239af5975c57468d
2017-09-10 20:32:31 +02: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
Umherirrender
a9007e8baf Add missing & to @param documentation to match functon call
Change-Id: I81e68310abcbc59964b22e0e74842d509f6b1fb9
2017-08-11 18:47:46 +02: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
Aaron Schulz
d735dc562d Move Database and subclasses to Rdbms namespace
Change-Id: I52bef87512f9ddd155d1f4cc0052f6b7a0db5b42
2017-04-12 10:43:57 -07:00
Aaron Schulz
e01fd44388 Move ResultWrapper subclasses to Rdbms
Change-Id: I6f3f0e85e268b24c57c537aa6ad8016e0b4cdddb
2017-03-03 00:44:41 +00:00
Erik Bernhardson
0f0b67047d Mark ApiQueryBase methods accepting arrays
These particular functions build up data to be passed into the database
abstraction, which accepts not only strings but arrays. Where conditions
generate `field IN ('a', 'b', 'c')` clauses. The options can be used
with, for example, sort to sort by one field and then a second.

Change-Id: I743f14f0e56c7f0546dfecd130925e15d63c7d64
2017-02-14 15:42:57 -08:00
Erik Bernhardson
d67197fa11 Cleanup some incorrect return annotations
Most of these are simply changing annotations to reflect
reality. If a function can return false to indicate failure
the @return should indicate it.

Some are fixing preg_match calls, preg match returns 1, 0 or false,
but the functions all claim to return booleans.

This is far from all the incorrect return types in mediawiki, there
are around 250 detected by phan, but have to start somewhere.

Change-Id: I1bbdfee6190747bde460f8a7084212ccafe169ef
2016-12-12 10:15:05 -08:00