Why:
* Maintenance scripts in core have bolierplate code that is
added before and after the class to allow directly running
the maintenance script.
* Running the maintenance script directly has been deprecated
since 1.40, so this boilerplate code is only to support a now
deprecated method of running maintenance scripts.
* This code cannot also be marked as covered, due to PHPUnit
not recognising code coverage for files.
* Therefore, it is best to ignore this boilerplate code in code
coverage reports as it cannot be marked as covered and also
is for deprecated code.
What:
* Wrap the boilerplate code (requiring Maintenance.php and then
later defining the maintenance script class and running if the
maintenance script was called directly) with @codeCoverageIgnore
comments.
* Some files use a different boilerplate code, however, these
should also be marked as ignored for coverage for the same
reason that coverage is not properly reported for files.
Bug: T371167
Change-Id: I32f5c6362dfb354149a48ce9c28da9a7fc494f7c
And start using them instead of wfGetDB(), LB/LBF connection methods or
worse, $this->getDB().
$this->getDB() reuses the database object regardless of whether you're
calling a replica or primary, leading to returning a replica on a
primary and other way around.
Bug: T330641
Change-Id: I9e2cf85ca277022284fc26b9f37db57bd12aaa81
For readability. Allowed since PHP 7.4.
I searched for integer literals of 6 or more digits, and also changed
some nearby smaller numbers for consistency.
Bug: T353205
Change-Id: I8518e04889ba8fd52e0f9476a74f8e3e1454b678
A few more fairly simple cases that don't quite match the regexp in
I2cfc3070c2a08fc3888ad48a995f7d79198cc336 or required other tweaks.
Change-Id: I5438c777344e9ba07f3b62a452fce9ec63baa48a
This reverts commit c5f4ffd4e6,
re-applies commit b0fe2c4111.
WikiPage::getRedirectTarget() needs to still allow missing rows,
but for a different reason.
Bug: T348881
Change-Id: I6e1fd823fbe140819c28096d5adc41cd15bcc8c0
This reverts commit b0fe2c4111.
Reason for revert: Causing test failures in the UserMerge extension.
Bug: T348881
Change-Id: I35e82df7a7f95150927dc6e4ad68588c3400b63f
After the other changes in T346290 there must always be a `redirect`
table row for each page with `page_is_redirect=1`. The only place
that needs to handle missing rows is the migration script
fixInconsistentRedirects.php.
Bug: T346290
Change-Id: I7e991aa5a33be37e0d6c9ef0900306706c171466
In 2008, the `redirect` table was added, and in 2011, it gained the
fields `rd_interwiki` and `rd_fragment`. We have never performed
proper maintenance for those changes, instead relying on code in
WikiPage to update it when the page was visited, or on an optional
run of refreshLinks.php.
I would like to remove the code in WikiPage, so we probably need to
perform this maintenance in the database updater. You know, for the
millions of people who have been dutifully upgrading their MediaWiki
installations since 2008, but never visited the pages there.
The script is a trimmed-down version of refreshLinks.php, without all
the weird stuff, and using a better index for the queries.
Bug: T346290
Change-Id: Iea251d2737b2fb472c4efb060ad2b97735b4ac53
Maintenance class provides a method for getting a fresh reference
of the MW services container instance. Let's make use of these in
maintenance scripts now that we have it.
NOTE: There are still some static methods like in refreshLinks.php
that makes use of services that we can't use this method for now.
Change-Id: Idba744057577896fc97c9ecf4724db27542bf01c
Follow up to commit 49e56ae11, the `page_id` field should always be
selected since we use it later.
Sorry, I only noticed this issue when I ran it with the `--verbose` option.
Bug: T344402
Change-Id: Ia8a3affea3324955a94ba5b2cd7a9fb39596cc44
This feature can not support query by namespace: only few link tables
have the `xxx_from_namespace` field, and we are looking for non-existing
pages.
Bug: T344402
Change-Id: I21485e2ce843489072a0d6dbeec621ceec9fe6ae
Use select queries for page IDs, so we can avoid loading and checking
each page via the WikiPage object.
Also, reused the doRefreshLinks() method for refreshCategory(), so the
fixRedirect() check also works for this case.
Other behavioral changes:
- Pass the start/end options to deleteLinksFromNonexistent() even when
not in the `dfn-only` mode, since we may want to run different
intervals in parallel to save time, and we don't need DFN without
intervals.
- fixRedirect() now won't delete entries for nonexistent pages,
since the page filtering method changed to use select queries,
and the deleting is covered by deleteLinksFromNonexistent().
- Removed the clearing of link cache, which was added to control the
memory usage in 2006, but now LinkCache uses a MapCacheLRU.
Bug: T344402
Change-Id: Iaefeeb0391393a2273edfa0f32d4f75ff4b7b22b
Tracking category keys are something like `broken-file-category`, not
category page name for Title::makeTitleSafe().
This partially reverted commit 06e2d0e874
Bug: T331473
Change-Id: Ic744a58ef56981c3aecc4e7cf5322b77894a9249
Knowning the reason why a secondary update was triggered is an useful
information for debugging. Some LinksUpdate hook consumers might also
want to fine-tune their behaviors based on this value.
Change-Id: I19c0620e409b31995080ee0111b0b78782276563
Add verbose output to refreshCategory() with total pages to refresh,
and per-page refresh status.
Add `Title::makeTitleSafe` to the passed `tracking-category` before
passing to refreshTrackingCategory().
Bug: T331473
Change-Id: I3234b1560156813b95355754de2212508f7ee6af
This makes this code easier to read and to maintain because it's more
obvious why a DB connection is passed. For now this patrch focusses
exclusively on private methods.
Change-Id: Id60dc90b124f4cae1dfbede990f45e3c69491a25
We want to be able to refresh pages that haven't been updated in quite a
while to ensure any MediaWiki parsing changes, etc. get reflected in
links tables. This information is already tracked in the
page.page_links_updated field, which we'll filter with. We can't
actually do it in SQL because there's no index on the column, but it
gets loaded by WikiPageFactory::newFromID(), so we simply check it
in the fixRedirect() and fixLinksFromArticle() functions.
== Test plan ==
* Run plain `refreshLinks.php` and see that all page_links_updated
fields have been updated to now (this patch doesn't break existing
functionality).
* Backdate some page_links_updated fields.
* Run refreshLinks.php --before-timestamp X, where X is between your
backdated values and now.
* Observe that only the backdated pages have had their
page_links_updated modified to now.
Bug: T159512
Change-Id: I695d971ef7cbabddda3125361975be0f94dabf4c
This is really hard to read. What is code, what is string? These
places are so simple, they really don't need the "{$var}" syntax.
Change-Id: I589dedb8c0193eec4eef500bbb896b5b790b727b
The concept of a redirect chain didn't really work for a value of
max redirect > 1. In the ideal world, we just want to have a source
which points to target (source -> target) discarding the concept of
a redirect chain completely.
Having something like: source -> target -> target1 -> target2 doesn't
really work well with the current database design.
NOTE: Support for $wgMaxRedirect will be removed soon hence
deprecation without interfaces for replacement.
Bug: T290639
Change-Id: I469de6f85e405e8ddbe7abaa5b99b77cb9cf415d
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