Commit graph

107 commits

Author SHA1 Message Date
Gergő Tisza
551e7448ca namespaceDupes.php: Handle invalid titles
Apply prefix and suffix to invalid titles just like it's applied
to conflicting titles. (Typically this will be needed when the
Foo namespace is created and there is a Foo: article already.)

Also remove a broken for loop. Presumably the intent was to
repeatedly add prefix/suffix on conflict, but actually it would
just get into an infinite loop. The behavior doesn't seem that
useful anyway.

Bug: T293407
Change-Id: Ieef6698b461e7db003dc326e5cd82accd2909540
2021-10-16 12:26:24 +00:00
Umherirrender
0e4bb6d611 Change 'fromdbmaster' to WikiPage::READ_LATEST
Constants are harder to misspell

Change-Id: Ie1afcc8580cccf815df1cc97f05a5be81676d9f7
2021-09-26 19:27:33 +00:00
James D. Forrester
df5eb22f83 Replace uses of DB_MASTER with DB_PRIMARY
Just an auto-replace from codesniffer for now.

Change-Id: I5240dc9ac5929d291b0ef1c743ea2bfd3f428266
2021-04-29 09:24:31 -07:00
Reedy
354848b0cd maintenance: Mark some closures as static
Bug: T274036
Change-Id: Ic959dfddcf2867e4cf26970f375b347f4b41584d
2021-02-07 02:18:30 +00:00
Thiemo Kreuz
20b2c5000d Make use of array deconstruction directly in foreach, if possible
Deconstructing non-sparse, numerically indexed arrays directly in
foreach (a.k.a. using the list() syntax in foreach) is possible since
PHP 5.5.

The possibility to use string array keys as well as non-sequential
numeric keys in array deconstruction was added in PHP 7.1.

Change-Id: I56a48552a45f61cedc291b306cad8548fc70d485
2020-11-12 18:38:06 +00:00
Thiemo Kreuz
6f901ef17c Make use of native array_column() function where possible
Change-Id: I78108e7dc5a10d892e97b0101c1b72cb8d363e97
2020-11-11 22:48:53 +00:00
Reedy
8ba1c75559 Replace wfWaitForSlaves() with LBFactory::waitForReplication()
Change-Id: I337147d61e2ec686a8672d0340dff4b6783f78cd
2020-05-02 02:00:01 +00:00
Reedy
4354b0d962 namespaceDupes.php: Delete links if they still exist after UPDATE
Bug: T226036
Change-Id: I4db32efdb10bb51b87e5e2116888655e7341b82d
2020-05-01 17:15:06 +00:00
Petr Pchelko
618236d204 Hard deprecate Revision::newFromPageId
Bug: T246284
Depends-On: I955d9c3478eb5278bdc807d11aab04e8e051d22f
Change-Id: I01ac581234980c6e7dbf916558c231ab648cbbae
2020-03-18 17:18:58 -07:00
Timo Tijhof
75ccdc6147 languages: Move default $wgNamespaceAliases to MessagesEn.php
These are not configuration but business logic, similar to the
canonical names that are in NamespaceInfo.php, these must always
exist and cannot be altered or unset.

They were previously unconditionally assigned during all requests
in Setup.php and passed down as "site configuration".

Changes:

* Move them to MessagesEn.php where they can be cached and
  processed the same way as other core-provided aliases.

  Document and confirm with tests that this is a mergeable
  attribute that follows the language chain.

* Remove the duplicated code in a few places that was reading
  this variable + Language::getNamespaceAliases(), to instead
  just call the latter and move the logic there, centralised,
  and tested.

  In doing so I noticed that these were applied in an
  inconsistent order. Sometimes the config won, sometimes not.
  There's no obvious right or wrong way here, but I've chosen
  to standardise on the way that Language::getNamespaceIds() did
  it, which is that config wins. This because that method seems
  to be most widely used of the three (it decides how URLs and
  titles are parsed), and thus the one I least want to change
  the behaviour of.

* Document that $wgNamespaceAliases may only be used to
  define (extra) aliases, it is and never was a way to access
  the complete list of aliases.

Bug: T189966
Change-Id: Ibb14181aba8c1b509264ed40523e9ab4000fd71a
2020-03-14 19:27:40 +00:00
James D. Forrester
4f2d1efdda Coding style: Auto-fix MediaWiki.Classes.UnsortedUseStatements.UnsortedUse
Change-Id: I94a0ae83c65e8ee419bbd1ae1e86ab21ed4d8210
2020-01-10 09:32:25 -08:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
Umherirrender
8f666cabcd Use Maintenance::getConfig in some maintenance scripts
This avoid global state

Change-Id: Id67d07597159a0bd2721a381775230c3cd1d5509
2019-09-01 20:55:08 +02:00
Aaron Schulz
9e04f0d086 maintenance: Cleanup db code and bogus RevisionRecord constants in NamespaceDupes
Change-Id: Ie31beb183d32663b368a32e4926a3ed55456719c
2019-08-24 19:55:46 +00:00
Derick Alangi
e16eec8caf maintenance: Avoid usage of deprecated Revision::* constants
Update deprecated Revision::* constants to use RevisionRecord::*
equivalents.

Change-Id: Icae1ebb088e4efadbc7c2806127a2073d337fa05
2019-07-21 11:35:09 +01:00
Umherirrender
fa607f56b2 Type hint against IResultWrapper in maintenance classes
Change-Id: I6a58e9cfe645056a854c80b2db1e71fb59bd226b
2019-06-19 21:42:32 +02:00
Aryeh Gregor
2e1ac38485 Mass conversion to NamespaceInfo
Change-Id: I2fef157ceec772f304c0923a1cd8c0eef2e82a0f
2019-05-07 22:44:56 +02:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Bartosz Dziewoński
b191e5e860 Use PHP 7 '<=>' operator in 'sort()' callbacks
`$a <=> $b` returns `-1` if `$a` is lesser, `1` if `$b` is lesser,
and `0` if they are equal, which are exactly the values 'sort()'
callbacks are supposed to return.

It also enables the neat idiom `$a[x] <=> $b[x] ?: $a[y] <=> $b[y]`
to sort arrays of objects first by 'x', and by 'y' if they are equal.

* Replace a common pattern like `return $a < $b ? -1 : 1` with the
  new operator (and similar patterns with the variables, the numbers
  or the comparison inverted). Some of the uses were previously not
  correctly handling the variables being equal; this is now
  automatically fixed.
* Also replace `return $a - $b`, which is equivalent to `return
  $a <=> $b` if both variables are integers but less intuitive.
* (Do not replace `return strcmp( $a, $b )`. It is also equivalent
  when both variables are strings, but if any of the variables is not,
  'strcmp()' converts it to a string before comparison, which could
  give different results than '<=>', so changing this would require
  careful review and isn't worth it.)
* Also replace `return $a > $b`, which presumably sort of works most
  of the time (returns `1` if `$b` is lesser, and `0` if they are
  equal or `$a` is lesser) but is erroneous.

Change-Id: I19a3d2fc8fcdb208c10330bd7a42c4e05d7f5cf3
2018-05-30 18:05:20 -07:00
Kunal Mehta
a2c166cb51 Have class match filename in some maintenance scripts
Each of these scripts had a class name that was not referenced outside
of the script file itself, and are safe to rename as a result.

Change-Id: Id605aca11db51ee433baeaa998a0e33184c930ca
2018-05-23 19:36:51 -07: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
Umherirrender
3f1a52805e Use short type bool/int in param documentation
Enable the phpcs sniffs for this and used phpcbf

Change-Id: Iaa36687154ddd2bf663b9dd519f5c99409d37925
2017-08-20 13:20:59 +02:00
Umherirrender
b5cddfb27b Remove empty lines at begin of function, if, foreach, switch
Organize phpcs.xml a bit

Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
2017-07-01 11:34:16 +00:00
Aaron Schulz
21e71e0235 Use IDatabase type hints in /maintenance
Relatedly, move lockTables()/unlockTables() to IMaintainableDatabase

Change-Id: Ib53e9fa948deb2f9a70f0ce16c002613d0060bf9
2017-04-07 23:37:41 +00:00
Aaron Schulz
e01fd44388 Move ResultWrapper subclasses to Rdbms
Change-Id: I6f3f0e85e268b24c57c537aa6ad8016e0b4cdddb
2017-03-03 00:44:41 +00:00
Yuriy Shnitkovskiy
85a52faa37 Removed deprecated usages of Interwiki methods in core
Change-Id: Ibd25968660466c44189ccb01df1d8bec6e1b207c
2017-01-10 12:19:31 +02:00
Aaron Schulz
30f4b3c103 Replace DatabaseBase => Database in more places
Change-Id: If37a7909056bf2c31a8228cbc84f0fbbf5f1c517
2016-09-28 15:53:02 -07:00
Aaron Schulz
b8b01aa589 Replace DataUpdate::doUpdates() callers in maintenance/
Change-Id: I51df9f419d6ea1e822fd0eef8c5dc4c43f9855e1
2016-09-01 21:30:34 -07:00
Aaron Schulz
911e7acb31 Run LinksDeletionUpdate after commit() in namespaceDupes.php
This DataUpdate (or any for that matter) is not meant to be run in
the same transaction as random other stuff.

Bug: T143631
Change-Id: Ic40865805c26acc88e613a592b922ffb121962d2
2016-08-22 16:15:29 -07:00
Kunal Mehta
c9d885f3b4 Namespace LinkTarget under MediaWiki\Linker
And add a GPL file header while we're at it.

Change-Id: I15a6f240124c879b21fb655ade1baaebf4f34ffd
2016-04-21 17:19:10 -07:00
Reedy
b5656b6953 Many more function case mismatches
Change-Id: I5d3a5eb8adea1ecbf136415bb9fd7a162633ccca
2016-03-19 00:20:58 +00: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
addshore
71d696aa9c Use LinkTarget in some namespaceDupes methods
Change-Id: I230054fab8c2e2ade9f3ef00bfd820bad2842c80
2016-02-03 16:16:35 +00: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
2e0787cf5b Make maintenance scripts use beginTransaction/commitTransaction
Change-Id: I700437a016a40ad82951ae56d215f6dace2bb612
2015-12-31 15:02:15 -07:00
Roan Kattouw
e305df10ae namespaceDupes: Ignore duplicate key errors in link table updates
Bug: T115824
Change-Id: I67f57f680587c2c1e00f63a268019270bf8d5f86
2015-11-18 16:24:17 -08:00
umherirrender
2320f5cfe2 Change some line comments to multi line comments
This allows empty lines inside the comment as found by the
MediaWiki.WhiteSpace.SpaceBeforeSingleLineComment.EmptyComment sniff

Change-Id: Iac155bbda4a84562db2b452baeae9b8973899453
2015-10-14 09:40:50 +02:00
Tim Starling
9b685a4a52 In namespaceDupes.php, fix link tables
* Fix link destinations where a link was previously made to the
  pseudo-namespace. Don't do this for --source-pseudo-namespace since it
  only makes sense when the PDBK is essentially unchanged.
* Update pl_from_namespace, il_from_namespace and tl_from_namespace when
  moving a page.
* Run LinksDeletionUpdate::doUpdate() when deleting a page, so that
  referential integrity is preserved.

Change-Id: I584ead93d6267d1a2928ecbcdf8a4cd8e5aeef94
2015-09-07 06:42:02 +00:00
Tim Starling
64765720b0 Improve namespaceDupes.php
General review and improvement in service of T87645.

* Add the option to add a prefix to a page on conflict, instead of a suffix.
  This makes it easier to find the pages after they are renamed, since
  [[Special:Prefixindex]] can be used.
* Rename options --prefix to --source-pseudo-ns, --suffix to --add-suffix,
  --key to --dest-ns.
* Document --source-pseudo-ns and verify that it does what I think it was
  meant to do, per T14371, thus allowing me to remove the "todo" note.
* Add the option to do a history merge instead of a rename to resolve
  conflicts.
* Pass around an options array instead of an ever-growing list of formal
  parameters.
* Rename resolveConflictOn() to movePage() and remove the $table and
  $prefix parameters which were unused since MW 1.5. Also get rid of
  the usage AS in getConflicts(), most instances of which were for MW 1.4
  compatibility.
* Rename getConflicts() to getTargetList() since "conflict" is a
  misnomer. A conflict occurs between two entities, really what the code
  was calling an "unresolvable conflict" is actually a conflict, whereas a
  "resolvable conflict" is merely a page in the wrong namespace.
* Add option --move-talk since checking the talk namespace doesn't make sense
  in the case of corruption, it only makes sense when introducing a new
  namespace, when a pseudo-namespace has previously been used.
* Use terse, greppable output, with a single line per page.
* Replace ksort() followed by asort() with a single uksort(), since I think
  that is what was intended. PHP's sort functions are not stable, so you
  can't run two different sort functions on the same array and expect to the
  first sort to have a predictable effect on the result.
* If --fix is not given, give the same output, just don't take the action.
* Refactor checkNamespace(). Move target title determination to its own
  function, was a mixture of SQL and a couple of lines in reportConflict().
  Move alternate title determination to its own function, was mostly in
  resolveConflict(). Get rid of reportConflict() and resolveConflict(), do
  what's left of them in the main loop. Get rid of modification of page row.
* Improve destination namespace calculation logic of --move-talk feature,
  per comments by PleaseStand.

Change-Id: I49921315315e1a29c9559ba221e9903b10b73d68
2015-02-13 01:00:15 +00:00
Legoktm
ba694fa8a5 Merge "Output number of conflicts" 2015-01-24 01:34:13 +00:00
Sam Reed
c5b7bdd4a0 Output number of conflicts
Change-Id: I1e52db4c3bc60ab41cff3f86aa565a99ffc564ef
2015-01-24 00:56:54 +00:00
Sam Reed
45eadb1052 Fix stdClass typo in namespaceDupes.php
Change-Id: I129c0d0ad5770d3d9bcdbc1881757f3c13f37c35
2015-01-24 00:37:53 +00:00
umherirrender
21e0c1c533 Correct variable names in @param to match method declarations
Some @param have a typo in the variable name,
some @param's were in wrong order.

Change-Id: Ie25806831027112b398f6f4a909c59147ac3a5fa
2014-08-13 21:48:28 +02:00
Kevin Israel
b43ac16fcc Remove use of strencode() outside Database classes
Change-Id: Idbc38d8089541e5154b2601297b429f7433fd59e
2014-06-02 13:45:26 -04: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
Ladsgroup
16a5102765 Change URLs to mediawiki.org in comments to HTTPS
These are only documentation fixes
http://www.mediawiki.org --> https://www.mediawiki.org

Change-Id: I62ad42be1a3aac410cc53e98ce79389ceddd8988
2014-03-20 16:59:46 +00:00
Chad Horohoe
518fa756f2 Remove $wgTitle from all maintenance scripts
Shouldn't be needed and aren't for any core operations. If any
extension relies on these $wgTitles being set in maintenance
environments those extensions are broken and should be fixed.

Change-Id: Ie02a5042ab96e155d783d56d5340dd0da8e3d55c
2014-03-12 18:28:47 -07: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