2 import distutils.version
9 from wizard import app, install, resolve, shell, sql, util
10 from wizard.app import php
12 def make_filename_regex(var):
13 """See :ref:`versioning config <seed>` for more information."""
14 return 'LocalSettings.php', php.re_var(var)
16 seed = util.dictmap(make_filename_regex, {
17 'WIZARD_IP': 'IP', # obsolete, remove after we're done
18 'WIZARD_SITENAME': 'wgSitename',
19 'WIZARD_SCRIPTPATH': 'wgScriptPath',
20 'WIZARD_EMERGENCYCONTACT': ('wgEmergencyContact', 'wgPasswordSender'),
21 'WIZARD_DBSERVER': 'wgDBserver',
22 'WIZARD_DBNAME': 'wgDBname',
23 'WIZARD_DBUSER': 'wgDBuser',
24 'WIZARD_DBPASSWORD': 'wgDBpassword',
25 'WIZARD_SECRETKEY': ('wgSecretKey', 'wgProxyKey'),
28 class Application(app.Application):
30 parametrized_files = ['LocalSettings.php'] + php.parametrized_files
31 deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys
32 extractors = app.make_extractors(seed)
33 extractors.update(php.extractors)
34 substitutions = app.make_substitutions(seed)
35 substitutions.update(php.substitutions)
36 install_schema = install.ArgSchema("db", "admin", "email", "title")
37 def download(self, version):
38 series = ".".join(str(version).split(".")[:2])
39 return "http://download.wikimedia.org/mediawiki/%s/mediawiki-%s.tar.gz" % (series, version)
40 def checkConfig(self, deployment):
41 return os.path.isfile("LocalSettings.php")
42 def detectVersion(self, deployment):
43 return self.detectVersionFromFile("includes/DefaultSettings.php", php.re_var("wgVersion"))
44 def checkWeb(self, deployment):
45 return self.checkWebPage(deployment, "/index.php?title=Main_Page", outputs=["<!-- Served"])
46 def install(self, version, options):
47 util.soft_unlink("LocalSettings.php")
48 os.chmod("config", 0777) # XXX: vaguely sketchy
51 'Sitename': options.title,
52 'EmergencyContact': options.email,
54 'DBserver': options.dsn.host,
55 'DBname': options.dsn.database,
56 'DBuser': options.dsn.username,
57 'DBpassword': options.dsn.password,
58 'DBpassword2': options.dsn.password,
59 'defaultEmail': options.email,
60 'SysopName': options.admin_name,
61 'SysopPass': options.admin_password,
62 'SysopPass2': options.admin_password,
64 result = install.fetch(options, '/config/index.php', post=postdata)
65 result_etree = lxml.etree.parse(StringIO.StringIO(result), lxml.etree.HTMLParser())
66 selector = lxml.cssselect.CSSSelector(".error")
67 error_messages = [e.text for e in selector(result_etree)]
68 logging.debug("Installation output:\n\n" + result)
69 if result.find("Installation successful") == -1:
70 if not error_messages:
71 raise app.InstallFailure()
73 raise app.RecoverableInstallFailure(error_messages)
74 os.rename('config/LocalSettings.php', 'LocalSettings.php')
75 php.ini_replace_vars()
77 def upgrade(self, d, version, options):
78 if not os.path.isfile("AdminSettings.php"):
79 shell.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
81 result = shell.eval("php", "maintenance/update.php", "--quick", log=True)
82 except shell.CallError as e:
83 raise app.UpgradeFailure("Update script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr))
84 results = result.rstrip().split()
85 if not results or not results[-1] == "Done.":
86 raise app.UpgradeFailure(result)
87 @app.throws_database_errors
88 def backup(self, deployment, backup_dir, options):
89 sql.backup(backup_dir, deployment)
90 @app.throws_database_errors
91 def restore(self, deployment, backup_dir, options):
92 sql.restore(backup_dir, deployment)
93 @app.throws_database_errors
94 def remove(self, deployment, options):
95 sql.drop(deployment.dsn)
96 def researchFilter(self, filename, added, deleted):
97 if filename == "LocalSettings.php":
98 return added == deleted == 10 or added == deleted == 9
99 elif filename == "AdminSettings.php":
100 return added == 0 and deleted == 20
101 elif filename == "config/index.php" or filename == "config/index.php5":
105 Application.resolutions = {
106 'LocalSettings.php': [
111 ## The URL base path to the directory containing the wiki;
112 ## defaults for all runtime URL paths are based off of this.
113 ## For more information on customizing the URLs please see:
114 ## http://www.mediawiki.org/wiki/Manual:Short_URL
116 $wgScriptExtension = ".php";
118 ## UPO means: this is also a user preference option
126 # MySQL specific settings
129 """, ["\n# MySQL specific settings", 1]),
132 ## is writable, then uncomment this:
135 ## is writable, then set this to true:
136 $wgEnableUploads = false;
142 $wgMathPath = "{$wgUploadPath}/math";
143 $wgMathDirectory = "{$wgUploadDirectory}/math";
144 $wgTmpDirectory = "{$wgUploadDirectory}/tmp";
149 # order of these rules is important
152 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
153 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
157 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
162 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
163 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
166 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
173 # When you make changes to this configuration file, this will make
174 # sure that cached pages are cleared.
175 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
183 # When you make changes to this configuration file, this will make
184 # sure that cached pages are cleared.
185 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
192 # When you make changes to this configuration file, this will make
193 # sure that cached pages are cleared.
194 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );