jenkins-bot has submitted this change and it was merged. Change subject: Add changeSkinPref ......................................................................
Add changeSkinPref For looping across lots of wikis to change a pref to monobook. Based on ori's work: https://gist.github.com/atdt/b742e8ba56456f82427d Bug: T114208 Change-Id: I9d7f180d3ed67776a34bb76cc49a5f7d3b2b4266 --- A changeSkinPref.php 1 file changed, 67 insertions(+), 0 deletions(-) Approvals: Ori.livneh: Looks good to me, approved jenkins-bot: Verified diff --git a/changeSkinPref.php b/changeSkinPref.php new file mode 100644 index 0000000..38171c6 --- /dev/null +++ b/changeSkinPref.php @@ -0,0 +1,67 @@ +<?php +/** + * @defgroup Wikimedia Wikimedia + */ + +/** + * Set a skin preference for a user. Mostly nice for running in a loop on + * bunches of wikis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * http://www.gnu.org/copyleft/gpl.html + * + * @file + * @ingroup Maintenance + * @ingroup Wikimedia + */ +require_once( __DIR__ . '/WikimediaMaintenance.php' ); + +class ChangeSkinPref extends WikimediaMaintenance { + public function __construct() { + parent::__construct(); + $this->mDescription = 'Set a skin for a user, usually monobook'; + $this->addArg( 'user', 'Which user to set the skin on' ); + $this->addOption( 'skin', 'Which skin to set (default monobook)', false, true ); + } + + public function execute() { + $this->setSkin( + $this->getArg(), + $this->getOption( 'skin', 'monobook' ) + ); + } + + private function setSkin( $userName, $newSkin ) { + $user = User::newFromName( $userName ); + $wiki = wfWikiID(); + if ( !$user || $user->getId() === 0 ) { + $this->error( "User $userName does not exist or is invalid.", 1 ); + } + if ( !array_key_exists( $newSkin, Skin::getSkinNames() ) ) { + $this->error( "$newSkin is not a valid skin", 1 ); + } + $skin = $user->getOption( 'skin' ); + if ( $skin === $newSkin ) { + $this->output( "{$userName}@{$wiki}: Skin already set to $newSkin; nothing to do.\n" ); + return; + } + $user->setOption( 'skin', $newSkin ); + $user->saveSettings(); + $this->output( "{$userName}@{$wiki}: Changed from $skin to $newSkin\n" ); + } +} + +$maintClass = "ChangeSkinPref"; +require_once( RUN_MAINTENANCE_IF_MAIN ); -- To view, visit https://gerrit.wikimedia.org/r/254407 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I9d7f180d3ed67776a34bb76cc49a5f7d3b2b4266 Gerrit-PatchSet: 6 Gerrit-Project: mediawiki/extensions/WikimediaMaintenance Gerrit-Branch: master Gerrit-Owner: Chad <[email protected]> Gerrit-Reviewer: Chad <[email protected]> Gerrit-Reviewer: Ori.livneh <[email protected]> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
