Skip to content

Commit

Permalink
Revert "MDL-40931 useragent: separated user agent functionality into …
Browse files Browse the repository at this point in the history
…a lib"

This reverts commit af62237.
This reverts commit 87a4194.
This reverts commit b2c66eb.

Conflicts:

	version.php
  • Loading branch information
Damyon Wiese committed Aug 22, 2013
1 parent 50cb891 commit 9ead041
Show file tree
Hide file tree
Showing 30 changed files with 1,045 additions and 1,460 deletions.
3 changes: 2 additions & 1 deletion auth/ldap/auth.php
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,8 @@ function loginpage_hook() {
// Now start the whole NTLM machinery.
if($this->config->ntlmsso_ie_fastpath == AUTH_NTLM_FASTPATH_YESATTEMPT ||
$this->config->ntlmsso_ie_fastpath == AUTH_NTLM_FASTPATH_YESFORM) {
if (core_useragent::check_ie_version()) {

if(check_browser_version('MSIE')) {
$sesskey = sesskey();
redirect($CFG->wwwroot.'/auth/ldap/ntlmsso_magic.php?sesskey='.$sesskey);
} else if ($this->config->ntlmsso_ie_fastpath == AUTH_NTLM_FASTPATH_YESFORM) {
Expand Down
2 changes: 1 addition & 1 deletion auth/ldap/ntlmsso_magic.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

if ($authplugin->ntlmsso_magic($sesskey) && file_exists($file)) {
if (!empty($authplugin->config->ntlmsso_ie_fastpath)) {
if (core_useragent::check_ie_version()) {
if (check_browser_version('MSIE')) {
// $PAGE->https_required() up above takes care of what $CFG->httpswwwroot should be.
redirect($CFG->httpswwwroot.'/auth/ldap/ntlmsso_finish.php');
}
Expand Down
6 changes: 2 additions & 4 deletions course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,8 @@
redirect($CFG->wwwroot .'/');
}

$ajaxenabled = ajaxenabled();

$completion = new completion_info($course);
if ($completion->is_enabled() && $ajaxenabled) {
if ($completion->is_enabled() && ajaxenabled()) {
$PAGE->requires->string_for_js('completion-title-manual-y', 'completion');
$PAGE->requires->string_for_js('completion-title-manual-n', 'completion');
$PAGE->requires->string_for_js('completion-alt-manual-y', 'completion');
Expand All @@ -243,7 +241,7 @@
$PAGE->set_heading($course->fullname);
echo $OUTPUT->header();

if ($completion->is_enabled() && $ajaxenabled) {
if ($completion->is_enabled() && ajaxenabled()) {
// This value tracks whether there has been a dynamic change to the page.
// It is used so that if a user does this - (a) set some tickmarks, (b)
// go to another page, (c) clicks Back button - the page will
Expand Down
16 changes: 8 additions & 8 deletions grade/report/grader/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1582,15 +1582,15 @@ public static function do_process_action($target, $action) {
* @return bool
*/
public function is_fixed_students() {
global $CFG;
global $USER, $CFG;
return $CFG->grade_report_fixedstudents &&
(core_useragent::check_ie_version('7.0') ||
core_useragent::check_firefox_version('2.0') ||
core_useragent::check_gecko_version('2006010100') ||
core_useragent::check_camino_version('1.0') ||
core_useragent::check_opera_version('6.0') ||
core_useragent::check_chrome_version('6') ||
core_useragent::check_safari_version('300'));
(check_browser_version('MSIE', '7.0') ||
check_browser_version('Firefox', '2.0') ||
check_browser_version('Gecko', '2006010100') ||
check_browser_version('Camino', '1.0') ||
check_browser_version('Opera', '6.0') ||
check_browser_version('Chrome', '6') ||
check_browser_version('Safari', '300'));
}

/**
Expand Down
7 changes: 3 additions & 4 deletions group/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@
require('tabs.php');

$disabled = 'disabled="disabled"';
$ajaxenabled = ajaxenabled();
if ($ajaxenabled) {
if (ajaxenabled()) {
// Some buttons are enabled if single group selected
$showaddmembersform_disabled = $singlegroup ? '' : $disabled;
$showeditgroupsettingsform_disabled = $singlegroup ? '' : $disabled;
Expand All @@ -179,7 +178,7 @@
echo "<td>\n";
echo '<p><label for="groups"><span id="groupslabel">'.get_string('groups').':</span><span id="thegrouping">&nbsp;</span></label></p>'."\n";

if ($ajaxenabled) { // TODO: move this to JS init!
if (ajaxenabled()) { // TODO: move this to JS init!
$onchange = 'M.core_group.membersCombo.refreshMembers();';
} else {
$onchange = '';
Expand Down Expand Up @@ -276,7 +275,7 @@
echo '</div>'."\n";
echo '</form>'."\n";

if ($ajaxenabled) {
if (ajaxenabled()) {
$PAGE->requires->js_init_call('M.core_group.init_index', array($CFG->wwwroot, $courseid));
$PAGE->requires->js_init_call('M.core_group.groupslist', array($preventgroupremoval));
}
Expand Down
12 changes: 6 additions & 6 deletions lib/ajax/ajaxlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function ajaxenabled(array $browsers = null) {
if (!empty($browsers)) {
$valid = false;
foreach ($browsers as $brand => $version) {
if (core_useragent::check_browser_version($brand, $version)) {
if (check_browser_version($brand, $version)) {
$valid = true;
}
}
Expand All @@ -61,11 +61,11 @@ function ajaxenabled(array $browsers = null) {
}
}

$ie = core_useragent::check_browser_version('MSIE', 6.0);
$ff = core_useragent::check_browser_version('Gecko', 20051106);
$op = core_useragent::check_browser_version('Opera', 9.0);
$sa = core_useragent::check_browser_version('Safari', 412);
$ch = core_useragent::check_browser_version('Chrome', 6);
$ie = check_browser_version('MSIE', 6.0);
$ff = check_browser_version('Gecko', 20051106);
$op = check_browser_version('Opera', 9.0);
$sa = check_browser_version('Safari', 412);
$ch = check_browser_version('Chrome', 6);

if (!$ie && !$ff && !$op && !$sa && !$ch) {
/** @see http://en.wikipedia.org/wiki/User_agent */
Expand Down
130 changes: 130 additions & 0 deletions lib/ajax/tests/ajaxlib_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* Unit tests for (some of) ../ajaxlib.php.
*
* @package core
* @category phpunit
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

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

global $CFG;
require_once($CFG->libdir . '/ajax/ajaxlib.php');


/**
* Unit tests for ../ajaxlib.php functions.
*
* @copyright 2008 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_ajaxlib_testcase extends advanced_testcase {

var $user_agents = array(
'MSIE' => array(
'5.5' => array('Windows 2000' => 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)'),
'6.0' => array('Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)'),
'7.0' => array('Windows XP SP2' => 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; YPC 3.0.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)')
),
'Firefox' => array(
'1.0.6' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.10) Gecko/20050716 Firefox/1.0.6'),
'1.5' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; nl; rv:1.8) Gecko/20051107 Firefox/1.5'),
'1.5.0.1' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-GB; rv:1.8.0.1) Gecko/20060111 Firefox/1.5.0.1'),
'2.0' => array('Windows XP' => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1',
'Ubuntu Linux AMD64' => 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1) Gecko/20060601 Firefox/2.0 (Ubuntu-edgy)')
),
'Safari' => array(
'312' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en-us) AppleWebKit/312.1 (KHTML, like Gecko) Safari/312'),
'2.0' => array('Mac OS X' => 'Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/412 (KHTML, like Gecko) Safari/412')
),
'Opera' => array(
'8.51' => array('Windows XP' => 'Opera/8.51 (Windows NT 5.1; U; en)'),
'9.0' => array('Windows XP' => 'Opera/9.0 (Windows NT 5.1; U; en)',
'Debian Linux' => 'Opera/9.01 (X11; Linux i686; U; en)')
)
);

/**
* Uses the array of user agents to test ajax_lib::ajaxenabled
*/
function test_ajaxenabled() {
global $CFG;

$this->resetAfterTest(true);

$CFG->enableajax = 1;

// Should be true
$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP'];
$this->assertTrue(ajaxenabled());

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['1.5']['Windows XP'];
$this->assertTrue(ajaxenabled());

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X'];
$this->assertTrue(ajaxenabled());

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP'];
$this->assertTrue(ajaxenabled());

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['6.0']['Windows XP SP2'];
$this->assertTrue(ajaxenabled());

// Should be false
$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['1.0.6']['Windows XP'];
$this->assertFalse(ajaxenabled());

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['312']['Mac OS X'];
$this->assertFalse(ajaxenabled());

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['8.51']['Windows XP'];
$this->assertFalse(ajaxenabled());

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['5.5']['Windows 2000'];
$this->assertFalse(ajaxenabled());

// Test array of tested browsers
$tested_browsers = array('MSIE' => 6.0, 'Gecko' => 20061111);
$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP'];
$this->assertTrue(ajaxenabled($tested_browsers));

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['7.0']['Windows XP SP2'];
$this->assertTrue(ajaxenabled($tested_browsers));

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X'];
$this->assertFalse(ajaxenabled($tested_browsers));

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP'];
$this->assertFalse(ajaxenabled($tested_browsers));

$tested_browsers = array('Safari' => 412, 'Opera' => 9.0);
$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Firefox']['2.0']['Windows XP'];
$this->assertFalse(ajaxenabled($tested_browsers));

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['MSIE']['7.0']['Windows XP SP2'];
$this->assertFalse(ajaxenabled($tested_browsers));

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Safari']['2.0']['Mac OS X'];
$this->assertTrue(ajaxenabled($tested_browsers));

$_SERVER['HTTP_USER_AGENT'] = $this->user_agents['Opera']['9.0']['Windows XP'];
$this->assertTrue(ajaxenabled($tested_browsers));
}
}
Loading

0 comments on commit 9ead041

Please sign in to comment.