X-Git-Url: https://scripts.mit.edu/gitweb/wizard.git/blobdiff_plain/6eae78b3d8ed73a0266ef09a30e4b09e791dd9fb..8939cb421d77e7469160f38381cf2106974e5ba8:/wizard/app/mediawiki.py diff --git a/wizard/app/mediawiki.py b/wizard/app/mediawiki.py index 9931b1b..600eccd 100644 --- a/wizard/app/mediawiki.py +++ b/wizard/app/mediawiki.py @@ -1,20 +1,270 @@ import re +import distutils.version +import os +import datetime +import logging +import shlex +import shutil -from wizard import deploy +from wizard import app, deploy, install, resolve, scripts, shell, util +from wizard.app import php -def make_regex(var): - return re.compile('^\$' + var + r'''\s*=\s*((["\']).*\2;)$''', re.M) +def make_filename_regex(var): + return 'LocalSettings.php', re.compile('^(\$' + app.expand_re(var) + r'''\s*=\s*)(.*)(;)''', re.M) -wizard_to_var = \ - {'WIZARD_IP': 'IP' # obsolete - ,'WIZARD_SITENAME': 'wgSitename' - ,'WIZARD_SCRIPTPATH': 'wgScriptPath' - ,'WIZARD_EMERGENCYCONTACT': 'wgEmergencyContact' - ,'WIZARD_DBSERVER': 'wgDBserver' - ,'WIZARD_DBNAME': 'wgDBname' - ,'WIZARD_DBUSER': 'wgDBuser' - ,'WIZARD_DBPASSWORD': 'wgDBpassword' - ,'WIZARD_PROXYKEY': 'wgProxyKey'} +make_extractor = app.filename_regex_extractor(make_filename_regex) +make_substitution = app.filename_regex_substitution(make_filename_regex) +seed = { + 'WIZARD_IP': 'IP', # obsolete, remove after we're done + 'WIZARD_SITENAME': 'wgSitename', + 'WIZARD_SCRIPTPATH': 'wgScriptPath', + 'WIZARD_EMERGENCYCONTACT': ('wgEmergencyContact', 'wgPasswordSender'), + 'WIZARD_DBSERVER': 'wgDBserver', + 'WIZARD_DBNAME': 'wgDBname', + 'WIZARD_DBUSER': 'wgDBuser', + 'WIZARD_DBPASSWORD': 'wgDBpassword', + 'WIZARD_SECRETKEY': ('wgSecretKey', 'wgProxyKey'), + } + +resolutions = { +'LocalSettings.php': [ + (""" +<<<<<<< +***1*** +======= +## The URL base path to the directory containing the wiki; +## defaults for all runtime URL paths are based off of this. +## For more information on customizing the URLs please see: +## http://www.mediawiki.org/wiki/Manual:Short_URL +***2*** +$wgScriptExtension = ".php"; + +## UPO means: this is also a user preference option +>>>>>>> +""", [-1]), + (""" +<<<<<<< +***1*** +======= + +# MySQL specific settings +$wgDBprefix = ""; +>>>>>>> +""", ["\n# MySQL specific settings", 1]), + (""" +<<<<<<< +## is writable, then uncomment this: +***1*** +======= +## is writable, then set this to true: +$wgEnableUploads = false; +>>>>>>> +""", [-1]), + (""" +<<<<<<< +***1*** +$wgMathPath = "{$wgUploadPath}/math"; +$wgMathDirectory = "{$wgUploadDirectory}/math"; +$wgTmpDirectory = "{$wgUploadDirectory}/tmp"; +======= +$wgUseTeX = false; +>>>>>>> +""", [1]), + # order of these rules is important + (""" +<<<<<<< +$configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) ); +$wgCacheEpoch = max( $wgCacheEpoch, $configdate ); +***1*** +?> +======= +$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) ); +>>>>>>> +""", [0, 1]), + (""" +<<<<<<< +$configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) ); +$wgCacheEpoch = max( $wgCacheEpoch, $configdate ); +***1*** +======= +$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) ); +>>>>>>> +""", [0, 1]), + (""" +<<<<<<< +?> +======= +# When you make changes to this configuration file, this will make +# sure that cached pages are cleared. +$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) ); +>>>>>>> +""", [0]), + (""" +<<<<<<< +***1*** +?> +======= +# When you make changes to this configuration file, this will make +# sure that cached pages are cleared. +$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) ); +>>>>>>> +""", [1, 0]), + (""" +<<<<<<< +***1*** +======= +# When you make changes to this configuration file, this will make +# sure that cached pages are cleared. +$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) ); +>>>>>>> +""", [1, 0]), + ] +} class Application(deploy.Application): - pass + parametrized_files = ['LocalSettings.php', 'php.ini'] + deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys + @property + def extractors(self): + if not self._extractors: + self._extractors = util.dictmap(make_extractor, seed) + self._extractors.update(php.extractors) + return self._extractors + @property + def substitutions(self): + if not self._substitutions: + self._substitutions = util.dictkmap(make_substitution, seed) + self._substitutions.update(php.substitutions) + return self._substitutions + @property + def install_handler(self): + handler = install.ArgHandler("mysql", "admin", "email") + handler.add(install.Arg("title", help="Title of your new MediaWiki install")) + return handler + def checkConfig(self, deployment): + return os.path.isfile(os.path.join(deployment.location, "LocalSettings.php")) + def detectVersion(self, deployment): + contents = deployment.read("includes/DefaultSettings.php") + regex = make_filename_regex("wgVersion")[1] + match = regex.search(contents) + if not match: return None + return distutils.version.LooseVersion(match.group(2)[1:-1]) + def checkWeb(self, d, out=None): + page = d.fetch("/index.php?title=Main_Page") + if type(out) is list: + out.append(page) + return page.find("