FreedomFighterSparrow has uploaded a new change for review. ( https://gerrit.wikimedia.org/r/352352 )
Change subject: A much improved query of pre-existing categories, by Brent Laabs (labster) ...................................................................... A much improved query of pre-existing categories, by Brent Laabs (labster) Bug: T161387 Change-Id: I290d785128184a32beaf41990cbce0d4f35fa7e1 --- M AutoCreateCategoryPages.body.php M README M extension.json 3 files changed, 11 insertions(+), 11 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/AutoCreateCategoryPages refs/changes/52/352352/1 diff --git a/AutoCreateCategoryPages.body.php b/AutoCreateCategoryPages.body.php index f0646d3..cd23d94 100644 --- a/AutoCreateCategoryPages.body.php +++ b/AutoCreateCategoryPages.body.php @@ -1,17 +1,16 @@ <?php class AutoCreateCategoryPages { - /** - * Get an array of existing categories, with the name in the key and sort key in the value. + /** + * Get an array of existing categories on this page, with the unprefixed name * * @return array */ - static function getExistingCategories() { - // TODO: cache this. Probably have to add to said cache every time a category page is created, - // by us or manually + static function getExistingCategories( $page_cats ) { $dbr = wfGetDB( DB_SLAVE ); - $res = $dbr->select( 'page', 'page_title', array( 'page_namespace' => NS_CATEGORY ) ); - + $res = $dbr->select( 'page', 'page_title', + array( 'page_namespace' => NS_CATEGORY, 'page_title' => $page_cats ) + ); $categories = array(); foreach ( $res as $row ) { $categories[] = $row->page_title; @@ -37,14 +36,14 @@ // array keys will cast numeric category names to ints // so we need to cast them back to strings to avoid potentially breaking things! $page_cats = array_map( 'strval', array_keys( $page_cats ) ); - $existing_cats = self::getExistingCategories(); + $existing_cats = self::getExistingCategories( $page_cats ); // Determine which categories on page do not exist $new_cats = array_diff( $page_cats, $existing_cats ); if( count( $new_cats ) > 0 ) { /* - * TODO probably need to use User::newSystemUser() + * @TODO probably need to use User::newSystemUser() * MW 1.27+ is supposed to use SessionManager, which requires some changes. * See https://www.mediawiki.org/wiki/Manual:SessionManager_and_AuthManager/Updating_tips */ diff --git a/README b/README index 48095e1..1e0bd23 100644 --- a/README +++ b/README @@ -8,7 +8,7 @@ == Compatibility == -Version 1.0.0 and above is compatible with MediaWiki 1.25+. +Version 1.0.0 and beyond are compatible with MediaWiki 1.25+. The previous version should work with MediaWiki 1.21-1.24. == Installation == @@ -35,6 +35,7 @@ The extension was released under GPLv3. See LICENSE file for more details. == Short changelog == +* Version 1.0.2, 2017-03-25: A much improved query of pre-existing categories, by Brent Laabs (labster) * Version 1.0.1, 2016-02-01: Fix bug where only the first new category page was actually created * Version 1.0.0, 2015-05-24: Convert to extension registration for MW 1.25 * Version 0.2.0, 2013-10-28: updated to work with MW 1.21.x & MW 1.22alpha. diff --git a/extension.json b/extension.json index 4642145..64edc58 100644 --- a/extension.json +++ b/extension.json @@ -1,6 +1,6 @@ { "name": "AutoCreateCategoryPages", - "version": "1.0.1", + "version": "1.0.2", "license-name": "GPL-3.0", "author": [ "Merrick Schaefer", -- To view, visit https://gerrit.wikimedia.org/r/352352 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I290d785128184a32beaf41990cbce0d4f35fa7e1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/AutoCreateCategoryPages Gerrit-Branch: master Gerrit-Owner: FreedomFighterSparrow <freedomfighterspar...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits