r39669 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r39668‎ | r39669 | r39670 >
Date:22:28, 19 August 2008
Author:vasilievvv
Status:old
Tags:
Comment:
Commit currently badly-working copy of ConfigureWMF extension.
* It overrides settings in $wgConf, so default and per-project settings may
be changed correctly.
* It has a neat logging with each change having its own description message.
* Group permissions manager is currently not working, because I haven't fully
implemented it yet and integrated with r39577 because of default permissions
determining issues.
* Work still in progress: namespace and group manager are ongoing. Don't
add it to Betawiki yet.
Modified paths:
  • /trunk/extensions/ConfigureWMF (added) (history)
  • /trunk/extensions/ConfigureWMF/ConfigureWMF.class.php (added) (history)
  • /trunk/extensions/ConfigureWMF/ConfigureWMF.i18n.php (added) (history)
  • /trunk/extensions/ConfigureWMF/ConfigureWMF.page.php (added) (history)
  • /trunk/extensions/ConfigureWMF/ConfigureWMF.php (added) (history)
  • /trunk/extensions/ConfigureWMF/config-by-action.txt (added) (history)

Diff [purge]

Index: trunk/extensions/ConfigureWMF/ConfigureWMF.i18n.php
@@ -0,0 +1,123 @@
 2+<?php
 3+/**
 4+ * Internationalisation file for extension ConfigureWMF.
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$messages = array();
 11+
 12+$messages['en'] = array(
 13+ // General
 14+ 'configurewmf-page' => 'Change wikis configuration',
 15+ 'configurewmf-desc' => 'Allow stewards to change configuration of Wikimedia wikis',
 16+ 'configurewmf-nav-rootpage' => 'Change wikis configuration form',
 17+
 18+ // Step 1
 19+ 'configurewmf-selectsite' => 'Select a wiki to configure',
 20+ 'configurewmf-selectsite-help' => 'Here you specify which wiki or group of wikis confiuration you want to change.
 21+To change configuration of one wiki, enter its ID, like "enwiki", "dewikiversity", "incubatorwiki". To change configuration of all wikis, enter "default".
 22+To change configuration of some site family, enter its name, like "wikibooks". Note that "wikipedia" will be rewritten to "wiki", and "wiki" settings
 23+are applied to all Wikipedias and special projects which have "wiki" suffix (like "commonswiki").',
 24+ 'configurewmf-attentionnotice' => 'Attention! Read ALL insturctions carefully, since many settings have very important details and invalid input may cause unexpected consequences.',
 25+ 'configurewmf-invalidwiki' => 'Invalid wiki: $1',
 26+ 'configurewmf-site' => 'Site:',
 27+ 'configurewmf-select' => 'Select',
 28+
 29+ // Step 2
 30+ 'configurewmf-chooseconfig' => 'Choose setting to change',
 31+ 'configurewmf-chooseconfig-intro' => 'Via this interface you may change:',
 32+
 33+ // Step 3
 34+ 'configurewmf-change' => 'Set new site configuration',
 35+ 'configurewmf-seealso' => 'For more information see following pages on MediaWiki.org: $1',
 36+ 'configurewmf-reason' => 'Reason:',
 37+ 'configurewmf-submit' => 'Submit',
 38+ 'configurewmf-success' => 'Settings successfully changed',
 39+
 40+ // Configuration names and variables
 41+ 'configurewmf-cfgname-sitename' => 'Site name',
 42+ 'configurewmf-cfgname-metans' => 'Project and project talk namespaces',
 43+ 'configurewmf-cfgname-readonly' => 'Read only mode',
 44+ 'configurewmf-cfgname-patrol' => 'Patrolling settings',
 45+ 'configurewmf-cfgname-importsrc' => 'Import sources',
 46+ 'configurewmf-cfgname-enotif' => 'Email notification settings',
 47+ 'configurewmf-cfgname-blockcfg' => 'Blocking settings',
 48+ 'configurewmf-cfgname-logo' => 'Site logo',
 49+ 'configurewmf-cfgname-timezone' => 'Signature time zone',
 50+ 'configurewmf-cfgname-groupperms' => 'Group permissions',
 51+ 'configurewmf-cfgname-chgrpperms' => 'Group change permissions',
 52+ 'configurewmf-var-wgsitename' => 'Site name',
 53+ 'configurewmf-var-wgmetanamespace' => 'Project namespace name',
 54+ 'configurewmf-var-wgmetanamespacetalk' => 'Project talk namespace name',
 55+ 'configurewmf-var-wgreadonly' => 'Reason for read-only mode',
 56+ 'configurewmf-var-wgusenppatrol' => 'Use new pages patrolling',
 57+ 'configurewmf-var-wgusercpatrol' => 'Use recent changes patrolling',
 58+ 'configurewmf-var-wgimportsources' => 'Import sources',
 59+ 'configurewmf-var-wgenotifusertalk' => 'Email notification on user talk messages',
 60+ 'configurewmf-var-wgenotifwatchlist' => 'Email notification on watchlist changes',
 61+ 'configurewmf-var-wgblockallowsutedit' => 'User talk edits for blocked users',
 62+ 'configurewmf-var-wglocaltimezone' => 'Signature time zone',
 63+ 'configurewmf-var-wglogo' => 'Site logo',
 64+ 'configurewmf-var-wggrouppermissions' => 'Group permissions',
 65+ 'configurewmf-var-wgaddgroups' => 'May add groups',
 66+ 'configurewmf-var-wgremovegroups' => 'May remove groups',
 67+
 68+ // Helps for various configuration variables
 69+ 'configurewmf-help-sitename' => 'Here you can change site name displayed in page title, page taglines, etc.',
 70+ 'configurewmf-help-metans' => 'Here you can change project and project talk namespaces.
 71+Note that project talk will be formed by "{project namespace}_talk" principle. Namespace names should be entered with "_" instead of spaces.',
 72+ 'configurewmf-help-readonly' => 'Here you can switch read only mode for site. It is usually used for closing sites.
 73+To disable read-only mode, just type empty string.',
 74+ 'configurewmf-help-patrol' => 'Here you can switch recent changes and new pages patrolling features.',
 75+ 'configurewmf-help-importsrc' => 'Here you can change import sources. They are specified in the format of interwiki prefix:
 76+* If you want to enable import from Polish Wikipedia on Polish Wikibooks, you have to add "w" to the list
 77+* If you want to enable import from English Wikibooks on Polish Wikibooks, you have to add "en" to the list
 78+* If you want to enable import from English Wikipedia on Polish Wikibooks, you have to add "w:en" to the list
 79+* If you want to enable import from Incubator on Polish Wikibooks, you have to add "incubator" to the list
 80+Each import source should be placed on a seperate line.',
 81+ 'configurewmf-help-enotif' => 'Here you can enable or disable email notification. Note that it may serioursly affect performance
 82+and therefore must not be enabled on large wikis.',
 83+ 'configurewmf-help-blockcfg' => 'Here you can enable or disable user talk editing for blocked users.',
 84+ 'configurewmf-help-timezone' => 'Here you can change time zone that is used in signatures.
 85+Note that it is specified in POSIX-compatible format. For example:
 86+* Use "CET" for Central European Time (UTC+1)
 87+* Use "Europe/Moscow" for time zone used in Moscow (UTC+3)',
 88+ 'configurewmf-help-logo' => 'Here you can change site logo.',
 89+ 'configurewmf-help-groupperms' => 'Here you can add or remove specific permissions from a specific group or create a new group.
 90+Please note that groups may not be changed project-wide (e.g. for all Wikibooks), only for all projects (default) or a specific project',
 91+ 'configurewmf-help-chgrpperms' => 'Here you can specify whether some group may add or remove other users permissions.
 92+Note that "userrights" permission means user may add or remove all groups regardless of specified there.
 93+Also note, that several groups like checkuser or oversight may be only appointed by stewards, because they requires legal identity.',
 94+
 95+ // Variable-specific messages
 96+ 'configurewmf-stdlogo' => 'Standard logo (Wiki.png)',
 97+ 'configurewmf-otherlogo' => 'Other logo:',
 98+ 'configurewmf-grouptochange' => 'Choose a group to change:',
 99+ 'configurewmf-creategroup' => 'Create',
 100+ 'configurewmf-groupname' => 'Group name:',
 101+ 'configurewmf-changexistinggroups' => 'Change existing groups',
 102+ 'configurewmf-createnewgroup' => 'Create a new group',
 103+ 'configurewmf-permission' => '$1 ($2)',
 104+
 105+ // Rights
 106+ 'right-configure' => 'Change wiki configuration',
 107+
 108+ // Logging
 109+ 'configurewmf-log' => 'Configuration changes log',
 110+ 'configurewmf-log-header' => 'This log contains all configuration changes made by stewards',
 111+ 'configurewmf-log-sitename' => 'changed site name of $2 to $3',
 112+ 'configurewmf-log-metans' => 'changed meta namespace name of $2 to $3 (talk: $4)',
 113+ 'configurewmf-log-readonly' => 'changed read only mode for $2 to "$3"',
 114+ 'configurewmf-log-patrol' => 'changed patrolling settings for $2 (new pages: $3, recent changes: $4)',
 115+ 'configurewmf-log-importsrc' => 'changed import sources for $2 to $3',
 116+ 'configurewmf-log-enotif' => 'changed email notification settings for $2 (on user talk edits: $3; on watchlist edits: $4)',
 117+ 'configurewmf-log-blockcfg' => '$3 user talk editing for blocked users on $2',
 118+ 'configurewmf-log-timezone' => 'changed signature time zone for $2 to $3',
 119+ 'configurewmf-log-logo' => 'changed site logo for $2 to "$3"',
 120+ 'configurewmf-log-groupperms' => 'changed group permissions for $3 on $2: added $4; removed $5',
 121+ 'configurewmf-log-true' => 'enabled',
 122+ 'configurewmf-log-false' => 'disabled',
 123+ 'configurewmf-log-stdlogo' => 'standard logo (Wiki.png)',
 124+);
Property changes on: trunk/extensions/ConfigureWMF/ConfigureWMF.i18n.php
___________________________________________________________________
Added: svn:eol-style
1125 + native
Index: trunk/extensions/ConfigureWMF/ConfigureWMF.php
@@ -0,0 +1,74 @@
 2+<?php
 3+
 4+if ( !defined( 'MEDIAWIKI' ) ) {
 5+ exit(1);
 6+}
 7+
 8+$wgExtensionCredits['other'][] = array(
 9+ 'name' => 'Configure (WMF)',
 10+ 'author' => 'Victor Vasiliev',
 11+ 'version' => '0.1not-for-productional-use',
 12+ 'url' => 'http://www.mediawiki.org/wiki/Extension:Configure_(WMF)',
 13+ 'description' => 'Allows to change configuration of Wikimedia sites',
 14+ 'descriptionmsg' => 'configurewmf-desc',
 15+);
 16+
 17+//Name of the database to store configuration
 18+$wgConfigureDatabase = 'wikiconfig';
 19+
 20+//Mapping for extensions => variable to enable them
 21+$wgConfigureExtensions = array(
 22+ 'ProofreadPage' => 'wmgUseProofreadPage',
 23+ 'LabeledTranscludedSections' => 'wmgUseLST',
 24+ 'Quiz' => 'wmgUseQuiz',
 25+ 'DynamicPageList' => 'wmgUseDPL',
 26+ 'Nuke' => 'wmgUseSpecialNuke',
 27+);
 28+
 29+//Available $wgConf tags
 30+$wgConfigureAvailableTags = array( 'default' );
 31+
 32+$wgConfigureStdlogo = '$stdlogo';
 33+
 34+$wgExtensionMessagesFiles['ConfigureWMF'] = dirname( __FILE__ ) . '/ConfigureWMF.i18n.php';
 35+$wgAutoloadClasses['ConfigureWMF'] = dirname( __FILE__ ) . '/ConfigureWMF.class.php';
 36+$wgAutoloadClasses['SpecialConfigure'] = dirname( __FILE__ ) . '/ConfigureWMF.page.php';
 37+
 38+$wgSpecialPages['Configure'] = 'SpecialConfigure';
 39+
 40+$wgGroupPermissions['steward']['configure'] = true;
 41+$wgGroupPermissions['developer']['configure'] = true;
 42+
 43+$wgAvailableRights[] = 'configure';
 44+
 45+$wgLogTypes[] = 'config';
 46+$wgLogNames['config'] = 'configurewmf-log';
 47+$wgLogHeareds['config'] = 'configurewmf-log-header';
 48+
 49+foreach( ConfigureWMF::$settings as $name => $value ) {
 50+ $logname = $name;
 51+ if( isset( $value['__log__'] ) )
 52+ $logname = $value['__log__'];
 53+ $wgLogActions["config/{$logname}"] = "configurewmf-log-{$name}";
 54+}
 55+
 56+function efLoadConfiguration() {
 57+ global $wgConfigure;
 58+ if( !isset( $wgConfigure ) ) {
 59+ $wgConfigure = new ConfigureWMF();
 60+ }
 61+}
 62+
 63+function efLoadDefaultSettings() {
 64+ global $wgGroupPermissions, $wgDefaultGroupPermissions;
 65+ if( !isset( $wgDefaultGroupPermissions ) ) {
 66+ $wgDefaultGroupPermissions = $wgGroupPermissions;
 67+ }
 68+}
 69+
 70+// To be applied on $wgConf->settings
 71+function efApplyConfiguration( &$settings ) {
 72+ global $wgConfigure;
 73+ efLoadConfiguration();
 74+ $wgConfigure->applyConfiguration( $settings );
 75+}
Property changes on: trunk/extensions/ConfigureWMF/ConfigureWMF.php
___________________________________________________________________
Added: svn:eol-style
176 + native
Index: trunk/extensions/ConfigureWMF/ConfigureWMF.class.php
@@ -0,0 +1,147 @@
 2+<?php
 3+
 4+class ConfigureWMF {
 5+ static $settings = array(
 6+ 'sitename' => array(
 7+ 'wgSitename' => 'string',
 8+ ),
 9+ 'metans' => array(
 10+ 'wgMetaNamespace' => 'string',
 11+ 'wgMetaNamespaceTalk' => 'string',
 12+ ),
 13+ 'readonly' => array(
 14+ 'wgReadOnly' => 'string',
 15+ ),
 16+ 'patrol' => array(
 17+ 'wgUseNPPatrol' => 'bool',
 18+ 'wgUseRCPatrol' => 'bool',
 19+ ),
 20+ 'importsrc' => array(
 21+ 'wgImportSources' => 'stringarray',
 22+ ),
 23+ 'enotif' => array(
 24+ 'wgEnotifUserTalk' => 'bool',
 25+ 'wgEnotifWatchlist' => 'bool',
 26+ ),
 27+ 'blockcfg' => array(
 28+ 'wgBlockAllowsUTEdit' => 'bool',
 29+ ),
 30+ 'timezone' => array(
 31+ 'wgLocaltimezone' => 'string',
 32+ ),
 33+ 'logo' => array(
 34+ 'wgLogo' => 'logo',
 35+ ),
 36+// 'groupperms' => array(
 37+// 'wgGroupPermissions' => 'groupperms',
 38+// ),
 39+// 'chgrpperms' => array(
 40+// 'wgAddGroups' => 'grouplist',
 41+// 'wgRemoveGroups' => 'grouplist',
 42+// ),
 43+ );
 44+
 45+ static $mergable = array( 'wgGroupPermissions', 'wgAddGroups', 'wgRemoveGroups' );
 46+
 47+ var $overrides;
 48+
 49+ public function __construct() {
 50+ global $IP;
 51+
 52+ // No Setup.php yet. Initialise everything by ourselves
 53+ require_once( $IP.'/includes/ObjectCache.php' );
 54+ $wgMemc = wfGetMainCache();
 55+
 56+ // Caching not yet working
 57+ //$cached = $wgMemc->get( 'configurewmf:data' );
 58+ if( $cached ) {
 59+ $this->overrides = $cached;
 60+ return;
 61+ }
 62+
 63+ $dbr = self::getSlaveDB();
 64+ $r = $dbr->select( 'config_overrides', array( 'cfg_target', 'cfg_value' ), null, __METHOD__ );
 65+ $overrides = array();
 66+ while( $row = $dbr->fetchObject( $r ) ) {
 67+ $overrides[] = array( 'target' => $row->cfg_target, 'value' => unserialize( $row->cfg_value ) );
 68+ }
 69+ $wgMemc->set( 'configurewmf:data', $overrides );
 70+ $this->overrides = $overrides;
 71+ }
 72+
 73+ public static function getSlaveDB() {
 74+ global $wgConfigureDatabase;
 75+ return wfGetLB( $wgConfigureDatabase )->getConnection( DB_SLAVE, 'wikiconfig',
 76+ $wgConfigureDatabase );
 77+ }
 78+
 79+ public static function getMasterDB() {
 80+ global $wgConfigureDatabase;
 81+ return wfGetLB( $wgConfigureDatabase )->getConnection( DB_MASTER, 'wikiconfig',
 82+ $wgConfigureDatabase );
 83+ }
 84+
 85+ public function getDefaultSetting( $setting ) {
 86+ global $IP, $wgDefaultGroupPermissions;
 87+ // $wgGroupPermissions may be modified by extensions, so we get it in another way
 88+ if( $setting == 'wgGroupPermissions' )
 89+ return $wgDefaultGroupPermissions;
 90+ require( "{$IP}/includes/DefaultSettings.php" );
 91+ return @$$setting;
 92+ }
 93+
 94+ static function isWiki( $name ) {
 95+ global $wgLocalDatabases;
 96+ return in_array( $name, $wgLocalDatabases );
 97+ }
 98+
 99+ static function isValidTarget( $target ) {
 100+ global $wgConf, $wgConfigureAvailableTags;
 101+ return in_array( $target, $wgConf->wikis ) ||
 102+ in_array( $target, $wgConf->suffixes ) ||
 103+ in_array( $target, $wgConfigureAvailableTags );
 104+ }
 105+
 106+ public function getSetting( $target, $setting ) {
 107+ global $wgConf;
 108+ $val = null;
 109+ if( self::isWiki( $target ) ) {
 110+ list( $site, $lang ) = $wgConf->siteFromDB( $target );
 111+ $val = $wgConf->get( $setting, $target, $site,
 112+ array( 'site' => $site, 'lang' => $lang )
 113+ );
 114+ } elseif( isset( $wgConf->settings[$setting][$target] ) ) {
 115+ $val = $wgConf->settings[$setting][$target];
 116+ } elseif( isset( $wgConf->settings[$setting]['default'] ) ) {
 117+ $val = $wgConf->settings[$setting]['default'];
 118+ }
 119+ if( $val !== null )
 120+ return $val;
 121+ else
 122+ return $this->getDefaultSetting( $setting );
 123+ }
 124+
 125+ public function getGroupPermissions( $target ) {
 126+ return $this->getSetting( $target, 'wgGroupPermissions' );
 127+ }
 128+
 129+ public function getOverride( $name, $target ) {
 130+ $dbr = self::getSlaveDB();
 131+ $row = $dbr->selectRow( 'config_overrides', '*', array( 'cfg_name' => $name, 'cfg_target' => $target ), __METHOD__ );
 132+ if( $row )
 133+ $row->cfg_value = unserialize( $row->cfg_value );
 134+ return $row;
 135+ }
 136+
 137+ public function applyConfiguration( &$settings ) {
 138+ foreach( $this->overrides as $override ) {
 139+ foreach( $override['value'] as $varname => $val ) {
 140+ if( in_array( $varname, self::$mergable ) ) {
 141+ //stub
 142+ } else {
 143+ $settings[$varname][$override['target']] = $val;
 144+ }
 145+ }
 146+ }
 147+ }
 148+}
Property changes on: trunk/extensions/ConfigureWMF/ConfigureWMF.class.php
___________________________________________________________________
Added: svn:eol-style
1149 + native
Index: trunk/extensions/ConfigureWMF/config-by-action.txt
@@ -0,0 +1,54 @@
 2+* Change common site settings [+]
 3+** $wgSitename - string [+]
 4+** $wgLocaltimezone - string, weird format (e.g. "Europe/Berlin") [+]
 5+** $wgReadOnly - string [+]
 6+** $wgUseRCPatrol - string [+]
 7+** $wgMetaNamespace - string [+]
 8+** $wgMetaNamespaceTalk - string [+]
 9+** $wgCapitalLinks - bool
 10+** $wgLanguageCode - string
 11+** $wgLogo - string (URL) [+]
 12+
 13+* Change import sources [+]
 14+** $wgImportSources - array( string (interwiki prefix ) ) [+]
 15+
 16+* Change upload-related settings
 17+** $wgEnableUploads - bool
 18+** $wgUploadNavigationUrl - string (URL)* Change grammar forms
 19+** $wgGrammarForms - array( string /*lang*/ => array( string /*form*/ => array( string => string ) ) )
 20+
 21+* Change site namespaces (except site namespace name)
 22+** $wgNamespaceAliases - array( string=> nsid )
 23+** $wgNamespacesWithSubpages - array( nsid => bool )
 24+** $wgExtraNamespaces - array( nsid => name )
 25+** $wgNamespacesToBeSearchedDefault - array( nsid => bool )
 26+** $wgImportTargetNamespace - nsid
 27+** $wgContentNamespaces - array( nsid )
 28+** $wgNamespaceProtection - array( nsid => array( string ) )
 29+
 30+* Group permissions
 31+** $wgGroupPermissions - array( string => array( string => bool ) )
 32+** $wgAddGroups, $wgRemoveGroups - array( string => array( string ) )
 33+** $wgAutoConfirmAge - int
 34+** $wgAutoConfirmCount - int
 35+** $wgWhitelistRead - array( string )
 36+
 37+* Change ENotif settings
 38+** $wgEnotifUserTalk - bool [+]
 39+** $wgEnotifWatchlist - bool [+]
 40+
 41+* Change misc settings
 42+** $wgBlockAllowsUTEdit - bool [+]
 43+** $wgRC2UDPPrefix - string
 44+** $wgLoginLanguageSelector - bool
 45+** $wgSpamRegex - string [deprecated by AbuseFilter]
 46+
 47+* Change installed extensions
 48+** $wmgUseDPL
 49+** $wmgUseSpecialNuke
 50+** $wgUseLST
 51+** $wmgUseQuiz
 52+
 53+* To implement once (too complicated):
 54+** $wgAutopromote - array( *autopromote conditions* )
 55+** $wgImplicitGroups - array( string )
\ No newline at end of file
Property changes on: trunk/extensions/ConfigureWMF/config-by-action.txt
___________________________________________________________________
Added: svn:eol-style
156 + native
Index: trunk/extensions/ConfigureWMF/ConfigureWMF.page.php
@@ -0,0 +1,344 @@
 2+<?php
 3+
 4+class SpecialConfigure extends SpecialPage {
 5+ function __construct() {
 6+ wfLoadExtensionMessages( 'ConfigureWMF' );
 7+ parent::__construct( 'Configure', 'configure' );
 8+ }
 9+
 10+ function getDescription() {
 11+ return wfMsg( 'configurewmf-page' );
 12+ }
 13+
 14+ function execute( $subpage ) {
 15+ global $wgRequest, $wgUser;
 16+ $this->setHeaders();
 17+
 18+ if( !( $wiki = $wgRequest->getVal( 'wiki' ) ) || !ConfigureWMF::isValidTarget( $wiki ) ) {
 19+ $this->showSiteSelectForm( $wiki );
 20+ return;
 21+ }
 22+ if( $wiki == 'wikipedia' ) $wiki = 'wiki';
 23+ if( !( $setting = $wgRequest->getVal( 'config' ) ) || !isset( ConfigureWMF::$settings[$setting] ) ) {
 24+ $this->showSettingsChoiceForm( $wiki );
 25+ return;
 26+ }
 27+ if( !( $et = $wgRequest->getVal( 'edittoken' ) ) || !$wgUser->matchEditToken( $et ) ) {
 28+ $this->handleChangeSettingsForm( $wiki, $setting );
 29+ return;
 30+ }
 31+ list( $values, $logs, $error ) = $this->formatValues( $wiki, $setting );
 32+ if( $error ) {
 33+ $this->handleChangeSettingsForm( $wiki, $setting );
 34+ return;
 35+ }
 36+
 37+ $dbw = ConfigureWMF::getMasterDB();
 38+ $dbw->delete( 'config_overrides',
 39+ array(
 40+ 'cfg_target' => $wiki,
 41+ 'cfg_name' => $setting,
 42+ ),
 43+ __METHOD__
 44+ );
 45+ $dbw->insert( 'config_overrides',
 46+ array(
 47+ 'cfg_target' => $wiki,
 48+ 'cfg_name' => $setting,
 49+ 'cfg_value' => serialize( $values ),
 50+ 'cfg_user_text' => $wgUser->getName(),
 51+ 'cfg_timestamp' => $dbw->timestamp(),
 52+ ),
 53+ __METHOD__
 54+ );
 55+ $this->logAction( $setting, $wgRequest->getVal( 'wpReason' ), $wiki, $logs );
 56+ $this->showSettingsChoiceForm( $wiki, true );
 57+ }
 58+
 59+ function showSiteSelectForm( $invalid = false ) {
 60+ global $wgOut, $wgScript, $wgTitle;
 61+ $legend = wfMsgHtml( 'configurewmf-selectsite' );
 62+ $wgOut->addHTML( "<fieldset><legend>{$legend}</legend>" );
 63+ if( $invalid ) {
 64+ $wgOut->addHTML( '<p><strong class="error">' . htmlspecialchars( wfMsg( 'configurewmf-invalidwiki', $invalid ) ) . '</strong></p>' );
 65+ }
 66+ $wgOut->addHTML( '<strong id="cfgwmf-attention" style="color: red; font-size: 12pt">' . wfMsgHTML( 'configurewmf-attentionnotice' ) . '</strong>' );
 67+ $wgOut->addWikiMsg( 'configurewmf-selectsite-help' );
 68+ $wgOut->addHTML( "<form action='{$wgScript}' method='get'>" );
 69+ $wgOut->addHTML( '<p>'. Xml::hidden( 'title', $wgTitle->getFullText() ) . '</p><table><tr>' );
 70+ $wgOut->addHTML( '<td class="mw-label">' . Xml::label( wfMsg( 'configurewmf-site' ), 'cfg-site' ) . '</td>' );
 71+ $wgOut->addHTML( '<td class="mw-input">' . Xml::input( 'wiki', false, false, array( 'id' => 'cfg-site' ) ) . '</td>' );
 72+ $wgOut->addHTML( '</tr><tr><td></td><td class="mw-input">' . Xml::submitButton( wfMsg( 'configurewmf-select' ) ) . '</td>' );
 73+ $wgOut->addHTML( "</tr></table></form></fieldset>" );
 74+ }
 75+
 76+ function showSettingsChoiceForm( $wiki, $success = false ) {
 77+ global $wgOut, $wgTitle;
 78+ $this->addNav( 1, $wiki );
 79+ $legend = wfMsgHtml( 'configurewmf-chooseconfig' );
 80+ $wgOut->addHTML( "<fieldset><legend>{$legend}</legend>" );
 81+ if( $success ) {
 82+ $wgOut->addHTML( '<p><strong class="success">' . wfMsgHtml( 'configurewmf-success' ) . '</strong></p>' );
 83+ }
 84+ $wgOut->addWikiMsg( 'configurewmf-chooseconfig-intro' );
 85+ $wgOut->addHTML( '<ul>' );
 86+ foreach( ConfigureWMF::$settings as $name => $value ) {
 87+ $descr = wfMsgHtml( "configurewmf-cfgname-{$name}" );
 88+ $url = htmlspecialchars( $wgTitle->getLocalURL( "wiki={$wiki}&config={$name}" ) );
 89+ $wgOut->addHTML( "<li><a href='{$url}'>{$descr}</a></li>" );
 90+ }
 91+ $wgOut->addHTML( '</ul></fieldset>' );
 92+ }
 93+
 94+ function handleChangeSettingsForm( $wiki, $config ) {
 95+ global $wgRequest;
 96+ if( ( $config == 'groupperms' || $config == 'chgrpperms' ) && !$wgRequest->getVal( 'group' ) ) {
 97+ $this->showGroupsList( $wiki, $config );
 98+ } else {
 99+ $this->showChangeSettingsForm( $wiki, $config );
 100+ }
 101+ }
 102+
 103+ function showGroupsList( $wiki, $config ) {
 104+ global $wgOut, $wgConfigure, $wgRequest, $wgScript;
 105+
 106+ $this->addNav( 2, $wiki, $config );
 107+ $changeExisting = wfMsgHtml( 'configurewmf-changexistinggroups' );
 108+ $wgOut->addHTML( "<fieldset><legend>{$changeExisting}</legend>" );
 109+ $wgOut->addWikiMsg( 'configurewmf-grouptochange' );
 110+ $wgOut->addHTML( "<ul>\n" );
 111+ $groups = $wgConfigure->getGroupPermissions( $wiki );
 112+ foreach( array_keys( $groups ) as $group ) {
 113+ $url = htmlspecialchars( $wgRequest->appendQueryValue( 'group', $group ) );
 114+ $wgOut->addHTML( "<li><a href=\"{$url}\">{$group}</a></li>\n" );
 115+ }
 116+ $wgOut->addHTML( "</ul></fieldset>\n" );
 117+
 118+ $newLegend = wfMsgHtml( 'configurewmf-createnewgroup' );
 119+ $wgOut->addHTML( "<fieldset><legend>{$newLegend}</legend><form method='get' action='{$wgScript}'>" );
 120+ foreach( $_GET as $var => $val ) $wgOut->addHTML( Xml::hidden( $var, $val ) );
 121+ $wgOut->addHTML( Xml::buildForm( array( 'configurewmf-groupname' => Xml::input( 'group' ) ), 'configurewmf-creategroup' ) );
 122+ $wgOut->addHTML( "</form></fieldset>\n" );
 123+ }
 124+
 125+ function showChangeSettingsForm( $wiki, $config ) {
 126+ global $wgOut, $wgTitle, $wgScript, $wgUser, $wgRequest;
 127+ $legend = wfMsgHtml( 'configurewmf-change' );
 128+ $submit = wfMsg( 'configurewmf-submit' );
 129+ $reason = wfMsg( 'configurewmf-reason' );
 130+ $reasonlabel = Xml::label( $reason, 'cfg-reason' );
 131+ $reasoninput = Xml::input( 'wpReason', false, false, array( 'id' => 'cfg-reason' ) );
 132+
 133+ $vars = array();
 134+ foreach( array_keys( ConfigureWMF::$settings[$config] ) as $var )
 135+ if( substr( $var, 0, 2 ) == 'wg' )
 136+ $vars[] = "<a href='http://mediawiki.org/wiki/Manual:\${$var}'>\${$var}</a>";
 137+ $vars = implode( ', ', $vars );
 138+
 139+ if( in_array( $config, array( 'groupperms', 'chgrpperms' ) ) )
 140+ $this->addNav( 3, $wiki, $config, $wgRequest->getVal( 'group' ) );
 141+ else
 142+ $this->addNav( 2, $wiki, $config );
 143+ $wgOut->addHTML( "<fieldset><legend>{$legend}</legend>" );
 144+ $wgOut->addWikiMsg( "configurewmf-help-{$config}" );
 145+ $wgOut->addHTML( wfMsgWikiHtml( 'configurewmf-seealso', $vars ) );
 146+ $wgOut->addHTML( "<hr/>" );
 147+ $wgOut->addHTML( "<form action='{$wgScript}' method='post'><p>" );
 148+ $wgOut->addHTML( Xml::hidden( 'title', $wgTitle->getFullText() ) );
 149+ $wgOut->addHTML( Xml::hidden( 'wiki', $wiki ) );
 150+ $wgOut->addHTML( Xml::hidden( 'config', $config ) );
 151+ $wgOut->addHTML( Xml::hidden( 'edittoken', $wgUser->editToken() ) );
 152+ $wgOut->addHTML( "</p><table><tbody>" );
 153+ foreach( ConfigureWMF::$settings[$config] as $key => $value ) {
 154+ if( substr( $key, 0, 2 ) == '__' )
 155+ continue;
 156+ $wgOut->addHTML( $this->formatConfigInput( $key, $value, $wiki ) );
 157+ }
 158+ $wgOut->addHTML( "<tr><td class='mw-label'>{$reasonlabel}</td><td class='mw-input'>{$reasoninput}</td></tr>" );
 159+ $wgOut->addHTML( '<tr><td></td><td class="mw-input">' .
 160+ Xml::submitButton( $submit ) . '</td></tr>' );
 161+ $wgOut->addHTML( "</tbody></table></form></fieldset>" );
 162+ }
 163+
 164+ function formatConfigInput( $var, $type, $wiki = '' ) {
 165+ global $wgConfigure, $wgRequest;
 166+ $val = $wgConfigure->getSetting( $wiki, $var );
 167+ $descr = wfMsg( 'configurewmf-var-' . strtolower( $var ) );
 168+ $descrlabel = Xml::label( $descr, $var );
 169+ $r = "<tr><td class='mw-label'>{$descrlabel}:</td>\n\n<td class='mw-input'>";
 170+ switch( $type ) {
 171+ case 'string':
 172+ $r .= Xml::input( $var, false, $val );
 173+ break;
 174+ case 'bool':
 175+ $r .= Xml::check( $var, $val );
 176+ break;
 177+ case 'stringarray':
 178+ $val = $val ? implode( "\n", $val ) : '';
 179+ $r .= Xml::textarea( $var, $val );
 180+ break;
 181+ case 'logo':
 182+ global $wgConfigureStdlogo;
 183+ $isstd = $val == $wgConfigureStdlogo;
 184+ $r .= '<div>' . Xml::radioLabel( wfMsgHtml( 'configurewmf-stdlogo' ),
 185+ $var, 'stdlogo', 'wgLogoStdlogo', $isstd ) . '</div>';
 186+ $r .= Xml::radioLabel( wfMsgHtml( 'configurewmf-otherlogo' ),
 187+ $var, 'other', 'wgLogoOther', !$isstd ) . '&nbsp;' .
 188+ Xml::input( "{$var}Other", false, $isstd ? '' : $val ) . '</div>';
 189+ break;
 190+ case 'groupperms':
 191+ $groups = $wgConfigure->getGroupPermissions( $wiki );
 192+ $group = $wgRequest->getVal( 'group' );
 193+ $perms = isset( $groups[$group] ) ? $groups[$group] : array();
 194+
 195+ $rights = User::getAllRights();
 196+
 197+ sort( $rights );
 198+
 199+ $checkboxes = array();
 200+
 201+ foreach( $rights as $right ) {
 202+ $label = wfMsgExt( 'configurewmf-permission', array( 'parseinline' ),
 203+ User::getRightDescription( $right ), $right );
 204+ $checkboxes[] = Xml::checkLabel(
 205+ $label, "{$var}-{$right}", "{$var}-{$right}", @$perms[$right]
 206+ );
 207+ }
 208+
 209+ $firstCol = round( count( $checkboxes ) / 2 );
 210+
 211+ $checkboxes1 = array_slice( $checkboxes, 0, $firstCol );
 212+ $checkboxes2 = array_slice( $checkboxes, $firstCol );
 213+
 214+ $r .= '<table><tbody><tr><td><ul><li>' . implode( '</li><li>', $checkboxes1 ) .
 215+ '</li></ul></td><td><ul><li>' . implode( '</li><li>', $checkboxes2 ) .
 216+ '</li></ul></td></tr></tbody></table>';
 217+ $r .= Xml::hidden( 'group', $group );
 218+ break;
 219+ case 'grouplist':
 220+ $targetgroup = $wgRequest->getVal( 'group' );
 221+ $r .= '<ul>';
 222+ foreach( array_keys( $wgConfigure->getGroupPermissions( $wiki ) ) as $group ) {
 223+ if( in_array( $group, $wgConfigure->getSetting( $wiki, 'wgImplicitGroups' ) ) )
 224+ continue;
 225+ $checked = isset( $val[$targetgroup] ) ? in_array( $group, $val[$targetgroup] ) : false;
 226+ $checkbox = Xml::checkLabel( User::getGroupName( $group ),
 227+ "{$var}-{$group}", "{$var}-{$group}", $checked );
 228+ $r .= "<li>{$checkbox}</li>\n";
 229+ }
 230+ $r .= '</ul>';
 231+ break;;
 232+ }
 233+ return $r . '</td></tr>';
 234+ }
 235+
 236+ function formatValues( $wiki, $config ) {
 237+ global $wgRequest, $wgConfigure;
 238+ $values = array();
 239+ $logs = array();
 240+ $error = false;
 241+ foreach( ConfigureWMF::$settings[$config] as $name => $value ) {
 242+ switch( $value ) {
 243+ case 'string':
 244+ $values[$name] = $wgRequest->getVal( $name );
 245+ $logs[] = $wgRequest->getVal( $name );
 246+ break;
 247+ case 'bool':
 248+ $values[$name] = $wgRequest->getCheck( $name );
 249+ $logs[] = wfMsgForContent( 'configurewmf-log-' . ($values[$name] ? 'true' : 'false') );
 250+ break;
 251+ case 'stringarray':
 252+ $values[$name] = array_unique( preg_split( '/\n/', $wgRequest->getVal( $name ), -1, PREG_SPLIT_NO_EMPTY ) );
 253+ $logs[] = $values[$name] ? implode( ', ', $values[$name] ) : wfMsgForContent( 'rightsnone' );
 254+ break;
 255+ case 'logo':
 256+ global $wgConfigureStdlogo;
 257+ $input = $wgRequest->getVal( $name );
 258+ $values[$name] = ($input == 'stdlogo' ? $wgConfigureStdlogo : $wgRequest->getVal( "{$name}Other" ));
 259+ $logs[] = ($input == 'stdlogo' ? wfMsgForContent( 'configurewmf-log-stdlogo' ) : $wgRequest->getVal( "{$name}Other" ));
 260+ break;
 261+ case 'groupperms':
 262+ $groupperms = $wgConfigure->getGroupPermissions( $wiki );
 263+ $group = $wgRequest->getVal( 'group' );
 264+ $perms = isset( $groupperms[$group] ) ? $groupperms[$group] : array();
 265+ $rights = User::getAllRights();
 266+ $changes = array();
 267+ foreach( $rights as $right ) {
 268+ if( ((bool)@$perms[$right]) != $wgRequest->getCheck( "{$name}-{$right}" ) ) {
 269+ $changes[$right] = $wgRequest->getCheck( "{$name}-{$right}" );
 270+ }
 271+ }
 272+
 273+ if( $changes ) {
 274+ $override = $wgConfigure->getOverride( $config, $wiki );
 275+ $override = $override && isset( $override->cfg_value['wgGroupPermissions'] ) ? $override->cfg_value['wgGroupPermissions'] : array();
 276+ if( !isset( $override[$group] ) )
 277+ $override[$group] = array();
 278+ $override[$group] = $changes + $override[$group];
 279+ $values[$name] = $override;
 280+ }
 281+
 282+ $added = $removed = array();
 283+ foreach( $changes as $perm => $value ) {
 284+ if( $value )
 285+ $added[] = $perm;
 286+ else
 287+ $removed[] = $perm;
 288+ }
 289+ $logs[] = $group;
 290+ $logs[] = $added ? implode( ', ', $added ) : wfMsgForContent( 'rightsnone' );
 291+ $logs[] = $removed ? implode( ', ', $removed ) : wfMsgForContent( 'rightsnone' );
 292+ break;
 293+ case 'grouplist':
 294+ $targetgroup = $wgRequest->getVal( 'group' );
 295+ $oldval = $wgConfigure->getSetting( $wiki, $name );
 296+ $old = isset( $oldval[$targetgroup] ) ? $oldval[$targetgroup] : array();
 297+ $override = $wgConfigure->getOverride( $config, $wiki );
 298+ $override = $override && isset( $override->cfg_value[$name] ) ? $override->cfg_value[$name] : array();
 299+ $new = array();
 300+ foreach( array_keys( $wgConfigure->getGroupPermissions( $wiki ) ) as $group ) {
 301+ if( $wgRequest->getCheck( "{$name}-{$group}" ) )
 302+ $new[] = $group;
 303+ }
 304+ var_dump( $old, $new, $override );
 305+ if( array_diff( $old, $new ) ) {
 306+ $override[$targetgroup] = $new;
 307+ $values[$name] = $new;
 308+ }
 309+ $logs[] = $new ? implode( ', ', $new ) : wfMsgForContent( 'rightsnone' );
 310+ break;
 311+ }
 312+ }
 313+ return array( $values, $logs, $error );
 314+ }
 315+
 316+ function addNav( $levels = 0, $wiki = '', $config = '', $group = '' ) {
 317+ global $wgUser, $wgTitle, $wgOut;
 318+ $skin = $wgUser->getSkin();
 319+ $bits = array();
 320+ $bits[] = array( '', wfMsg( 'configurewmf-nav-rootpage' ) );
 321+ if( $levels >= 1 ) {
 322+ $bits[] = array( "wiki={$wiki}", $wiki );
 323+ }
 324+ if( $levels >= 2 ) {
 325+ $bits[] = array( "wiki={$wiki}&config={$config}", wfMsg( "configurewmf-cfgname-{$config}" ) );
 326+ }
 327+ if( $levels >= 3 ) {
 328+ $bits[] = array( "wiki={$wiki}&config={$config}&group={$group}", $group );
 329+ }
 330+ if( $bits ) {
 331+ for( $i = 0; $i < count( $bits ); $i++ )
 332+ if( $i == count( $bits ) - 1 )
 333+ $bits[$i] = $bits[$i][1];
 334+ else
 335+ $bits[$i] = $skin->makeLinkObj( $wgTitle, $bits[$i][1], $bits[$i][0] );
 336+ $wgOut->setSubtitle( '<div id="contentSub"><span class="subpages">&lt; ' .
 337+ implode( '&nbsp;|&nbsp;', $bits ) . '</span></div>' );
 338+ }
 339+ }
 340+
 341+ function logAction( $action, $reason, $wiki, $params ) {
 342+ $log = new LogPage( 'config' );
 343+ $log->addEntry( $action, Title::newFromText( "Special:Configure" ), $reason, array_merge( array( $wiki ), $params ) );
 344+ }
 345+}
Property changes on: trunk/extensions/ConfigureWMF/ConfigureWMF.page.php
___________________________________________________________________
Added: svn:eol-style
1346 + native

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r39577Allowed array-merging for site config. You can now set a setting for '+whatev...werdna09:26, 18 August 2008

Status & tagging log