For example, documenting the method getUser() with "get the User
object" does not add any information that's not already there.
But I have to read the text first to understand that it doesn't
document anything that's not already obvious from the code.
Some of this is from a time when we had a PHPCS sniff that was
complaining when a line like `@param User $user` doesn't end
with some descriptive text. Some users started adding text like
`@param User $user The User` back then. Let's please remove
this.
Change-Id: I0ea8d051bc732466c73940de9259f87ffb86ce7a
This avoids failures due to WikitextContent::isCountable() erroring
out when no title is set for the main RequestContext.
Bug: T257009
Change-Id: I70274e3876c5b7c273110f9afa713a85edcc6339
This method is useful when overriding getParserOutputForIndexing(), to
avoid the equivalent of T247859.
Note that the method is not stable to override, only to call.
Change-Id: Idd7e6ca6786f2c463737a47296b3da5f5e0e16f1
Require that getDataForSearchIndex() is only called with the result of
getParserOutputForIndexing(), and update the documentation of both
methods. Extensions may now override getParserOutputForIndexing() to
skip generating HTML; MediaWiki guarantees that the HTML itself is not
required by the base implementation of getDataForSearchIndex().
Note that for Wikitext content, many meta-data fields of ParserOutput –
links, sections, etc. – can only be obtained by actually parsing the
content and generating HTML, whether the caller asked for it or not.
However, this is not the case for all content models. This change allows
those content models to save some work when indexing their content,
while still working with the MediaWiki getDataForSearchIndex() method.
The new requirement on getDataForSearchIndex() is strictly speaking a
breaking change, but not one that could be marked as a deprecation
first. Hopefully, the release notes entry is enough.
Bug: T239931
Bug: T264283
Change-Id: I50f3a530f25fbcf019d36d09c070b11a46066c61
Test Plan:
* Logged-in, preview a change adding {{subst:CURRENTYEAR}}
to User:You/common.css, User:You/common.js and Main_Page.
* Observe that it expands to 2020 in all cases.
* Run `(new mw.Api).saveOption('pst-cssjs', '0')`
* Try again. Observe that the first two are now left unchanged.
Bug: T236828
Change-Id: Ic13e2ff3b90f0c3587cdb1e97fffcd96be650e0e
This causes RevisionStore to use FallbackContent instances to represent
content for which no content handler is defined.
This may happen when loading revisions using a model that was defined
by an extension that has since been uninstalled.
Bug: T220594
Bug: T220793
Bug: T228921
Change-Id: I5cc9e61223ab22406091479617b077512aa6ae2d
Instead of checking if the resulting $matches array is complete, we can
safely assume it is, as long as the preg_match() call returned a
non-false value.
Note that some of these used empty() before and are actually bogus
because of this! empty() considers the string "0" to be empty. In case
of a ==0== headline that's an actual bug.
I'm also removing the `= []` initialization before the preg_match.
I understand why it was added: to make it a little more obvious that the
variable is guaranteed to be initialized. But:
* This is guaranteed by the preg_match anyway.
* Neither initializing it with null or an empty array makes much sense
because the code below assumes so much more, e.g. that specific
elements exist, and are arrays. Again, these guarantees are all given
by the preg_match.
I find the additional initialization more distracting than helpful.
Change-Id: I22b192b59038d9fa51a7e6f04d8d76634ae3de73
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
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
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
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
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
This annotates classes that can safely be instantiated by
extensions, per the Stable Interface Policy.
Bug: T247862
Change-Id: Ia280f559874fc0750265ddeb7f831e65fd7d7d6a
Done with `composer fix` and suppressing the rest (i.e. sniffs for
global variables, which for core should be suppressed anyway).
Additionally, add `-p` to `phpcbf`, as otherwise it just seems stuck.
Change-Id: Ide8d6cdd083655891b6d654e78440fbda81ab2bc
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
Follows-up 30e54b3962, which accidentally passed the string
'MediaWiki\Content\ContentHandlerFactory::getContentHandler' as
the log channel. We generally use wide and generic channel names
named after a whole component. Or, if using wfDebug(), we
sometimes prefix the method name to the message. It looks like
these two idioms were accidentally mixed up which means this
message is missing when looking for 'ContentHandler', but it
also meant that when viewing the full debug log in Kibana, that
the channel column breaks due to this being too long.
Change-Id: If578893f568905ac0d560ecf544fcc28dd61ba91
Phan flagged a lot of incorrect type hints when run against the call
site migration patch.
Bug: T240307
Change-Id: I698de5536446c241b200430198b21b72763b0c69
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
When retrieving indexable content for a WikiPage the page may be
brand new and not replicated yet. When no revision is found try
again reading from the master, then fail with a clear message instead
of the previous behaviour of dereferencing null.
Bug: T247859
Change-Id: Iab93984b26d40de00f3331ee1bbdde46b3370733