From f3621a274de3cdf1992b36a347ea36c495242e1f Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Sun, 9 Apr 2023 15:58:13 +0530 Subject: [PATCH] mediawiki: Make retrieving list of supported languages robust - Invoke PHP command to retrieve the list instead of parsing PHP file. This fixes issue with regex not being generic enough to retrieve languages list using double quotes. Also make is much more robust to future formatting changes. - If there is an error in retrieving, which may happen due to future code changes, fall back to showing a safe list of languages instead of making the app unusable. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- plinth/modules/mediawiki/forms.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/plinth/modules/mediawiki/forms.py b/plinth/modules/mediawiki/forms.py index 81e29f56b..5843b99a0 100644 --- a/plinth/modules/mediawiki/forms.py +++ b/plinth/modules/mediawiki/forms.py @@ -3,13 +3,17 @@ FreedomBox app for configuring MediaWiki. """ +import json +import logging import pathlib -import re +import subprocess from django import forms from django.core import validators from django.utils.translation import gettext_lazy as _ +from . import privileged + def get_skins(): """Return a list of available skins as choice field values.""" @@ -31,12 +35,19 @@ def get_languages(): if not names_old.exists(): names_file = names_new - with open(names_file, 'r') as lang_file: - content = lang_file.read() - matches = re.findall(r"'([a-z_-]+)' => '(.+)', # .+", content) - language_choices = [(code, name) for code, name in matches] - - return language_choices + script = rf'''