mediawiki: Allow admin to set default skin

Fixes #1731

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
[sunil: Refactor getting skins and form field for simplicity]
[sunil: Remove incorrect change to showing success form message]
[sunil: Minor simplification to editing the configuration]
[sunil: Read configuration value enclosed in single as well as double quote]
Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Joseph Nuthalapati authored and Sunil Mohan Adapa committed 2020-01-03 16:31:28 -08:00
1 parent 890d45bd64
commit cfe014a3f4
4 files changed
+76 -4

No files matched your search

+26
View File
@@ -59,6 +59,10 @@ def parse_arguments():
change_password.add_argument('--password',
help='new password for the MediaWiki user')
default_skin = subparsers.add_parser('set-default-skin',
help='Set the default skin')
default_skin.add_argument('skin', help='name of the skin')
subparsers.required = True
return parser.parse_args()
@@ -198,6 +202,28 @@ def subcommand_private_mode(arguments):
conf_value + '\n')
def subcommand_set_default_skin(arguments):
"""Set a default skin"""
skin = arguments.skin
skin_setting = f'$wgDefaultSkin = "{skin}";\n'
with open(CONF_FILE, 'r') as conf_file:
lines = conf_file.readlines()
inserted = False
for i, line in enumerate(lines):
if line.strip().startswith('$wgDefaultSkin'):
lines[i] = skin_setting
inserted = True
break
if not inserted:
lines.append(skin_setting)
with open(CONF_FILE, 'w') as conf_file:
conf_file.writelines(lines)
def main():
"""Parse arguments and perform all duties."""
arguments = parse_arguments()