mirror of
https://github.com/freedombox/FreedomBox.git
synced 2026-05-27 10:44:33 +00:00
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:
parent
890d45bd64
commit
cfe014a3f4
@ -59,6 +59,10 @@ def parse_arguments():
|
|||||||
change_password.add_argument('--password',
|
change_password.add_argument('--password',
|
||||||
help='new password for the MediaWiki user')
|
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
|
subparsers.required = True
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
@ -198,6 +202,28 @@ def subcommand_private_mode(arguments):
|
|||||||
conf_value + '\n')
|
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():
|
def main():
|
||||||
"""Parse arguments and perform all duties."""
|
"""Parse arguments and perform all duties."""
|
||||||
arguments = parse_arguments()
|
arguments = parse_arguments()
|
||||||
|
|||||||
@ -18,6 +18,8 @@
|
|||||||
FreedomBox app to configure MediaWiki.
|
FreedomBox app to configure MediaWiki.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import re
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from plinth import actions
|
from plinth import actions
|
||||||
@ -137,3 +139,20 @@ def is_private_mode_enabled():
|
|||||||
""" Return whether private mode is enabled or disabled"""
|
""" Return whether private mode is enabled or disabled"""
|
||||||
output = actions.superuser_run('mediawiki', ['private-mode', 'status'])
|
output = actions.superuser_run('mediawiki', ['private-mode', 'status'])
|
||||||
return output.strip() == 'enabled'
|
return output.strip() == 'enabled'
|
||||||
|
|
||||||
|
|
||||||
|
def get_default_skin():
|
||||||
|
"""Return the value of the default skin"""
|
||||||
|
def _find_skin(config_file):
|
||||||
|
with open(config_file, 'r') as config:
|
||||||
|
for line in config:
|
||||||
|
if line.startswith('$wgDefaultSkin'):
|
||||||
|
return re.findall(r'["\'][^"\']*["\']',
|
||||||
|
line)[0].strip('"\'')
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
user_config = '/etc/mediawiki/FreedomBoxSettings.php'
|
||||||
|
static_config = '/etc/mediawiki/FreedomBoxStaticSettings.php'
|
||||||
|
|
||||||
|
return _find_skin(user_config) or _find_skin(static_config)
|
||||||
|
|||||||
@ -18,12 +18,24 @@
|
|||||||
FreedomBox app for configuring MediaWiki.
|
FreedomBox app for configuring MediaWiki.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import pathlib
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
|
|
||||||
from plinth.forms import AppForm
|
from plinth.forms import AppForm
|
||||||
|
|
||||||
|
|
||||||
|
def get_skins():
|
||||||
|
"""Return a list of available skins as choice field values."""
|
||||||
|
skins_dir = pathlib.Path('/var/lib/mediawiki/skins')
|
||||||
|
if not skins_dir.exists():
|
||||||
|
return []
|
||||||
|
|
||||||
|
return [(skin.name.lower(), skin.name) for skin in skins_dir.iterdir()
|
||||||
|
if skin.is_dir()]
|
||||||
|
|
||||||
|
|
||||||
class MediaWikiForm(AppForm): # pylint: disable=W0232
|
class MediaWikiForm(AppForm): # pylint: disable=W0232
|
||||||
"""MediaWiki configuration form."""
|
"""MediaWiki configuration form."""
|
||||||
password = forms.CharField(
|
password = forms.CharField(
|
||||||
@ -42,3 +54,9 @@ class MediaWikiForm(AppForm): # pylint: disable=W0232
|
|||||||
help_text=_('If enabled, access will be restricted. Only people '
|
help_text=_('If enabled, access will be restricted. Only people '
|
||||||
'who have accounts can read/write to the wiki. '
|
'who have accounts can read/write to the wiki. '
|
||||||
'Public registrations will also be disabled.'))
|
'Public registrations will also be disabled.'))
|
||||||
|
|
||||||
|
default_skin = forms.ChoiceField(
|
||||||
|
label=_('Default Skin'), required=False,
|
||||||
|
help_text=_('Choose a default skin for your MediaWiki installation. '
|
||||||
|
'Users have the option to select their preferred skin.'),
|
||||||
|
choices=get_skins)
|
||||||
|
|||||||
@ -26,7 +26,8 @@ from django.utils.translation import ugettext as _
|
|||||||
from plinth import actions, views
|
from plinth import actions, views
|
||||||
from plinth.modules import mediawiki
|
from plinth.modules import mediawiki
|
||||||
|
|
||||||
from . import is_private_mode_enabled, is_public_registration_enabled
|
from . import (get_default_skin, is_private_mode_enabled,
|
||||||
|
is_public_registration_enabled)
|
||||||
from .forms import MediaWikiForm
|
from .forms import MediaWikiForm
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
@ -49,7 +50,8 @@ class MediaWikiAppView(views.AppView):
|
|||||||
initial = super().get_initial()
|
initial = super().get_initial()
|
||||||
initial.update({
|
initial.update({
|
||||||
'enable_public_registrations': is_public_registration_enabled(),
|
'enable_public_registrations': is_public_registration_enabled(),
|
||||||
'enable_private_mode': is_private_mode_enabled()
|
'enable_private_mode': is_private_mode_enabled(),
|
||||||
|
'default_skin': get_default_skin()
|
||||||
})
|
})
|
||||||
return initial
|
return initial
|
||||||
|
|
||||||
@ -64,13 +66,15 @@ class MediaWikiAppView(views.AppView):
|
|||||||
app_same = is_unchanged('is_enabled')
|
app_same = is_unchanged('is_enabled')
|
||||||
pub_reg_same = is_unchanged('enable_public_registrations')
|
pub_reg_same = is_unchanged('enable_public_registrations')
|
||||||
private_mode_same = is_unchanged('enable_private_mode')
|
private_mode_same = is_unchanged('enable_private_mode')
|
||||||
|
default_skin_same = is_unchanged('default_skin')
|
||||||
|
|
||||||
if new_config['password']:
|
if new_config['password']:
|
||||||
actions.superuser_run('mediawiki', ['change-password'],
|
actions.superuser_run('mediawiki', ['change-password'],
|
||||||
input=new_config['password'].encode())
|
input=new_config['password'].encode())
|
||||||
messages.success(self.request, _('Password updated'))
|
messages.success(self.request, _('Password updated'))
|
||||||
|
|
||||||
if app_same and pub_reg_same and private_mode_same:
|
if (app_same and pub_reg_same and private_mode_same
|
||||||
|
and default_skin_same):
|
||||||
if not self.request._messages._queued_messages:
|
if not self.request._messages._queued_messages:
|
||||||
messages.info(self.request, _('Setting unchanged'))
|
messages.info(self.request, _('Setting unchanged'))
|
||||||
elif not app_same:
|
elif not app_same:
|
||||||
@ -100,11 +104,11 @@ class MediaWikiAppView(views.AppView):
|
|||||||
if not private_mode_same:
|
if not private_mode_same:
|
||||||
if new_config['enable_private_mode']:
|
if new_config['enable_private_mode']:
|
||||||
actions.superuser_run('mediawiki', ['private-mode', 'enable'])
|
actions.superuser_run('mediawiki', ['private-mode', 'enable'])
|
||||||
|
messages.success(self.request, _('Private mode enabled'))
|
||||||
if new_config['enable_public_registrations']:
|
if new_config['enable_public_registrations']:
|
||||||
# If public registrations are enabled, then disable it
|
# If public registrations are enabled, then disable it
|
||||||
actions.superuser_run('mediawiki',
|
actions.superuser_run('mediawiki',
|
||||||
['public-registrations', 'disable'])
|
['public-registrations', 'disable'])
|
||||||
messages.success(self.request, _('Private mode enabled'))
|
|
||||||
else:
|
else:
|
||||||
actions.superuser_run('mediawiki', ['private-mode', 'disable'])
|
actions.superuser_run('mediawiki', ['private-mode', 'disable'])
|
||||||
messages.success(self.request, _('Private mode disabled'))
|
messages.success(self.request, _('Private mode disabled'))
|
||||||
@ -112,4 +116,9 @@ class MediaWikiAppView(views.AppView):
|
|||||||
shortcut = mediawiki.app.get_component('shortcut-mediawiki')
|
shortcut = mediawiki.app.get_component('shortcut-mediawiki')
|
||||||
shortcut.login_required = new_config['enable_private_mode']
|
shortcut.login_required = new_config['enable_private_mode']
|
||||||
|
|
||||||
|
if not default_skin_same:
|
||||||
|
actions.superuser_run(
|
||||||
|
'mediawiki', ['set-default-skin', new_config['default_skin']])
|
||||||
|
messages.success(self.request, _('Default skin changed'))
|
||||||
|
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user