Commit graph

161 commits

Author SHA1 Message Date
Timo Tijhof
35d62b19e2 context: Remove duplicate log message from RequestContext::getLanguage()
> A long, long time ago,
> I can still remember how those warnings used to make me smile.
> And, I knew if I had my chance, that I could make those traces dance,
> and... Maybe they'd be present for a while.

Ever since T45086, we have traces for warnings in production
so this is no longer needed. Also it uses getTraceAsString()
which is something we're trying to phase out.

Bug: T233342
Change-Id: I79ce582c7f057b22a9ead2f2b014aba41f869325
2020-07-23 22:10:54 +00:00
jenkins-bot
a5f4732261 Merge "Replace "@stable for implementation" with "@stable to implement"" 2020-07-13 09:31:44 +00:00
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
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
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
aedc93fdb0 Mark remaining eligible classes as stable for subclassing
This classes were found by surveying concrete classes derved from base
classes in core.

Bug: T247862
Change-Id: I231752aaad26e2ab3f097301e449b31e723590f0
2020-07-10 15:02:27 +02:00
daniel
7572a152fc Annotate extensible classes.
This marks some base classes as stable for subclassing.

Bug: T247862
Change-Id: I7b77075849aa40960f2486b463e498a3ea8058e9
2020-07-09 11:07:38 +02:00
daniel
128565505c Mark additional classes as newable for now.
The following glasses are marked as newable per the
Stable Interface Policy, even though logically, they should not be
newable. This is done for classes that are currently instantiated
by extensions, and lack an alternative.

A better way for obtaining an instance of these classes should be
created in the future. At that point, direct instantiation should
be deprecated and replaced.

- includes/ApiMain.php - needs factory
- includes/media/BitmapMetadataHandler.php - should become a stateless service or use handler pattern
- includes/GitInfo.php - should become a stateless service
- includes/logging/LogPage.php - should become a stateless service or use command pattern
- includes/logging/ManualLogEntry.php - should become a stateless service or use command pattern
- includes/poolcounter/PoolCounterWorkViaCallback.php - needs a factory
- includes/context/RequestContext.php - needs to be narrowed down, and should use a factory
- includes/search/SearchHighlighter.php - should have a factory
- includes/TitleArrayFromResult.php - should perhaps be part of TitleFactory
- includes/user/User.php - should at least get a factory method for anons
- includes/diff/Diff.php: needs a TextDiffGenerator service or a factory
- includes/EditPage.php: needs a factory

Bug: T247862
Change-Id: I033158e693c98630ee167d9528fc8c9936f978d4
2020-07-08 18:06:12 +02:00
daniel
442fb30ce1 Stability annotations for interfaces.
Per the Stable Interface Policy, PHP interfaces should not be
directly implemented by extensions, unless they are marked to be safe
for that purpose.

Bug: T247862
Change-Id: Idd5783b70fc00c03d57f5b1a887f0e47c4d7b146
2020-07-07 22:01:29 +00:00
daniel
bd5c3d06a2 Annotate newable classes
This annotates classes that can safely be instantiated by
extensions, per the Stable Interface Policy.

Bug: T247862
Change-Id: Ia280f559874fc0750265ddeb7f831e65fd7d7d6a
2020-07-07 15:38:57 +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
Petr Pchelko
204fa7e509 Remove usages of deprecated Language methods
Change-Id: Iad3375b141b1d87c890baec6ecd16ed92f93e699
2020-02-16 00:45:48 +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
jenkins-bot
b874e6ab98 Merge "Provide a full trace to GlobalTitleFail debug entries" 2020-01-06 19:24:24 +00:00
Kunal Mehta
99007e96c7 Use namespaced IPUtils class
Change-Id: I047e099a93203a59093946d336a143d899d0271f
2020-01-01 02:36:49 -08:00
Daimona Eaytoy
f16d87a8cc Provide a full trace to GlobalTitleFail debug entries
None of these is currently useful: see for instance [1]. Having a whole
trace can help a lot in finding where the faulty call is. Also avoid the
overhead of calling wfDebugLog.

[1] - https://logstash.wikimedia.org/app/kibana#/doc/logstash-*/logstash-mediawiki-2019.12.19/mediawiki?id=AW8gPL5bKWrIH1QRtQa3&_g=h@1251ff0

Bug: T159284
Change-Id: I25e0f0e2ef4899b4eaa644c74fdeaba21d79aefe
2019-12-20 14:12:59 +01:00
jenkins-bot
393909537e Merge "RequestContext: Clarify uselang support and how it works" 2019-11-01 03:08:19 +00:00
Timo Tijhof
c26ba1f162 RequestContext: Clarify uselang support and how it works
Follows-up to cad882954a. I considered augmenting
the sanitizeLangCode() or isValidCode() function to reject
invalid UTF-8. But I realise now that it isn't so much about
"invalid" UTF-8 as it is about non-canonical forms for expressing
otherwise valid UTF-8 strings.

For example "Le\xcc\x81cole" and "L\xc3\xa9cole" both render
as "Lécole" but use different ways to accomplish it. To prevent
creation of inaccessible page titles, and to make link creation
easy, UtfNormal is used to normalises these when opening redlink
urls and when saving wikitext.

While non-ASCII will continue to work after cad882954a, any
links to such characters must be made in normal form. Given
these are generally linked to from wiki pages or gadgets with
a predefined set of urls (and not typed ad-hoc by an end user)
this seems fine to require. I fid not find violations of this
on Commons.

Document the ceveat for now.

Change-Id: I36fece34e40f7e58b7aed5521c49a241a67d006f
2019-10-31 19:57:03 -07:00
Aryeh Gregor
0de9c47b50 Remove Language::factory and getParentLanguage use
Change-Id: I11f8801ef47ec1a1f63d840116e69667e6f3ae3c
2019-10-27 12:34:28 +02:00
Umherirrender
8752df6592 Use varargs for MessageLocalizer::msg and similar
Bug: T191666
Change-Id: I59f2ae1a96af392026fc106e57d23553003c16b8
2019-10-05 17:47:49 +00:00
Daimona Eaytoy
b65af759f1 RequestContext: Declare the dynamic property for language recursion
Change-Id: I601f98190cb8f760541ba1f05a3070fc43c25ccb
2019-09-08 18:32:05 +00:00
Daimona Eaytoy
5eac6d131c Unsuppress more phan issues (part 3)
Bug: T231636
Depends-On: I78354bf5f0c831108c8f606e50c87cf6bc00d8bd
Change-Id: I58e67c2b38389df874438deada4239510d21654f
2019-08-31 16:38:55 +00:00
jenkins-bot
66ac8dbd43 Merge "context: Use getRawVal instead of getVal for 'uselang' and 'useskin'" 2019-07-31 23:07:22 +00:00
Timo Tijhof
2058d79330 context: Make the getSkin() fallback logic more explicit
Previously the first two post-hook checks where mutually exclusive
and the fallback was generic (not conditional) which means we
would also allow the first two conditions to succeed in a way that
leaves $this->skin as null.

Aside from that not being possible right now, it also duplicates a
null check in two places, which isn't ideal.

Codify that the first two blocks always result in $this->skin
being assigned non-null by using an 'else' branch instead of another
generic check.

Change-Id: I7986684bf1bb2daad3aaddfbcd2ca02e652f78c2
2019-07-29 23:42:23 +00:00
Timo Tijhof
cad882954a context: Use getRawVal instead of getVal for 'uselang' and 'useskin'
Bug: T189966
Change-Id: I9db7b3f36f5457e80aa9b673bcb56deb83e47a18
2019-07-30 00:02:52 +01:00
Derick Alangi
c51f012739 Use AtEase::quietCall() instead of Wikimedia\quietCall()
Wikimedia\quietCall() is deprecated and AtEase is here for use.
I would have loved to do restoreWarnings() and suppressWarnings()
in this same patch set but will continue the work for a later patch.

Bug: T182273
Change-Id: I43e3a5f378c99b5c40883b35ba133cbd126fc433
2019-06-10 14:18:19 +00:00
Derick Alangi
3086799014 context: Replace deprecated use of SkinFactory::getDefaultInstance()
Replace with MediaWikiServices::getInstance()->getSkinFactory()

Change-Id: I2cf7afad249e52e13a56fbe92b1665dfebec793f
2019-04-15 20:21:21 +01:00
Lucas Werkmeister
46f79f8eb3 Use finally instead of try-catch-throw
When this exception handler was introduced in change Ifbc1db4b82 (commit
9636d44448), MediaWiki still supported PHP 5.3.2, where finally was not
available. It was added in PHP 5.5, though, which we’ve required for a
while now, so we can simplify this a bit.

Change-Id: I7c967fb713de7495739e18ff6c6058a630129fda
2019-03-26 14:13:51 +01:00
Derick Alangi
5479c37368 context: Cleanup is_null() checks and irrelevant else code paths
This class specifically has these 2 things in many cases and converts
into the use of a tenary operations.

Quoting @Thiemo_WMDE from Gerrit comment: "The ?: operator will skip
empty arrays, empty strings, as well as the string "0". But this is
not a problem here because the properties under test are all objects.
Objects are always considered true in PHP."

Sample change can be seen below as, from;
```
if ( !is_null( $this->skin )) {
    return $this->skin;
} else {
    return $this->getContext()->getSkin();
}

```

to

```
return $this->skin ?: $this->getContext()->getSkin();
```

Change-Id: I377b118d86a24c7bcb15512f6714e6201a3e36ee
2019-03-20 20:51:58 +01:00
Derick Alangi
34f78a69ef specialpage: Fix login crash caused by unknown language via ?uselang
Per Krinkle's comments here: T198054#4598447, it's exactly what is
happening. @Fomafix suggests we handle the exception that is been
thrown by Language::factory() when there is an invalid language code
provided. The attempt is to fix this in the central way of ever request
whether POST or GET.

We're working within a particular context, and within this request
context, we can create a language user's language object then generate
a language object. If uselang parameter is provided an invalid language
code, getLanguage in this request context will default to $wgLanguageCode
then use this code to create the user's language object. In addition,
getLanguage() invalidates cached user interface language.

Bug: T198054
Change-Id: I825fdfa882a4243ffc63c9de0d7f482e2cfb9862
2019-01-29 16:16:02 +00:00
Umherirrender
7f68979bec Replace some wfMessage by ContextSource::msg
Change-Id: Ie056af7a002dbbf4e8defc8032bfcc0bdefc6566
2018-08-22 15:42:31 +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
Max Semenik
8085c58a4b Replace call_user_func_array(), part 1
Uses new PHP 5.6 syntax like ...parameter unpacking and
calling anything looking like a callback to make the code more readable.
There are much more occurrences but this commit is intentionally limited
to an easily reviewable size.

Change-Id: Idcec077ef3fdf029b632cceafd0150851ad723e3
2018-06-04 23:39:04 -07:00
Reedy
fbc0347466 Update MediaWiki\quietCall() -> Wikimedia\quietCall()
Bug: T182273
Change-Id: Id7d8e176fcd93040e30e46cb64fc6a3d36bc8230
2018-02-10 10:49:33 +00:00
Thiemo Mättig
4d9de6140e Improve 1-letter variable names in MutableContext and implementations
I'm also removing obsolete short comments that don't add anything to
whats already obvious from the method header. For example, I really don't
need a comment to understand that a method that's called "setUser" and
accepts a parameter named "$user" of type "User" is meant to "set the
User object". I mean, how more obvious can it be? ;-)

Change-Id: Ib079108457a5aa2a6896e95837542ab93b465144
2018-01-07 15:53:55 +01:00
jenkins-bot
58f37bd13c Merge "Remove self-explaining "section heading" comments from classes" 2017-12-30 21:25:15 +00:00
Thiemo Mättig
fa15c98787 Improve (weak and strict) type hints invarious places
Change-Id: I3a42ec1547fae971d7b495c99dd144739d8521ab
2017-12-28 16:31:56 +01:00
Thiemo Mättig
544122a6c2 Remove self-explaining "section heading" comments from classes
I can see that "parent::__construct" literally calls the parent
constructor. I can see that stuff preceeded by the keyword "protected"
is protected. I really (really) don't need comments explaining such.

Change-Id: I7458e714976a6acd3ba6a7c93fdc27d03903df83
2017-12-28 16:12:08 +01:00
Niklas Laxström
a6c9c21983 Remove unuseful debug messages
I spotted one of these in my debug log. Without context it is not
useful nor informative. Given it can actually come from three places,
it is useless.

Change-Id: Ic293d8944e9a1a8152c5a5e0b695c5ddc07ee6aa
2017-12-04 10:40:05 +00:00
Umherirrender
bd741b83bc build: Updating mediawiki/mediawiki-codesniffer to 13.0.0
Change-Id: Ia24dbf015f2b4781683ca980a460d0ac3e85674e
2017-09-25 17:31:56 +02:00
Umherirrender
ace44e2064 Use correct variable name in @param documentation
For some varargs a variable name is added with suffix ,... as seen for
many other varargs

Some @param are swapped, because there are in the wrong order

Enable Sniff MediaWiki.Commenting.FunctionComment.ParamNameNoMatch

Change-Id: I60fec6025bce824d5c67563ab7b65ad6cd628ad8
2017-08-11 19:27:19 +02:00
jenkins-bot
e72303c9f3 Merge "Remove auto-generated "Constructor" documentation on constructors" 2017-07-21 13:19:44 +00:00
Thiemo Mättig
91a920fd85 Remove auto-generated "Constructor" documentation on constructors
Having such comments is worse than not having them. They add zero
information. But you must read the text to understand there is
nothing you don't already know from the class and the method name.

This is similar to I994d11e. Even more trivial, because this here is
about comments that don't say anything but "constructor".

Change-Id: I474dcdb5997bea3aafd11c0760ee072dfaff124c
2017-07-21 12:19:30 +02:00
Timo Tijhof
01938ae7db statsd: Rename MediawikiStatsdDataFactory to IBufferingStatsdDataFactory
Follows-up I2874175647e (7fdc3d09a3).

* Avoid "MediaWiki" in class names. If unavoidable, always camelcase.
* Use a more descriptive name, matching the implementing the class ("Buffering").
* Use "I" prefix for consistency with other MediaWiki-provided interfaces.
  (Avoid "Interface" suffix, which is foreign to MediaWiki and is only used
  in the StatsdClient namespace, which this interface is not in).

Bug: T166354
Change-Id: I06de59122625f9c23e7c1a1bfa69a7ddabbf379e
2017-07-07 17:22:50 -07:00