Commit graph

55 commits

Author SHA1 Message Date
Dreamy Jazz
e7393b3cc7 Exclude boilerplate maintenance code from code coverage reports
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
2024-08-27 13:22:29 +01:00
Amir Sarabadani
d9370003fb maintenance: Introduce getReplicaDB() and getPrimaryDB()
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
2024-01-18 15:12:04 +01:00
Amir Sarabadani
69cabb628c maintenance: Migrate to expression builders
This was somehow left out

Bug: T210206
Change-Id: I70851b5b99fa865dbfd629caf2c1866c85418350
2024-01-17 20:27:08 +01:00
Derick Alangi
74033c50cd maintenance: Begin using Maintenance::getServiceContainer()
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
2023-09-04 10:39:58 +00:00
Amir Sarabadani
310333906a maintenance: Switch simple calls of Database::select to SQB
Done semi-automatically via a php parser written on top of ANTLR4.

Bug: T311866
Change-Id: I33f5b6703c0aa9c80c907a21c2a770e30642edd3
2023-07-19 17:42:23 +02:00
James D. Forrester
ad06527fb4 Reorg: Namespace the Title class
This is moderately messy.

Process was principally:

* xargs rg --files-with-matches '^use Title;' | grep 'php$' | \
  xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1'
* rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \
  xargs rg --files-with-matches 'Title\b' | \
  xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1'
* composer fix

Then manual fix-ups for a few files that don't have any use statements.

Bug: T166010
Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a
Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
2023-03-02 08:46:53 -05:00
Timo Tijhof
3e482baa92 purgeList.php: Clarify that --db-touch is only for purging by title
Bug: T263957
Change-Id: I65e6e63dceaaa55c56b4c66d56f9e1eca92f635c
2022-09-19 18:39:52 +00:00
Aryeh Gregor
79fc95d39c Use MainConfigNames instead of string literals, #5
This should be the last of the usages in core, although I'm sure a few
are hiding somehow.

Change-Id: I7bf0b24bf23d3efb4c56a891830bbfe67945e899
2022-04-27 18:46:29 +03:00
Umherirrender
31bfc71c37 purgeList.php: Swap usleep() to sleep()
sleep is sleeping for seconds, while usleep sleeps for microseconds.
But the value is multiply by 1e6, which makes it real seconds.
The option is also documented to take seconds and not fraction of
seconds.

Change-Id: I507fa549729456a05ba45e9b3ee2e0bf04c49d14
2022-03-09 13:33:53 +00:00
Umherirrender
1b80321f39 Replace deprecated Title::getCdnUrls
Change-Id: Ie3cd9ebd6ef442af19a054a1bb81e5c3574fb2bb
2020-11-03 11:58:05 +01:00
Reedy
ae53a750cb purgeList.php Fix all-namespaces option to match one used in code
Bug: T263929
Change-Id: I6782c83019c834a1d04ecdb0903d732762e9949c
2020-09-27 19:54:30 +01: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
Timo Tijhof
55439af8f7 maintenance: Rename purgeList.php --purge to --db-touch
Also:

* Prevent use of this option for namespace-wide purges when
  MiserMode is enabled (e.g. large wiki farms such as WMF).

* Store normalised options in members to rule out future mistakes
  of e.g. check of option and application of option not being
  in sync. Also allows better static analysis to ensure correct
  use of these values.

Change-Id: Iac4033c2aa509a3b6021793820a1e2101e8bcce3
2019-10-04 00:02:36 +00:00
Gilles Dubuc
2501d1dedf Make purgeList.php use getCdnUrls()
Bug: T233095
Change-Id: I8c1d3f273ff2d81b9f28403136f4a6e4c3311724
2019-09-18 23:25:45 +02:00
James D. Forrester
f9f8dff40f Rename CDN config variables to be generic, deprecating the old names
Hook, methods, classes still to rename where appropriate.

Bug: T104148
Depends-On: Id34339dff88bc6d1863378ac94b96b2d590b891d
Depends-On: I4e2938395bcbf7956b83fff00978f09c61dcfa36
Change-Id: I7a725dae551c867a4fa7c213838d52c7fb862756
2019-05-24 21:09:22 +00:00
Umherirrender
ad776c7d5f Use ::class to resolve class names in maintenance scripts
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I1d4567f47f93eb1436cb98558388e48d35258666
2018-01-23 17:40:16 +00:00
Max Semenik
dac20d0ffa Introduce Maintenance::getBatchSize()
Just to isolate the internals. Fix most of usages in the core.

Change-Id: I8b3e9ca1f42b7c49ee57f17b88ca2fc7b404f342
2017-11-05 13:26:12 -08:00
Aaron Schulz
950cf6016c Rename DB_SLAVE constant to DB_REPLICA
This is more consistent with LoadBalancer, modern, and inclusive
of master/master mysql, NDB cluster, and MariaDB galera cluster.

The old constant is an alias now.

Change-Id: I0b37299ecb439cc446ffbe8c341365d1eef45849
2016-09-05 22:55:53 -07:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Max Semenik
59db24e90b Use addDescription() instead of accessing mDescription directly
Change-Id: I0e2aa83024b8abf5298cfea4b21bf45722ad3103
2016-01-30 01:28:32 -08:00
Reedy
44cebea941 Update wfGetDB calls in Maintenance scripts to use getDB()
Change-Id: I9ad6745d84506b736dae94747256caac89715899
2016-01-02 16:58:23 +00:00
Aaron Schulz
282c5fa9f3 Rename SquidUpdate => CdnCacheUpdate
Squid is not the only possible CDN

Change-Id: Ie2a2955847c5706e630322bbbab71c9d063b378f
2015-12-09 16:31:17 -08:00
Siebrand Mazeland
5a77286a1e Update formatting in maintenance/ (3/4)
Change-Id: I4390c4ea12a6a626b0e6817b6446635116ca9fe3
2014-04-23 20:09:13 +02:00
umherirrender
e78776373e Fixed some @params documentation (maintenance)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: I727deec35a712de0f0c676cc87dfa661f1ee965b
2014-04-17 22:48:32 +02:00
umherirrender
4c81a710fa Fix formatting of some php docs
php docs of functions should have newline in it and not in one line.

Change-Id: If4a29aefb46a7f73d75593814e597fdb792d5470
2014-03-15 20:49:55 +00:00
Timo Tijhof
beb1c4a0ec phpcs: More require/include is not a function
Follows-up I1343872de7, Ia533aedf63 and I2df2f80b81.

Also updated usage in text in documentation and the
installer LocalSettingsGenerator.

Most of them were handled by this regex:
- find: (require|include|require_once|include_once)\s*\(\s*(.+?)\s*\)\s*;$
- replace: $1 $2;

Change-Id: I6b38aad9a5149c9c43ce18bd8edbab14b8ce43fa
2013-05-21 23:26:28 +02:00
Timo Tijhof
50e7985d4d phpcs: Fix WhiteSpace.LanguageConstructSpacing warnings
Squiz.WhiteSpace.LanguageConstructSpacing:
   Language constructs must be followed by a single space;
   expected "require_once expression" but found
   "require_once(expression)"

It is a keyword (e.g. like `new`, `return` and `print`). As
such the parentheses don't make sense.

Per our code conventions, we use a space after keywords like
these. We appeared to have an unwritten exception for `require`
that doesn't make sense. About 60% of require/include usage
was missing the space and/or had superfluous parentheses.

It is as silly as print("foo") or return("foo"), it works
because keywords have no significance for whitespace between
it and the expression that follows, and since experessions can
be wrapped in parentheses for clarity (e.g. when doing string
concatenation or mathematical operations) the parenthesis
before and after basiclaly just ignored.

Change-Id: I2df2f80b8123714bea7e0771bf94b51ad5bb4b87
2013-05-09 05:56:26 +02:00
umherirrender
b114f5e1c1 Fixed some spacing in maintenance folder
Added spaces before if, foreach
Added some braces for one line statements

Change-Id: I9657f72996358f8c1c154cea1ea97970d973723c
2013-04-18 20:48:44 +02:00
umherirrender
15abcf71ca Added/Removed spaces around string concatenation
And added/removed spaces around some other tokens,
like +, -, *, /, <, >, =, !

Fixed windows newline style

Change-Id: I0b9c8c408f3f6bfc0d685a074d7ec468fb848fc8
2013-04-13 13:36:24 +02:00
Alexandre Emsenhuber
df5265e14d Fix case of some Title methods
Change-Id: I37ce7fe392f4941c500fa0a88007664501d7e338
2013-03-27 14:36:05 +01:00
Tim Starling
b4624ff17b Merge "Added --all option and other features to purgeList.php" 2013-02-13 05:01:14 +00:00
Tim Starling
3e668f5ebf Added --all option and other features to purgeList.php
Added --all, --delay and --verbose options to purgeList.php. Rewrote the
implementation of the --namespace feature. For bug 43466.

Change-Id: I560bffb7b7d765e408687522580ccee22dffd1e2
2013-02-13 15:49:16 +11:00
jenkins-bot
63d6a736ff Merge "misc style issues" 2013-02-11 21:14:30 +00:00
Antoine Musso
7006e1df93 style: fix up commas in function arguments
Fix up spaces in our function calls, we do not want spaces before a
comma and try to avoid multiple commas whenever possible.

Errors:

* No space found after comma in function call
* Space found before comma in function call

Change-Id: I51aec02016f742422fa60b92ad35ba3f0ef59ba3
2013-02-06 19:30:39 +01:00
Antoine Musso
bb497c97b6 misc style issues
7zip.inc : $stream is really a private property.

userDupes.inc : still only used by MysqlUpdater, added a comment about
it and made the properties private.

sql.php : make sure we actually do nothing in some method. Previously we
just had an empty IF statement.

purgeList : a private method was named the same as the class, that is
how we declared constructor with PHP4. Renamed it to doPurge() to make
it clear that it is not the constructor.

Rests are whitespaces fixes.

Change-Id: I0b83f83ee3af37c770817ebfce3e804082c2fb41
2013-01-30 16:12:59 +01:00
Alexandre Emsenhuber
d85239a186 Use ResultWrapper::numRows() instead of DatabaseBase::numRows()
Change-Id: I87f059aaff72bf06ebc72ad3a7904cca8e11fab9
2013-01-06 11:52:40 +01:00
jeroendedauw
38c7f444e1 Use __DIR__ instead of dirname( __FILE__ )
We can now do this since we finally switched to PHP 5.3 for MW 1.20 and get rid of the silly dirname(__FILE__) stuff :)

Change-Id: Id9b2c9cd2e678197aa81c78adced5d1d31ff57b1
2012-08-27 21:45:00 +02:00
Alexandre Emsenhuber
73ae67c6ed Improve documentation of maintenance scripts.
Change-Id: I557f85e8526a3e4b48107fbf299ff39f6af1ac12
2012-08-05 12:00:37 +02:00
Antoine Musso
4706945686 enable purge of HTTPS URLs 2012-02-14 20:20:56 +00:00
Roan Kattouw
39e2d66b62 Use getInternalUrl() instead of getFullUrl() in purgeList.php . This was potentially a serious bug if $wgServer differed from $wgInternalServer in command-line mode (this is not the case on WMF, but might be the case on 3rd-party installs) 2011-08-19 17:20:35 +00:00
Antoine Musso
1017746597 Fix space/tab indentation FU r94444 2011-08-15 10:23:48 +00:00
Antoine Musso
7cfecb0f2c (bug 28273) Merge purgeList and purgeNamespace scripts
Nothing fancy, just copy pasted from purgeNamespace into purgeList.
This need to be in 1.18 to avoid publishing purgeNamespace to everyone
and removing it in 1.19 =)
2011-08-14 08:51:36 +00:00
Roan Kattouw
ae51814cb2 Fix fatal in r77354 (!!), discovered this when purgeList.php fataled on me on the WMF cluster 2011-06-30 15:15:54 +00:00
Chad Horohoe
26505b170a Fix concern raised by Brion in r74108 (but has really existed since the maintenance rewrite). Right now, including a maintenance script causes it to execute. This is bad when you want to reuse the particular class but not have it start executing all by itself.
Until now, we relied on setting MW_NO_SETUP which was a) hacky, b) irreversable, and c) likely to be forgotten if you didn't use one of the wrappers like runChild().

Instead, move the freaky magic to doMaintenance and have *it* check if it's in a specific call stack that indicates this is being run from the file scope and should be executed. Rename DO_MAINTENANCE to RUN_MAINTENANCE_IF_MAIN so it's nice and clear what magic happens behind the require_once().
2011-01-13 22:58:55 +00:00
Roan Kattouw
e0d90342e4 Followup r77354: it's page_touched, with an underscore 2010-12-14 15:33:14 +00:00
Sam Reed
17f36279cf $options doesn't exist in PurgeList
Change to getOptions, and addOption in Constructor
2010-11-27 14:18:54 +00:00
Sam Reed
659778619c Stylize maintenance folder.. 2010-05-22 16:50:39 +00:00
Chad Horohoe
567f244e36 Revert r54244 which was stupid and fix this properly. Require commandLine.inc/Maintenance.php using the full path every time. 2009-08-03 21:56:41 +00:00
Chad Horohoe
a1c51e18af Merge maintenance-work branch (now with less errors!):
* Docs have been updated to indicate the standard on how to write maintenance scripts (MW.org docs will follow) Have ported vast majority of maintenance scripts to new format. Remaining ones (mostly FiveUpgrade-related) are a bit more tricky. commandLine.inc is untouched for now. Many have gotten code-style updates as well. Deleted .inc files were only used by their .php counterparts, and have been merged into single files.
* (bug 11867) Lock error on redirect table when running orphans.php
* (bug 16322) Allow maintenance scripts to accept DB user/pass over input or params
* (bug 18566) Maintenance script to un/protect pages
* initStats overhaul, now uses class SiteStatsInit. Also fixes bug 18930
2009-08-02 19:35:17 +00:00
Alexandre Emsenhuber
087a9f70c5 WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>

Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage

One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00