From 8a4fd1def4476836fd50561da125e7686fa57ff9 Mon Sep 17 00:00:00 2001 From: Sunil Mohan Adapa Date: Mon, 30 Dec 2019 14:44:15 -0800 Subject: [PATCH] mediawiki: Fix problem with session cache failing logins Set the session cache to use database. This will also have the added benefit of sessions persisting across reboots (and PHP session cleanups). See bug report on why this is needed. https://salsa.debian.org/freedombox-team/plinth/issues/1736 We are unfortunately modifying the MediaWiki settings that file that we are shipping when preferences are modified in the FreedomBox UI. This means that if a newer version of this settings file is shipped, then FreedomBox package will show configuration file prompts. To solve this, introduce a new static settings file that will have lower priority than the file modified by FreedomBox UI. Closes: #1736. Tests: - Test that running FreedomBox daemon with changes runs the MediaWiki app's setup and introduces the new line into LocalSettings.php - That LocalSettings.php will be populated with lines to include FreedomBoxStaticSettings.php and FreedomBoxSettings.php in that order when 'actions/mediawiki setup' is run. This should work when no lines are present, one of the lines is already present and both the lines are already present. - Test that running './setup.py install' installs FreedomBoxStaticSettings.php. - Test that MediaWiki runs without FreedomBoxStaticSettings.php - Test that private wiki and public registrations settings work with the new changes. - Run functional tests for MediaWiki app with the changes. Signed-off-by: Sunil Mohan Adapa Reviewed-by: James Valleroy --- actions/mediawiki | 32 ++++++++++++---- plinth/modules/mediawiki/__init__.py | 2 +- .../mediawiki/FreedomBoxStaticSettings.php | 37 +++++++++++++++++++ 3 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 plinth/modules/mediawiki/data/etc/mediawiki/FreedomBoxStaticSettings.php diff --git a/actions/mediawiki b/actions/mediawiki index c12a5eaa9..eada16fb4 100755 --- a/actions/mediawiki +++ b/actions/mediawiki @@ -25,7 +25,7 @@ import subprocess import sys import tempfile -from plinth.utils import generate_password, grep +from plinth.utils import generate_password MAINTENANCE_SCRIPTS_DIR = "/usr/share/mediawiki/maintenance" CONF_FILE = '/etc/mediawiki/FreedomBoxSettings.php' @@ -87,12 +87,30 @@ def subcommand_setup(_): def include_custom_config(): - """Include FreedomBox specific configuration in LocalSettings.php - """ - if not grep(r'FreedomBoxSettings', LOCAL_SETTINGS_CONF): - with open(LOCAL_SETTINGS_CONF, 'a') as conf_file: - conf_file.write( - 'include dirname(__FILE__)."/FreedomBoxSettings.php";\n') + """Include FreedomBox specific configuration in LocalSettings.php.""" + with open(LOCAL_SETTINGS_CONF, 'r') as conf_file: + lines = conf_file.readlines() + + static_settings_index = None + settings_index = None + for line_number, line in enumerate(lines): + if 'FreedomBoxSettings.php' in line: + settings_index = line_number + + if 'FreedomBoxStaticSettings.php' in line: + static_settings_index = line_number + + if settings_index is None: + settings_index = len(lines) + lines.append('include dirname(__FILE__)."/FreedomBoxSettings.php";\n') + + if static_settings_index is None: + lines.insert( + settings_index, + 'include dirname(__FILE__)."/FreedomBoxStaticSettings.php";\n') + + with open(LOCAL_SETTINGS_CONF, 'w') as conf_file: + conf_file.writelines(lines) def subcommand_change_password(arguments): diff --git a/plinth/modules/mediawiki/__init__.py b/plinth/modules/mediawiki/__init__.py index 00a2bda31..66320d118 100644 --- a/plinth/modules/mediawiki/__init__.py +++ b/plinth/modules/mediawiki/__init__.py @@ -29,7 +29,7 @@ from plinth.modules.firewall.components import Firewall from .manifest import backup, clients # noqa, pylint: disable=unused-import -version = 6 +version = 7 managed_packages = ['mediawiki', 'imagemagick', 'php-sqlite3'] diff --git a/plinth/modules/mediawiki/data/etc/mediawiki/FreedomBoxStaticSettings.php b/plinth/modules/mediawiki/data/etc/mediawiki/FreedomBoxStaticSettings.php new file mode 100644 index 000000000..4b77aa163 --- /dev/null +++ b/plinth/modules/mediawiki/data/etc/mediawiki/FreedomBoxStaticSettings.php @@ -0,0 +1,37 @@ +