r49405 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r49404‎ | r49405 | r49406 >
Date:16:42, 11 April 2009
Author:ialex
Status:deferred
Tags:
Comment:
Bug fixes for the Farmer extension:
* Add local groups when creating a new wiki rather than using "[farmer][$wiki][admin]" if not using a shared user_groups table
* Use MW_DB and MW_PREFIX in command line mode to get the wiki to use if the identifier function could not find the wiki
Modified paths:
  • /trunk/extensions/Farmer/MediaWikiFarmer.php (modified) (history)
  • /trunk/extensions/Farmer/MediaWikiFarmer_Wiki.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Farmer/MediaWikiFarmer.php
@@ -149,22 +149,33 @@
150150 * This function does all the fun stuff
151151 */
152152 public function run() {
 153+ global $wgCommandLineMode;
 154+
153155 if( !$this->_defaultWiki ) {
154156 throw new MWException( 'Default wiki must be set' );
155157 }
156158
157 - // first we try to find the wiki name that was accessed by calling the appropriate function
 159+ // first we try to find the wiki name that was accessed by calling the
 160+ // appropriate function
158161 if( is_callable( $this->_matchFunction ) ){
159162 $wiki = call_user_func( $this->_matchFunction, $this );
160163
161164 // if our function coudln't identify the wiki from the environment
162165 if ( !$wiki ) {
163 - $wiki = $this->_defaultWiki;
 166+ // if the admin passed the --wiki option in command line mode
 167+ // then use it to get the wiki
 168+ if( $wgCommandLineMode && defined( 'MW_DB' ) ) {
 169+ $wiki = MW_DB;
 170+ if( defined( 'MW_PREFIX' ) && MW_PREFIX )
 171+ $wiki .= '-' . MW_PREFIX;
 172+ } else {
 173+ $wiki = $this->_defaultWiki;
 174+ }
164175 }
165176
166177 // sanitize wiki name
167 - // we force to lcase b/c having all types of case combos would just be confusing to end-user
168 - // besides, hostnames are not case sensitive
 178+ // we force to lcase b/c having all types of case combos would just
 179+ // be confusing to end-user besides, hostnames are not case sensitive
169180 $wiki = strtolower( preg_replace( '/[^[:alnum:_\-]]/', '', $wiki ) );
170181
171182 // now we have a valid wiki name
Index: trunk/extensions/Farmer/MediaWikiFarmer_Wiki.php
@@ -277,12 +277,14 @@
278278 $wgGroupPermissions['sysop']['read'] = true;
279279
280280 //assign permissions to administrators of this wiki
281 - $group = '[farmer]['.$this->_name.'][admin]';
 281+ if( $farmer->sharingGroups() ){
 282+ $group = '[farmer]['.$this->_name.'][admin]';
282283
283 - $grantToWikiAdmins = array( 'read', 'edit' );
 284+ $grantToWikiAdmins = array( 'read', 'edit' );
284285
285 - foreach ( $grantToWikiAdmins as $v ) {
286 - $wgGroupPermissions[$group][$v] = true;
 286+ foreach ( $grantToWikiAdmins as $v ) {
 287+ $wgGroupPermissions[$group][$v] = true;
 288+ }
287289 }
288290
289291 if( $callback = $farmer->initCallback() ) {
@@ -504,11 +506,22 @@
505507 }
506508
507509 protected function _populateUserGroups() {
508 - $db = $this->getDatabase();
509510 if ( $this->creator ) {
510 - $user = User::newFromname( $this->creator );
511 - $group = '[farmer]['.$this->name.'][admin]';
512 - $user->addGroup( $group );
 511+ if( MediaWikiFarmer::getInstance()->sharingGroups() ){
 512+ $user = User::newFromname( $this->creator );
 513+ $group = '[farmer]['.$this->name.'][admin]';
 514+ $user->addGroup( $group );
 515+ } else {
 516+ $userId = User::idFromName( $this->creator );
 517+ if( $userId ) {
 518+ $insert = array(
 519+ array( 'ug_user' => $userId, 'ug_group' => 'sysop' ),
 520+ array( 'ug_user' => $userId, 'ug_group' => 'bureaucrat' ),
 521+ );
 522+ $db = $this->getDatabase();
 523+ $db->insert( 'user_groups', $insert, __METHOD__ );
 524+ }
 525+ }
513526 }
514527 }
515528
@@ -527,7 +540,7 @@
528541 $prefix = $db->getProperty( 'mTablePrefix' );
529542
530543 while( $row = $result->fetchRow() ) {
531 - if( strpos( $row[0], $prefix ) === 0 ) {
 544+ if( $prefix == '' || strpos( $row[0], $prefix ) === 0 ) {
532545 $query = 'DROP TABLE `'. $row[0] . '`';
533546 $db->query( $query, __METHOD__ );
534547 }
@@ -535,11 +548,12 @@
536549 }
537550
538551 protected function _deleteWikiGroups() {
539 - $db = $this->getDatabase();
540 - $query = 'DELETE FROM ' . $db->tableName( 'user_groups' ) . ' WHERE ug_group LIKE ';
541 - $query .= '\'[farmer]['.$this->_name.']%\'';
542 -
543 - $db->query( $query, __METHOD__ );
 552+ if( MediaWikiFarmer::getInstance()->sharingGroups() ){
 553+ $db = $this->getDatabase();
 554+ $query = 'DELETE FROM ' . $db->tableName( 'user_groups' ) . ' WHERE ug_group LIKE ';
 555+ $query .= '\'[farmer]['.$this->_name.']%\'';
 556+ $db->query( $query, __METHOD__ );
 557+ }
544558 }
545559
546560 protected function _deleteInterwiki() {

Status & tagging log