]> scripts.mit.edu Git - wizard.git/blob - wizard/app/mediawiki.py
Minor doc updates and code refinements.
[wizard.git] / wizard / app / mediawiki.py
1 import re
2 import distutils.version
3 import os
4
5 from wizard import app, install, resolve, shell, util
6 from wizard.app import php
7
8 def make_filename_regex(var):
9     return 'LocalSettings.php', php.re_var(var)
10
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'),
21         })
22
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", "title")
31     def checkConfig(self, deployment):
32         return os.path.isfile("LocalSettings.php")
33     def detectVersion(self, deployment):
34         contents = deployment.read("includes/DefaultSettings.php")
35         regex = php.re_var("wgVersion")
36         match = regex.search(contents)
37         if not match: return None
38         return distutils.version.LooseVersion(match.group(2)[1:-1])
39     def checkWeb(self, deployment, out=None):
40         page = deployment.fetch("/index.php?title=Main_Page")
41         if type(out) is list:
42             out.append(page)
43         return page.find("<!-- Served") != -1
44     def prepareMerge(self, deployment):
45         resolve.fix_newlines("LocalSettings.php")
46     def install(self, version, options):
47         try:
48             os.unlink("LocalSettings.php")
49         except OSError:
50             pass
51
52         os.chmod("config", 0777) # XXX: vaguely sketchy
53
54         postdata = {
55             'Sitename': options.title,
56             'EmergencyContact': options.email,
57             'LanguageCode': 'en',
58             'DBserver': options.mysql_host,
59             'DBname': options.mysql_db,
60             'DBuser': options.mysql_user,
61             'DBpassword': options.mysql_password,
62             'DBpassword2': options.mysql_password,
63             'defaultEmail': options.email,
64             'SysopName': options.admin_name,
65             'SysopPass': options.admin_password,
66             'SysopPass2': options.admin_password,
67             }
68         result = install.fetch(options, '/config/index.php', post=postdata)
69         if options.verbose or options.debug: print result
70         if result.find("Installation successful") == -1:
71             raise install.Failure()
72         os.rename('config/LocalSettings.php', 'LocalSettings.php')
73     def upgrade(self, d, version, options):
74         sh = shell.Shell()
75         if not os.path.isfile("AdminSettings.php"):
76             sh.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
77         try:
78             result = sh.eval("php", "maintenance/update.php", "--quick", log=True)
79         except shell.CallError as e:
80             raise app.UpgradeFailure("Update script returned non-zero exit code\nSTDOUT: %s\nSTDERR: %s" % (e.stdout, e.stderr))
81         results = result.rstrip().split()
82         if not results or not results[-1] == "Done.":
83             raise app.UpgradeFailure(result)
84     def backup(self, deployment, backup_dir, options):
85         app.backup_database(backup_dir, deployment)
86     def restore(self, deployment, backup_dir, options):
87         app.restore_database(backup_dir, deployment)
88
89 Application.resolutions = {
90 'LocalSettings.php': [
91     ("""
92 <<<<<<<
93 ***1***
94 =======
95 ## The URL base path to the directory containing the wiki;
96 ## defaults for all runtime URL paths are based off of this.
97 ## For more information on customizing the URLs please see:
98 ## http://www.mediawiki.org/wiki/Manual:Short_URL
99 ***2***
100 $wgScriptExtension  = ".php";
101
102 ## UPO means: this is also a user preference option
103 >>>>>>>
104 """, [-1]),
105     ("""
106 <<<<<<<
107 ***1***
108 =======
109
110 # MySQL specific settings
111 $wgDBprefix         = "";
112 >>>>>>>
113 """, ["\n# MySQL specific settings", 1]),
114     ("""
115 <<<<<<<
116 ## is writable, then uncomment this:
117 ***1***
118 =======
119 ## is writable, then set this to true:
120 $wgEnableUploads       = false;
121 >>>>>>>
122 """, [-1]),
123     ("""
124 <<<<<<<
125 ***1***
126 $wgMathPath         = "{$wgUploadPath}/math";
127 $wgMathDirectory    = "{$wgUploadDirectory}/math";
128 $wgTmpDirectory     = "{$wgUploadDirectory}/tmp";
129 =======
130 $wgUseTeX           = false;
131 >>>>>>>
132 """, [1]),
133     # order of these rules is important
134     ("""
135 <<<<<<<
136 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
137 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
138 ***1***
139 ?>
140 =======
141 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
142 >>>>>>>
143 """, [0, 1]),
144     ("""
145 <<<<<<<
146 $configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
147 $wgCacheEpoch = max( $wgCacheEpoch, $configdate );
148 ***1***
149 =======
150 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
151 >>>>>>>
152 """, [0, 1]),
153     ("""
154 <<<<<<<
155 ?>
156 =======
157 # When you make changes to this configuration file, this will make
158 # sure that cached pages are cleared.
159 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
160 >>>>>>>
161 """, [0]),
162     ("""
163 <<<<<<<
164 ***1***
165 ?>
166 =======
167 # When you make changes to this configuration file, this will make
168 # sure that cached pages are cleared.
169 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
170 >>>>>>>
171 """, [1, 0]),
172     ("""
173 <<<<<<<
174 ***1***
175 =======
176 # When you make changes to this configuration file, this will make
177 # sure that cached pages are cleared.
178 $wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
179 >>>>>>>
180 """, [1, 0]),
181     ]
182 }
183