r51677 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r51676‎ | r51677 | r51678 >
Date:03:39, 10 June 2009
Author:demon
Status:deferred
Tags:
Comment:
* AdminSettings is dead, forever and ever
* Make DB settings respect dbuser,dbpass params
* Handle settings loading
Modified paths:
  • /branches/maintenance-work/AdminSettings.sample (deleted) (history)
  • /branches/maintenance-work/UPGRADE (modified) (history)
  • /branches/maintenance-work/config/index.php (modified) (history)
  • /branches/maintenance-work/docs/scripts.txt (modified) (history)
  • /branches/maintenance-work/maintenance/Doxyfile (modified) (history)
  • /branches/maintenance-work/maintenance/Maintenance.php (modified) (history)
  • /branches/maintenance-work/maintenance/README (modified) (history)
  • /branches/maintenance-work/profileinfo.php (modified) (history)
  • /branches/maintenance-work/t/Search.inc (modified) (history)

Diff [purge]

Index: branches/maintenance-work/AdminSettings.sample
@@ -1,32 +0,0 @@
2 -<?php
3 -/**
4 - * This file should be copied to AdminSettings.php, and modified
5 - * to reflect local settings. It is required for the maintenance
6 - * scripts which run on the command line, as an extra security
7 - * measure to allow using a separate user account with higher
8 - * privileges to do maintenance work.
9 - *
10 - * Developers: Do not check AdminSettings.php into Subversion
11 - */
12 -
13 -/*
14 - * This data is used by all database maintenance scripts
15 - * (see directory maintenance/). The SQL user MUST BE
16 - * MANUALLY CREATED or set to an existing user with
17 - * necessary permissions.
18 - *
19 - * This is not to be confused with sysop accounts for the
20 - * wiki.
21 - *
22 - * NOTE: for PostgreSQL this should be set to the same user and
23 - * password as the web user, that is, the same as $wgDBuser and
24 - * $wgDBpassword in LocalSettings.php. This is necessary to
25 - * ensure that the owner for new tables is set correctly.
26 - */
27 -$wgDBadminuser = 'wikiadmin';
28 -$wgDBadminpassword = 'adminpass';
29 -
30 -/*
31 - * Whether to enable the profileinfo.php script.
32 - */
33 -$wgEnableProfileInfo = false;
Index: branches/maintenance-work/maintenance/README
@@ -10,8 +10,8 @@
1111
1212 Certain scripts will require elevated access to the database. In order to
1313 provide this, first create a MySQL user with "all" permissions on the wiki
14 -database, and then place their username and password in an AdminSettings.php
15 -file in the directory above. See AdminSettings.sample for specifics on this.
 14+database, and then set $wgDBadminuser and $wgDBadminpassword in your
 15+LocalSettings.php
1616
1717 === Brief explanation of files ===
1818
Index: branches/maintenance-work/maintenance/Doxyfile
@@ -135,7 +135,7 @@
136136 RECURSIVE = YES
137137 EXCLUDE =
138138 EXCLUDE_SYMLINKS = YES
139 -EXCLUDE_PATTERNS = LocalSettings.php AdminSettings.php
 139+EXCLUDE_PATTERNS = LocalSettings.php
140140 EXAMPLE_PATH =
141141 EXAMPLE_PATTERNS = *
142142 EXAMPLE_RECURSIVE = NO
Index: branches/maintenance-work/maintenance/Maintenance.php
@@ -83,10 +83,9 @@
8484 *
8585 * @param $name String The name of the param (help, version, etc)
8686 * @param $description String The description of the param to show on --help
87 - * @param $isFlag boolean Whether the param is a flag (like --help) or needs
88 - * a value (like --dbuser=someuser)
 87+ * @param $required boolean Is the param required?
8988 */
90 - protected function addParam( $name, $description, $isFlag = false, $required = true ) {
 89+ protected function addParam( $name, $description, $required = false ) {
9190 $this->mParams[ $name ] = array( 'desc' => $description, 'require' => $required );
9291 }
9392
@@ -142,10 +141,9 @@
143142 * Add the default parameters to the scripts
144143 */
145144 private function addDefaultParams() {
146 - $this->addParam( 'help', "Display this help message", true );
147 - $this->addParam( 'quiet', "Whether to supress non-error output", true );
 145+ $this->addParam( 'help', "Display this help message" );
 146+ $this->addParam( 'quiet', "Whether to supress non-error output" );
148147 $this->addParam( 'conf', "Location of LocalSettings.php, if not default" );
149 - $this->addParam( 'aconf', "Same, but for AdminSettings.php" );
150148 $this->addParam( 'wiki', "For specifying the wiki ID" );
151149 if( $this->needsDB() ) {
152150 $this->addParam( 'dbuser', "The DB user to use for this script" );
@@ -304,8 +302,6 @@
305303 $this->mOptions = $options;
306304 $this->mArgs = $args;
307305 }
308 -
309 - private function validateParam(
310306
311307 /**
312308 * Maybe show the help.
@@ -328,8 +324,9 @@
329325 * Handle some last-minute setup here.
330326 */
331327 private function finalSetup() {
332 - global $wgCommandLineMode, $wgUseNormalUser, $wgShowSQLErrors, $wgTitle, $wgProfiling, $IP;
333 - global $wgDBadminuser, $wgDBadminpassword, $wgDBuser, $wgDBpassword, $wgDBservers, $wgLBFactoryConf;
 328+ global $wgCommandLineMode, $wgUseNormalUser, $wgShowSQLErrors;
 329+ global $wgTitle, $wgProfiling, $IP, $wgDBadminuser, $wgDBadminpassword;
 330+ global $wgDBuser, $wgDBpassword, $wgDBservers, $wgLBFactoryConf;
334331
335332 # Turn off output buffering again, it might have been turned on in the settings files
336333 if( ob_get_level() ) {
@@ -337,7 +334,13 @@
338335 }
339336 # Same with these
340337 $wgCommandLineMode = true;
341 -
 338+
 339+ # If these were passed, use them
 340+ if( $this->mDbUser )
 341+ $wgDBadminuser = $this->mDbUser;
 342+ if( $this->mDbPass )
 343+ $wgDBadminpass = $this->mDbPass;
 344+
342345 if ( empty( $wgUseNormalUser ) && isset( $wgDBadminuser ) ) {
343346 $wgDBuser = $wgDBadminuser;
344347 $wgDBpassword = $wgDBadminpassword;
@@ -370,7 +373,90 @@
371374 }
372375
373376 private function loadWikimediaSettings() {
 377+ global $wgWikiFarm, $cluster, $IP, $wgNoDBParam, $wgUseNormalUser;
 378+
 379+ $wgWikiFarm = true;
 380+ $cluster = 'pmtpa';
 381+ require_once( "$IP/includes/AutoLoader.php" );
 382+ require_once( "$IP/includes/SiteConfiguration.php" );
 383+
 384+ # Get $wgConf
 385+ require( "$IP/wgConf.php" );
 386+
 387+ if ( empty( $wgNoDBParam ) ) {
 388+ # Check if we were passed a db name
 389+ if ( isset( $this->mOptions['wiki'] ) ) {
 390+ $db = $this->mOptions['wiki'];
 391+ } else {
 392+ $db = array_shift( $this->mArgs );
 393+ }
 394+ list( $site, $lang ) = $wgConf->siteFromDB( $db );
 395+
 396+ # If not, work out the language and site the old way
 397+ if ( is_null( $site ) || is_null( $lang ) ) {
 398+ if ( !$db ) {
 399+ $lang = 'aa';
 400+ } else {
 401+ $lang = $db;
 402+ }
 403+ if ( isset( $this->mArgs[0] ) ) {
 404+ $site = array_shift( $this->mArgs );
 405+ } else {
 406+ $site = 'wikipedia';
 407+ }
 408+ }
 409+ } else {
 410+ $lang = 'aa';
 411+ $site = 'wikipedia';
 412+ }
 413+
 414+ # This is for the IRC scripts, which now run as the apache user
 415+ # The apache user doesn't have access to the wikiadmin_pass command
 416+ if ( $_ENV['USER'] == 'apache' ) {
 417+ #if ( posix_geteuid() == 48 ) {
 418+ $wgUseNormalUser = true;
 419+ }
 420+
 421+ putenv( 'wikilang='.$lang);
 422+
 423+ $DP = $IP;
 424+ ini_set( 'include_path', ".:$IP:$IP/includes:$IP/languages:$IP/maintenance" );
 425+
 426+ if ( $lang == 'test' && $site == 'wikipedia' ) {
 427+ define( 'TESTWIKI', 1 );
 428+ }
 429+
 430+ #require_once( $IP.'/includes/ProfilerStub.php' );
 431+ require( $IP.'/includes/Defines.php' );
 432+ require( $IP.'/CommonSettings.php' );
374433 }
 434+
375435 private function loadSettings() {
 436+ global $wgWikiFarm, $wgCommandLineMode, $IP, $DP;
 437+
 438+ $wgWikiFarm = false;
 439+ if ( isset( $this->mOptions['conf'] ) ) {
 440+ $settingsFile = $this->mOptions['conf'];
 441+ } else {
 442+ $settingsFile = "$IP/LocalSettings.php";
 443+ }
 444+ if ( isset( $this->mOptions['wiki'] ) ) {
 445+ $bits = explode( '-', $this->mOptions['wiki'] );
 446+ if ( count( $bits ) == 1 ) {
 447+ $bits[] = '';
 448+ }
 449+ define( 'MW_DB', $bits[0] );
 450+ define( 'MW_PREFIX', $bits[1] );
 451+ }
 452+
 453+ if ( ! is_readable( $settingsFile ) ) {
 454+ $this->error( "A copy of your installation's LocalSettings.php\n" .
 455+ "must exist and be readable in the source directory.\n", true );
 456+ }
 457+ $wgCommandLineMode = true;
 458+ $DP = $IP;
 459+ require_once( "$IP/includes/AutoLoader.php" );
 460+ require_once( "$IP/includes/Defines.php" );
 461+ require_once( $settingsFile );
376462 }
377 -}
 463+}
\ No newline at end of file
Index: branches/maintenance-work/UPGRADE
@@ -42,8 +42,7 @@
4343 repository, via a checkout or export operation.
4444
4545 Replace the existing MediaWiki files with the new. You should preserve the
46 -LocalSettings.php file, AdminSettings.php file (if present), and the
47 -"extensions" and "images" directories.
 46+LocalSettings.php file and the "extensions" and "images" directories.
4847
4948 Depending upon your configuration, you may also need to preserve additional
5049 directories, including a custom upload directory ($wgUploadDirectory),
@@ -51,8 +50,8 @@
5251
5352 === Perform the database upgrade ===
5453
55 -You will need an AdminSettings.php file set up in the correct format; see
56 -AdminSettings.sample in the wiki root for more information and examples.
 54+You will need to have $wgDBadminuser and $wgDBadminpass set in your
 55+LocalSettings.php, see there for more info.
5756
5857 From the command line, browse to the "maintenance" directory and run the
5958 update.php script to check and update the schema. This will insert missing
@@ -172,10 +171,10 @@
173172 === Web installer ===
174173
175174 You can use the web-based installer wizard if you first remove the
176 -LocalSettings.php (and AdminSettings.php, if any) files; be sure to
177 -give the installer the same information as you did on the original
178 -install (language/encoding, database name, password, etc). This will
179 -also generate a fresh LocalSettings.php, which you may need to customize.
 175+LocalSettings.php file; be sure to give the installer the same
 176+information as you did on the original install (language/encoding,
 177+database name, password, etc). This will also generate a fresh
 178+LocalSettings.php, which you may need to customize.
180179
181180 You may change some settings during the install, but be very careful!
182181 Changing the encoding in particular will generally leave you with a
@@ -185,8 +184,8 @@
186185
187186 Additionally, as of 1.4.0 you can run an in-place upgrade script from
188187 the command line, keeping your existing LocalSettings.php. This requires
189 -that you create an AdminSettings.php giving an appropriate database user
190 -and password with privileges to modify the database structure.
 188+that you set $wgDBadminuser and $wgDBadminpassword with an appropriate
 189+database user and password with privileges to modify the database structure.
191190
192191 Once the new files are in place, go into the maintenance subdirectory and
193192 run the script:
Index: branches/maintenance-work/docs/scripts.txt
@@ -35,10 +35,9 @@
3636 to force the profiler to save the informations in the database and apply the
3737 maintenance/archives/patch-profiling.sql patch to the database.
3838
39 - To enable the profileinfo.php itself, you'll need to create the
40 - AdminSettings.php file (see AdminSettings.sample for more information) and
41 - set $wgEnableProfileInfo to true in that file. See also
42 - http://www.mediawiki.org/wiki/How_to_debug#Profiling.
 39+ To enable the profileinfo.php itself, you'll need to set $wgDBadminuser
 40+ and $wgDBadminpassword in your LocalSettings.php, as well as $wgEnableProfileInfo
 41+ See also http://www.mediawiki.org/wiki/How_to_debug#Profiling.
4342
4443 redirect.php
4544 Script that only redirect to the article passed in the wpDropdown parameter
Index: branches/maintenance-work/profileinfo.php
@@ -4,7 +4,6 @@
55 $wgEnableProfileInfo = $wgProfileToDatabase = false;
66
77 require_once( './includes/WebStart.php' );
8 -@include_once( './AdminSettings.php' );
98
109 ?>
1110 <!--
Index: branches/maintenance-work/t/Search.inc
@@ -7,7 +7,6 @@
88 require 'includes/Defines.php';
99 require 'includes/ProfilerStub.php';
1010 require 'LocalSettings.php';
11 -require 'AdminSettings.php';
1211 require 'includes/Setup.php';
1312
1413 function buildTestDatabase( $tables ) {
Index: branches/maintenance-work/config/index.php
@@ -615,6 +615,7 @@
616616 $conf->RootUser = importPost( "RootUser", "root" );
617617 $conf->RootPW = importPost( "RootPW", "" );
618618 $useRoot = importCheck( 'useroot', false );
 619+ $conf->populateadmin = importCheck( 'populateadmin', false );
619620 $conf->LanguageCode = importPost( "LanguageCode", "en" );
620621 ## MySQL specific:
621622 $conf->DBprefix = importPost( "DBprefix" );
@@ -1527,6 +1528,8 @@
15281529 <label class="column">Superuser account:</label>
15291530 <input type="checkbox" name="useroot" id="useroot" <?php if( $useRoot ) { ?>checked="checked" <?php } ?> />
15301531 &nbsp;<label for="useroot">Use superuser account</label>
 1532+ <input type="checkbox" name="populateadmin" id="populateadmin" <?php if( $conf->populateadmin ) { ?>checked="checked" <?php } ?> />
 1533+ &nbsp;<label for="populateadmin">Set as admin user for maintenance</label>
15311534 </div>
15321535 <div class="config-input"><?php aField( $conf, "RootUser", "Superuser name:", "text" ); ?></div>
15331536 <div class="config-input"><?php aField( $conf, "RootPW", "Superuser password:", "password" ); ?></div>
@@ -1792,6 +1795,11 @@
17931796 # Needs literal string interpolation for the current style path
17941797 $slconf['RightsIcon'] = $conf->RightsIcon;
17951798 }
 1799+
 1800+ if( $conf->populateadmin ) {
 1801+ $slconf['DBadminuser'] = $conf->RootUser;
 1802+ $slconf['DBadminpassword'] = $conf->RootPW;
 1803+ }
17961804
17971805 if( $conf->DBtype == 'mysql' ) {
17981806 $dbsettings =
@@ -1899,6 +1907,10 @@
19001908
19011909 {$dbsettings}
19021910
 1911+## Database admin settings, used for maintenance scripts
 1912+\$wgDBadminuser = \"{$slconf['DBadminuser']}\";
 1913+\$wgDBadminpassword = \"{$slconf['DBadminpassword']}\";
 1914+
19031915 ## Shared memory settings
19041916 \$wgMainCacheType = $cacheType;
19051917 \$wgMemCachedServers = $mcservers;

Follow-up revisions

RevisionCommit summaryAuthorDate
r63545Fix regression from r51677, still need to load AdminSettings if it exists for...demon12:44, 10 March 2010
r63548Backport r63545,r63546 REL1_16 (Fix regression from r51677, still need to loa...demon12:54, 10 March 2010

Status & tagging log