Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] safe-mode #44765

Open
wants to merge 9 commits into
base: 5.3-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS `#__noncore_extensions_safemode` (
`extension_id` INT NOT NULL,
`name` VARCHAR(100) NOT NULL,
`type` VARCHAR(20) NOT NULL,
`element` VARCHAR(100) NOT NULL,
`time` TIMESTAMP NOT NULL,
PRIMARY KEY (`extension_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;

INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`, `client_id`, `enabled`, `access`, `protected`, `locked`, `manifest_cache`, `params`, `custom_data`, `ordering`, `state`) VALUES
(0, 'plg_system_safemode', 'plugin', 'safemode', 'system', 0, 1, 1, 0, 0, '', '{}', '', 55, 0);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CREATE TABLE IF NOT EXISTS "#__noncore_extensions_safemode" (
"extension_id" BIGINT NOT NULL,
"name" VARCHAR(100) NOT NULL,
"type" VARCHAR(20) NOT NULL,
"element" VARCHAR(100) NOT NULL,
"time" TIMESTAMP NOT NULL,
PRIMARY KEY ("extension_id")
);

INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder", "client_id", "enabled", "access", "protected", "locked", "manifest_cache", "params", "custom_data", "ordering", "state") VALUES
(0, 'plg_system_safemode', 'plugin', 'safemode', 'system', 0, 1, 1, 0, 0, '', '{}', '', 55, 0);
13 changes: 13 additions & 0 deletions administrator/components/com_config/forms/application.xml
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@
<option value="1">COM_CONFIG_FIELD_DEBUG_VALUE</option>
</field>

<field
name="safemode"
type="radio"
label="COM_CONFIG_FIELD_DEBUG_SAFEMODE_LABEL"
description="COM_CONFIG_FIELD_DEBUG_SAFEMODE_DESC"
alikon marked this conversation as resolved.
Show resolved Hide resolved
layout="joomla.form.field.radio.switcher"
default="0"
filter="boolean"
>
<option value="0">JOFF</option>
<option value="1">JON</option>
</field>

</fieldset>

<fieldset name="webservices" label="CONFIG_WEBSERVICES_SETTINGS_LABEL">
Expand Down
2 changes: 2 additions & 0 deletions administrator/language/en-GB/com_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ COM_CONFIG_FIELD_DEBUG_CONST_LANG_DESC="Select if you should display the languag
COM_CONFIG_FIELD_DEBUG_CONST_LANG_LABEL="Language Display"
COM_CONFIG_FIELD_DEBUG_LANG_DESC="Displays <strong><code>??</code></strong> around a language string constant when the string is not present in the currently loaded language files or <strong><code>**</code></strong> around the string value when the string is present. If none of the above is displayed, it could mean the text is hardcoded and needs a language string."
COM_CONFIG_FIELD_DEBUG_LANG_LABEL="Debug Language"
COM_CONFIG_FIELD_DEBUG_SAFEMODE_LABEL="Safe Mode"
COM_CONFIG_FIELD_DEBUG_SAFEMODE_DESC="When switched on, it will disable third party plugin extensions on your site. This can be useful for troubleshooting."
COM_CONFIG_FIELD_DEBUG_SYSTEM_DESC="Use it only for troubleshooting, ideally on <em>private</em> copies of your site. The more technical information displayed in this mode can be a security risk if left enabled on live sites. Remember to publish the \"System - Debug\" plugin to get detailed information on each page being loaded."
COM_CONFIG_FIELD_DEBUG_SYSTEM_LABEL="Debug System"
COM_CONFIG_FIELD_DEBUG_VALUE="Value"
Expand Down
13 changes: 13 additions & 0 deletions administrator/language/en-GB/plg_system_safemode.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
; Joomla! Project
; (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_SYSTEM_SAFEMODE="System - Joomla! SafeMode"
PLG_SYSTEM_SAFEMODE_DEFAULT_AUTHENTICATION_PLUGIN_NOT_ENABLED="The default authentication plugin is not enabled"
alikon marked this conversation as resolved.
Show resolved Hide resolved
PLG_SYSTEM_SAFEMODE_OFF="Safe Mode is switched off."
PLG_SYSTEM_SAFEMODE_ON="Safe Mode is switched on."
PLG_SYSTEM_SAFEMODE_INSTALLED_NONCORE_WHEN_SAFEMODEON="You have installed non-core plugins when Safe Mode is on."
PLG_SYSTEM_SAFEMODE_PUBLISH_NONCORE_WHEN_SAFEMODEON="You have published non-core extensions when Safe Mode is on."
PLG_SYSTEM_SAFEMODE_UPDATED_NONCORE_WHEN_SAFEMODEON="You have updated non-core plugins when Safe Mode is on."
PLG_SYSTEM_SAFEMODE_XML_DESCRIPTION="System Plugin that controls the safe mode."
7 changes: 7 additions & 0 deletions administrator/language/en-GB/plg_system_safemode.sys.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
; Joomla! Project
; (C) 2015 Open Source Matters, Inc. <https://www.joomla.org>
; License GNU General Public License version 2 or later; see LICENSE.txt
; Note : All ini files need to be saved as UTF-8

PLG_SYSTEM_SAFEMODE="System - Joomla! SafeMode"
PLG_SYSTEM_SAFEMODE_XML_DESCRIPTION="System Plugin that controls the safe mode."
16 changes: 13 additions & 3 deletions installation/sql/mysql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -358,9 +358,10 @@ INSERT INTO `#__extensions` (`package_id`, `name`, `type`, `element`, `folder`,
(0, 'plg_system_privacyconsent', 'plugin', 'privacyconsent', 'system', 0, 0, 1, 0, 1, '', '{}', '', 14, 0),
(0, 'plg_system_redirect', 'plugin', 'redirect', 'system', 0, 0, 1, 0, 1, '', '', '', 15, 0),
(0, 'plg_system_remember', 'plugin', 'remember', 'system', 0, 1, 1, 0, 1, '', '', '', 16, 0),
(0, 'plg_system_schedulerunner', 'plugin', 'schedulerunner', 'system', 0, 1, 1, 0, 1, '', '{}', '', 17, 0),
(0, 'plg_system_schemaorg', 'plugin', 'schemaorg', 'system', 0, 1, 1, 0, 0, '', '{}', '', 18, 0),
(0, 'plg_system_sef', 'plugin', 'sef', 'system', 0, 1, 1, 0, 1, '', '{"domain":"","indexphp":"1","trailingslash":"0","enforcesuffix":"1","strictrouting":"1"}', '', 19, 0),
(0, 'plg_system_safemode', 'plugin', 'safemode', 'system', 0, 1, 1, 0, 1, '', '{}', '', 17, 0),
(0, 'plg_system_schedulerunner', 'plugin', 'schedulerunner', 'system', 0, 1, 1, 0, 1, '', '{}', '', 18, 0),
(0, 'plg_system_schemaorg', 'plugin', 'schemaorg', 'system', 0, 1, 1, 0, 0, '', '{}', '', 19, 0),
(0, 'plg_system_sef', 'plugin', 'sef', 'system', 0, 1, 1, 0, 1, '', '{"domain":"","indexphp":"1","trailingslash":"0","enforcesuffix":"1","strictrouting":"1"}', '', 20, 0),
(0, 'plg_system_shortcut', 'plugin', 'shortcut', 'system', 0, 1, 1, 0, 1, '', '{}', '', 21, 0),
(0, 'plg_system_skipto', 'plugin', 'skipto', 'system', 0, 1, 1, 0, 1, '', '{}', '', 22, 0),
(0, 'plg_system_stats', 'plugin', 'stats', 'system', 0, 1, 1, 0, 1, '', '', '', 23, 0),
Expand Down Expand Up @@ -1256,3 +1257,12 @@ INSERT INTO `#__workflow_transitions` (`id`, `asset_id`, `published`, `ordering`
(5, 62, 1, 5, 1, 'FEATURE', '', -1, 1, '{"featuring":"1"}'),
(6, 63, 1, 6, 1, 'UNFEATURE', '', -1, 1, '{"featuring":"0"}'),
(7, 64, 1, 7, 1, 'PUBLISH_AND_FEATURE', '', -1, 1, '{"publishing":"1","featuring":"1"}');

CREATE TABLE IF NOT EXISTS `#__noncore_extensions_safemode` (
`extension_id` INT NOT NULL,
`name` VARCHAR(100) NOT NULL,
`type` VARCHAR(20) NOT NULL,
`element` VARCHAR(100) NOT NULL,
`time` TIMESTAMP NOT NULL,
PRIMARY KEY (`extension_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci;
16 changes: 13 additions & 3 deletions installation/sql/postgresql/base.sql
Original file line number Diff line number Diff line change
Expand Up @@ -364,9 +364,10 @@ INSERT INTO "#__extensions" ("package_id", "name", "type", "element", "folder",
(0, 'plg_system_privacyconsent', 'plugin', 'privacyconsent', 'system', 0, 0, 1, 0, 1, '', '{}', '', 14, 0),
(0, 'plg_system_redirect', 'plugin', 'redirect', 'system', 0, 0, 1, 0, 1, '', '', '', 15, 0),
(0, 'plg_system_remember', 'plugin', 'remember', 'system', 0, 1, 1, 0, 1, '', '', '', 16, 0),
(0, 'plg_system_schedulerunner', 'plugin', 'schedulerunner', 'system', 0, 1, 1, 0, 1, '', '{}', '', 17, 0),
(0, 'plg_system_schemaorg', 'plugin', 'schemaorg', 'system', 0, 1, 1, 0, 0, '', '{}', '', 18, 0),
(0, 'plg_system_sef', 'plugin', 'sef', 'system', 0, 1, 1, 0, 1, '', '{"domain":"","indexphp":"1","trailingslash":"0","enforcesuffix":"1","strictrouting":"1"}', '', 19, 0),
(0, 'plg_system_safemode', 'plugin', 'safemode', 'system', 0, 1, 1, 0, 1, '', '{}', '', 17, 0),
(0, 'plg_system_schedulerunner', 'plugin', 'schedulerunner', 'system', 0, 1, 1, 0, 1, '', '{}', '', 18, 0),
(0, 'plg_system_schemaorg', 'plugin', 'schemaorg', 'system', 0, 1, 1, 0, 0, '', '{}', '', 19, 0),
(0, 'plg_system_sef', 'plugin', 'sef', 'system', 0, 1, 1, 0, 1, '', '{"domain":"","indexphp":"1","trailingslash":"0","enforcesuffix":"1","strictrouting":"1"}', '', 20, 0),
(0, 'plg_system_shortcut', 'plugin', 'shortcut', 'system', 0, 1, 1, 0, 1, '', '{}', '', 21, 0),
(0, 'plg_system_skipto', 'plugin', 'skipto', 'system', 0, 1, 1, 0, 1, '', '{}', '', 22, 0),
(0, 'plg_system_stats', 'plugin', 'stats', 'system', 0, 1, 1, 0, 1, '', '', '', 23, 0),
Expand Down Expand Up @@ -1279,3 +1280,12 @@ INSERT INTO "#__workflow_transitions" ("id", "asset_id", "published", "ordering"
(7, 64, 1, 7, 1, 'PUBLISH_AND_FEATURE', '', -1, 1, '{"publishing":"1","featuring":"1"}');

SELECT setval('#__workflow_transitions_id_seq', 8, false);

CREATE TABLE IF NOT EXISTS "#__noncore_extensions_safemode" (
"extension_id" BIGINT NOT NULL,
"name" VARCHAR(100) NOT NULL,
"type" VARCHAR(20) NOT NULL,
"element" VARCHAR(100) NOT NULL,
"time" TIMESTAMP NOT NULL,
PRIMARY KEY ("extension_id")
);
1 change: 1 addition & 0 deletions libraries/src/Extension/ExtensionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ class ExtensionHelper
['plugin', 'privacyconsent', 'system', 0],
['plugin', 'redirect', 'system', 0],
['plugin', 'remember', 'system', 0],
['plugin', 'safemode', 'system', 0],
['plugin', 'schedulerunner', 'system', 0],
['plugin', 'schemaorg', 'system', 0],
['plugin', 'sef', 'system', 0],
Expand Down
22 changes: 22 additions & 0 deletions plugins/system/safemode/safemode.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension type="plugin" group="system" method="upgrade">
<name>plg_system_safemode</name>
<author>Joomla! Project</author>
<creationDate>2025-01</creationDate>
<copyright>(C) 2025 Open Source Matters, Inc.</copyright>
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
<authorEmail>[email protected]</authorEmail>
<authorUrl>www.joomla.org</authorUrl>
<version>5.3</version>
<description>PLG_SYSTEM_SAFEMODE_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\System\SafeMode</namespace>
<files>
<folder>forms</folder>
<folder plugin="safemode">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_system_safemode.ini</language>
<language tag="en-GB">language/en-GB/plg_system_safemode.sys.ini</language>
</languages>
</extension>
50 changes: 50 additions & 0 deletions plugins/system/safemode/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage System.safemode
*
* @copyright (C) 2025 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

\defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\User\UserFactoryInterface;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\System\SafeMode\Extension\SafeMode;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since 4.4.0
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$plugin = new SafeMode(
$container->get(DispatcherInterface::class),
(array) PluginHelper::getPlugin('system', 'safemode')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));
$plugin->setUserFactory($container->get(UserFactoryInterface::class));

return $plugin;
}
);
}
};
Loading