Commit graph

1776 commits

Author SHA1 Message Date
daniel
10ccdb2281 Define equality for PageIdentity and LinkTarget
Bug: T272420
Change-Id: I2e0eb21989e2d733088ab77d7461bf003c2905eb
2021-01-19 23:07:37 +00:00
daniel
61a5531e4a Strict return types for PageIdentity
Bug: T208776
Change-Id: I7e71ffc209465b7cca385603d844cd40178485a9
2021-01-18 17:33:14 +01:00
daniel
1a60008a9a Introduce PageIdentity interface
PageIdentity is intended as a lightweight alternative to Title,
similar to LinkTarget, but providing a page ID. It follows the precedent
of UserIdentity.

Bug: T208776
Change-Id: Iaed4871e0d32c67d4fb13e487625527f6a21e9c5
2021-01-14 13:18:05 -06:00
Petr Pchelko
c954a2bb28 Temporary debug log if Title::getLocalURL is used from render action
Going through calls of this method to verify that dropping the special
case will not cause problems proved to be exhausting - too many callers,
too many possible chains of calls. Instead, I propose to debug log
when this happens and analyze those logs.

Bug: T263581
Change-Id: I215c6aebf9f4cc23701911cf86750731858c759c
2021-01-05 15:24:18 -06:00
Reedy
412d0f1ac2 Title::convertByteClassToUnicodeClass(): Cleanup
* Remove unused $d2
* Swap == to ===
* Swap += 1 for ++

Change-Id: If2b7bbfd912a368d91a9a3c7b242d01bf9a0dbc6
2020-12-30 09:49:30 +00:00
Tim Starling
9af96ef4c7 Improve custom folding and grouping
PHPStorm can use custom folding regions defined in either the
VisualStudio style or the NetBeans style. The VisualStudio style is more
pleasing to the eye and also works as a vim foldmarker. So get rid of
the previous vim foldmarkers, and use region/endregion.

region/endregion need to be in a single-line comment which is not a doc
comment, and the rest of the comment is used as a region heading (by
both PHPStorm and vim). So to retain Doxygen @name tags, it is
necessary to repeat the section heading, once in a @name and once in a
region. Establish a standard style for this, with a divider and three
spaces before the heading, to better set off the heading name in plain
text.

Besides being the previous vim foldmarker, @{ is also a Doxygen
grouping command. However, almost all prior usages of @{ ... @} in this
sense were broken for one reason or another. It's necessary for the @{
to be in a doc comment, and DISTRIBUTE_GROUP_DOC doesn't work if any of
the individual members in the group are separately documented.

@name alone is sufficient to create a Doxygen section when the sections
are adjacent, but if there is ungrouped content after the section, it
is necessary to use @{ ... @} to avoid having the Doxygen group run on.
So I retained, fixed or added @{ ... @} in certain cases.

I wasn't able to test the changes to the trait documentation in Doxygen
since trait syntax is not recognised and the output is badly broken.

Change-Id: I7d819fdb376c861f40bfc01aed74cd3706141b20
2020-12-23 12:41:47 +11:00
Umherirrender
4c2d2ec407 Improve docs about @param/@return object[] $row to stdClass[]
Change-Id: I4f85d90548caa1403e822ecb2333ab44787346f2
2020-11-13 23:38:06 +01:00
jenkins-bot
1976283835 Merge "Update a lot of unspecific "array" types in PHPDocs" 2020-11-13 21:48:24 +00:00
Ammar Abdulhamid
7d776726aa Rename two Title methods that have confusing names
These methods are renamed to names that are less misleading:

* Title::isDeleted() => Title::getDeletedEditsCount()
* Title::isDeletedQuick() => Title::hasDeletedEdits()

The new names reflect what the methods actually do/return;

Both methods (old names) are also soft-deprecated.

Bug: T261880
Change-Id: I0a7894661a4370cd4cbc23e33639d41f333ca330
2020-10-30 16:48:28 +00:00
Thiemo Kreuz
b0130ca649 Update a lot of unspecific "array" types in PHPDocs
This includes fixing some mistakes, as well as removing
redundant text that doesn't add new information, either because
it literally repeats what the code already says, or is actually
duplicated.

Change-Id: I3a8dd8ce57192deda8916cc444c87d7ab1a36515
2020-10-28 11:01:33 +01:00
DannyS712
a0b5292413 Title::getNotificationTimestamp - require passing a user
Not passing a user was hard deprecated, all known callers
already provide one

Bug: T245702
Change-Id: Ib38ab507ba1078ccb453e3fc9ddd9f0758ee66a9
2020-08-27 00:19:17 +00:00
DannyS712
eea7e16df4 Remove deprecated title permissions functions
Title::userCan, ::quickUserCan, and ::getUserPermissionsErrors, hard deprecated in 1.35

Bug: T246138
Change-Id: Iee990a16c15bd827cf631fb5ff683367082d2ebe
2020-08-26 21:21:11 +00:00
jenkins-bot
a63b0f6270 Merge "Title::mRedirect can be bool" 2020-08-25 08:55:08 +00:00
addshore
3e910cbf17 Title::mRedirect can be bool
Change-Id: I2198ed044197efb32f7e096d41bfd8b47cff82b6
2020-08-24 16:12:12 +01:00
Ferran Tufan
33754d4be5 Deprecate Title::nameOf()
The Title::nameOf() method does not seem to be used anywhere.
Title::newFromID()->getPrefixedDBkey() returns the same, so deprecate
this method.

Bug: T254087
Change-Id: I75be98fed5fd30b3bcd28a3cc28278453028b28b
2020-08-24 01:36:21 +02:00
jenkins-bot
16fc03ca1a Merge "Fix bad use of |= PHP bit operation where = … || bool is intended" 2020-08-12 03:04:03 +00:00
Umherirrender
eec141e3cc Fix bad use of |= PHP bit operation where = … || bool is intended
Do not use bit operator on bool as it does not work the same way.

|= is not a short form of bool or (||) and assignment (=).
It is the short form of bitwise or (|) and assignment (=)

Change-Id: I64988cd3aeb8f4cbc53b0b866f1ac96f12976cca
2020-08-12 02:33:01 +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
Ed Sanders
0cf40a4f7a Flip Yoda conditionals
Change-Id: Id3495b6f15c267123c89f3a0ace496e6ecbeb58e
2020-07-22 17:49:12 +01:00
jenkins-bot
484ea3fa9a Merge "title: Make getSubpageText() return the title text if there's no subpage" 2020-07-02 20:54:27 +00:00
jenkins-bot
8b2f44b6e7 Merge "phan: Enable redundant_condition_detection" 2020-07-02 00:28:10 +00:00
Daimona Eaytoy
719e185357 title: Make getSubpageText() return the title text if there's no subpage
This is for consistency with the previous behaviour.

Follow-up: I3d8c6f6ffc4234ac938a39f5cc55691d62e1d7ac

Bug: T256922
Change-Id: I0928f85c862d3b2baf49317a206ca140a1ab3c16
2020-07-02 00:08:51 +02:00
Umherirrender
bc5cb7ae64 phan: Enable redundant_condition_detection
Remove duplicate casts
Suppress false positives

Bug: T248438
Change-Id: I2f89664a4bcd3b39b15e7cf850adda2f0c90ae6f
2020-07-01 20:13:07 +00:00
daniel
f59bf8a22f Use @internal instead of @private per policy
https://www.mediawiki.org/wiki/Stable_interface_policy mandates the use
of @internal. The semantics of @private was never properly defined.

Bug: T247862
Change-Id: I4c7c6e7b5a80e86456965521f88d1dfa7d698f84
2020-06-26 14:14:23 +02:00
jenkins-bot
7ba77c21c8 Merge "Title: fix subpage split for degenerate cases" 2020-06-25 16:46:34 +00:00
daniel
03397e46c5 Title: fix subpage split for degenerate cases
This ensures that getBaseText and getRootText always
return a valid title, even for degenerate cases like "/" or
"//foo//bar//baz//".

Bug: T229443
Change-Id: I3d8c6f6ffc4234ac938a39f5cc55691d62e1d7ac
2020-06-22 12:58:29 +02:00
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