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