Merge branch 'MDL-78468-master' of https://github.com/meirzamoodle/moodle

This commit is contained in:
Jun Pataleta 2023-08-22 11:00:11 +08:00
commit 9b2917f183
No known key found for this signature in database
GPG key ID: F83510526D99E2C7
12 changed files with 79 additions and 66 deletions

View file

@ -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 <support@pimenko.com><pimenko.com>
* @author Jordan Kesraoui | Sylvain Revenu | Pimenko based on David Monllaó <david.monllao@urv.cat> 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) {

View file

@ -46,8 +46,6 @@ reports,core_reportbuilder|/reportbuilder/index.php',
'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'));

View file

@ -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.

View file

@ -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 ===

View file

@ -235,7 +235,6 @@ $string['configdeleteunconfirmed'] = 'For certain authentication methods, such a
$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.';
@ -519,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}';
@ -595,7 +589,6 @@ $string['enablecourserequests'] = 'Enable course requests';
$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';
@ -1624,6 +1617,13 @@ $string['multilangforceold'] = 'Force old multilang syntax: &lt;span&gt; without
$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';

View file

@ -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

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) [

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,17 +161,6 @@ class core_useragent {
* @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()) {
@ -235,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();
@ -318,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;

View file

@ -3375,5 +3375,13 @@ privatefiles,moodle|/user/files.php';
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;
}

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.

View file

@ -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 ===

View file

@ -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