From 4cfa361e0a9900586364dfd9be895ce4f99f967d Mon Sep 17 00:00:00 2001 From: Meirza Date: Fri, 18 Aug 2023 13:56:42 +0700 Subject: [PATCH] MDL-78468 admin: Removed devicedetectregex theme setting --- ...resets_admin_setting_devicedetectregex.php | 11 +++++++ admin/settings/appearance.php | 1 - .../setting_devicedetectregex.mustache | 2 ++ admin/upgrade.txt | 3 ++ lang/en/admin.php | 10 +++--- lang/en/deprecated.txt | 4 +++ lib/adminlib.php | 30 ++++++++++++++++++ lib/classes/useragent.php | 31 ++++++------------- lib/tests/theme_config_test.php | 29 ----------------- 9 files changed, 64 insertions(+), 57 deletions(-) diff --git a/admin/presets/classes/local/setting/adminpresets_admin_setting_devicedetectregex.php b/admin/presets/classes/local/setting/adminpresets_admin_setting_devicedetectregex.php index 0ff584f6873..e881a95fa81 100644 --- a/admin/presets/classes/local/setting/adminpresets_admin_setting_devicedetectregex.php +++ b/admin/presets/classes/local/setting/adminpresets_admin_setting_devicedetectregex.php @@ -19,6 +19,8 @@ namespace core_adminpresets\local\setting; /** * Reimplementation to allow human friendly view of the selected regexps. * + * @deprecated Moodle 4.3 MDL-78468 - No longer used since the devicedetectregex was removed. + * @todo Final deprecation on Moodle 4.7 MDL-79052 * @package core_adminpresets * @copyright 2021 Pimenko * @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó code @@ -26,7 +28,16 @@ namespace core_adminpresets\local\setting; */ class adminpresets_admin_setting_devicedetectregex extends adminpresets_admin_setting_configtext { + /** + * @deprecated Moodle 4.3 MDL-78468 - No longer used since the devicedetectregex was removed. + * @todo Final deprecation on Moodle 4.7 MDL-79052 + */ public function set_visiblevalue() { + debugging( + __FUNCTION__ . '() is deprecated.' . + 'All functions associated with devicedetectregex theme setting are being removed.', + DEBUG_DEVELOPER + ); $values = json_decode($this->get_value()); if (!$values) { diff --git a/admin/settings/appearance.php b/admin/settings/appearance.php index 0c21a5af480..c2701e897e9 100644 --- a/admin/settings/appearance.php +++ b/admin/settings/appearance.php @@ -46,7 +46,6 @@ reports,core_reportbuilder|/reportbuilder/index.php', '50', '10' )); - $temp->add(new admin_setting_devicedetectregex('devicedetectregex', new lang_string('devicedetectregex', 'admin'), new lang_string('devicedetectregex_desc', 'admin'), '')); $ADMIN->add('themes', $temp); $ADMIN->add('themes', new admin_externalpage('themeselector', new lang_string('themeselector','admin'), $CFG->wwwroot . '/theme/index.php')); diff --git a/admin/templates/setting_devicedetectregex.mustache b/admin/templates/setting_devicedetectregex.mustache index 97f97f250ef..bebaf4d9e97 100644 --- a/admin/templates/setting_devicedetectregex.mustache +++ b/admin/templates/setting_devicedetectregex.mustache @@ -15,6 +15,8 @@ along with Moodle. If not, see . }} {{! + @deprecated since Moodle 4.3 + @todo Final deprecation on Moodle 4.7 MDL-79052 @template core_admin/setting_devicedetectregex Admin devicedetectregex setting template. diff --git a/admin/upgrade.txt b/admin/upgrade.txt index a9036ec013c..2f76124b45b 100644 --- a/admin/upgrade.txt +++ b/admin/upgrade.txt @@ -10,6 +10,9 @@ This files describes API changes in /admin/*. Existing cookies will not be affected by this change, until they are expired or deleted. * Theme setting "Enable device detection" (enabledevicedetection) and related to it has been removed. +* Theme setting "Device detection regular expressions" (devicedetectregex) and related to it has been removed. +* Class adminpresets_admin_setting_devicedetectregex has been deprecated. +* The admin_setting_devicedetectregex class has been deprecated. === 4.2 === diff --git a/lang/en/admin.php b/lang/en/admin.php index 299f2d2da28..c8b077ba046 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -518,11 +518,6 @@ $string['density'] = 'Density'; $string['denyemailaddresses'] = 'Denied email domains'; $string['devlibdirpresent'] = 'Directories with development libraries, especially /vendor and /node_modules, should not be present on public sites. See the security overview report for more details.'; $string['development'] = 'Development'; -$string['devicedetectregex'] = 'Device detection regular expressions'; -$string['devicedetectregex_desc'] = '

By default, Moodle can detect devices of the type default (desktop PCs, laptops, etc), mobile (phones and small hand held devices), tablet (iPads, Android tablets) and legacy (Internet Explorer 6 users). The theme selector can be used to apply separate themes to all of these. This setting allows regular expressions that allow the detection of extra device types (these take precedence over the default types).

-

For example, you could enter the regular expression \'/(MIDP-1.0|Maemo|Windows CE)/\' to detect some commonly used feature phones add the return value \'featurephone\'. This adds \'featurephone\' on the theme selector that would allow you to add a theme that would be used on these devices. Other phones would still use the theme selected for the mobile device type.

'; -$string['devicedetectregexexpression'] = 'Regular expression'; -$string['devicedetectregexvalue'] = 'Return value'; $string['devicetype'] = 'Device type'; $string['disabled'] = 'Disabled'; $string['disableplugin'] = 'Disable {$a}'; @@ -1623,6 +1618,11 @@ $string['blockunprotect'] = 'Unprotect'; // Deprecated since Moodle 4.3. $string['configenabledevicedetection'] = 'Enables detection of mobiles, smartphones, tablets or default devices (desktop PCs, laptops, etc) for the application of themes and other features.'; +$string['devicedetectregex'] = 'Device detection regular expressions'; +$string['devicedetectregex_desc'] = '

By default, Moodle can detect devices of the type default (desktop PCs, laptops, etc), mobile (phones and small hand held devices), tablet (iPads, Android tablets) and legacy (Internet Explorer 6 users). The theme selector can be used to apply separate themes to all of these. This setting allows regular expressions that allow the detection of extra device types (these take precedence over the default types).

+

For example, you could enter the regular expression \'/(MIDP-1.0|Maemo|Windows CE)/\' to detect some commonly used feature phones add the return value \'featurephone\'. This adds \'featurephone\' on the theme selector that would allow you to add a theme that would be used on these devices. Other phones would still use the theme selected for the mobile device type.

'; +$string['devicedetectregexexpression'] = 'Regular expression'; +$string['devicedetectregexvalue'] = 'Return value'; $string['enabledevicedetection'] = 'Enable device detection'; $string['selectdevice'] = 'Select device'; $string['selecttheme'] = 'Select theme for {$a} device'; diff --git a/lang/en/deprecated.txt b/lang/en/deprecated.txt index b7928e90496..5caa4c6248d 100644 --- a/lang/en/deprecated.txt +++ b/lang/en/deprecated.txt @@ -86,3 +86,7 @@ editcoursecompletionsettings,core_completion clicktochangeinbrackets,core configenabledevicedetection,core_admin enabledevicedetection,core_admin +devicedetectregex,core_admin +devicedetectregex_desc,core_admin +devicedetectregexexpression,core_admin +devicedetectregexvalue,core_admin diff --git a/lib/adminlib.php b/lib/adminlib.php index ad81ea2664a..cca2cc34c32 100644 --- a/lib/adminlib.php +++ b/lib/adminlib.php @@ -10689,6 +10689,8 @@ class admin_setting_configstoredfile extends admin_setting { /** * Administration interface for user specified regular expressions for device detection. * + * @deprecated Moodle 4.3 MDL-78468 - No longer used since the devicedetectregex was removed. + * @todo Final deprecation on Moodle 4.7 MDL-79052 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class admin_setting_devicedetectregex extends admin_setting { @@ -10696,12 +10698,19 @@ class admin_setting_devicedetectregex extends admin_setting { /** * Calls parent::__construct with specific args * + * @deprecated Moodle 4.3 MDL-78468 - No longer used since the devicedetectregex was removed. + * @todo Final deprecation on Moodle 4.7 MDL-79052 * @param string $name * @param string $visiblename * @param string $description * @param mixed $defaultsetting */ public function __construct($name, $visiblename, $description, $defaultsetting = '') { + debugging( + __FUNCTION__ . '() is deprecated.' . + 'All functions associated with devicedetectregex theme setting are being removed.', + DEBUG_DEVELOPER + ); global $CFG; parent::__construct($name, $visiblename, $description, $defaultsetting); } @@ -10709,9 +10718,16 @@ class admin_setting_devicedetectregex extends admin_setting { /** * Return the current setting(s) * + * @deprecated Moodle 4.3 MDL-78468 - No longer used since the devicedetectregex was removed. + * @todo Final deprecation on Moodle 4.7 MDL-79052 * @return array Current settings array */ public function get_setting() { + debugging( + __FUNCTION__ . '() is deprecated.' . + 'All functions associated with devicedetectregex theme setting are being removed.', + DEBUG_DEVELOPER + ); global $CFG; $config = $this->config_read($this->name); @@ -10725,10 +10741,17 @@ class admin_setting_devicedetectregex extends admin_setting { /** * Save selected settings * + * @deprecated Moodle 4.3 MDL-78468 - No longer used since the devicedetectregex was removed. + * @todo Final deprecation on Moodle 4.7 MDL-79052 * @param array $data Array of settings to save * @return bool */ public function write_setting($data) { + debugging( + __FUNCTION__ . '() is deprecated.' . + 'All functions associated with devicedetectregex theme setting are being removed.', + DEBUG_DEVELOPER + ); if (empty($data)) { $data = array(); } @@ -10743,10 +10766,17 @@ class admin_setting_devicedetectregex extends admin_setting { /** * Return XHTML field(s) for regexes * + * @deprecated Moodle 4.3 MDL-78468 - No longer used since the devicedetectregex was removed. + * @todo Final deprecation on Moodle 4.7 MDL-79052 * @param array $data Array of options to set in HTML * @return string XHTML string for the fields and wrapping div(s) */ public function output_html($data, $query='') { + debugging( + __FUNCTION__ . '() is deprecated.' . + 'All functions associated with devicedetectregex theme setting are being removed.', + DEBUG_DEVELOPER + ); global $OUTPUT; $context = (object) [ diff --git a/lib/classes/useragent.php b/lib/classes/useragent.php index b984928180a..43f94af2234 100644 --- a/lib/classes/useragent.php +++ b/lib/classes/useragent.php @@ -86,12 +86,6 @@ class core_useragent { */ protected $devicetype = null; - /** - * Custom device types entered into the admin interface. - * @var array - */ - protected $devicetypecustoms = array(); - /** * True if the user agent supports the display of svg images. False if not. * @var bool|null Null until initialised, then true or false. @@ -118,15 +112,6 @@ class core_useragent { * @param string|null $forceuseragent Optional a user agent to force. */ protected function __construct($forceuseragent = null) { - global $CFG; - if (!empty($CFG->devicedetectregex)) { - $this->devicetypecustoms = json_decode($CFG->devicedetectregex, true); - } - if ($this->devicetypecustoms === null) { - // This shouldn't happen unless you're hardcoding the config value. - debugging('Config devicedetectregex is not valid JSON object'); - $this->devicetypecustoms = array(); - } if ($forceuseragent !== null) { $this->useragent = $forceuseragent; } else if (!empty($_SERVER['HTTP_USER_AGENT'])) { @@ -176,12 +161,6 @@ class core_useragent { * @return string */ protected function guess_device_type() { - foreach ($this->devicetypecustoms as $value => $regex) { - if (preg_match($regex, $this->useragent)) { - $this->devicetype = $value; - return $this->devicetype; - } - } if ($this->is_useragent_mobile()) { $this->devicetype = self::DEVICETYPE_MOBILE; } else if ($this->is_useragent_tablet()) { @@ -230,10 +209,18 @@ class core_useragent { /** * Gets a list of known device types. * + * @deprecated Moodle 4.3 MDL-78468 - No longer used. Please use core_useragent::devicetypes instead. + * @todo Final deprecation on Moodle 4.7 MDL-79052 * @param bool $includecustomtypes If set to true we'll include types that have been added by the admin. * @return array */ public static function get_device_type_list($includecustomtypes = true) { + debugging( + __FUNCTION__ . '() is deprecated.' . + 'All functions associated with devicedetectregex theme setting are being removed. + Please use core_useragent::devicetypes instead', + DEBUG_DEVELOPER + ); $types = self::$devicetypes; if ($includecustomtypes) { $instance = self::instance(); @@ -313,7 +300,7 @@ class core_useragent { unset_user_preference('switchdevice'.$devicetype); return true; } else { - $devicetypes = self::get_device_type_list(); + $devicetypes = self::$devicetypes; if (in_array($newdevice, $devicetypes)) { set_user_preference('switchdevice'.$devicetype, $newdevice); return true; diff --git a/lib/tests/theme_config_test.php b/lib/tests/theme_config_test.php index 1c62f3a6f6c..773f05b7a40 100644 --- a/lib/tests/theme_config_test.php +++ b/lib/tests/theme_config_test.php @@ -129,35 +129,6 @@ class theme_config_test extends advanced_testcase { } } - /** - * This function will test custom device detection regular expression setting. - * - * @covers \core_useragent - */ - public function test_devicedetectregex() { - global $CFG; - - $this->resetAfterTest(); - - // Check config currently empty. - $this->assertEmpty(json_decode($CFG->devicedetectregex)); - $this->assertTrue(core_useragent::set_user_device_type('tablet')); - $exceptionoccured = false; - try { - core_useragent::set_user_device_type('featurephone'); - } catch (moodle_exception $e) { - $exceptionoccured = true; - } - $this->assertTrue($exceptionoccured); - - // Set config and recheck. - $config = array('featurephone' => '(Symbian|MIDP-1.0|Maemo|Windows CE)'); - $CFG->devicedetectregex = json_encode($config); - core_useragent::instance(true); // Clears singleton cache. - $this->assertTrue(core_useragent::set_user_device_type('tablet')); - $this->assertTrue(core_useragent::set_user_device_type('featurephone')); - } - /** * Confirm that the editor_css_url contains the theme revision and the * theme subrevision if not in theme designer mode.