Anomie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/187624
Change subject: Support ListDefinedTags and ChangeTagsListActive hooks
......................................................................
Support ListDefinedTags and ChangeTagsListActive hooks
We define a tag if it's actually in use for a known consumer, and mark
it active if the consumer is proposed or approved. This avoids flooding
Special:Tags with tags for consumers that aren't taking any logged
actions.
Bug: T60312
Change-Id: I893bfdef051f03216787801d6ed4317917d74a11
---
M OAuth.setup.php
M backend/MWOAuth.hooks.php
2 files changed, 60 insertions(+), 3 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/OAuth
refs/changes/24/187624/1
diff --git a/OAuth.setup.php b/OAuth.setup.php
index 979f68e..8784ab3 100644
--- a/OAuth.setup.php
+++ b/OAuth.setup.php
@@ -107,6 +107,8 @@
global $wgHooks;
$wgHooks['ChangeTagCanCreate'][] =
'MediaWiki\Extensions\OAuth\MWOAuthHooks::onChangeTagCanCreate';
+ $wgHooks['ListDefinedTags'][] = array(
'MediaWiki\Extensions\OAuth\MWOAuthHooks::getUsedConsumerTags', false );
+ $wgHooks['ChangeTagsListActive'][] = array(
'MediaWiki\Extensions\OAuth\MWOAuthHooks::getUsedConsumerTags', true );
$wgHooks['MergeAccountFromTo'][] =
'MediaWiki\Extensions\OAuth\MWOAuthHooks::onMergeAccountFromTo';
$wgHooks['CentralAuthGlobalUserMerged'][] =
'MediaWiki\Extensions\OAuth\MWOAuthHooks::onCentralAuthGlobalUserMerged';
$wgHooks['LoadExtensionSchemaUpdates'][] =
'MediaWiki\Extensions\OAuth\MWOAuthUpdaterHooks::addSchemaUpdates';
diff --git a/backend/MWOAuth.hooks.php b/backend/MWOAuth.hooks.php
index 541c008..c1bb5cb 100644
--- a/backend/MWOAuth.hooks.php
+++ b/backend/MWOAuth.hooks.php
@@ -10,9 +10,6 @@
* Reserve all change tags beginning with 'OAuth CID:'
(case-insensitive) so
* that the user may not create them
*
- * @todo Also consume ListDefinedTags and ChangeTagsListActive hooks in
a
- * sensible way, so OAuth tags don't appear undefined and inactive on
Special:Tags
- *
* @param string $tag
* @param User $user
* @param Status $status
@@ -63,4 +60,62 @@
__METHOD__
);
}
+
+ /**
+ * List tags that should show as defined/active on Special:Tags
+ *
+ * Handles both the ChangeTagsListActive and ListDefinedTags hooks. Only
+ * lists those tags that are actually in use on the local wiki, to avoid
+ * flooding Special:Tags with tags for consumers that will never be
making
+ * logged actions.
+ *
+ * @param boolean $activeOnly true for ChangeTagsListActive, false for
ListDefinedTags
+ * @param array &$tags
+ * @return bool
+ */
+ public static function getUsedConsumerTags( $activeOnly, &$tags ) {
+ // Step 1: Get the list of (active) consumers' tags for this
wiki
+ $db = MWOAuthUtils::getCentralDB( DB_SLAVE );
+ $conds = array(
+ $db->makeList( array(
+ 'oarc_wiki = ' . $db->addQuotes( '*' ),
+ 'oarc_wiki = ' . $db->addQuotes( wfWikiId() ),
+ ), LIST_OR ),
+ 'oarc_deleted' => 0,
+ );
+ if ( $activeOnly ) {
+ $conds[] = $db->makeList( array(
+ 'oarc_stage = ' .
MWOAuthConsumer::STAGE_APPROVED,
+ // Proposed consumers are active for the owner,
so count them too
+ 'oarc_stage = ' .
MWOAuthConsumer::STAGE_PROPOSED,
+ ), LIST_OR );
+ }
+ $res = $db->select(
+ 'oauth_registered_consumer',
+ array( 'oarc_id' ),
+ $conds,
+ __METHOD__
+ );
+ $allTags = array();
+ foreach ( $res as $row ) {
+ $allTags[] = "OAuth CID: $row->oarc_id";
+ }
+
+ // Step 2: Return only those that are in use.
+ if ( $allTags ) {
+ $db = wfGetDB( DB_SLAVE );
+ $res = $db->select(
+ 'change_tag',
+ array( 'ct_tag' ),
+ array( 'ct_tag' => $allTags ),
+ __METHOD__,
+ array( 'DISTINCT' )
+ );
+ foreach ( $res as $row ) {
+ $tags[] = $row->ct_tag;
+ }
+ }
+
+ return true;
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/187624
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I893bfdef051f03216787801d6ed4317917d74a11
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/OAuth
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits