MDL-78468 admin: Removed devicedetectregex theme setting

This commit is contained in:
Meirza
2023-08-22 09:47:36 +07:00
parent 352e427520
commit 4cfa361e0a
9 changed files with 64 additions and 57 deletions
@@ -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 <[email protected]><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <[email protected]> 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) {
-1
View File
@@ -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'));
@@ -15,6 +15,8 @@
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@deprecated since Moodle 4.3
@todo Final deprecation on Moodle 4.7 MDL-79052
@template core_admin/setting_devicedetectregex
Admin devicedetectregex setting template.
+3
View File
@@ -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 ===
+5 -5
View File
@@ -518,11 +518,6 @@ $string['density'] = 'Density';
$string['denyemailaddresses'] = 'Denied email domains';
$string['devlibdirpresent'] = 'Directories with development libraries, especially <em>/vendor</em> and <em>/node_modules</em>, should not be present on public sites. See the <a href="{$a->moreinfourl}">security overview report</a> for more details.';
$string['development'] = 'Development';
$string['devicedetectregex'] = 'Device detection regular expressions';
$string['devicedetectregex_desc'] = '<p>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).</p>
<p>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.</p>';
$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'] = '<p>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).</p>
<p>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.</p>';
$string['devicedetectregexexpression'] = 'Regular expression';
$string['devicedetectregexvalue'] = 'Return value';
$string['enabledevicedetection'] = 'Enable device detection';
$string['selectdevice'] = 'Select device';
$string['selecttheme'] = 'Select theme for {$a} device';
+4
View File
@@ -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
+30
View File
@@ -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) [
+9 -22
View File
@@ -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;
-29
View File
@@ -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.