Commit graph

1750 commits

Author SHA1 Message Date
Tim Starling
d459add63d Introduce wfDeprecatedMsg()
Deprecating something means to say something nasty about it, or to draw
its character into question. For example, "this function is lazy and good
for nothing". Deprecatory remarks by a developer are generally taken as a
warning that violence will soon be done against the function in question.
Other developers are thus warned to avoid associating with the deprecated
function.

However, since wfDeprecated() was introduced, it has become obvious that
the targets of deprecation are not limited to functions. Developers can
deprecate literally anything: a parameter, a return value, a file
format, Mondays, the concept of being, etc. wfDeprecated() requires
every deprecatory statement to begin with "use of", leading to some
awkward sentences. For example, one might say: "Use of your mouth to
cough without it being covered by your arm is deprecated since 2020."

So, introduce wfDeprecatedMsg(), which allows deprecation messages to be
specified in plain text, with the caller description being optionally
appended. Migrate incorrect or gramatically awkward uses of wfDeprecated()
to wfDeprecatedMsg().

Change-Id: Ib3dd2fe37677d98425d0f3692db5c9e988943ae8
2020-06-22 14:34:39 +10:00
Thiemo Kreuz
b1850a49a7 title: Don't query/create LinkCache service when not needed
It seems in the vast majority of cases (when $flags is 0 and
$this->mArticleID is already known) none of the conditions is true, and
this service is not needed. As this is a very basic, heavily used method
I feel it's worth avoiding unnecessary calls like this.

Change-Id: Ib668071ffe029f3318e110b9f791e400a2becc7a
2020-06-18 14:01:42 +02:00
jenkins-bot
4882a4a2bc Merge "Revert "title: Mark Title::getPrefixedDBKey and ::getPrefixedText as tainted"" 2020-06-13 09:40:56 +00:00
DannyS712
26381b8468 Hard deprecate Title::getFirstRevision
Bug: T249393
Change-Id: I2454b8f8e3eaaba18446a536a7a523d733ed0002
2020-06-10 02:38:04 +00:00
DannyS712
c3181c6f62 WatchlistNotificationManager: Add deprecations and release notes
Bug: T208777
Change-Id: I8c9bbdc286dde6287967f5f9e82cf38987f9fb28
2020-06-04 21:31:33 +00:00
jenkins-bot
748965cb95 Merge "Add new WatchlistNotificationManager service" 2020-06-04 20:24:20 +00:00
Daimona Eaytoy
c0cc7b8152 Revert "title: Mark Title::getPrefixedDBKey and ::getPrefixedText as tainted"
This reverts commit a9ba5f98a4.

Reason for revert: these props are unsafe iff the instance they belong to is unsafe. Marking them as *always* unsafe turned out to be a source of false positives which doesn't compensate the gain. Note: merging this patch will likely make phan check in a few repos with "UnusedSuppression ...". It can be fixed by simply removing the suppression it complains about.

Change-Id: I6e2c13400f51b42269d7d07976809a986eb67b05
2020-06-03 12:17:20 +00: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
DannyS712
c243c1b06e Add new WatchlistNotificationManager service
Replaces watchlist notification methods in Title and User classes:
* Title::getNotificationTimestamp -> ::getTitleNotificationTimestamp
* User::clearNotification -> ::clearTitleUserNotifications
* User::clearAllNotifications -> ::clearAllUserNotifications

New service has 67.90% code coverage with pure Unit tests; as well
as integration tests for the DeferredUpdates part

A follow-up patch will deprecate the replaced methods, as well
as document that the `UserClearNewTalkNotification` hook now only
provides a UserIdentity (typehint added in T253435 but until now
a full User was still provided).

Bug: T208777
Change-Id: I6f388c04cb9dc65b20ff028ece607c3dc131dfc5
2020-06-02 23:22:02 +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
jenkins-bot
e1162acecd Merge "title: Mark Title::getPrefixedDBKey and ::getPrefixedText as tainted" 2020-05-21 23:49:25 +00:00
Daimona Eaytoy
a9ba5f98a4 title: Mark Title::getPrefixedDBKey and ::getPrefixedText as tainted
Currently taint-check is already able to infer this, but this might
change because of T203651. The Title class is just too huge for us to
analyze on-demand without slowing everything down.

Change-Id: I85f2ecf42b51aedda600c5aa7eca88a1d77650bd
2020-05-21 23:31:26 +00:00
Reedy
32aefeaa08 Fix Squiz.Scope.MethodScope.Missing for Title.php
Change-Id: Icbfd055f9a14cabf2b61f643630f6e574a1ebf4b
2020-05-17 15:47:09 +00:00
Reedy
a8467a0fd7 Fix numerous PSR12.Properties.ConstantVisibility.NotFound
Change-Id: I157220c4e9ff516283a60f06af99efa2439332e3
2020-05-12 18:41:43 +00:00
Timo Tijhof
2f35c3ae67 HtmlCacheUpdater: Add getUrls() method and support selective purging
* Move the Title::getCdnUrls() logic to the new HtmlCacheUpdater service.

* Introduce a runtime option to decide whether this is for a direct
  revision or a cascading LinksUpdate.

Bug: T250261
Change-Id: I514b9052761e0d949234996e97fdef255582df86
2020-04-30 18:16:07 +00:00
jenkins-bot
9a939d38d0 Merge "RevisionStore and PageUpdater: handle stale page ID" 2020-04-27 21:16:52 +00:00
Timo Tijhof
f2be921509 title: Remove broken handling of language variant in getCdnUrls()
* This currently produced urls like "index.php?title=…&<langcode>"
  which don't actually do anything. The proper syntax is "variant=langcode".
  These danging variants were nothing but PURGE noise, as random
  as e.g. purging a url like "…&rand123" would have been.

* Regardless of all this, page views with a language variant don't
  actually emit a public cache header right now in MediaWiki, which
  means there is not actually anything to purge from the CDN in the first
  place. Revisiting whether we want to start caching them (and then
  where/when to purge them) is subject of T250511, which can happen
  after this logic is moved to the HtmlCacheUpdater service.

Bug: T250511
Bug: T250261
Change-Id: I497cb2be2e9f16156cf02afeb437bdca1b2cc1fd
2020-04-20 18:55:17 +00:00
daniel
1fcd23878c RevisionStore and PageUpdater: handle stale page ID
Sometimes, an edit is done with a Title object that has gone
out of sync with the database after a page move. In this case,
we should re-load the current page ID from the database,
instead of failing the update hard.

Bug: T246720
Bug: T204793
Bug: T221763
Bug: T225366
Change-Id: If7701205ec2bf4d4495349d3e67cf53d32ee8357
2020-04-20 18:11:45 +02:00
DannyS712
eeef56ec49 Fix remaining uses and hard deprecate Title::(get|count)AuthorsBetween
Bug: T249561
Bug: T249183
Change-Id: Ib25de71d4870c2832e06efc46ce372695c5031fd
2020-04-18 02:03:24 +00:00
jenkins-bot
c24d719a33 Merge "Hard deprecate Title::countRevisionsBetween" 2020-04-15 18:15:06 +00:00
Aaron Schulz
3c7f29a6b9 Add small HtmlCacheUpdater service class to normalize purging code (2)
This is a re-submit of 35da1bbd7c, which was accidentally merged before
CR (and reverted with aa4da3c2e8).

The purge() method handles purging of both file cache and CDN, using
a PRESEND deferred update. This avoids code duplication and missing
file cache purge calls.

Also:
* Migrate HTMLCacheUpdate callers to just directly using HTMLCacheUpdateJob
* Add HtmlFileCacheUpdate class and defer such updates just like with CDN
* Simplify HTMLCacheUpdate constructor parameters
* Remove BacklinkCache::clear() calls which do nothing since the backlink
  query does not actually happen until the job runs

Bug: T230025
Change-Id: Ic1005e70e2c22d5bd1ca36dcdb618108ebe290f3
2020-04-14 03:19:07 +00:00
Petr Pchelko
685c78584d Hard deprecate Title::countRevisionsBetween
Bug: T246284
Change-Id: I47d0c4f3ffab6dc2577ded30046a9cb29d797430
2020-04-10 17:59:32 +00:00
jenkins-bot
516c859643 Merge "CdnCacheUpdate: Accept Titles in addition to strings" 2020-04-08 10:23:07 +00:00
jenkins-bot
bdd722e310 Merge "Remove compat code for pre-MCR schema." 2020-03-25 18:19:33 +00:00
Petr Pchelko
a749000d39 Deprecate Title and WikiPage getFirstRevision methods
They naturally belong in RevisionLookup. They return Revision,
so should be replaced anyway.

Bug: T246284
Change-Id: Ie5c478e4667ca0e773186b9cb8a319cd09145112
2020-03-24 11:56:08 -07:00
daniel
495323c063 Remove compat code for pre-MCR schema.
NOTE: This was manually tested to ensure it does not
break updates, see T242764.

Bug: T198557
Change-Id: I1d9f5465018bae10124514bc38169e23e0e613e6
2020-03-24 19:45:47 +01:00
Brad Jorsch
d83e00cb92 CdnCacheUpdate: Accept Titles in addition to strings
The class was already documented as "given a list of URLs or Title
instances", this makes that work.

Title objects will have ->getCdnUrls() called when the update is
resolved, which avoids problems like those encountered in T240083 where
that was being called too early.

Bug: T240083
Change-Id: I30b29a7359a8f393fb19ffc199211a421d3ea4d9
2020-03-19 09:56:19 -04:00
Daimona Eaytoy
43123eca46 Make Title::__construct private
The method was already marked as protected. This, together with the
Stable interface policy [1], means that it can be treated as unstable
and changed without prior notification.

In the future, we might want to make the Title class only instantiable
by TitleFactory (T247190). The first step is making the constructor
private, so that we can safely change the signature later.

[1] - https://www.mediawiki.org/wiki/Stable_interface_policy

Change-Id: I65830616ce584e9a553b93d99d58f8ecb02237b4
2020-03-16 10:20:41 +00:00
Umherirrender
3161311c5a Use MediaWikiServices::getMessageCache
Change-Id: I07fcc9529991adc634c10e5ed8498ac138a1c2b7
2020-03-14 14:25:03 +01:00
ankit
69608f77cd Fix typo, remove double "a"s
Bug: T201491

Change-Id: Icd8f59af4a56ec3cb6dee13b3c01ef057541f30a
2020-03-11 00:09:59 +05:30
Daimona Eaytoy
d425feeaa3 Remove deprecated Title::getUserCaseDBKey
Unused https://codesearch.wmflabs.org/search/?q=getUserCaseDBKey&i=nope&files=&repos=

Change-Id: I00b8f56ddeaf9d725be5e0290eea98ee7be30494
2020-03-09 20:32:52 +00:00
DannyS712
7186b63f82 Hard deprecate Title::getUserPermissionsErrors
Remove final uses as well

Bug: T244929
Change-Id: I65e937c7b9904b1e93f649508b14148849589f82
2020-02-26 05:09:55 +00:00
DannyS712
1948049498 Hard deprecate Title::userCan and ::quickUserCan
Bug: T244923
Bug: T244927
Change-Id: I1a064aeb3fc87573af50ae5b14793e750696371d
2020-02-22 01:53:03 +00:00
jenkins-bot
4e18398c30 Merge "Remove Title move functions, deprecated in favor of MovePage class" 2020-02-21 04:50:39 +00:00
DannyS712
fdd814d3ee Remove Title move functions, deprecated in favor of MovePage class
Removes Title::isValidMoveOperation(), ::moveTo(), and
::isValidMoveTarget()

Bug: T241341
Change-Id: I56993a7f29923c467940318ee77f58dd64abcc30
2020-02-19 20:44:55 -08:00
DannyS712
b3451ba87a Use __METHOD__ instead of __FUNCTION__
Follow up to I8990bc16

Change-Id: Id6435add2eea34ee8f79b70df152d08c3fb29ce1
2020-02-20 03:08:51 +00:00
DannyS712
328f093458 Deprecate falling back to $wgUser in some functions
Not passing a user to the following functions is deprecated:
* Title::getNotificationTimestamp
* Revision::newNullRevision
* WikiPage::insertProtectNullRevision
* PatrolLog::record
* LogEventsList::userCan
* LogEventsList::userCanBitfield
* LogEventsList::userCanViewLogType
* LogPage::addEntry

Bug: T242935
Bug: T243652
Change-Id: I8990bc16ac72680fb65f8ca37eb7908749a9e5cc
2020-02-19 21:43:46 +00:00
DannyS712
1219162885 Remove Title::moveSubpages
Deprecated and unused

Bug: T245483
Change-Id: I8d9d5002a47a93127a45d48d0387565d9e38fe61
2020-02-18 20:35:01 +00:00
DannyS712
2e3bdb3498 Miscellaneous documentation updates
Update references from .txt to .md when files have moved, a few other
tweaks, no changes to code.

Change-Id: I0bfd38c47b9fb0fc11ae98a0a674af66fb4c5a84
2020-02-16 04:38:38 +00:00
ArtBaltai
30e54b3962 Introduce ContentHandlerFactory
Added:
- ContentHandlerFactory
Tests:
- PHPUnit
Changed
- Calls of changed and deprecated
- DI for some service/api
Deprecated:
- ContentHandler::* then similar to ContentHandlerFactory
- ContentHandler::getForTitle
- ContentHandler::$handlers

Bug: T235165
Change-Id: I59246938c7ad7b3e70e46c9e698708ef9bc672c6
2020-02-07 00:53:51 +03:00
Peter Ovchyn
ed18dba8f4 language: remove Language hints for type check as it breaks using of StubUserLang
Bug: T244300
Change-Id: Iec1b5629617f1c171e8af507dc1dcebfef0666eb
2020-02-05 16:11:31 +02:00
Peter Ovchyn
61e0908fa2 languages: Introduce LanguageConverterFactory
Done:
* Replace LanguageConverter::newConverter by LanguageConverterFactory::getLanguageConverter
* Remove LanguageConverter::newConverter from all subclasses
* Add LanguageConverterFactory integration tests which covers all languages by their code.
* Caching of LanguageConverters in factory
* Make all tests running (hope that's would be enough)
* Uncomment  the deprecated functions.
* Rename FakeConverter to TrivialLanguageConverter
* Create ILanguageConverter to have shared ancestor
* Make the LanguageConverter class abstract.
* Create table with mapping between lang code and converter instead of using name convention
* ILanguageConverter @internal
* Clean up code

Change-Id: I0e4d77de0f44e18c19956a1ffd69d30e63cf51bf
Bug: T226833, T243332
2020-02-03 11:38:03 +02:00
James D. Forrester
0958a0bce4 Coding style: Auto-fix MediaWiki.Usage.IsNull.IsNull
Change-Id: I90cfe8366c0245c9c67e598d17800684897a4e27
2020-01-10 14:17:13 -08: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
f5fd067a7a Merge "resourceloader: Fix WikiModule cache invalidation order in Title::invalidateCache" 2020-01-02 20:18:26 +00:00
Umherirrender
6213817b81 Allow any kind of array on Skin::makeSpecialUrl
It is passed to Title::getLocalUrl, which accept this

Change-Id: I3774126619c28aea5de998de47da463b58071a7a
2019-12-30 17:15:07 +00:00
Timo Tijhof
89421ca978 resourceloader: Fix WikiModule cache invalidation order in Title::invalidateCache
Previously, the WANObjectCache key used by WikiModule was purged
by Title::invalidateCache from a db-precommit/idle callback.
This means it either runs right away (if there is no transaction
active) or from $dbw->commit().

This is a problem because the data that WikiModule is caching
relates directly to the 'page_touched' database field, which
Title::invalidateCache has not yet bumped at this point. Rather,
it does so later on, from a deferred update.

It's possible this has not yet caused an issue so far because
the WANObjectCache::touchCheckKey method leaves a tombstone
for 11 seconds (to counter race conditions and replication lag)
which might be enough for the current web request to finish
processing, and commit its transaction, and run any other deferred
update, and for Title's deferred update to bump page_touched,
and for that to be committed and replicated; all within 11s before
another web request interacts with WikiModule to repopulate the
cache key.

But, it's fragile at best and likely to get worse when we're
actually serving traffic multi-dc.

Change-Id: Icd9b3c11f60a829ea4c5d779eef3bebb643ebcf3
2019-12-15 19:20:51 +00:00
Umherirrender
2cc97d844a Use array for 'ORDER BY'
It is converted to a valid sql string from the abstract database layer

Also use array for GROUP BY and column alias

Change-Id: I293a563607d115a42c8456c9b9ac66665d71d943
2019-11-29 23:01:07 +01:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
jenkins-bot
3039165854 Merge "Fix bad comparison of Title::getCascadeProtectionSources result" 2019-11-18 08:34:57 +00:00