PleaseStand has uploaded a new change for review.
https://gerrit.wikimedia.org/r/274403
Change subject: MovePage: When changing cl_type, update category counts
......................................................................
MovePage: When changing cl_type, update category counts
As part of this, I added getCategoryLinkType() methods to both
MWNamespace and Title, and used the new Title method in a few
places, to avoid code duplication.
Follows-up e0ff770adee0695b.
Change-Id: Ia45a53ede8f580ffa57aae3b4fe4ebf26377d5f1
---
M includes/MWNamespace.php
M includes/MovePage.php
M includes/Title.php
M includes/deferred/LinksUpdate.php
M maintenance/updateCollation.php
5 files changed, 55 insertions(+), 21 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/03/274403/1
diff --git a/includes/MWNamespace.php b/includes/MWNamespace.php
index 61e34ee..fc00792 100644
--- a/includes/MWNamespace.php
+++ b/includes/MWNamespace.php
@@ -509,4 +509,26 @@
return $usableLevels;
}
+
+ /**
+ * Returns the link type to be used for categories.
+ *
+ * This determines which section of a category page titles
+ * in the namespace will appear within.
+ *
+ * @since 1.27
+ * @param int $index Namespace index
+ * @return string One of 'subcat', 'file', 'page'
+ */
+ public static function getCategoryLinkType( $index ) {
+ self::isMethodValidFor( $index, __METHOD__ );
+
+ if ( $index == NS_CATEGORY ) {
+ return 'subcat';
+ } elseif ( $index == NS_FILE ) {
+ return 'file';
+ } else {
+ return 'page';
+ }
+ }
}
diff --git a/includes/MovePage.php b/includes/MovePage.php
index afa4e1c..dbfd357 100644
--- a/includes/MovePage.php
+++ b/includes/MovePage.php
@@ -267,13 +267,8 @@
[ 'cl_from' => $pageid ],
__METHOD__
);
- if ( $this->newTitle->getNamespace() == NS_CATEGORY ) {
- $type = 'subcat';
- } elseif ( $this->newTitle->getNamespace() == NS_FILE ) {
- $type = 'file';
- } else {
- $type = 'page';
- }
+ $type = $this->newTitle->getCategoryLinkType();
+ $catTitles = [];
foreach ( $prefixes as $prefixRow ) {
$prefix = $prefixRow->cl_sortkey_prefix;
$catTo = $prefixRow->cl_to;
@@ -289,6 +284,22 @@
'cl_to' => $catTo ],
__METHOD__
);
+
+ $catTitles[] = $catTo;
+ }
+
+ // Also update the category counts if necessary to reflect
+ // a change in the cl_type value for this page.
+ $oldType = $this->oldTitle->getCategoryLinkType();
+ if ( $catTitles && $type !== $oldType ) {
+ $set = [];
+ if ( $oldType !== 'page' ) {
+ $set[] = "cat_{$oldType}s = cat_{$oldType}s -
1";
+ }
+ if ( $type !== 'page' ) {
+ $set[] = "cat_{$type}s = cat_{$type}s + 1";
+ }
+ $dbw->update( 'category', $set, [ 'cat_title' =>
$catTitles ], __METHOD__ );
}
$redirid = $this->oldTitle->getArticleID();
diff --git a/includes/Title.php b/includes/Title.php
index c0ec97f..15dd7b6 100644
--- a/includes/Title.php
+++ b/includes/Title.php
@@ -4590,6 +4590,19 @@
}
/**
+ * Returns the link type to be used for categories.
+ *
+ * This determines which section of a category page this title
+ * will appear within.
+ *
+ * @since 1.27
+ * @return string One of 'subcat', 'file', 'page'
+ */
+ public function getCategoryLinkType() {
+ return MWNamespace::getCategoryLinkType( $this->mNamespace );
+ }
+
+ /**
* Returns the raw sort key to be used for categories, with the
specified
* prefix. This will be fed to Collation::getSortKey() to get a
* binary sortkey that can be used for actual sorting.
diff --git a/includes/deferred/LinksUpdate.php
b/includes/deferred/LinksUpdate.php
index 4215ed0..f783846 100644
--- a/includes/deferred/LinksUpdate.php
+++ b/includes/deferred/LinksUpdate.php
@@ -451,13 +451,7 @@
$nt = Title::makeTitleSafe( NS_CATEGORY, $name );
$wgContLang->findVariantLink( $name, $nt, true );
- if ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
- $type = 'subcat';
- } elseif ( $this->mTitle->getNamespace() == NS_FILE ) {
- $type = 'file';
- } else {
- $type = 'page';
- }
+ $type = $this->mTitle->getCategoryLinkType();
# Treat custom sortkeys as a prefix, so that if multiple
# things are forced to sort as '*' or something, they'll
diff --git a/maintenance/updateCollation.php b/maintenance/updateCollation.php
index af666b0..4232107 100644
--- a/maintenance/updateCollation.php
+++ b/maintenance/updateCollation.php
@@ -162,13 +162,7 @@
}
# cl_type will be wrong for lots of pages if
cl_collation is 0,
# so let's update it while we're here.
- if ( $title->getNamespace() == NS_CATEGORY ) {
- $type = 'subcat';
- } elseif ( $title->getNamespace() == NS_FILE ) {
- $type = 'file';
- } else {
- $type = 'page';
- }
+ $type = $title->getCategoryLinkType();
$newSortKey = $collation->getSortKey(
$title->getCategorySortkey( $prefix ) );
if ( $verboseStats ) {
--
To view, visit https://gerrit.wikimedia.org/r/274403
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ia45a53ede8f580ffa57aae3b4fe4ebf26377d5f1
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: PleaseStand <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits