jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/338971 )

Change subject: Add a maintenance script for opt-in
......................................................................


Add a maintenance script for opt-in

To test, do
mwscript 
extensions/UniversalLanguageSelector/maintenance/ULSCompactLinksDisablePref.php 
XXwiki

(Where "XXwiki" is the database name, like "enwiki".)

To actually run,
mwscript 
extensions/UniversalLanguageSelector/maintenance/ULSCompactLinksDisablePref.php 
XXwiki --really

Bug: T133031
Change-Id: Ic4a5cd9561535aa1c8e049843b15c1731977ef7b
(cherry picked from commit 3e17adcf5f1c3fe112d0e933fa5b553d7ccd17e0)
---
A maintenance/ULSCompactLinksDisablePref.php
1 file changed, 100 insertions(+), 0 deletions(-)

Approvals:
  Hashar: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/maintenance/ULSCompactLinksDisablePref.php 
b/maintenance/ULSCompactLinksDisablePref.php
new file mode 100644
index 0000000..f53d15d
--- /dev/null
+++ b/maintenance/ULSCompactLinksDisablePref.php
@@ -0,0 +1,100 @@
+<?php
+/**
+ * Disables the UniversalLanguageSelector compact-language-links
+ * preference for appropriate users
+ *
+ * @copyright 2017 Wikimedia Language team and others; see AUTHORS.txt
+ * @license GPL-2.0+
+ * @author Niklas Laxström
+ * @author Amir E. Aharoni
+ * Based on autodisablePref.php from the VisualEditor repository by Alex Monk
+ * @file
+ * @ingroup Extensions
+ * @ingroup Maintenance
+ */
+
+require_once ( getenv( 'MW_INSTALL_PATH' ) !== false
+       ? getenv( 'MW_INSTALL_PATH' ) . '/maintenance/Maintenance.php'
+       : __DIR__ . '/../../../maintenance/Maintenance.php' );
+
+class ULSCompactLinksDisablePref extends Maintenance {
+       public function __construct() {
+               parent::__construct();
+               $this->requireExtension( 'UniversalLanguageSelector' );
+               $this->mDescription = 'Disables the UniversalLanguageSelector 
compact-language-links ' .
+                       'preference for appropriate users.';
+               $this->setBatchSize( 100 );
+
+               $this->addOption( 'really', 'Really change the preferences' );
+       }
+
+       public function execute() {
+               $dbr = wfGetDB( DB_REPLICA );
+
+               $this->really = $this->hasOption( 'really' );
+
+               $lastUserId = 0;
+               do {
+                       $tables = [ 'revision', 'user_properties', 
'user_groups' ];
+                       $fields = [ 'rev_user', 'isbot' => 'ug_group', 
'hasbeta' => 'up_value' ];
+                       $conds = [
+                               'rev_timestamp > ' . $dbr->timestamp( 
20161001000000 ),
+                               "rev_user > $lastUserId"
+                       ];
+                       $options = [
+                               'GROUP BY' => 'rev_user',
+                               'HAVING' => 'count(*) >= 20',
+                               'ORDER BY' => 'rev_user',
+                               'LIMIT' => $this->mBatchSize,
+                       ];
+                       $joins = [
+                               'user_properties' => [
+                                       'LEFT OUTER JOIN',
+                                       "rev_user = up_user AND up_property = 
'uls-compact-links' AND up_value = 1"
+                               ],
+                               'user_groups' => [
+                                       'LEFT OUTER JOIN',
+                                       "rev_user = ug_user AND ug_group = 
'bot'"
+                               ]
+                       ];
+
+                       if ( !$this->really ) {
+                               echo "\n\n" .
+                                       $dbr->selectSqlText( $tables, $fields, 
$conds, __METHOD__, $options, $joins ) .
+                                       "\n";
+                       }
+
+                       $results = $dbr->select( $tables, $fields, $conds, 
__METHOD__, $options, $joins );
+
+                       $disabled = 0;
+
+                       foreach ( $results as $row ) {
+                               $lastUserId = $row->rev_user;
+                               if ( $row->isbot === 'bot' || $row->hasbeta !== 
null ) {
+                                       continue;
+                               }
+
+                               $user = User::newFromId( $lastUserId );
+                               $user->load( User::READ_LATEST );
+
+                               if ( $this->really ) {
+                                       $user->setOption( 
'compact-language-links', 0 );
+
+                                       $user->saveSettings();
+                               }
+
+                               $disabled++;
+                               // If we ever need to revert, print the 
affected user ids
+                               $this->output( $row->rev_user . " ", 'userids' 
);
+                       }
+
+                       $this->output( "Disabled compact-language-links for 
$disabled users.\n" );
+                       wfWaitForSlaves();
+               } while ( $results->numRows() === $this->mBatchSize );
+
+               $this->output( "done.\n" );
+       }
+}
+
+$maintClass = "ULSCompactLinksDisablePref";
+require_once RUN_MAINTENANCE_IF_MAIN;

-- 
To view, visit https://gerrit.wikimedia.org/r/338971
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic4a5cd9561535aa1c8e049843b15c1731977ef7b
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/UniversalLanguageSelector
Gerrit-Branch: wmf/1.29.0-wmf.12
Gerrit-Owner: Hashar <[email protected]>
Gerrit-Reviewer: Amire80 <[email protected]>
Gerrit-Reviewer: Hashar <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to