Commit graph

84 commits

Author SHA1 Message Date
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
Umherirrender
e1a203603c Replace wfGetLB
@deprecated since 1.27

Change-Id: Ibdd49fdfc0d1511503e1ed2173a592c612996c53
2018-05-02 22:30:24 +02:00
Fomafix
73a514b574 Remove superfluous spaces and semicolons in comments
Change-Id: Ib4b452f1843ec250c8c1fcc2a738d80726b6135d
2018-02-05 19:05:57 +00:00
Thiemo Mättig
409da2d8b3 Remove leading backslashes from "use \…" tags
Change-Id: I494b029de089a07e3b946ee78293a12d5036f63e
2017-12-28 16:30:05 +01:00
Umherirrender
c0930e9491 Fix return of Interwiki::invalidateCache
InterwikiLookup::invalidateCache does not expected a return value

Change-Id: I5b2ba21ccb42ba9925205eb1645f2152fd51c0a0
2017-09-10 00:17:26 +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
jenkins-bot
ca55cfd87d Merge "Fix inconsistent spec of InterwikiLookup::getAllPrefixes." 2017-05-04 16:38:08 +00:00
daniel
7b45d112e6 Fix inconsistent spec of InterwikiLookup::getAllPrefixes.
The documented return type was not what existing callers expected,
and not what the default implementation actually returned.

This patch fixes the interface documentation and the behavior of
an alternative implementation.

Change-Id: Ib09bffeba3ddc5b43da1c7c299f1fa946be4e2e2
2017-05-04 08:40:35 +00:00
Timo Tijhof
0548f1902c Interwiki: Don't override interwiki map order
The ksort() here was causing the order to be enforced as
alphabetical instead of preserving the original order.

The order usually doesn't matter, except with regards to handling
of duplicates. Due to Parsoid normalising external links to interwiki
links, it has to do a reverse lookup. In doing so it has to decide
which one to prefer. It currently picks the first match from the
API request for meta=siteinfo&siprop=interwikimap, which didn't
match the defined order in the actual Interwiki map due to ksort()
being called in getAllPrefixes().

Sort in this function was originally introduced in 2010 with
commit 844e7c83e4 (2011; r92528; T21838), which is otherwise unrelated
and left no rationale.

The existing unit tests needed to be adjusted slightly as they
assumed alphabetical order. While it appeared they were also defined
in alphabetical order, this was merely the order of the variable
creation. The effective order is preserved within locals and globals,
but overall globals come before locals.

Also removed the duplicate test for Hash and CDB in InterwikiTest
that belongs in ClassicInterwikiLookupTest instead.

Bug: T145337
Change-Id: I7348748801cbdf16c6ceea5b0654fc174b79707e
2017-04-25 15:38:32 -07:00
jenkins-bot
0697e41485 Merge "Move Database and subclasses to Rdbms namespace" 2017-04-12 18:07:43 +00:00
Aaron Schulz
d735dc562d Move Database and subclasses to Rdbms namespace
Change-Id: I52bef87512f9ddd155d1f4cc0052f6b7a0db5b42
2017-04-12 10:43:57 -07:00
Timo Tijhof
6375900e96 interwiki: Remove inappropiate use of wfMemcKey()
This is used for lookup in a CDB file or PHP static array.
In neither case is the key created by wfMemcKey() or any other
implementation of BagOStuff::makeKey().

This is already broken if:
* An interwiki prefix were to contain characters not supported by
  Memcached.
* An interwiki prefix and wikiid together are too long for Memcached.
* If the site has wgCachePrefix configured, which overrides the
  wfWikiID() namespace makeKey() normally uses.

dumpInterwiki.php does not use wfMemcKey() either (and should not).

This was simply here as leftover from many rewrites ago, its
only purpose is to create wikiid + prefix joined by colon.

Ref T148958.

Change-Id: I45682133ed593fbb0d66af5a67751f77f15a4a14
2017-04-11 22:39:41 +00:00
Reedy
2956bee005 ClassicInterwikiLookup: Call static function selectFields statically
Change-Id: I5260ccad99057323d0f3a669a420bbd723363986
2017-04-05 18:27:02 +00: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
addshore
66556fb1b9 Fix case of MediaWikiSite in IWLookupAdapter
Change-Id: Ice98cb0a3127333c045cfb4328081ad5c490c435
2016-11-05 09:21:06 +00:00
addshore
501327550c Fix @since tags of changes that missed the branch
Follows:
FormOptions: I29ae63472536f99f7f9546f30d86e7bd324d3094
MediaWikiServices: Ie5fd2c523ceec8cc2656e749928f38909dc4bdf1
InterwikiLookupAdapter: I387dc2ff3f5564fcedde835dec66781d8e9424fd

Change-Id: I8d99d0b559d04083fb83b0fcf45cde95dab32d64
2016-11-05 09:20:27 +00:00
Amir Sarabadani
56195efaa1 Introduce InterwikiLookupAdapter on top of SiteLookup
This adapter assumes the db name (Interwiki wiki id) equals global ids.

Bug: T135146
Change-Id: I387dc2ff3f5564fcedde835dec66781d8e9424fd
2016-10-18 10:18:31 +00:00
Leszek Manicki
8f9169f123 Fix doc typo in InterwikiLookup
Change-Id: I2a547a005955cb9f596ff6927feb7df3d5d91872
2016-09-08 15:11:55 +02: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
daniel
025f15a208 Factor InterwikiLookup out of Interwiki class.
This keeps the existing app logic for looking up interwiki information
intact in ClassicInterwikiLookup. The idea is to seamlessly switch to a new
implementation when it becomes available, while also allowing us to
switch back in case of problems.

Change-Id: I7d7424345d0ce3ce90ba284006ee9615e3d99baa
2016-05-18 11:57:32 +02:00
Aaron Schulz
109feaba80 Remove wfDebug() from getInterwikiCacheEntry()
This is uses a fair amount of time according to flamegraphs.

Change-Id: I178a590ab5de2f6fb9366ad59434d8b27dad710d
2016-05-09 22:40:31 -07:00
daniel
ff764440da Introduce InterwikiTest
This test class verifies that Interwiki currectly handles information
from the database, CDB files, and plain arrays. This is intended to
allow confident refactoring when implementing T113034.

Bug: T113034
Change-Id: I2b68d11e3e946d81fa5f5f65a28fc399e7936c0f
2016-04-23 21:44:59 +02:00