Skip to content

Commit

Permalink
Merge branch 'MDL-78468-master' of https://github.com/meirzamoodle/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Aug 22, 2023
2 parents d7ad0f8 + 38a0173 commit 9b2917f
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 66 deletions.
Expand Up @@ -19,14 +19,25 @@
/**
* 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 <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> code
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
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) {
Expand Down
2 changes: 0 additions & 2 deletions admin/settings/appearance.php
Expand Up @@ -46,8 +46,6 @@
'50',
'10'
));
$temp->add(new admin_setting_configcheckbox('enabledevicedetection', new lang_string('enabledevicedetection', 'admin'), new lang_string('configenabledevicedetection', 'admin'), 1));
$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'));

Expand Down
2 changes: 2 additions & 0 deletions admin/templates/setting_devicedetectregex.mustache
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions admin/upgrade.txt
Expand Up @@ -9,6 +9,10 @@ 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 ===

Expand Down
14 changes: 7 additions & 7 deletions lang/en/admin.php
Expand Up @@ -235,7 +235,6 @@
$string['configdenyemailaddresses'] = 'To deny email addresses from particular domains list them here in the same way. All other domains will be accepted. To deny subdomains add the domain with a preceding \'.\'. eg <strong>hotmail.com yahoo.co.uk .live.com</strong>';
$string['configenableanalytics'] = 'Analytics models, such as \'Students at risk of dropping out\' or \'Upcoming activities due\', can generate predictions, send insight notifications and offer further actions such as messaging users.';
$string['configenableblogs'] = 'This switch provides all site users with their own blog.';
$string['configenabledevicedetection'] = 'Enables detection of mobiles, smartphones, tablets or default devices (desktop PCs, laptops, etc) for the application of themes and other features.';
$string['configdisableuserimages'] = 'Disable the ability for users to change user profile images.';
$string['configdisplayloginfailures'] = 'This will display information to users about previous failed logins.';
$string['configdndallowtextandlinks'] = 'Enable or disable the dragging and dropping of text and links onto a course page, alongside the dragging and dropping of files. Note that the dragging of text into Firefox or between different browsers is unreliable and may result in no data being uploaded, or corrupted text being uploaded.';
Expand Down Expand Up @@ -519,11 +518,6 @@
$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}';
Expand Down Expand Up @@ -595,7 +589,6 @@
$string['enabled'] = 'Enabled';
$string['enabledashboard'] = 'Enable Dashboard';
$string['enabledashboard_help'] = 'The Dashboard shows Timeline, Calendar and Recently accessed items by default. You can set a different default Dashboard for everyone and allow users to customise their own Dashboard. If disabled, you need to set \'Start page for users\' to a value other than Dashboard.';
$string['enabledevicedetection'] = 'Enable device detection';
$string['enableglobalsearch'] = 'Enable global search';
$string['enableglobalsearch_desc'] = 'If enabled, data will be indexed and synchronised by a scheduled task.';
$string['enablegravatar'] = 'Enable Gravatar';
Expand Down Expand Up @@ -1624,6 +1617,13 @@
$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';
$string['themenoselected'] = 'No theme selected';
Expand Down
6 changes: 6 additions & 0 deletions lang/en/deprecated.txt
Expand Up @@ -84,3 +84,9 @@ backpackemail,core_badges
backpackemail_help,core_badges
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 changes: 30 additions & 0 deletions lib/adminlib.php
Expand Up @@ -10689,29 +10689,45 @@ public function output_html($data, $query = '') {
/**
* 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 {

/**
* 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);
}

/**
* 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);
Expand All @@ -10725,10 +10741,17 @@ public function get_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();
}
Expand All @@ -10743,10 +10766,17 @@ public function write_setting($data) {
/**
* 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) [
Expand Down
36 changes: 9 additions & 27 deletions lib/classes/useragent.php
Expand Up @@ -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.
Expand All @@ -118,15 +112,6 @@ public static function instance($reload = false, $forceuseragent = null) {
* @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'])) {
Expand Down Expand Up @@ -176,17 +161,6 @@ public static function get_device_type() {
* @return string
*/
protected function guess_device_type() {
global $CFG;
if (empty($CFG->enabledevicedetection)) {
$this->devicetype = self::DEVICETYPE_DEFAULT;
return $this->devicetype;
}
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()) {
Expand Down Expand Up @@ -235,10 +209,18 @@ protected function is_useragent_web_crawler() {
/**
* 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();
Expand Down Expand Up @@ -318,7 +300,7 @@ public static function set_user_device_type($newdevice) {
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;
Expand Down
8 changes: 8 additions & 0 deletions lib/db/upgrade.php
Expand Up @@ -3375,5 +3375,13 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2023081500.00);
}

if ($oldversion < 2023081800.01) {
// Remove enabledevicedetection and devicedetectregex from config table.
unset_config('enabledevicedetection');
unset_config('devicedetectregex');
// Main savepoint reached.
upgrade_main_savepoint(true, 2023081800.01);
}

return true;
}
29 changes: 0 additions & 29 deletions lib/tests/theme_config_test.php
Expand Up @@ -129,35 +129,6 @@ public function test_svg_image_use() {
}
}

/**
* 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.
Expand Down
1 change: 1 addition & 0 deletions lib/upgrade.txt
Expand Up @@ -86,6 +86,7 @@ information provided here is intended especially for developers.
* New behat behat_navigation::i_close_block_drawer_if_open() and behat_navigation::i_keep_block_drawer_closed()
to ensure in some test that the block drawer is closed. This helps with random failures due to the block drawer
being forced open in all behat tests.
* The core_useragent::get_device_type_list() function has been deprecated. Use core_useragent::devicetypes instead as a replacement.

=== 4.2 ===

Expand Down
2 changes: 1 addition & 1 deletion version.php
Expand Up @@ -29,7 +29,7 @@

defined('MOODLE_INTERNAL') || die();

$version = 2023081800.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2023081800.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.3dev+ (Build: 20230818)'; // Human-friendly version name
Expand Down

0 comments on commit 9b2917f

Please sign in to comment.