Commit graph

77 commits

Author SHA1 Message Date
DannyS712
c1db64b808 Make use of ??= in more places
New feature from PHP 7.4

Change-Id: Ifa7a9bc7b2ec415ad7ecb23f4c1776f51f58fd6b
2022-12-17 01:10:13 +00:00
Umherirrender
2515199b2f Hard-deprecate BacklinkCache::get/getLinks/getCascadeProtectedLinks
Depends-On: I39a532bcce35191db6abe4fdcdd6f95df74e5e87
Depends-On: I4c8bcec6bb2396b31a7cc73cb7f6f83742dc001a
Change-Id: I09d0aae2400d3b70d8ad59df4e47ee23d3f5072b
2022-12-15 10:51:44 +00:00
jenkins-bot
f9a548b6ea Merge "remove unused BacklinkCache::$instance" 2022-12-14 22:12:06 +00:00
jenkins-bot
0fb254ffa5 Merge "cache: Inject HookContainer into BacklinkCache" 2022-12-14 22:03:37 +00:00
DannyS712
1c174968b5 remove unused BacklinkCache::$instance
Usage was removed with the introduction of the
BacklinkCacheFactory service

Follow-up: I2943935e2d8148fce4457f76eca0234be72a5a5a
Change-Id: Id14b7c466d4a950142477f01e1786d5d630afa9d
2022-12-14 21:47:18 +00:00
Lucas Werkmeister
94c86d017e Use SelectQueryBuilder in BacklinkCache
Mostly replace the traditional / ANSI-89 JOINs in this class (i.e.,
select from two tables, empty $joinConds, actual join condition in
$conds) with proper JOINs, and also mostly replace the “kind of janky”
$conds filter in queryLinks(): instead, initQueryBuilderForTable(), the
new replacement for getConditions(), now knows whether the page table
needs to be joined or not.

However, the hook still needs to be supported (there is one extension in
codesearch that actually uses it and seems to be maintained), and in
that hook we don’t know which part of the $conds are JOIN conditions; in
this case, we have to keep the “kind of janky” filter, and also join the
page table using table() instead of join().

Bug: T311866
Change-Id: Ic49bf5d8fd136d296752e8807f6032bfae74dcdf
2022-12-08 12:20:54 +01:00
Amir Sarabadani
09b18a8f4c Reorg: Move Title-related classes to title/
These three classes:
 - TitleArray
 - TitleArrayFromResult
 - TitleFactory

We need to move these and the rest of files under title/ to Title/ (and
namespace them) but the patch will become way too big given that Title class is
also one of them.

Bug: T321882
Change-Id: Iac1688172ee457348a08a470c86e047571feb8e0
2022-11-26 09:30:32 +00:00
Matěj Suchánek
501a16eb18 Hard-deprecate BacklinkCache::get
It has been deprecated since 1.37 and it is unused.

Change-Id: I8b588073f1d22846a8564e340e019de45e7566a3
2022-11-20 20:32:11 +01:00
Umherirrender
6e97aa65b7 cache: Inject HookContainer into BacklinkCache
Change-Id: I1defcfde8a71e9e0bfb4a667c00e280aca83d868
2022-11-19 22:15:32 +00:00
Bartosz Dziewoński
af6b4e91c2 Remove unnecessary wrappers for generator functions
We define an anonymous function just to immediately call it.
Why not run the code directly?

Follow-up to:
* I8f1ed821cf1d8a4ef5b073e788386920dc337e0c (BacklinkCache)
* Ibcb37affa9ba1c891bc62964a3dd34b67214cfa1 (PageSelectQueryBuilder)
* Ibb1c58016e3956a46bfaf1a9f51f265114bb9ace (UserQueryBuilder)

Change-Id: I5a7827623c93ce524761ba501a6c6c75d17d6aae
2022-11-14 18:34:54 +00:00
Tim Starling
0077c5da15 Use short array destructuring instead of list()
Introduced in PHP 7.1. Because it's shorter and looks nice.

I used regex replacement.

Change-Id: I0555e199d126cd44501f859cb4589f8bd49694da
2022-10-21 15:33:37 +11:00
Brian Wolff
466fa62321 BackLinkCache::queryLinks: Make janky filter more robust
The conds part of the query, could potentially be a string instead
of an array. The individual keys can have values that are not strings
like numbers or null. This casts everything appropriately to be
more robust.

Additionally, this fixes a deprecation warning on php8.1 about
passing null to preg_match.

Bug: T313663
Change-Id: I5671c7882af57be29299e9032c6e8f056fe10e30
2022-09-12 08:36:51 +00:00
Amir Sarabadani
84edec9825 LinksUpdate: Last pieces of templatelinks migration
I dropped the columns and these paths started to fatal. Nothing super
complicated.

Bug: T312865
Change-Id: Ic44edc5b4a2d8da924ba6176b619715e4780bddd
2022-07-25 20:23:30 +02:00
Aryeh Gregor
7b791474a5 Use MainConfigNames instead of string literals, #4
Now largely automated:

VARS=$(grep -o "'[A-Za-z0-9_]*'" includes/MainConfigNames.php | \
  tr "\n" '|' | sed "s/|$/\n/;s/'//g")
sed -i -E "s/'($VARS)'/MainConfigNames::\1/g" \
  $(grep -ERIl "'($VARS)'" includes/)

Then git add -p with lots of error-prone manual checking. Then
semi-manually add all the necessary "use" lines:

vim $(grep -L 'use MediaWiki\\MainConfigNames;' \
  $(git diff --cached --name-only --diff-filter=M HEAD^))

I didn't bother fixing lines that were over 100 characters unless they
were over 120 and triggered phpcs.

Bug: T305805
Change-Id: I74e0ab511abecb276717ad4276a124760a268147
2022-04-26 19:03:37 +03:00
Amir Sarabadani
6fd2843361 linker: Add LinksMigration service for read new
Bug: T304780
Change-Id: Ifdea1ef80c34831564fe12827c5c06ade6200df8
2022-04-07 16:54:38 +00:00
Umherirrender
1f71eccf63 phan: Disable null_casts_as_any_type setting
Make phan stricter about null types by setting null_casts_as_any_type to
false (the default in mediawiki-phan-config)
Remaining false positive issues are suppressed.
The suppression and the setting change can only be done together

Bug: T242536
Bug: T301991
Change-Id: I0f295382b96fb3be8037a01c10487d9d591e7e01
2022-03-21 18:25:07 +00:00
Umherirrender
fe48e1223a cache: Fix various scalar and null types to match documentation
Adding float as type when INF is used as argument

Found by phan strict checks

Change-Id: I7e19cd0d9b09bf685e4e8387c900f303b669ad54
2022-03-14 17:36:04 +00:00
Umherirrender
d7248d63fb Fix various documentation related to null types (part II)
The functions returning null or the class property is set explict null.
Some function should not accept null or return null.

Found by phan strict checks

Change-Id: Ie50f23249282cdb18caa332f562a3945a58d86ff
2022-03-08 23:45:31 +00:00
TChin
47adb6d65a Refactor global variables to use MediaWikiServices instead
Automatically refactors wg prefixed globals to use MediaWikiServices config using Rector. Doesn't include files that set globals or files that fail CI.

Rector Gist: https://gist.github.com/tchin25/7cc54f6d23aedef010b22e4dfbead228

* This patch uses a modified source code rector library for our specific use case and the rector will have different effects without it.

A writeup for future reference is here: https://meta.wikimedia.org/wiki/User:TChin_(WMF)/Using_Rector_On_MediaWiki

Change-Id: I1a691f01cd82e60bf41207d32501edb4b9835e37
2022-01-10 13:55:53 -05:00
Reedy
2a2bb1e9bd Remove or replace usages of "sane"
Bug: T254646
Change-Id: I096b2cf738a1395a14f1d47bcbed0c2c686c2581
2021-11-22 13:35:17 +00:00
Reedy
7bf779524a Remove or replace usages of "sanity"
Bug: T254646
Change-Id: I2b120f0b9c9e1dc1a6c216bfefa3f2463efe1001
2021-11-19 23:19:42 +00:00
TChin
fd5915823f Update callers of deprecated BacklinkCache methods
Bug: T290015
Change-Id: I73a111d064f7778bbeb90fd4ea85d8bec201427b
2021-09-29 18:56:17 +00:00
Derick Alangi
db43511e6a Title: Make use of BacklinkCacheFactory service
Change-Id: I48161585de6f329ec4037156234e0b07b3b837e6
2021-09-09 14:04:02 +01:00
Derick Alangi
96bc83e8eb Add BacklinkCacheFactory Service
Bug: T279433
Change-Id: I2943935e2d8148fce4457f76eca0234be72a5a5a
2021-09-09 09:58:52 +01:00
Aryeh Gregor
f79b99b7b4 Remove Title usage from BacklinkCache
Change-Id: I8f1ed821cf1d8a4ef5b073e788386920dc337e0c
2021-08-30 10:53:02 -04:00
TChin
d4cb97952f Add logger to BacklinkCache serializing
While refactoring BacklinkCache, it was noticed that there is a __sleep method even though it doesn't seem to be used anywhere.

Git blame indicated that the last time BacklinkCache could've been potentially serialized was back in 2012 when Title used to save an instance of it. This is no longer the case.

However, there is a slight possibility that it's used in a hidden corner of some extension out there, so the plan is to add a logger, wait a week to see if __sleep is ever hit, and if not, we can just remove it so we don't have to worry about it when refactoring and writing tests.

Bug: T288278
Change-Id: Idb0f9985cb321cd53fea60d1fc94613c914e0de2
2021-08-20 12:58:26 -04:00
Umherirrender
8de3b7d324 Use static closures where safe to use
This is micro-optimization of closure code to avoid binding the closure
to $this where it is not needed.

Created by I25a17fb22b6b669e817317a0f45051ae9c608208

Change-Id: I0ffc6200f6c6693d78a3151cb8cea7dce7c21653
2021-02-11 00:13:52 +00:00
Ed Sanders
7683f7d839 Use strict (in)equality with namespaces constants when LHS is definitely an integer
Change-Id: I8fede00dfe1270d93c5d78d3c36e788cddfc8a99
2020-07-31 18:03:28 +01:00
Tim Starling
47a1619027 Remove terminating line breaks from debug messages
A terminating line break has not been required in wfDebug() since 2014,
however no migration was done. Some of these line breaks found their way
into LoggerInterface::debug() calls, where they mess up the formatting
of the debug log.

So, remove terminating line breaks from wfDebug() and
LoggerInterface::debug() calls.

Also:
* Fix the stripping of leading line breaks from the log header emitted
  by Setup.php. This feature, accidentally broken in 2014, allows
  requests to be distinguished in the log file.
* Avoid using the global variable $self.
* Move the logging of the client IP back to Setup.php. It was moved to
  WebRequest in the hopes that it would not always be needed, however
  $wgRequest->getIP() is now called unconditionally a few lines up in
  Setup.php. This means that it is put in its proper place after the
  "start request" message.
* Wrap the log header code in a closure so that variables like $name do
  not leak into global scope.
* In Linker.php, remove a few instances of an unnecessary second
  parameter to wfDebug().

Change-Id: I96651d3044a95b9d210b51cb8368edc76bebbb9e
2020-06-03 12:01:16 +10: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
Reedy
b1e515e36e Fix even more PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I4a30a44bc33fc98479799438d65342f6529e14f9
2020-05-16 00:51:46 +01:00
Umherirrender
8660ca657d Avoid small code duplication in BacklinkCache
Reuse $fromField to build the _from field name
Also build it only when needed and do not hard code AS,
let it add by the abstract database layer

Change-Id: I2c3a2a863b963fb7f24c02e1ce44a56fccea95e5
2020-05-07 22:17:02 +02:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Umherirrender
eb2373dcd1 Set visibility on php magic functions __destruct/sleep/wakeup/get/call
All the magic functions needs public visibility to be callable from php
internals like garbage collector

Change-Id: I1baf04bf8ff787da880d46e4a6daa77f5a6de73f
2019-12-05 18:52:55 +01:00
Daimona Eaytoy
fb3428eb8f Unsuppress other phan issues with low count
And also update approximated counts, which for the most part are lower
than reported (hooray!)

Bug: T231636
Depends-On: Ica50297ec7c71a81ba2204f9763499da925067bd
Change-Id: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
2019-08-30 09:42:15 +00:00
Umherirrender
e6c5093515 Use IResultWrapper in LinkBatch and BacklinkCache
Change-Id: If96d6dfeea17e73073b78c19526787e788f7b412
2019-06-06 21:56:18 +02:00
Alangi Derick
b4ecf374fe Fix PHPDoc type for instance variables and methods
Should be "string" not "String" and "array" not "Array" in
@param, @return and @var use cases. Also, minor typo fixes.

Change-Id: I9d5ebc5b741c6560907b95f7c0c4039da2861f4a
2018-10-21 13:00:25 +01:00
Cormac Parle
23ead9bbd6 Clear the backlink cache on file delete
When a file is deleted pages that link to the file
(backlinks) are purged. The set of backlinks for a file
is cached in the backlink cache, and this is where the set
of backlinks that need purging is read from. If, at file delete
time, there is a backlink cache for the file but it is not
up to date, then backlinks missing from the set of cached
backlinks for that file will not be purged, leading to
broken links.

This patch clears the backlink cache on file delete before
initiating purging of backlinks.

Bug: T183478
Change-Id: I3bbd79e5a8fa14bf80ceee81e944108edada322e
2018-01-16 09:32:28 +00: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
82e2c924e4 Remove "@author Aaron Schulz" annotations
Bug: T139301
Change-Id: Ib5248e8e27d60611c7373bce4b29dd5e85aa3489
2017-06-27 15:24:14 -07:00
Aaron Schulz
33bc3e7dfb Use makeKey() in BacklinkCache
Change-Id: I23c000c8c2c77aa538fe258ea34eb764987eb52d
2017-04-20 12:26:23 -07:00
Aaron Schulz
d735dc562d Move Database and subclasses to Rdbms namespace
Change-Id: I52bef87512f9ddd155d1f4cc0052f6b7a0db5b42
2017-04-12 10:43:57 -07:00
Aaron Schulz
488a647831 Move IDatabase/IMaintainableDatabase to Rdbms namespace
Change-Id: If7e8a8ff574661fd827de8bcec11d2c39a687300
2017-03-28 15:32:38 -07:00
Aaron Schulz
e01fd44388 Move ResultWrapper subclasses to Rdbms
Change-Id: I6f3f0e85e268b24c57c537aa6ad8016e0b4cdddb
2017-03-03 00:44:41 +00:00
James D. Forrester
9635dda73a includes: Replace implicit 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: I6f59febaf8fc96e80f8cfc11f4356283f461142a
2017-02-21 18:13:24 +00:00
Aaron Schulz
30f4b3c103 Replace DatabaseBase => Database in more places
Change-Id: If37a7909056bf2c31a8228cbc84f0fbbf5f1c517
2016-09-28 15:53:02 -07: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
Aaron Schulz
16266edff3 Change "slave" => "replica DB" in /includes
Change-Id: Icb716219c9335ff8fa447b1733d04b71d9712bf9
2016-09-05 21:01:01 +00:00
Amir Sarabadani
efa0d7af44 Clean up array() syntax in docs, part III
Also fixing some typos here and there

Change-Id: I29c29acf87f84ba9993ba75ebf2ad8091d981574
2016-08-13 05:40:40 +04:30
Reedy
b5656b6953 Many more function case mismatches
Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
2016-03-19 00:20:58 +00:00