Index: trunk/extensions/Farmer/Farmer.i18n.php |
— | — | @@ -137,6 +137,8 @@ |
138 | 138 | 'farmer-log-header' => 'This is a log of changes made to the wiki farm.', |
139 | 139 | 'farmer-log-create' => 'created the wiki "$2"', |
140 | 140 | 'farmer-log-delete' => 'deleted the wiki "$2"', |
| 141 | + 'right-farmeradmin' => 'Manage the wiki farm', |
| 142 | + 'right-createwiki' => 'Create wikis in the wiki farm', |
141 | 143 | ); |
142 | 144 | |
143 | 145 | /** Message documentation (Message documentation) |
Index: trunk/extensions/Farmer/Farmer.php |
— | — | @@ -19,17 +19,17 @@ |
20 | 20 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Farmer', |
21 | 21 | 'description' => 'Manage a MediaWiki farm', |
22 | 22 | 'descriptionmsg' => 'farmer-desc', |
23 | | - 'version' => '0.0.6', |
| 23 | + 'version' => '0.0.7', |
24 | 24 | ); |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Extension's configuration |
28 | 28 | */ |
29 | 29 | $wgFarmerSettings = array( |
30 | | - //Path to the directory that holds settings for wikis |
| 30 | + // Path to the directory that holds settings for wikis |
31 | 31 | 'configDirectory' => realpath( dirname( __FILE__ ) ) . '/configs/', |
32 | 32 | |
33 | | - //Or use a database |
| 33 | + // Or use a database |
34 | 34 | 'databaseName' => null, |
35 | 35 | |
36 | 36 | // Default wiki |
Index: trunk/extensions/Farmer/MediaWikiFarmer_Extension.php |
— | — | @@ -11,9 +11,9 @@ |
12 | 12 | protected $_description; |
13 | 13 | protected $_id; |
14 | 14 | |
15 | | - /** |
16 | | - * List of files that need to be included for this extension to work |
17 | | - */ |
| 15 | + /** |
| 16 | + * List of files that need to be included for this extension to work |
| 17 | + */ |
18 | 18 | protected $_includeFiles = array(); |
19 | 19 | |
20 | 20 | public static function newFromRow( $row ) { |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | * open them |
45 | 45 | */ |
46 | 46 | public function isValid() { |
47 | | - foreach( $this->_includeFiles as $file ) { |
| 47 | + foreach ( $this->_includeFiles as $file ) { |
48 | 48 | $result = @fopen( $file, 'r', true ); |
49 | 49 | |
50 | 50 | if ( $result === false ) return false; |
Index: trunk/extensions/Farmer/SpecialFarmer.php |
— | — | @@ -18,7 +18,6 @@ |
19 | 19 | public function __construct() { |
20 | 20 | parent::__construct( 'Farmer' ); |
21 | 21 | wfLoadExtensionMessages( 'MediaWikiFarmer' ); |
22 | | - |
23 | 22 | } |
24 | 23 | |
25 | 24 | /** |
— | — | @@ -43,14 +42,14 @@ |
44 | 43 | $this->_executeUpdateList( $wgFarmer ); |
45 | 44 | } elseif ( $arr[0] == 'list' ) { |
46 | 45 | $this->_executeList( $wgFarmer ); |
47 | | - } elseif ( $arr[0] == 'admin') { |
| 46 | + } elseif ( $arr[0] == 'admin' ) { |
48 | 47 | $this->_executeAdminister( $wgFarmer ); |
49 | | - } elseif ( $arr[0] == 'delete') { |
| 48 | + } elseif ( $arr[0] == 'delete' ) { |
50 | 49 | $this->_executeDelete( $wgFarmer ); |
51 | 50 | } |
52 | 51 | } else { |
53 | | - //no parameters were given |
54 | | - //display the main page |
| 52 | + // no parameters were given |
| 53 | + // display the main page |
55 | 54 | |
56 | 55 | $this->_executeMainPage( $wgFarmer ); |
57 | 56 | } |
— | — | @@ -75,7 +74,7 @@ |
76 | 75 | $wgOut->wrapWikiMsg( '* $1', array( 'farmer-createwiki-text', 'Special:Farmer/create' ) ); |
77 | 76 | } |
78 | 77 | |
79 | | - //if the user is a farmer admin, give them a menu of cool admin tools |
| 78 | + // if the user is a farmer admin, give them a menu of cool admin tools |
80 | 79 | if ( MediaWikiFarmer::userIsFarmerAdmin( $wgUser ) ) { |
81 | 80 | $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-administration' ); |
82 | 81 | $wgOut->wrapWikiMsg( '=== $1 ===', 'farmer-administration-extension' ); |
— | — | @@ -86,7 +85,6 @@ |
87 | 86 | |
88 | 87 | $wgOut->wrapWikiMsg( '=== $1 ===', 'farmer-administration-delete' ); |
89 | 88 | $wgOut->wrapWikiMsg( '* $1', array( 'farmer-administration-delete-text', 'Special:Farmer/delete' ) ); |
90 | | - |
91 | 89 | } |
92 | 90 | } |
93 | 91 | |
— | — | @@ -96,24 +94,21 @@ |
97 | 95 | $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-administer-thiswiki' ); |
98 | 96 | $wgOut->wrapWikiMsg( '* $1', array( 'farmer-administer-thiswiki-text', 'Special:Farmer/admin' ) ); |
99 | 97 | } |
100 | | - |
101 | | - |
102 | | - |
103 | 98 | } |
104 | 99 | |
105 | 100 | /** |
106 | 101 | * Displays form to create wiki |
107 | 102 | */ |
108 | | - protected function _executeCreate( $wgFarmer, $wiki ){ |
| 103 | + protected function _executeCreate( $wgFarmer, $wiki ) { |
109 | 104 | global $wgOut, $wgUser, $wgRequest; |
110 | 105 | |
111 | | - if( !$wgFarmer->getActiveWiki()->isDefaultWiki() ) { |
| 106 | + if ( !$wgFarmer->getActiveWiki()->isDefaultWiki() ) { |
112 | 107 | $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-notavailable' ); |
113 | 108 | $wgOut->addWikiMsg( 'farmer-notavailable-text' ); |
114 | 109 | return; |
115 | 110 | } |
116 | 111 | |
117 | | - if( !MediaWikiFarmer::userCanCreateWiki( $wgUser, $wiki ) ){ |
| 112 | + if ( !MediaWikiFarmer::userCanCreateWiki( $wgUser, $wiki ) ) { |
118 | 113 | $wgOut->addWikiMsg( 'farmercantcreatewikis' ); |
119 | 114 | return; |
120 | 115 | } |
— | — | @@ -124,10 +119,10 @@ |
125 | 120 | $reason = $wgRequest->getVal( 'wpReason' ); |
126 | 121 | $action = $this->getTitle( 'create' )->escapeLocalURL(); |
127 | 122 | |
128 | | - //if something was POST'd |
129 | | - if( $wgRequest->wasPosted() ){ |
130 | | - //we create the wiki if the user pressed 'Confirm' |
131 | | - if( $wgRequest->getCheck( 'wpConfirm' ) ) { |
| 123 | + // if something was POST'd |
| 124 | + if ( $wgRequest->wasPosted() ) { |
| 125 | + // we create the wiki if the user pressed 'Confirm' |
| 126 | + if ( $wgRequest->getCheck( 'wpConfirm' ) ) { |
132 | 127 | $wikiObj = MediaWikiFarmer_Wiki::newFromParams( $name, $title, $description, $wgUser->getName() ); |
133 | 128 | $wikiObj->create(); |
134 | 129 | |
— | — | @@ -136,14 +131,14 @@ |
137 | 132 | |
138 | 133 | $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-wikicreated' ); |
139 | 134 | $wgOut->addWikiMsg( 'farmer-wikicreated-text', $wikiObj->getUrl( wfUrlencode( wfMsgNoDB( 'mainpage' ) ) ) ); |
140 | | - $wgOut->addWikiMsg( 'farmer-default', '[['.$title.':Special:Farmer|Special:Farmer]]' ); |
| 135 | + $wgOut->addWikiMsg( 'farmer-default', '[[' . $title . ':Special:Farmer|Special:Farmer]]' ); |
141 | 136 | return; |
142 | 137 | } |
143 | 138 | |
144 | | - if( $name && $title && $description ){ |
| 139 | + if ( $name && $title && $description ) { |
145 | 140 | $wiki = new MediaWikiFarmer_Wiki( $name ); |
146 | 141 | |
147 | | - if( $wiki->exists() || $wiki->databaseExists() ){ |
| 142 | + if ( $wiki->exists() || $wiki->databaseExists() ) { |
148 | 143 | $wgOut->wrapWikiMsg( "== $1 ==\n\n$2", 'farmer-wikiexists', array( 'farmer-wikiexists-text', $name ) ); |
149 | 144 | return; |
150 | 145 | } |
— | — | @@ -168,7 +163,7 @@ |
169 | 164 | $nametitle = htmlspecialchars( $title ); |
170 | 165 | $namedescript = htmlspecialchars( $description ); |
171 | 166 | $confirmaccount = wfMsgHtml( 'farmer-button-confirm' ); |
172 | | - $wgOut->addHTML(" |
| 167 | + $wgOut->addHTML( " |
173 | 168 | |
174 | 169 | <form id=\"farmercreate2\" method=\"post\" action=\"$action\"> |
175 | 170 | <input type=\"hidden\" name=\"wpName\" value=\"{$nameaccount}\" /> |
— | — | @@ -180,7 +175,6 @@ |
181 | 176 | ); |
182 | 177 | |
183 | 178 | return; |
184 | | - |
185 | 179 | } |
186 | 180 | } |
187 | 181 | |
— | — | @@ -204,7 +198,7 @@ |
205 | 199 | |
206 | 200 | $token = htmlspecialchars( $wgUser->editToken() ); |
207 | 201 | |
208 | | - $wgOut->addHTML( |
| 202 | + $wgOut->addHTML( |
209 | 203 | Xml::openElement( 'form', array( 'method' => 'post', 'action' => $action ) ) . "\n" . |
210 | 204 | Xml::buildForm( |
211 | 205 | array( |
— | — | @@ -223,7 +217,7 @@ |
224 | 218 | protected function _executeUpdateList( $wgFarmer ) { |
225 | 219 | global $wgUser, $wgOut; |
226 | 220 | |
227 | | - if( !MediaWikiFarmer::userIsFarmerAdmin( $wgUser ) ){ |
| 221 | + if ( !MediaWikiFarmer::userIsFarmerAdmin( $wgUser ) ) { |
228 | 222 | $wgOut->permissionRequired( 'farmeradmin' ); |
229 | 223 | return; |
230 | 224 | } |
— | — | @@ -234,21 +228,21 @@ |
235 | 229 | $wgOut->returnToMain( null, $this->getTitle() ); |
236 | 230 | } |
237 | 231 | |
238 | | - protected function _executeDelete( $wgFarmer ){ |
| 232 | + protected function _executeDelete( $wgFarmer ) { |
239 | 233 | global $wgOut, $wgUser, $wgRequest; |
240 | 234 | |
241 | | - if( !$wgFarmer->getActiveWiki()->isDefaultWiki() ){ |
| 235 | + if ( !$wgFarmer->getActiveWiki()->isDefaultWiki() ) { |
242 | 236 | $wgOut->wrapWikiMsg( "== $1 ==\n$2", 'farmer-notaccessible', 'farmer-notaccessible-test' ); |
243 | 237 | return; |
244 | 238 | } |
245 | 239 | |
246 | | - if( !MediaWikiFarmer::userIsFarmerAdmin( $wgUser ) ){ |
| 240 | + if ( !MediaWikiFarmer::userIsFarmerAdmin( $wgUser ) ) { |
247 | 241 | $wgOut->wrapWikiMsg( "== $1 ==\n$2", 'farmer-permissiondenied', 'farmer-permissiondenied-text' ); |
248 | 242 | return; |
249 | 243 | } |
250 | 244 | |
251 | | - if( $wgRequest->wasPosted() && ( $wiki = $wgRequest->getVal( 'wpWiki' ) ) && $wiki != '-1' ) { |
252 | | - if( $wgRequest->getCheck( 'wpConfirm' ) ) { |
| 245 | + if ( $wgRequest->wasPosted() && ( $wiki = $wgRequest->getVal( 'wpWiki' ) ) && $wiki != '-1' ) { |
| 246 | + if ( $wgRequest->getCheck( 'wpConfirm' ) ) { |
253 | 247 | $wgOut->wrapWikiMsg( '<div class="successbox">$1</div>', array( 'farmer-deleting', $wiki ) ); |
254 | 248 | |
255 | 249 | $log = new LogPage( 'farmer' ); |
— | — | @@ -278,7 +272,7 @@ |
279 | 273 | $select = new XmlSelect( 'wpWiki', false, $wgRequest->getVal( 'wpWiki' ) ); |
280 | 274 | $select->addOption( wfMsg( 'farmer-delete-form' ), '-1' ); |
281 | 275 | foreach ( $list as $wiki ) { |
282 | | - if( $wiki['name'] != $wgFarmer->getDefaultWiki() ) { |
| 276 | + if ( $wiki['name'] != $wgFarmer->getDefaultWiki() ) { |
283 | 277 | $name = $wiki['name']; |
284 | 278 | $title = $wiki['title']; |
285 | 279 | $select->addOption( "$name - $title", $name ); |
— | — | @@ -291,10 +285,9 @@ |
292 | 286 | Xml::submitButton( wfMsg( 'farmer-delete-form-submit' ) ) . "\n" . |
293 | 287 | Xml::closeElement( 'form' ) |
294 | 288 | ); |
295 | | - |
296 | 289 | } |
297 | 290 | |
298 | | - protected function _executeList( $wgFarmer ){ |
| 291 | + protected function _executeList( $wgFarmer ) { |
299 | 292 | global $wgOut; |
300 | 293 | |
301 | 294 | $list = $wgFarmer->getFarmList(); |
— | — | @@ -304,7 +297,7 @@ |
305 | 298 | |
306 | 299 | foreach ( $list as $wiki ) { |
307 | 300 | $link = ( $current == $wiki['name'] ? wfMsgForContent( 'mainpage' ) : $wiki['name'] . ':' ); |
308 | | - $wgOut->addWikiText( '; [[' . $link .'|'.$wiki['title'].']] : ' . $wiki['description'] ); |
| 301 | + $wgOut->addWikiText( '; [[' . $link . '|' . $wiki['title'] . ']] : ' . $wiki['description'] ); |
309 | 302 | } |
310 | 303 | } |
311 | 304 | |
— | — | @@ -315,7 +308,7 @@ |
316 | 309 | |
317 | 310 | $action = $this->getTitle( 'admin' )->escapeLocalURL(); |
318 | 311 | |
319 | | - if( !( MediaWikiFarmer::userIsFarmerAdmin( $wgUser ) || $currentWiki->userIsAdmin( $wgUser ) ) ) { |
| 312 | + if ( !( MediaWikiFarmer::userIsFarmerAdmin( $wgUser ) || $currentWiki->userIsAdmin( $wgUser ) ) ) { |
320 | 313 | $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-permissiondenied' ); |
321 | 314 | $wgOut->addWikiMsg( 'farmer-permissiondenied-text1' ); |
322 | 315 | return; |
— | — | @@ -342,9 +335,9 @@ |
343 | 336 | $wgOut->addWikiMsg( 'farmer-basic-title1-text' ); |
344 | 337 | |
345 | 338 | $wgOut->addHTML( |
346 | | - '<form method="post" name="wikiTitle" action="'.$action.'">' . |
347 | | - '<input name="wikiTitle" size="30" value="'. $wiki->title . '" />' . |
348 | | - '<input type="submit" name="submit" value="'.wfMsgHtml( 'farmer-button-submit' ).'" />' . |
| 339 | + '<form method="post" name="wikiTitle" action="' . $action . '">' . |
| 340 | + '<input name="wikiTitle" size="30" value="' . $wiki->title . '" />' . |
| 341 | + '<input type="submit" name="submit" value="' . wfMsgHtml( 'farmer-button-submit' ) . '" />' . |
349 | 342 | '</form>' |
350 | 343 | ); |
351 | 344 | } |
— | — | @@ -353,22 +346,22 @@ |
354 | 347 | $wgOut->addWikiMsg( 'farmer-basic-description-text' ); |
355 | 348 | |
356 | 349 | $wgOut->addHTML( |
357 | | - '<form method="post" name="wikiDescription" action="'.$action.'">'. |
358 | | - '<textarea name="wikiDescription" rows="5" cols="30">'.htmlspecialchars( $wiki->description ).'</textarea>'. |
359 | | - '<input type="submit" name="submit" value="'.wfMsgHtml( 'farmer-button-submit' ).'" />'. |
| 350 | + '<form method="post" name="wikiDescription" action="' . $action . '">' . |
| 351 | + '<textarea name="wikiDescription" rows="5" cols="30">' . htmlspecialchars( $wiki->description ) . '</textarea>' . |
| 352 | + '<input type="submit" name="submit" value="' . wfMsgHtml( 'farmer-button-submit' ) . '" />' . |
360 | 353 | '</form>' |
361 | 354 | ); |
362 | 355 | |
363 | 356 | # Permissions stuff |
364 | 357 | if ( wfRunHooks( 'FarmerAdminPermissions', array( $wgFarmer ) ) ) { |
365 | 358 | |
366 | | - # Import |
| 359 | + # Import |
367 | 360 | if ( $wgRequest->wasPosted() && $permissions = $wgRequest->getArray( 'permission' ) ) { |
368 | 361 | foreach ( $permissions['*'] as $k => $v ) { |
369 | 362 | $wiki->setPermissionForAll( $k, $v ); |
370 | 363 | } |
371 | 364 | |
372 | | - foreach ($permissions['user'] as $k => $v) { |
| 365 | + foreach ( $permissions['user'] as $k => $v ) { |
373 | 366 | $wiki->setPermissionForUsers( $k, $v ); |
374 | 367 | } |
375 | 368 | |
— | — | @@ -379,9 +372,9 @@ |
380 | 373 | $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-basic-permission' ); |
381 | 374 | $wgOut->addWikiMsg( 'farmer-basic-permission-text' ); |
382 | 375 | |
383 | | - $wgOut->addHTML( '<form method="post" name="permissions" action="'.$action.'">' ); |
| 376 | + $wgOut->addHTML( '<form method="post" name="permissions" action="' . $action . '">' ); |
384 | 377 | |
385 | | - $wgOut->wrapWikiMsg('=== $1 ===', 'farmer-basic-permission-visitor' ); |
| 378 | + $wgOut->wrapWikiMsg( '=== $1 ===', 'farmer-basic-permission-visitor' ); |
386 | 379 | $wgOut->addWikiMsg( 'farmer-basic-permission-visitor-text' ); |
387 | 380 | |
388 | 381 | $doArray = array( |
— | — | @@ -409,11 +402,11 @@ |
410 | 403 | array( 'minoredit', wfMsg( 'farmer-basic-permission-minoredit' ) ) |
411 | 404 | ); |
412 | 405 | |
413 | | - foreach( $doArray as $arr ) { |
| 406 | + foreach ( $doArray as $arr ) { |
414 | 407 | $this->_doPermissionInput( $wgOut, $wiki, 'user', $arr[0], $arr[1] ); |
415 | 408 | } |
416 | 409 | |
417 | | - $wgOut->addHTML('<input type="submit" name="setPermissions" value="'.wfMsg( 'farmer-setpermission' ).'" />'); |
| 410 | + $wgOut->addHTML( '<input type="submit" name="setPermissions" value="' . wfMsg( 'farmer-setpermission' ) . '" />' ); |
418 | 411 | $wgOut->addHTML( "</form>\n\n\n" ); |
419 | 412 | } |
420 | 413 | |
— | — | @@ -438,17 +431,17 @@ |
439 | 432 | $skins = Skin::getSkinNames(); |
440 | 433 | global $wgSkipSkins; |
441 | 434 | |
442 | | - foreach( $wgSkipSkins as $skin ) { |
| 435 | + foreach ( $wgSkipSkins as $skin ) { |
443 | 436 | if ( array_key_exists( $skin, $skins ) ) { |
444 | 437 | unset( $skins[$skin] ); |
445 | 438 | } |
446 | 439 | } |
447 | 440 | |
448 | | - $wgOut->addHTML( '<form method="post" name="formDefaultSkin" action="'.$action.'">' ); |
| 441 | + $wgOut->addHTML( '<form method="post" name="formDefaultSkin" action="' . $action . '">' ); |
449 | 442 | |
450 | 443 | foreach ( $skins as $k => $skin ) { |
451 | | - $toAdd = '<input type="radio" name="defaultSkin" value="'.$k.'"'; |
452 | | - if ($k == $defaultSkin) { |
| 444 | + $toAdd = '<input type="radio" name="defaultSkin" value="' . $k . '"'; |
| 445 | + if ( $k == $defaultSkin ) { |
453 | 446 | $toAdd .= ' checked="checked" '; |
454 | 447 | } |
455 | 448 | $toAdd .= '/>' . $skin; |
— | — | @@ -464,30 +457,30 @@ |
465 | 458 | |
466 | 459 | $extensions = $wgFarmer->getExtensions(); |
467 | 460 | |
468 | | - //if we post a list of new extensions, wipe the old list from the wiki |
| 461 | + // if we post a list of new extensions, wipe the old list from the wiki |
469 | 462 | if ( $wgRequest->wasPosted() && $wgRequest->getCheck( 'submitExtension' ) ) { |
470 | 463 | $wiki->extensions = array(); |
471 | | - |
472 | | - //go through all posted extensions and add the appropriate ones |
473 | | - foreach( (array)$wgRequest->getArray( 'extension' ) as $k => $e ) { |
| 464 | + |
| 465 | + // go through all posted extensions and add the appropriate ones |
| 466 | + foreach ( (array)$wgRequest->getArray( 'extension' ) as $k => $e ) { |
474 | 467 | if ( array_key_exists( $k, $extensions ) ) { |
475 | 468 | $wiki->addExtension( $extensions[$k] ); |
476 | 469 | } |
477 | 470 | } |
478 | | - |
| 471 | + |
479 | 472 | $wiki->save(); |
480 | 473 | } |
481 | 474 | |
482 | 475 | # Form |
483 | 476 | $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-extensions' ); |
484 | | - $wgOut->addHTML( '<form method="post" name="formActiveExtensions" action="'.$action.'">' ); |
| 477 | + $wgOut->addHTML( '<form method="post" name="formActiveExtensions" action="' . $action . '">' ); |
485 | 478 | |
486 | 479 | foreach ( $extensions as $extension ) { |
487 | | - $toAdd = '<input type="checkbox" name="extension['.$extension->name.']" '; |
| 480 | + $toAdd = '<input type="checkbox" name="extension[' . $extension->name . ']" '; |
488 | 481 | if ( $wiki->hasExtension( $extension ) ) { |
489 | 482 | $toAdd .= 'checked="checked" '; |
490 | 483 | } |
491 | | - $toAdd .=' /><strong>'.htmlspecialchars( $extension->name ) . '</strong> - ' . htmlspecialchars( $extension->description ) . "<br />\n"; |
| 484 | + $toAdd .= ' /><strong>' . htmlspecialchars( $extension->name ) . '</strong> - ' . htmlspecialchars( $extension->description ) . "<br />\n"; |
492 | 485 | $wgOut->addHTML( $toAdd ); |
493 | 486 | } |
494 | 487 | |
— | — | @@ -530,7 +523,6 @@ |
531 | 524 | } |
532 | 525 | } |
533 | 526 | |
534 | | - |
535 | 527 | $wgOut->wrapWikiMsg( '== $1 ==', 'farmer-extensions-available' ); |
536 | 528 | |
537 | 529 | $extensions = $wgFarmer->getExtensions(); |
— | — | @@ -553,34 +545,33 @@ |
554 | 546 | $wgOut->addWikiText( '*' . $path ); |
555 | 547 | } |
556 | 548 | |
557 | | - $wgOut->addHTML(" |
| 549 | + $wgOut->addHTML( " |
558 | 550 | <form id=\"registerExtension\" method=\"post\"> |
559 | 551 | <table> |
560 | 552 | <tr> |
561 | | - <td align=\"right\">".wfMsgHtml( 'farmer-extensions-register-name' )."</td> |
| 553 | + <td align=\"right\">" . wfMsgHtml( 'farmer-extensions-register-name' ) . "</td> |
562 | 554 | <td align=\"left\"><input type=\"text\" size=\"20\" name=\"name\" value=\"\" /></td> |
563 | 555 | </tr> |
564 | 556 | <tr> |
565 | | - <td align=\"right\">".wfMsgHtml( 'farmer-description' )."</td> |
| 557 | + <td align=\"right\">" . wfMsgHtml( 'farmer-description' ) . "</td> |
566 | 558 | <td align=\"left\"><input type=\"text\" size=\"50\" name=\"description\" value=\"\" /></td> |
567 | 559 | </tr> |
568 | 560 | <tr> |
569 | | - <td align=\"right\">".wfMsgHtml( 'farmer-extensions-register-includefile' )."</td> |
| 561 | + <td align=\"right\">" . wfMsgHtml( 'farmer-extensions-register-includefile' ) . "</td> |
570 | 562 | <td align=\"left\"><input type=\"text\" size=\"50\" name=\"include\" value=\"\" /></td> |
571 | 563 | </tr> |
572 | 564 | <tr> |
573 | 565 | <td> </td> |
574 | | - <td align=\"right\"><input type=\"submit\" name=\"submit\" value=\"".wfMsgHtml( 'farmer-button-submit' )."\" /></td> |
| 566 | + <td align=\"right\"><input type=\"submit\" name=\"submit\" value=\"" . wfMsgHtml( 'farmer-button-submit' ) . "\" /></td> |
575 | 567 | </tr> |
576 | 568 | </table> |
577 | | -</form>"); |
578 | | - |
| 569 | +</form>" ); |
579 | 570 | } |
580 | 571 | |
581 | 572 | /** |
582 | 573 | * Creates form element representing an individual permission |
583 | 574 | */ |
584 | | - protected function _doPermissionInput( $wgOut, &$wiki, $group, $permission, $description) { |
| 575 | + protected function _doPermissionInput( $wgOut, &$wiki, $group, $permission, $description ) { |
585 | 576 | $value = $wiki->getPermission( $group, $permission ); |
586 | 577 | |
587 | 578 | $wgOut->addHTML( '<p>' . $description . wfMsgExt( 'colon-separator', array( 'escapenoentities' ) ) ); |
— | — | @@ -591,7 +582,7 @@ |
592 | 583 | $input .= 'checked="checked" '; |
593 | 584 | } |
594 | 585 | |
595 | | - $input .= ' />'.wfMsgHtml( 'farmer-yes' ).' '; |
| 586 | + $input .= ' />' . wfMsgHtml( 'farmer-yes' ) . ' '; |
596 | 587 | |
597 | 588 | $wgOut->addHTML( $input ); |
598 | 589 | |
— | — | @@ -601,10 +592,8 @@ |
602 | 593 | $input .= 'checked="checked" '; |
603 | 594 | } |
604 | 595 | |
605 | | - $input .= ' />'.wfMsgHtml( 'farmer-no' ); |
| 596 | + $input .= ' />' . wfMsgHtml( 'farmer-no' ); |
606 | 597 | |
607 | 598 | $wgOut->addHTML( $input . '</p>' ); |
608 | | - |
609 | 599 | } |
610 | | - |
611 | 600 | } |
Index: trunk/extensions/Farmer/MediaWikiFarmer.php |
— | — | @@ -5,7 +5,6 @@ |
6 | 6 | * @author Gregory Szorc <gregory.szorc@gmail.com> |
7 | 7 | */ |
8 | 8 | |
9 | | - |
10 | 9 | /** |
11 | 10 | * This class exposes functionality for a MediaWiki farm |
12 | 11 | * |
— | — | @@ -61,7 +60,7 @@ |
62 | 61 | |
63 | 62 | /** Instance of MediaWikiFarmer_Wiki */ |
64 | 63 | protected $_activeWiki = null; |
65 | | - |
| 64 | + |
66 | 65 | /** Instance of this class */ |
67 | 66 | protected static $_instance = null; |
68 | 67 | |
— | — | @@ -102,24 +101,24 @@ |
103 | 102 | |
104 | 103 | $this->_parameters = $params; |
105 | 104 | |
106 | | - //register this object as the static instance |
| 105 | + // register this object as the static instance |
107 | 106 | self::$_instance = $this; |
108 | 107 | |
109 | | - //if the groups table is being shared |
110 | | - if( in_array( 'user_groups', $wgSharedTables ) ){ |
| 108 | + // if the groups table is being shared |
| 109 | + if ( in_array( 'user_groups', $wgSharedTables ) ) { |
111 | 110 | $this->_sharedGroups = true; |
112 | 111 | } |
113 | 112 | |
114 | 113 | $this->_useDatabase = ( $this->_databaseName !== null ); |
115 | 114 | |
116 | | - if( $this->_useDatabase ) { |
| 115 | + if ( $this->_useDatabase ) { |
117 | 116 | global $IP; |
118 | 117 | require_once( "$IP/includes/GlobalFunctions.php" ); |
119 | 118 | } else { |
120 | | - if( !is_dir( $this->_configDirectory ) ){ |
| 119 | + if ( !is_dir( $this->_configDirectory ) ) { |
121 | 120 | throw new MWException( 'configDirectory not found: ' . $this->_configDirectory ); |
122 | 121 | } else { |
123 | | - if ( !is_dir( $this->_configDirectory . '/wikis/' ) ){ |
| 122 | + if ( !is_dir( $this->_configDirectory . '/wikis/' ) ) { |
124 | 123 | mkdir( $this->_configDirectory . '/wikis' ); |
125 | 124 | } |
126 | 125 | } |
— | — | @@ -127,7 +126,7 @@ |
128 | 127 | } |
129 | 128 | |
130 | 129 | public function __get( $key ) { |
131 | | - if( array_key_exists( $key, $this->_parameters ) ){ |
| 130 | + if ( array_key_exists( $key, $this->_parameters ) ) { |
132 | 131 | return $this->_parameters[$key]; |
133 | 132 | } |
134 | 133 | |
— | — | @@ -151,22 +150,22 @@ |
152 | 151 | public function run() { |
153 | 152 | global $wgCommandLineMode; |
154 | 153 | |
155 | | - if( !$this->_defaultWiki ) { |
| 154 | + if ( !$this->_defaultWiki ) { |
156 | 155 | throw new MWException( 'Default wiki must be set' ); |
157 | 156 | } |
158 | 157 | |
159 | 158 | // first we try to find the wiki name that was accessed by calling the |
160 | 159 | // appropriate function |
161 | | - if( is_callable( $this->_matchFunction ) ){ |
| 160 | + if ( is_callable( $this->_matchFunction ) ) { |
162 | 161 | $wiki = call_user_func( $this->_matchFunction, $this ); |
163 | 162 | |
164 | 163 | // if our function coudln't identify the wiki from the environment |
165 | 164 | if ( !$wiki ) { |
166 | 165 | // if the admin passed the --wiki option in command line mode |
167 | 166 | // then use it to get the wiki |
168 | | - if( $wgCommandLineMode && defined( 'MW_DB' ) ) { |
| 167 | + if ( $wgCommandLineMode && defined( 'MW_DB' ) ) { |
169 | 168 | $wiki = MW_DB; |
170 | | - if( defined( 'MW_PREFIX' ) && MW_PREFIX ) |
| 169 | + if ( defined( 'MW_PREFIX' ) && MW_PREFIX ) |
171 | 170 | $wiki .= '-' . MW_PREFIX; |
172 | 171 | } else { |
173 | 172 | $wiki = $this->_defaultWiki; |
— | — | @@ -191,11 +190,11 @@ |
192 | 191 | * |
193 | 192 | * @param string $wiki Wiki to load |
194 | 193 | */ |
195 | | - protected function _doWiki( $wiki ){ |
| 194 | + protected function _doWiki( $wiki ) { |
196 | 195 | $wiki = MediaWikiFarmer_Wiki::factory( $wiki ); |
197 | 196 | $this->_activeWiki = $wiki; |
198 | 197 | |
199 | | - if( !$wiki->exists() ){ |
| 198 | + if ( !$wiki->exists() ) { |
200 | 199 | // if the default wiki doesn't exist (probably first-time user) |
201 | 200 | if ( $wiki->isDefaultWiki() ) { |
202 | 201 | |
— | — | @@ -204,7 +203,7 @@ |
205 | 204 | |
206 | 205 | $wiki->save(); |
207 | 206 | |
208 | | - if( !$wiki->exists() ){ |
| 207 | + if ( !$wiki->exists() ) { |
209 | 208 | throw new MWException( 'MediaWikiFarmer could not write the default wiki configuration file.' ); |
210 | 209 | } else { |
211 | 210 | $this->updateFarmList(); |
— | — | @@ -214,7 +213,7 @@ |
215 | 214 | // we are not dealing with the default wiki |
216 | 215 | |
217 | 216 | // we invoke the function to be called when an unknown wiki is accessed |
218 | | - if( is_callable( $this->_onUnknownWikiFunction ) ){ |
| 217 | + if ( is_callable( $this->_onUnknownWikiFunction ) ) { |
219 | 218 | call_user_func( $this->_onUnknownWikiFunction, $this, $wiki ); |
220 | 219 | } else { |
221 | 220 | throw new MWException( 'Could not call function: ' . print_r( $this->_onUnknownFunction, true ) ); |
— | — | @@ -225,7 +224,6 @@ |
226 | 225 | // we initialize this wiki |
227 | 226 | $wiki->initialize(); |
228 | 227 | } |
229 | | - |
230 | 228 | } |
231 | 229 | |
232 | 230 | # Callback functions |
— | — | @@ -248,12 +246,12 @@ |
249 | 247 | * want to use the default wiki, as specified by the 'defaultWiki' |
250 | 248 | * parameter. |
251 | 249 | */ |
252 | | - protected static function _matchByURLRegExp( MediaWikiFarmer $farmer, $url = null ){ |
253 | | - if( is_null( $url ) ) |
| 250 | + protected static function _matchByURLRegExp( MediaWikiFarmer $farmer, $url = null ) { |
| 251 | + if ( is_null( $url ) ) |
254 | 252 | $url = $_SERVER['REQUEST_URI']; |
255 | 253 | |
256 | | - if( preg_match( $farmer->_matchRegExp, $url, $matches ) === 1 ){ |
257 | | - if( array_key_exists( $farmer->_matchOffset, $matches ) ) { |
| 254 | + if ( preg_match( $farmer->_matchRegExp, $url, $matches ) === 1 ) { |
| 255 | + if ( array_key_exists( $farmer->_matchOffset, $matches ) ) { |
258 | 256 | return $matches[$farmer->_matchOffset]; |
259 | 257 | } |
260 | 258 | } |
— | — | @@ -272,10 +270,10 @@ |
273 | 271 | * @param string $url URL to match to a wiki |
274 | 272 | * @return string|bool Wiki name on success. false on failure |
275 | 273 | */ |
276 | | - protected static function _matchByURLHostname( MediaWikiFarmer $farmer, $url = null ){ |
277 | | - if( is_null( $url ) ) |
| 274 | + protected static function _matchByURLHostname( MediaWikiFarmer $farmer, $url = null ) { |
| 275 | + if ( is_null( $url ) ) |
278 | 276 | $url = $_SERVER['REQUEST_URI']; |
279 | | - |
| 277 | + |
280 | 278 | if ( $result = parse_url( $url, PHP_URL_HOST ) ) { |
281 | 279 | if ( $host = $result['host'] ) { |
282 | 280 | if ( preg_match( $farmer->_matchRegExp, $host, $matches ) === 1 ) { |
— | — | @@ -298,17 +296,16 @@ |
299 | 297 | * period |
300 | 298 | * |
301 | 299 | */ |
302 | | - protected static function _matchByServerName( MediaWikiFarmer $farmer ){ |
| 300 | + protected static function _matchByServerName( MediaWikiFarmer $farmer ) { |
303 | 301 | $serverName = $_SERVER['SERVER_NAME']; |
304 | 302 | |
305 | | - //if string ends with the suffix specified |
306 | | - if ( substr( $serverName, -strlen( $farmer->_matchServerNameSuffix ) ) == $farmer->_matchServerNameSuffix |
| 303 | + // if string ends with the suffix specified |
| 304 | + if ( substr( $serverName, - strlen( $farmer->_matchServerNameSuffix ) ) == $farmer->_matchServerNameSuffix |
307 | 305 | && $serverName != $farmer->_matchServerNameSuffix ) { |
308 | | - return substr( $serverName, 0, -strlen( $farmer->_matchServerNameSuffix ) - 1 ); |
| 306 | + return substr( $serverName, 0, - strlen( $farmer->_matchServerNameSuffix ) - 1 ); |
309 | 307 | } |
310 | 308 | |
311 | 309 | return false; |
312 | | - |
313 | 310 | } |
314 | 311 | |
315 | 312 | /** |
— | — | @@ -331,10 +328,9 @@ |
332 | 329 | /** |
333 | 330 | * Returns the database table prefix, as suitable for $wgDBprefix |
334 | 331 | */ |
335 | | - public function splitWikiDB( $wiki ){ |
| 332 | + public function splitWikiDB( $wiki ) { |
336 | 333 | $callback = $this->_dbFromWikiFunction; |
337 | 334 | return call_user_func( $callback, $this, $wiki ); |
338 | | - |
339 | 335 | } |
340 | 336 | |
341 | 337 | /** |
— | — | @@ -345,8 +341,8 @@ |
346 | 342 | * @param $wiki String |
347 | 343 | * @return Array |
348 | 344 | */ |
349 | | - protected static function _prefixTable( MediaWikiFarmer $farmer, $wiki ){ |
350 | | - if( $farmer->useWgConf() ){ |
| 345 | + protected static function _prefixTable( MediaWikiFarmer $farmer, $wiki ) { |
| 346 | + if ( $farmer->useWgConf() ) { |
351 | 347 | global $wgConf; |
352 | 348 | return array( $wgConf->get( 'wgDBname', $wiki ), $wgConf->get( 'wgDBprefix', $wiki ) ); |
353 | 349 | } else { |
— | — | @@ -363,12 +359,12 @@ |
364 | 360 | * @return Database object |
365 | 361 | */ |
366 | 362 | public function getDB( $type ) { |
367 | | - if( !$this->useDatabase() ) |
| 363 | + if ( !$this->useDatabase() ) |
368 | 364 | throw new MWException( __METHOD__ . ' called when not using database backend.' ); |
369 | 365 | |
370 | 366 | try { |
371 | 367 | $db = wfGetDB( $type, array(), $this->_databaseName ); |
372 | | - } catch( DBConnectionError $e ) { |
| 368 | + } catch ( DBConnectionError $e ) { |
373 | 369 | throw new MWException( __METHOD__ . ": impossible to connect to {$this->_databaseName} to get farm configuration." ); |
374 | 370 | } |
375 | 371 | return $db; |
— | — | @@ -425,20 +421,20 @@ |
426 | 422 | $dbr = $this->getDB( DB_SLAVE ); |
427 | 423 | $res = $dbr->select( 'farmer_extension', '*', array(), __METHOD__ ); |
428 | 424 | $this->_extensions = array(); |
429 | | - foreach( $res as $row ) { |
| 425 | + foreach ( $res as $row ) { |
430 | 426 | $this->_extensions[$row->fe_name] = MediaWikiFarmer_Extension::newFromRow( $row ); |
431 | 427 | } |
432 | 428 | } else { |
433 | | - if( is_readable( $this->_getExtensionFile() ) ) { |
| 429 | + if ( is_readable( $this->_getExtensionFile() ) ) { |
434 | 430 | $contents = file_get_contents( $this->_getExtensionFile() ); |
435 | 431 | |
436 | 432 | $extensions = unserialize( $contents ); |
437 | 433 | |
438 | | - if( is_array( $extensions ) ) { |
| 434 | + if ( is_array( $extensions ) ) { |
439 | 435 | $this->_extensions = $extensions; |
440 | 436 | } |
441 | 437 | } else { |
442 | | - //perhaps we should throw an error or something? |
| 438 | + // perhaps we should throw an error or something? |
443 | 439 | } |
444 | 440 | } |
445 | 441 | |
— | — | @@ -458,7 +454,7 @@ |
459 | 455 | 'fe_path' => $e->includeFiles[0], |
460 | 456 | ), __METHOD__ ); |
461 | 457 | } else { |
462 | | - //force reload of file |
| 458 | + // force reload of file |
463 | 459 | $this->getExtensions( true ); |
464 | 460 | $this->_extensions[$e->name] = $e; |
465 | 461 | $this->_writeExtensions(); |
— | — | @@ -504,11 +500,11 @@ |
505 | 501 | $dbr = $this->getDB( DB_SLAVE ); |
506 | 502 | $res = $dbr->select( 'farmer_wiki', array( 'fw_name', 'fw_title', 'fw_description' ), array(), __METHOD__ ); |
507 | 503 | $arr = array(); |
508 | | - foreach( $res as $row ) { |
| 504 | + foreach ( $res as $row ) { |
509 | 505 | $arr[$row->fw_name] = array( |
510 | 506 | 'name' => $row->fw_name, |
511 | 507 | 'title' => $row->fw_title, |
512 | | - 'description' => $row->fw_description |
| 508 | + 'description' => $row->fw_description |
513 | 509 | ); |
514 | 510 | } |
515 | 511 | return $arr; |
— | — | @@ -524,13 +520,13 @@ |
525 | 521 | public function updateFarmList() { |
526 | 522 | if ( $this->useDatabase() ) |
527 | 523 | return; |
528 | | - |
| 524 | + |
529 | 525 | $directory = new DirectoryIterator( $this->_configDirectory . '/wikis/' ); |
530 | 526 | $wikis = array(); |
531 | 527 | |
532 | | - foreach( $directory as $file ) { |
533 | | - if( !$file->isDot() && !$file->isDir() ) { |
534 | | - if( substr( $file->getFilename(), -7 ) == '.farmer' ) { |
| 528 | + foreach ( $directory as $file ) { |
| 529 | + if ( !$file->isDot() && !$file->isDir() ) { |
| 530 | + if ( substr( $file->getFilename(), -7 ) == '.farmer' ) { |
535 | 531 | $base = substr( $file->getFileName(), 0, -7 ); |
536 | 532 | $wikis[$base] = MediaWikiFarmer_Wiki::factory( $base ); |
537 | 533 | } |
— | — | @@ -539,7 +535,7 @@ |
540 | 536 | |
541 | 537 | $farmList = array(); |
542 | 538 | |
543 | | - foreach( $wikis as $k => $v ) { |
| 539 | + foreach ( $wikis as $k => $v ) { |
544 | 540 | $arr = array(); |
545 | 541 | $arr['name'] = $v->name; |
546 | 542 | $arr['title'] = $v->title; |
— | — | @@ -559,7 +555,7 @@ |
560 | 556 | $wikis = $this->getFarmList(); |
561 | 557 | $dbw = wfGetDB( DB_MASTER ); |
562 | 558 | $replacements = array(); |
563 | | - foreach( $wikis as $key => $stuff ){ |
| 559 | + foreach ( $wikis as $key => $stuff ) { |
564 | 560 | $wiki = MediaWikiFarmer_Wiki::factory( $key ); |
565 | 561 | $replacements[] = array( |
566 | 562 | 'iw_prefix' => $wiki->name, |
Index: trunk/extensions/Farmer/MediaWikiFarmer_Wiki.php |
— | — | @@ -33,13 +33,13 @@ |
34 | 34 | /** |
35 | 35 | * Creates a wiki instance from a wiki name |
36 | 36 | */ |
37 | | - public function __construct( $wiki, $variables = array() ){ |
| 37 | + public function __construct( $wiki, $variables = array() ) { |
38 | 38 | $this->_name = $wiki; |
39 | 39 | $this->_variables = $variables; |
40 | 40 | } |
41 | 41 | |
42 | 42 | public function __get( $key ) { |
43 | | - if( substr( $key, 0, 2 ) == 'wg' ) { |
| 43 | + if ( substr( $key, 0, 2 ) == 'wg' ) { |
44 | 44 | return isset( $this->_variables[$key] ) ? $this->_variables[$key] : null; |
45 | 45 | } |
46 | 46 | |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | } |
51 | 51 | |
52 | 52 | public function __set( $k, $v ) { |
53 | | - if( in_array( $k, array( 'name', 'title', 'description', 'creator', 'extensions' ) ) ){ |
| 53 | + if ( in_array( $k, array( 'name', 'title', 'description', 'creator', 'extensions' ) ) ) { |
54 | 54 | $property = '_' . $k; |
55 | 55 | $this->$property = $v; |
56 | 56 | } else if ( substr( $k, 0, 2 ) == 'wg' ) { |
— | — | @@ -67,10 +67,10 @@ |
68 | 68 | public static function factory( $wiki, $variables = array() ) { |
69 | 69 | $farmer = MediaWikiFarmer::getInstance(); |
70 | 70 | |
71 | | - if( $farmer->useDatabase() ) { |
| 71 | + if ( $farmer->useDatabase() ) { |
72 | 72 | $dbr = $farmer->getDB( DB_SLAVE ); |
73 | 73 | $row = $dbr->selectRow( 'farmer_wiki', '*', array( 'fw_name' => $wiki ), __METHOD__ ); |
74 | | - if( $row === false ) { |
| 74 | + if ( $row === false ) { |
75 | 75 | return new MediaWikiFarmer_Wiki( $wiki, $variables ); |
76 | 76 | } else { |
77 | 77 | return self::newFromRow( $row ); |
— | — | @@ -78,10 +78,10 @@ |
79 | 79 | } else { |
80 | 80 | $file = self::_getWikiConfigFile( $wiki ); |
81 | 81 | |
82 | | - if( is_readable( $file ) ){ |
| 82 | + if ( is_readable( $file ) ) { |
83 | 83 | $content = file_get_contents( $file ); |
84 | 84 | $obj = unserialize( $content ); |
85 | | - if( $obj instanceof MediaWikiFarmer_Wiki ){ |
| 85 | + if ( $obj instanceof MediaWikiFarmer_Wiki ) { |
86 | 86 | return $obj; |
87 | 87 | } else { |
88 | 88 | throw new MWException( 'Stored wiki is corrupt.' ); |
— | — | @@ -123,7 +123,7 @@ |
124 | 124 | array( 'farmer_wiki_extension' => array( 'LEFT JOIN', 'fwe_extension = fe_id' ) ) |
125 | 125 | ); |
126 | 126 | $wiki->_extensions = array(); |
127 | | - foreach( $res as $row ) { |
| 127 | + foreach ( $res as $row ) { |
128 | 128 | $wiki->_extensions[$row->fe_name] = MediaWikiFarmer_Extension::newFromRow( $row ); |
129 | 129 | } |
130 | 130 | |
— | — | @@ -137,7 +137,7 @@ |
138 | 138 | $this->wgDefaultSkin = $farmer->defaultSkin; |
139 | 139 | |
140 | 140 | // before we create the database, make sure this database doesn't really exist yet |
141 | | - if( !$this->exists() && !$this->databaseExists() ){ |
| 141 | + if ( !$this->exists() && !$this->databaseExists() ) { |
142 | 142 | $this->save(); |
143 | 143 | $this->createDatabase(); |
144 | 144 | $farmer->updateFarmList(); |
— | — | @@ -155,7 +155,7 @@ |
156 | 156 | public function exists() { |
157 | 157 | $farmer = MediaWikiFarmer::getInstance(); |
158 | 158 | |
159 | | - if( $farmer->useDatabase() ) { |
| 159 | + if ( $farmer->useDatabase() ) { |
160 | 160 | return (bool)$farmer->getDB( DB_SLAVE )->selectField( 'farmer_wiki', 1, array( 'fw_name' => $this->_name ), __METHOD__ ); |
161 | 161 | } else { |
162 | 162 | return file_exists( self::_getWikiConfigFile( $this->_name ) ); |
— | — | @@ -165,7 +165,7 @@ |
166 | 166 | public function save() { |
167 | 167 | $farmer = MediaWikiFarmer::getInstance(); |
168 | 168 | |
169 | | - if( $farmer->useDatabase() ) { |
| 169 | + if ( $farmer->useDatabase() ) { |
170 | 170 | $dbw = $farmer->getDB( DB_MASTER ); |
171 | 171 | $new = array( |
172 | 172 | 'fw_name' => $this->_name, |
— | — | @@ -177,7 +177,7 @@ |
178 | 178 | ); |
179 | 179 | |
180 | 180 | $curId = $dbw->selectField( 'farmer_wiki', 'fw_id', array( 'fw_name' => $this->_name ), __METHOD__ ); |
181 | | - if( $curId == null ) { |
| 181 | + if ( $curId == null ) { |
182 | 182 | $dbw->insert( 'farmer_wiki', $new, __METHOD__ ); |
183 | 183 | $curId = $dbw->insertId(); |
184 | 184 | } else { |
— | — | @@ -185,7 +185,7 @@ |
186 | 186 | } |
187 | 187 | |
188 | 188 | $insert = array(); |
189 | | - foreach( $this->_extensions as $ext ) { |
| 189 | + foreach ( $this->_extensions as $ext ) { |
190 | 190 | $insert[] = array( 'fwe_wiki' => $curId, 'fwe_extension' => $ext->id ); |
191 | 191 | } |
192 | 192 | $dbw->delete( 'farmer_wiki_extension', array( 'fwe_wiki' => $curId ), __METHOD__ ); |
— | — | @@ -199,12 +199,12 @@ |
200 | 200 | } |
201 | 201 | |
202 | 202 | public function delete() { |
203 | | - if( !$this->exists() ) |
| 203 | + if ( !$this->exists() ) |
204 | 204 | return; |
205 | 205 | |
206 | 206 | $farmer = MediaWikiFarmer::getInstance(); |
207 | | - |
208 | | - if( $farmer->useDatabase() ) { |
| 207 | + |
| 208 | + if ( $farmer->useDatabase() ) { |
209 | 209 | $dbw = $farmer->getDB( DB_MASTER ); |
210 | 210 | $dbw->deleteJoin( 'farmer_wiki_extension', 'farmer_wiki', 'fwe_wiki', 'fw_id', array( 'fw_name' => $this->_name ), __METHOD__ ); |
211 | 211 | $dbw->delete( 'farmer_wiki', array( 'fw_name' => $this->_name ), __METHOD__ ); |
— | — | @@ -217,8 +217,8 @@ |
218 | 218 | try { |
219 | 219 | $db = $this->getDatabase(); |
220 | 220 | return $db->tableExists( 'page' ); |
221 | | - } catch( Exception $e ){ |
222 | | - return false; |
| 221 | + } catch ( Exception $e ) { |
| 222 | + return false; |
223 | 223 | } |
224 | 224 | } |
225 | 225 | |
— | — | @@ -227,15 +227,15 @@ |
228 | 228 | * use this wiki |
229 | 229 | */ |
230 | 230 | public function initialize() { |
231 | | - //loop over defined variables and set them in the global scope |
232 | | - foreach( $this->_variables as $k => $v ) { |
| 231 | + // loop over defined variables and set them in the global scope |
| 232 | + foreach ( $this->_variables as $k => $v ) { |
233 | 233 | $GLOBALS[$k] = $v; |
234 | 234 | } |
235 | 235 | |
236 | | - //we need to bring some global variables into scope so we can load extensions properly |
| 236 | + // we need to bring some global variables into scope so we can load extensions properly |
237 | 237 | extract( $GLOBALS, EXTR_REFS ); |
238 | 238 | |
239 | | - //register all the extensions |
| 239 | + // register all the extensions |
240 | 240 | foreach ( $this->_extensions as $extension ) { |
241 | 241 | foreach ( $extension->includeFiles as $file ) { |
242 | 242 | require_once $file; |
— | — | @@ -243,7 +243,7 @@ |
244 | 244 | } |
245 | 245 | |
246 | 246 | $farmer = MediaWikiFarmer::getInstance(); |
247 | | - if( $farmer->useWgConf() ){ |
| 247 | + if ( $farmer->useWgConf() ) { |
248 | 248 | // Nothing for now |
249 | 249 | } else { |
250 | 250 | $wgSitename = $this->_title; |
— | — | @@ -264,21 +264,21 @@ |
265 | 265 | list( $wgDBname, $wgDBprefix ) = $farmer->splitWikiDB( $this->name ); |
266 | 266 | } |
267 | 267 | |
268 | | - //we allocate permissions to the necessary groups |
| 268 | + // we allocate permissions to the necessary groups |
269 | 269 | |
270 | | - foreach ( $this->_permissions['*'] as $k=>$v ) { |
| 270 | + foreach ( $this->_permissions['*'] as $k => $v ) { |
271 | 271 | $wgGroupPermissions['*'][$k] = $v; |
272 | 272 | } |
273 | 273 | |
274 | | - foreach ( $this->_permissions['user'] as $k=>$v ) { |
| 274 | + foreach ( $this->_permissions['user'] as $k => $v ) { |
275 | 275 | $wgGroupPermissions['user'][$k] = $v; |
276 | 276 | } |
277 | 277 | |
278 | 278 | $wgGroupPermissions['sysop']['read'] = true; |
279 | 279 | |
280 | | - //assign permissions to administrators of this wiki |
281 | | - if( $farmer->sharingGroups() ){ |
282 | | - $group = '[farmer]['.$this->_name.'][admin]'; |
| 280 | + // assign permissions to administrators of this wiki |
| 281 | + if ( $farmer->sharingGroups() ) { |
| 282 | + $group = '[farmer][' . $this->_name . '][admin]'; |
283 | 283 | |
284 | 284 | $grantToWikiAdmins = array( 'read', 'edit' ); |
285 | 285 | |
— | — | @@ -287,8 +287,8 @@ |
288 | 288 | } |
289 | 289 | } |
290 | 290 | |
291 | | - if( $callback = $farmer->initCallback() ) { |
292 | | - if( is_callable( $callback ) ) { |
| 291 | + if ( $callback = $farmer->initCallback() ) { |
| 292 | + if ( is_callable( $callback ) ) { |
293 | 293 | call_user_func( $callback, $this ); |
294 | 294 | } else { |
295 | 295 | trigger_error( '$wgFarmerSettings[\'initCallback\'] is not callable', E_USER_WARNING ); |
— | — | @@ -314,28 +314,28 @@ |
315 | 315 | } |
316 | 316 | |
317 | 317 | public function getUrl( $article = null ) { |
318 | | - if( MediaWikiFarmer::getInstance()->useWgConf() ){ |
| 318 | + if ( MediaWikiFarmer::getInstance()->useWgConf() ) { |
319 | 319 | global $wgConf; |
320 | 320 | $server = $wgConf->get( 'wgServer', $this->name ); |
321 | 321 | $articlePath = $wgConf->get( 'wgArticlePath', $this->name ); |
322 | | - if( !$articlePath ){ |
| 322 | + if ( !$articlePath ) { |
323 | 323 | $usePathInfo = $wgConf->get( 'wgUsePathInfo', $this->name ); |
324 | | - if( is_null( $usePathInfo ) ){ |
| 324 | + if ( is_null( $usePathInfo ) ) { |
325 | 325 | global $wgUsePathInfo; |
326 | 326 | $usePathInfo = $wgUsePathInfo; |
327 | 327 | } |
328 | 328 | $articlePath = $wgConf->get( 'wgScriptPath', $this->name ) . ( $usePathInfo ? '/$1' : '?title=$1' ); |
329 | 329 | } |
330 | | - $url = $server . $articlePath; |
| 330 | + $url = $server . $articlePath; |
331 | 331 | } else { |
332 | 332 | $url = wfMsgForContent( 'farmerinterwikiurl', $this->name, '$1' ); |
333 | 333 | } |
334 | | - if( !is_null( $article ) ) |
| 334 | + if ( !is_null( $article ) ) |
335 | 335 | $url = str_replace( '$1', $article, $url ); |
336 | 336 | return $url; |
337 | 337 | } |
338 | 338 | |
339 | | - public function isDefaultWiki(){ |
| 339 | + public function isDefaultWiki() { |
340 | 340 | return $this->_name == MediaWikiFarmer::getInstance()->getDefaultWiki(); |
341 | 341 | } |
342 | 342 | |
— | — | @@ -344,7 +344,7 @@ |
345 | 345 | # ---------------- |
346 | 346 | |
347 | 347 | public function setPermission( $group, $permission, $value ) { |
348 | | - if( !array_key_exists( $group, $this->_permissions ) ) { |
| 348 | + if ( !array_key_exists( $group, $this->_permissions ) ) { |
349 | 349 | $this->_permissions[$group] = array(); |
350 | 350 | } |
351 | 351 | |
— | — | @@ -371,8 +371,8 @@ |
372 | 372 | return $this->getPermission( 'user', $permission ); |
373 | 373 | } |
374 | 374 | |
375 | | - public function userIsAdmin( $user ){ |
376 | | - $adminGroup = '[farmer]['.$this->_name.'][admin]'; |
| 375 | + public function userIsAdmin( $user ) { |
| 376 | + $adminGroup = '[farmer][' . $this->_name . '][admin]'; |
377 | 377 | |
378 | 378 | return in_array( $adminGroup, $user->getGroups() ); |
379 | 379 | } |
— | — | @@ -388,7 +388,7 @@ |
389 | 389 | public function hasExtension( MediaWikiFarmer_Extension $e ) { |
390 | 390 | return array_key_exists( $e->name, $this->_extensions ); |
391 | 391 | } |
392 | | - |
| 392 | + |
393 | 393 | # -------------- |
394 | 394 | # Database stuff |
395 | 395 | # -------------- |
— | — | @@ -401,8 +401,8 @@ |
402 | 402 | public function getDatabase( $selectDB = true ) { |
403 | 403 | global $wgDBserver, $wgDBtype; |
404 | 404 | $farmer = MediaWikiFarmer::getInstance(); |
405 | | - if( $selectDB ){ |
406 | | - if( isset( $this->_db ) && is_object( $this->_db ) ) |
| 405 | + if ( $selectDB ) { |
| 406 | + if ( isset( $this->_db ) && is_object( $this->_db ) ) |
407 | 407 | return $this->_db; |
408 | 408 | list( $db, $prefix ) = $farmer->splitWikiDB( $this->name ); |
409 | 409 | } else { |
— | — | @@ -413,7 +413,7 @@ |
414 | 414 | $password = $farmer->dbAdminPassword; |
415 | 415 | $class = 'Database' . ucfirst( $wgDBtype ); |
416 | 416 | $object = new $class( $wgDBserver, $user, $password, $db, false, 0, $prefix ); |
417 | | - if( $selectDB ) |
| 417 | + if ( $selectDB ) |
418 | 418 | $this->_db = $object; |
419 | 419 | return $object; |
420 | 420 | } |
— | — | @@ -444,11 +444,11 @@ |
445 | 445 | $db = false; |
446 | 446 | try { |
447 | 447 | $db = $this->getDatabase(); |
448 | | - } catch( DBConnectionError $e ) { |
| 448 | + } catch ( DBConnectionError $e ) { |
449 | 449 | $db = false; |
450 | 450 | } |
451 | 451 | |
452 | | - if( !$db ){ |
| 452 | + if ( !$db ) { |
453 | 453 | list( $dbname, $prefix ) = $farmer->splitWikiDB( $this->name ); |
454 | 454 | $db = $this->getDatabase( false ); |
455 | 455 | $db->query( "CREATE DATABASE `{$dbname}`", __METHOD__ ); |
— | — | @@ -477,7 +477,7 @@ |
478 | 478 | $revid = $revision->insertOn( $db ); |
479 | 479 | $article->updateRevisionOn( $db, $revision ); |
480 | 480 | |
481 | | - //site_stats table entry |
| 481 | + // site_stats table entry |
482 | 482 | $db->insert( 'site_stats', array( |
483 | 483 | 'ss_row_id' => 1, |
484 | 484 | 'ss_total_views' => 0, |
— | — | @@ -507,13 +507,13 @@ |
508 | 508 | |
509 | 509 | protected function _populateUserGroups() { |
510 | 510 | if ( $this->creator ) { |
511 | | - if( MediaWikiFarmer::getInstance()->sharingGroups() ){ |
| 511 | + if ( MediaWikiFarmer::getInstance()->sharingGroups() ) { |
512 | 512 | $user = User::newFromname( $this->creator ); |
513 | | - $group = '[farmer]['.$this->name.'][admin]'; |
| 513 | + $group = '[farmer][' . $this->name . '][admin]'; |
514 | 514 | $user->addGroup( $group ); |
515 | 515 | } else { |
516 | 516 | $userId = User::idFromName( $this->creator ); |
517 | | - if( $userId ) { |
| 517 | + if ( $userId ) { |
518 | 518 | $insert = array( |
519 | 519 | array( 'ug_user' => $userId, 'ug_group' => 'sysop' ), |
520 | 520 | array( 'ug_user' => $userId, 'ug_group' => 'bureaucrat' ), |
— | — | @@ -539,19 +539,19 @@ |
540 | 540 | |
541 | 541 | $prefix = $db->getProperty( 'mTablePrefix' ); |
542 | 542 | |
543 | | - while( $row = $result->fetchRow() ) { |
544 | | - if( $prefix == '' || strpos( $row[0], $prefix ) === 0 ) { |
545 | | - $query = 'DROP TABLE `'. $row[0] . '`'; |
| 543 | + while ( $row = $result->fetchRow() ) { |
| 544 | + if ( $prefix == '' || strpos( $row[0], $prefix ) === 0 ) { |
| 545 | + $query = 'DROP TABLE `' . $row[0] . '`'; |
546 | 546 | $db->query( $query, __METHOD__ ); |
547 | 547 | } |
548 | 548 | } |
549 | 549 | } |
550 | 550 | |
551 | 551 | protected function _deleteWikiGroups() { |
552 | | - if( MediaWikiFarmer::getInstance()->sharingGroups() ){ |
| 552 | + if ( MediaWikiFarmer::getInstance()->sharingGroups() ) { |
553 | 553 | $db = $this->getDatabase(); |
554 | 554 | $query = 'DELETE FROM ' . $db->tableName( 'user_groups' ) . ' WHERE ug_group LIKE '; |
555 | | - $query .= '\'[farmer]['.$this->_name.']%\''; |
| 555 | + $query .= '\'[farmer][' . $this->_name . ']%\''; |
556 | 556 | $db->query( $query, __METHOD__ ); |
557 | 557 | } |
558 | 558 | } |
Index: trunk/extensions/Farmer/farmer.sql |
— | — | @@ -30,4 +30,4 @@ |
31 | 31 | CREATE INDEX farmer_wiki_extension_wiki ON farmer_wiki_extension ( fwe_wiki ); |
32 | 32 | CREATE INDEX farmer_wiki_extension_extension ON farmer_wiki_extension ( fwe_extension ); |
33 | 33 | ALTER TABLE farmer_wiki_extension |
34 | | - ADD CONSTRAINT farmer_wiki_extension_wiki_extension PRIMARY KEY ( fwe_wiki, fwe_extension ); |
\ No newline at end of file |
| 34 | + ADD CONSTRAINT farmer_wiki_extension_wiki_extension PRIMARY KEY ( fwe_wiki, fwe_extension ); |