2 import distutils.version
9 from wizard import app, deploy, install, resolve, scripts, shell, util
10 from wizard.app import php
12 def make_filename_regex(var):
13 return 'LocalSettings.php', re.compile('^(\$' + app.expand_re(var) + r'''\s*=\s*)(.*)(;)''', re.M)
15 seed = util.dictmap(make_filename_regex, {
16 'WIZARD_IP': 'IP', # obsolete, remove after we're done
17 'WIZARD_SITENAME': 'wgSitename',
18 'WIZARD_SCRIPTPATH': 'wgScriptPath',
19 'WIZARD_EMERGENCYCONTACT': ('wgEmergencyContact', 'wgPasswordSender'),
20 'WIZARD_DBSERVER': 'wgDBserver',
21 'WIZARD_DBNAME': 'wgDBname',
22 'WIZARD_DBUSER': 'wgDBuser',
23 'WIZARD_DBPASSWORD': 'wgDBpassword',
24 'WIZARD_SECRETKEY': ('wgSecretKey', 'wgProxyKey'),
27 class Application(app.Application):
28 parametrized_files = ['LocalSettings.php', 'php.ini']
29 deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys
30 extractors = app.make_extractors(seed)
31 extractors.update(php.extractors)
32 substitutions = app.make_substitutions(seed)
33 substitutions.update(php.substitutions)
34 install_handler = install.ArgHandler("mysql", "admin", "email")
35 install_handler.add(install.Arg("title", help="Title of your new MediaWiki install"))
36 def checkConfig(self, deployment):
37 return os.path.isfile(os.path.join(deployment.location, "LocalSettings.php"))
38 def detectVersion(self, deployment):
39 contents = deployment.read("includes/DefaultSettings.php")
40 regex = make_filename_regex("wgVersion")[1]
41 match = regex.search(contents)
42 if not match: return None
43 return distutils.version.LooseVersion(match.group(2)[1:-1])
44 def checkWeb(self, deployment, out=None):
45 page = deployment.fetch("/index.php?title=Main_Page")
48 return page.find("<!-- Served") != -1
49 def prepareMerge(self, deployment):
50 resolve.fix_newlines("LocalSettings.php")
51 def install(self, version, options):
53 os.unlink("LocalSettings.php")
57 os.chmod("config", 0777) # XXX: vaguely sketchy
60 'Sitename': options.title,
61 'EmergencyContact': options.email,
63 'DBserver': options.mysql_host,
64 'DBname': options.mysql_db,
65 'DBuser': options.mysql_user,
66 'DBpassword': options.mysql_password,
67 'DBpassword2': options.mysql_password,
68 'defaultEmail': options.email,
69 'SysopName': options.admin_name,
70 'SysopPass': options.admin_password,
71 'SysopPass2': options.admin_password,
73 result = install.fetch(options, '/config/index.php', post=postdata)
74 if options.verbose or options.debug: print result
75 if result.find("Installation successful") == -1:
76 raise install.Failure()
77 os.rename('config/LocalSettings.php', 'LocalSettings.php')
78 def upgrade(self, d, version, options):
80 if not os.path.isfile("AdminSettings.php"):
81 sh.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
83 result = sh.eval("php", "maintenance/update.php", "--quick", log=True)
84 except shell.CallError as e:
85 raise app.UpgradeFailure("Update script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr))
86 results = result.rstrip().split()
87 if not results or not results[-1] == "Done.":
88 raise app.UpgradeFailure(result)
89 def backup(self, deployment, backup_dir, options):
90 app.backup_database(backup_dir, deployment)
91 def restore(self, deployment, backup_dir, options):
92 app.restore_database(backup_dir, deployment)
94 Application.resolutions = {
95 'LocalSettings.php': [
100 ## The URL base path to the directory containing the wiki;
101 ## defaults for all runtime URL paths are based off of this.
102 ## For more information on customizing the URLs please see:
103 ## http://www.mediawiki.org/wiki/Manual:Short_URL
105 $wgScriptExtension = ".php";
107 ## UPO means: this is also a user preference option
115 # MySQL specific settings
118 """, ["\n# MySQL specific settings", 1]),
121 ## is writable, then uncomment this:
124 ## is writable, then set this to true:
125 $wgEnableUploads = false;
131 $wgMathPath = "{$wgUploadPath}/math";
132 $wgMathDirectory = "{$wgUploadDirectory}/math";
133 $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
138 # order of these rules is important
141 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
142 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
146 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
151 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
152 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
155 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
162 # When you make changes to this configuration file, this will make
163 # sure that cached pages are cleared.
164 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
172 # When you make changes to this configuration file, this will make
173 # sure that cached pages are cleared.
174 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
181 # When you make changes to this configuration file, this will make
182 # sure that cached pages are cleared.
183 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );