Commit graph

106 commits

Author SHA1 Message Date
Umherirrender
e662614f95 Use explicit nullable type on parameter arguments
Implicitly marking parameter $... as nullable is deprecated in php8.4,
the explicit nullable type must be used instead

Created with autofix from Ide15839e98a6229c22584d1c1c88c690982e1d7a

Break one long line in SpecialPage.php

Bug: T376276
Change-Id: I807257b2ba1ab2744ab74d9572c9c3d3ac2a968e
2024-10-16 20:58:33 +02:00
thiemowmde
b1c9ec74fa Remove meaningless @var documentation from constants
A constant is not a variable. The type is hard-coded via the value
and can never change. While the extra @var probably doesn't hurt much,
it's redundant and error-prone and can't provide any additional
information.

Change-Id: Iee1f36a1905d9b9c6b26d0684b7848571f0c1733
2024-10-09 09:33:12 +02:00
C. Scott Ananian
15ddf1140d interwiki: Document order significance in InterwikiLookup return value
Probably not the /only/ place this should be documented, but putting
it somewhere is a start.

Bug: T370691
Change-Id: Ia75709d3f1a6e37bf807ad549e3621e08d5cbe1b
2024-10-08 22:04:26 +00:00
James D. Forrester
53b67ae0a6 Add namespace to remaining parts of Wikimedia\ObjectCache
Bug: T353458
Change-Id: I3b736346550953e3b2977c14dc3eb10edc07cf97
2024-09-27 16:19:10 -04:00
James D. Forrester
bc662aec9b Move Language and friends into Language namespace
Bug: T353458
Change-Id: Id3202c0c4f4a2043bf97b7caee081acab684155c
2024-08-10 13:36:30 +02:00
Derick Alangi
bdbd853806
tests: Avoid usage of deprecated setContentLang()
This patch uses the new style to override config: overrideConfigValue().
It also updates some minor typos in the Interwiki.php class.

Change-Id: I74f7f47a31789e79d6f045a542d14db662bd1754
2024-07-19 17:28:39 +02:00
James D. Forrester
4cf719019a Namespace remaining files in includes/site
Bug: T353458
Change-Id: I38da09f28cd68add721ba7b05f351acb56515d95
2023-12-14 14:57:34 -05:00
Amir Sarabadani
74287cf721 Namespace Site and SiteList
Bug: T353458
Change-Id: I31f7cba42c02701e462eb3ed6bcc3928d438c1ef
2023-12-14 11:23:56 -05:00
Amir Sarabadani
e282d37272 interwiki: Switch ClassicInterwikiLookup to use ICP
Bug: T330641
Change-Id: Ibb1381b75bdc12d469ca04ec33ca552a69655a34
2023-08-24 13:28:19 +02:00
Amir Sarabadani
7432b21816 Migrate more calls of Database::select* to SelectQueryBuilder
Using a php parser written on top of ANTLR4, done semi-automatically.

I checked everything and made adjustments.

Bug: T311866
Change-Id: I6150c6909bce8f3dbd745a26380cc0af9d9c547f
2023-07-26 13:01:28 +02:00
Derick Alangi
cfbdd8cfb5
interwiki: Hard deprecate InterwikiLoadPrefix hook
This hook interface was soft deprecated in 3d40c43b1f
and is no longer used anywhere. Let's hard deprecate it.

Change-Id: Ic15978f0d798c6b7e0dcd616ad876ffddd1446ea
2023-07-10 15:45:38 +03:00
Tim Starling
317b460500 Fix even more PHPStorm inspections (#3)
* Inappropriate @inheritDoc usage. Arguably all @inheritDoc is
  inappropriate but these are the ones PHPStorm flags as misleading
  due to the method not being inherited.
* Doc comment type does not match actual argument/return type.
* I replaced "@return void|never" with "@return void" since never means
  never, it doesn't make sense for it to be conditional. If a method
  can return (even if that is unlikely) then @return contains the type
  that it returns. "@return never" means that there is no such type
  because the method never returns.
* Incomplete/partial/broken doc tags

Change-Id: Ide86bd6d2b44387f37d234c2b059d6fbc42ec962
2023-03-25 00:30:15 +00:00
Amir Sarabadani
4bb2886562 Reorg: Migrate WikiMap to WikiMap/ out of includes
And WikiReference

Bug: T321882
Change-Id: I60cf4b9ef02b9d58118caa39172677ddfe03d787
2023-02-27 05:19:46 +01:00
Derick Alangi
471a84cddf interwiki: Inject wikiId into ClassicInterwikiLookup
Change-Id: I16594bbeeaa4ddab61e6a5b1fdb4b75b24b9491a
2023-01-27 13:50:07 +02: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
Timo Tijhof
09a6e51499 interwiki: Overall clean up and simplification
* Remove inline `false` fallback in fetch().
  load() does this already and can't return other falsey values
  like null.

* Remove use of Database::getCacheSetOptions as this data is
  generally not mutable.

* Remove foreach-wiki logic from clearInterwikiCache.php.
  Usually to make scripts apply cross-wiki they are iterated
  externally via something like foreachwiki (as WMF does) and
  by using the `--wiki` parameter that core supports. Iterating
  in-process is somewhat fragile and depended on various hardcoding
  and assumptions, including e.g. BagOStuff::makeKey() and how
  ClassicInterwikiLookup calls this.

  Also fix clearInterwikiCache.php to actually work on simple wikis.
  Previously it did nothing locally as $wgLocalDatabases is empty.

* Remove non-confident code from loadFromArray() for tolerating
  absence of iw_url. Move the isset() check to the one place that
  needs it, namely the hook handler in load(), and document what it
  is for.

* Simplify load() usage by inlining and moving fetchPregenerated()
  responsibility there.

* Simplify load() by merging the aborted and non-aborted hook cases,
  and document the reasons explicitly.

* Move use of WikiMap::getCurrentWikiId() to the constructor
  with TODO for proper injection.

* Rename a bunch of variables and apply more consistent terminology
  within interwiki-related source code. In particular, it was
  confusing that the variable 'objectCache' in fact did not cache
  the objects, which are cached in 'localCache' instead. Use the
  common naming found in other MW components instead ("wanCache" and
  "instances").

Bug: T315315
Change-Id: If3429b0604974efd4ff5914660979d3e49266848
2022-09-29 19:46:35 +00:00
Timo Tijhof
0ba2242300 interwiki: Remove outdated CDB references
* CDB stands for "constant database" file, hence also changes references
  to "constant" when likely intended to refer to CDB.

* Remove reference to non-existent docs/Configuration.md.

* Remove unused resetLocalCache() method. This was documented as
  internal for testing only, but tests did not use it.
  It was left behind in 2016 with I7d7424345d0ce3ce90 (025f15a208).

Bug: T315315
Change-Id: I61d9689160d9bf5715c4ff18009fbd16236d34e6
2022-09-23 16:41:08 +01:00
jenkins-bot
e31b1fbe20 Merge "interwiki: Adjust documentation for InterwikiLookup::getAllPrefixes" 2022-03-09 22:28:04 +00:00
Umherirrender
e0c3e75414 interwiki: Adjust documentation for InterwikiLookup::getAllPrefixes
Use bool instead of string, most caller provided int instead.

The InterwikiLookupAdapter class is strict comparing Interwiki::isLocal
(a bool) with the given $local value, which evaluates always to false
and the expected filter option is not working.
The unit tests is using bool, not the documented string.

The ClassicInterwikiLookup is not affected.

Found by phan strict checks

Change-Id: I63ed9772429c6f5bfe38a9fad190491812866f3f
2022-02-24 17:08:29 +00:00
daniel
a5277ce87f Avoid references to DefaultSettings.
This replaces references to DefaultSettings with
references to config-schema.yaml where appropriate.

NOTE: this does not yet change Setup.php. DefaultSettings.php
remains intact and is still being used.

NOTE: this does not remove usages in the installer, see I5d8843a1062fbf
for that.

Bug: T300129
Change-Id: Ie6152cf510c3be61bc22167ca6d90dfc28910a45
2022-02-22 19:43:50 +01:00
Tim Starling
b90d2dd5c2 Optimise Skin::getLanguages()
Skin::getLanguages() was consuming 4% of index.php CPU time. In local
testing, it was called three times per page view. So:

* Memoize it, analogous to the nonfunctional code in SkinVector.
* Simplify ClassicInterwikiLookup by removing the option to pass a CDB
  file path. This was only ever supported by a WikimediaMaintenance
  script. In the unlikely event that someone is using this feature, they
  have the same motivation to switch to PHP as we did in T122362.
* Increase the size of ClassicInterwikiLookup's MapCacheLRU from 100 to
  1000. This helps greatly in the case when $wgInterwikiCache is false
  and more than 100 interwikis are requested and seems harmless
  otherwise.
* Optimise Title::getNsText() by assuming that the canonical name of
  NS_MAIN is the empty string.
* Rearrange Message::__construct() to avoid duplicate type checks.

Change-Id: I736cb74efc267fd2473a3267471735238217251c
2022-02-08 22:34:15 +00:00
Daimona Eaytoy
e0d3b3e8fc Use getWithSetCallback() instead of get() + set()
This allows the backend to do whatever it can to ensure atomicity, and
is also easier to read, since the intent is obvious.

Change-Id: Ibbfecd92a2c6d9a5997ca37ea101e068bd1e8202
2021-11-18 18:58:13 +00:00
Umherirrender
8831b494c1 Use @deprecated annotation on hook interfaces, not functions
Use only one place to document the deprecation of hook
interfaces/functions

Bug: T282903
Change-Id: Ie7d2d7a50afe2897e5c2369f473a33ecaa821637
2021-05-17 23:00:40 +02:00
Kunal Mehta
ec0be22116 Update Legoktm's email address
Change-Id: Icd58c93bb0cff5b0a4e7b7f02873a271bab8964f
2021-05-02 05:39:37 +00:00
DannyS712
ebf762cc67 ClassicInterwikiLookup: inject load balancer
Per todo comments, to avoid using wfGetDB

Change-Id: Ic4a7f9c5bcbfef3042e5ec0606babbd14d3e6124
2021-04-22 23:23:00 +00:00
C. Scott Ananian
3d40c43b1f Deprecate InterwikiLoadPrefix hook
The InterwikiLoadPrefix hook isn't compatible with Parsoid, as it is
unidirectional and doesn't support enumerating all valid prefixes
(T270444).  Set/reset $wgInterwikiCache to mock the interwiki table
for parserTests and other unit tests instead.

This is a soft deprecation, as the used-in-production
Extension:Interwiki still uses InterwikiLoadPrefix, although not in a
way that would break Parsoid (since $wgInterwikiCache is set in
production).

Bug: T270444
Change-Id: If2507017c99c4ee42c104a0890bc45a84d7239d5
2020-12-21 19:28:48 +00:00
C. Scott Ananian
3cfe800871 ClassicInterwikiLookup: Fix typo in comment
Change-Id: I24bf99554f6005bc37d2c5aa4dc0fd18c1585388
2020-12-18 21:36:27 +00:00
Reedy
b3731e119c InterwikiLookupAdapter: Move code out of loop that doesn't vary based on loop variable
Change-Id: If090a4603a22166b0e907ba2163f3bf68ae1e3a3
2020-12-06 00:22:42 +00:00
daniel
2e57447c58 Document hook names in hook interfaces.
Bug: T258665
Change-Id: Ifddbf57f8aa2e3eb0d5845601376cbafa08ed407
2020-09-27 12:03:12 +02:00
daniel
e6e0ad2472 Replace "@stable for implementation" with "@stable to implement"
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: I17e5e92e24c708ffc846945a136347670a3a20c7
2020-07-13 11:05:49 +02: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
apaskulin
c44488f725 docs: Hook interface doc comment review
Edited doc comments for hook interfaces to improve
consistency and add type hints.

Bug: T246855
Change-Id: I38fa802463cd6f39bf5946dbbeb1b3ebaea604b2
2020-04-21 09:10:08 +10:00
Tim Starling
f5aaf75ad1 Automatically generated hook interfaces
Add hook interfaces which were generated by a script which parses
hooks.txt and identifies caller namespaces and directories.

Hook interfaces are mostly placed in a Hook/ subdirectory
relative to the caller location. When there are callers in multiple
directories, a "primary" caller was manually selected. The exceptions to
this are:

* The source root, maintenance and tests, which use includes/Hook. Test
  hooks need to be autoloadable in a non-test request so that
  implementing test interfaces in a generic handler will not fail.
* resources uses includes/resourceloader/Hook
* The following third-level subdirectories had their hooks placed in
  the parent ../Hook:
    * includes/filerepo/file
    * includes/search/searchwidgets
    * includes/specials/forms
    * includes/specials/helpers
    * includes/specials/pagers

Parameters marked as legacy references in hooks.txt are passed
by value in the interfaces.

Bug: T240307
Change-Id: I6efe2e7dd1f0c6a3d0f4d100a4c34e41f8428720
2020-04-20 13:31:05 +10:00
Daimona Eaytoy
a1f26de804 Remove deprecated methods in the Interwiki class
codesearch lists 0 usages: https://codesearch.wmflabs.org/deployed/?q=%3A%3A(isValidInterwiki%7Cfetch%7CinvalidateCache%7CgetAllPrefixes)%5C(&i=nope&files=&repos=

Change-Id: Ieea4ee724197d949db31c0430a8460ee273f9aba
2020-03-09 20:36:50 +00:00
Timo Tijhof
95ec909e52 WikiMap: Add WikiMap::getCurrentWikiId() to make common use case easier
Change-Id: Ie225ebfc37c824e3167742137bbbc9f64aca5f5e
2020-03-03 16:04:21 +00: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
0688dd7c6d Set method visibility for various constructors
Change-Id: Id3c88257e866923b06e878ccdeddded7f08f2c98
2019-12-03 20:17:30 +01:00
Daimona Eaytoy
114ee6e412 Fix new phan errors, part 6
Bug: T231636
Change-Id: I1870b6cbeb31e54fde5e675fec51446b330e06c5
2019-10-20 17:53:48 +00:00
Thiemo Kreuz
8a4e15db7f Add missing newline between <?php and namespace/use section
The rest of the codebase is using this code formatting standard.

Change-Id: I4d2ba61757a7e28d40096d9dc5915005c340d4f2
2019-06-03 13:36:48 +00:00
Aaron Schulz
798d3d048a Clean up some database domain ID related code and fix some comments
Change-Id: Id5c5640e05301161dbb7c2be363e32d7d1c9a511
2019-03-29 14:30:21 -07:00
Aaron Schulz
5196ac32c6 Rename WikiMap DB domain ID methods to reduce confusion with web domains
Those added in this same release do not need alias methods.

Change-Id: I05feeb9b0b13afe43aea1f95551965489cdbe094
2019-02-06 12:28:45 -08:00
Aaron Schulz
afc530c33e Use WikiMap methods in ClassicInterwikiLookup instead of wfWikiId()
Change-Id: Ia3d843c79fa31fec59a04b92f4619458ae06de62
2018-10-29 22:01:50 +00:00
Umherirrender
13dd2b95c2 Fix caller name in ClassicInterwikiLookup::load
Seeing MediaWiki\Interwiki\{closure} in the logs as caller is not
helpful

Change-Id: I39af68a02d40667e428c7f30c88aacab8a02cd86
2018-09-30 13:09:46 +02:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Kunal Mehta
c2b506a59f Hard deprecate Interwiki static methods
Change-Id: I803df3ef90bf6b602e85ae48f25745f4dc6aab3a
2018-06-07 11:40:46 -07:00
Kunal Mehta
a498abf272 installer: Fix display of UPGRADE by disabling InterwikiLookup
Since 129067c907, parsing section titles has looked up interwiki
prefixes with InterwikiLookup. In the web upgrader, this triggers
database access, and since that service is disabled, it throws
exceptions, causing parsing to fail.

Work around that by using a dummy InterwikiLookup service that knows
about no interwiki prefixes. Maybe one could be written to just read
from the stock `interwiki.list`, but that's a project for another time.

Bug: T196607
Change-Id: I13485a9af79297b552a1128240cb8597c2ef83d8
2018-06-07 01:01:13 -07:00
Bartosz Dziewoński
485f66f174 Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenient
Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/
Replace with: '\1 ?? '

(Everywhere except includes/PHPVersionCheck.php)
(Then, manually fix some line length and indentation issues)

Then manually reviewed the replacements for cases where confusing
operator precedence would result in incorrect results
(fixing those in I478db046a1cc162c6767003ce45c9b56270f3372).

Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
2018-05-30 18:06:13 -07:00
Kunal Mehta
e0193327bd Fix MediaWiki.Commenting.LicenseComment.InvalidLicenseTag errors
Change-Id: I936c3f5fca1a0061f215e80469f5d882cb32ee29
2018-05-23 16:23:42 -07:00