[Phpmyadmin-git] [SCM] phpMyAdmin branch, master, updated. RELEASE_3_4_0BETA2-1589-gb1fe08f

Michal Čihař nijel at users.sourceforge.net
Wed Feb 2 14:38:35 CET 2011


The branch, master has been updated
       via  b1fe08fa9222df068fb471a69af65bc0fe46fe47 (commit)
       via  42c8e651398eb1267c616499c895f5a81e0f978a (commit)
       via  34546681a8d7af1f33b2d210e322d1b4545e608f (commit)
       via  5b28e356aa29f7f91c2cb884fe9e9f677e5526b5 (commit)
      from  775abf73929ba56c36d84d670839dd358cda1abc (commit)


- Log -----------------------------------------------------------------
commit b1fe08fa9222df068fb471a69af65bc0fe46fe47
Author: Michal Čihař <mcihar at novell.com>
Date:   Wed Feb 2 14:37:05 2011 +0100

    Add version check to vendor configuration.
    
    This is something what most Linux distributions will want to disable, so
    give it to place where this customisation should happen.

commit 42c8e651398eb1267c616499c895f5a81e0f978a
Author: Michal Čihař <mcihar at novell.com>
Date:   Wed Feb 2 14:32:46 2011 +0100

    Make version check configurable.

commit 34546681a8d7af1f33b2d210e322d1b4545e608f
Author: Michal Čihař <mcihar at novell.com>
Date:   Wed Feb 2 14:32:34 2011 +0100

    Allow to specify class for list item.

commit 5b28e356aa29f7f91c2cb884fe9e9f677e5526b5
Author: Michal Čihař <mcihar at novell.com>
Date:   Wed Feb 2 11:43:21 2011 +0100

    Display notification if newer version is available.
    
    This is done using asynchronous javascript so it should not block any
    actions.

-----------------------------------------------------------------------

Summary of changes:
 Documentation.html                          |    4 ++
 js/functions.js                             |   64 +++++++++++++++++++++++++
 js/jquery/jquery.sprintf.js                 |   68 +++++++++++++++++++++++++++
 js/messages.php                             |    9 ++++
 libraries/config.default.php                |    7 +++
 libraries/config/messages.inc.php           |    2 +
 libraries/config/setup.forms.php            |    1 +
 libraries/config/user_preferences.forms.php |    1 +
 libraries/vendor_config.php                 |    5 ++
 main.php                                    |   15 +++++-
 10 files changed, 173 insertions(+), 3 deletions(-)
 create mode 100644 js/jquery/jquery.sprintf.js

diff --git a/Documentation.html b/Documentation.html
index c8d1fc6..ac8692c 100644
--- a/Documentation.html
+++ b/Documentation.html
@@ -1301,6 +1301,10 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE</pre>
     for example, the Designer feature is Ajax-only so this directive
     does not apply to it.</dd>
 
+    <dt id="cfg_VersionCheck">$cfg['VersionCheck'] boolean</dt>
+    <dd>Enables check for latest versions using javascript on main phpMyAdmin
+    page.</dd>
+
     <dt id="cfg_MaxTableList">$cfg['MaxTableList'] integer</dt>
     <dd>The maximum number of table names to be displayed in the
     main panel's list (except on the Export page). This limit is also enforced in the navigation panel
diff --git a/js/functions.js b/js/functions.js
index bfbcca1..d8f75cf 100644
--- a/js/functions.js
+++ b/js/functions.js
@@ -45,6 +45,55 @@ function suggestPassword(passwd_form) {
 }
 
 /**
+ * Version string to integer conversion.
+ */
+function parseVersionString (str) {
+    if (typeof(str) != 'string') { return false; }
+    var add = 0;
+    // Parse possible alpha/beta/rc/
+    var state = str.split('-');
+    if (state.length >= 2) {
+        if (state[1].substr(0, 2) == 'rc') {
+            add = - 20 - parseInt(state[1].substr(2));
+        } else if (state[1].substr(0, 4) == 'beta') {
+            add =  - 40 - parseInt(state[1].substr(4));
+        } else if (state[1].substr(0, 5) == 'alpha') {
+            add =  - 60 - parseInt(state[1].substr(5));
+        } else if (state[1].substr(0, 3) == 'dev') {
+            /* We don't handle dev, it's git snapshot */
+            add = 0;
+        }
+    }
+    // Parse version
+    var x = str.split('.');
+    // Use 0 for non existing parts
+    var maj = parseInt(x[0]) || 0;
+    var min = parseInt(x[1]) || 0;
+    var pat = parseInt(x[2]) || 0;
+    var hotfix = parseInt(x[3]) || 0;
+    return  maj * 100000000 + min * 1000000 + pat * 10000 + hotfix * 100 + add;
+}
+
+/**
+ * Indicates current available version on main page.
+ */
+function PMA_current_version() {
+    var current = parseVersionString('3.4.0'/*pmaversion*/);
+    var latest = parseVersionString(PMA_latest_version);
+    $('#li_pma_version').append(PMA_messages['strLatestAvailable'] + ' ' + PMA_latest_version);
+    if (latest > current) {
+        var message = $.sprintf(PMA_messages['strNewerVersion'], PMA_latest_version, PMA_latest_date);
+        if (Math.floor(latest / 10000) == Math.floor(current / 10000)) {
+            /* Security update */
+            klass = 'warning';
+        } else {
+            klass = 'notice';
+        }
+        $('#maincontainer').after('<div class="' + klass + '">' + message + '</div>');
+    }
+}
+
+/**
  * for libraries/display_change_password.lib.php
  *     libraries/user_password.php
  *
@@ -2414,5 +2463,20 @@ $(document).ready(function() {
         $(this).closest("form").submit();
     });
 
+    /**
+     * Load version information asynchronously.
+     */
+    if ($('.jsversioncheck').length > 0) {
+        (function() {
+            var s = document.createElement('script');
+            s.type = 'text/javascript';
+            s.async = true;
+            s.src = 'http://www.phpmyadmin.net/home_page/version.js';
+            s.onload = PMA_current_version;
+            var x = document.getElementsByTagName('script')[0];
+            x.parentNode.insertBefore(s, x);
+        })();
+    }
+
 }) // end of $(document).ready()
 
diff --git a/js/jquery/jquery.sprintf.js b/js/jquery/jquery.sprintf.js
new file mode 100644
index 0000000..3d39b76
--- /dev/null
+++ b/js/jquery/jquery.sprintf.js
@@ -0,0 +1,68 @@
+/**
+ * sprintf and vsprintf for jQuery
+ * somewhat based on http://jan.moesen.nu/code/javascript/sprintf-and-printf-in-javascript/
+ *
+ * Copyright (c) 2008 Sabin Iacob (m0n5t3r) <iacobs at m0n5t3r.info>
+ * This program 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.
+ *
+ * This program 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.
+ *
+ * @license http://www.gnu.org/licenses/gpl.html
+ * @project jquery.sprintf
+ */
+(function($){
+        var formats = {
+                'b': function(val) {return parseInt(val, 10).toString(2);},
+                'c': function(val) {return String.fromCharCode(parseInt(val, 10));},
+                'd': function(val) {return parseInt(val, 10);},
+                'u': function(val) {return Math.abs(val);},
+                'f': function(val, p) {
+                        p = parseInt(p, 10);
+                        val = parseFloat(val);
+                        if(isNaN(p && val)) {
+                                return NaN;
+                        }
+                        return p && val.toFixed(p) || val;
+                },
+                'o': function(val) {return parseInt(val, 10).toString(8);},
+                's': function(val) {return val;},
+                'x': function(val) {return ('' + parseInt(val, 10).toString(16)).toLowerCase();},
+                'X': function(val) {return ('' + parseInt(val, 10).toString(16)).toUpperCase();}
+        };
+
+        var re = /%(?:(\d+)?(?:\.(\d+))?|\(([^)]+)\))([%bcdufosxX])/g;
+
+        var dispatch = function(data){
+                if(data.length == 1 && typeof data[0] == 'object') { //python-style printf
+                        data = data[0];
+                        return function(match, w, p, lbl, fmt, off, str) {
+                                return formats[fmt](data[lbl]);
+                        };
+                } else { // regular, somewhat incomplete, printf
+                        var idx = 0;
+                        return function(match, w, p, lbl, fmt, off, str) {
+                                if(fmt == '%') {
+                                        return '%';
+                                }
+                                return formats[fmt](data[idx++], p);
+                        };
+                }
+        };
+
+        $.extend({
+                sprintf: function(format) {
+                        var argv = Array.apply(null, arguments).slice(1);
+                        return format.replace(re, dispatch(argv));
+                },
+                vsprintf: function(format, data) {
+                        return format.replace(re, dispatch(data));
+                }
+        });
+})(jQuery);
+
diff --git a/js/messages.php b/js/messages.php
index f9f764e..ded9546 100644
--- a/js/messages.php
+++ b/js/messages.php
@@ -109,6 +109,11 @@ $js_messages['strChangePassword'] = __('Change Password');
 /* navigation tabs */
 $js_messages['strMore'] = __('More');
 
+/* update */
+$js_messages['strNewerVersion'] = __('A newer version of phpMyAdmin is available and you should consider upgrading. The newest version is %s, released on %s.');
+/* l10n: Latest available phpMyAdmin version */
+$js_messages['strLatestAvailable'] = __(', latest available:');
+
 echo "var PMA_messages = new Array();\n";
 foreach ($js_messages as $name => $js_message) {
     PMA_printJsValue("PMA_messages['" . $name . "']", $js_message);
@@ -116,6 +121,10 @@ foreach ($js_messages as $name => $js_message) {
 
 /* Calendar */
 echo "var themeCalendarImage = '" . $GLOBALS['pmaThemeImage'] . 'b_calendar.png' . "';\n";
+
+/* Version */
+echo "var pmaversion = '" . PMA_VERSION . "';\n";
+
 echo "if ($.datepicker) {\n";
 /* l10n: Display text for calendar close link */
 PMA_printJsValue("$.datepicker.regional['']['closeText']", __('Done'));
diff --git a/libraries/config.default.php b/libraries/config.default.php
index d7df77e..9fece7a 100644
--- a/libraries/config.default.php
+++ b/libraries/config.default.php
@@ -495,6 +495,13 @@ $cfg['ServerDefault'] = 1;
 $cfg['AjaxEnable'] = true;
 
 /**
+ * whether version check is active
+ *
+ * @global boolean $cfg['VersionCheck']
+ */
+$cfg['VersionCheck'] = VERSION_CHECK_DEFAULT;
+
+/**
  * maximum number of db's displayed in left frame and database list
  *
  * @global integer $cfg['MaxDbList']
diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php
index 560b1e5..b2363c1 100644
--- a/libraries/config/messages.inc.php
+++ b/libraries/config/messages.inc.php
@@ -495,6 +495,8 @@ $strConfigUserprefsDeveloperTab_name = __('Enable the Developer tab in settings'
 $strConfigVerboseMultiSubmit_desc = __('Show affected rows of each statement on multiple-statement queries. See libraries/import.lib.php for defaults on how many queries a statement may contain.');
 $strConfigVerboseMultiSubmit_name = __('Verbose multiple statements');
 $strConfigVersionCheckLink = __('Check for latest version');
+$strConfigVersionCheck_desc = __('Enables check for latest version on main phpMyAdmin page');
+$strConfigVersionCheck_name = __('Version check');
 $strConfigZipDump_desc = __('Enable [a at http://en.wikipedia.org/wiki/ZIP_(file_format)]ZIP[/a] compression for import and export operations');
 $strConfigZipDump_name = __('ZIP');
 
diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php
index 7783065..5287aad 100644
--- a/libraries/config/setup.forms.php
+++ b/libraries/config/setup.forms.php
@@ -121,6 +121,7 @@ $forms['Features']['Developer'] = array(
     'DBG/sql');
 $forms['Features']['Other_core_settings'] = array(
     'AjaxEnable',
+    'VersionCheck',
     'NaturalOrder',
     'InitialSlidersState',
     'ErrorIconic',
diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php
index cfa78ae..ea5ac59 100644
--- a/libraries/config/user_preferences.forms.php
+++ b/libraries/config/user_preferences.forms.php
@@ -23,6 +23,7 @@
 $forms = array();
 $forms['Features']['General'] = array(
     'AjaxEnable',
+    'VersionCheck',
     'NaturalOrder',
     'InitialSlidersState',
     'ErrorIconic',
diff --git a/libraries/vendor_config.php b/libraries/vendor_config.php
index 5cea609..41f7c23 100644
--- a/libraries/vendor_config.php
+++ b/libraries/vendor_config.php
@@ -54,4 +54,9 @@ define('CUSTOM_HEADER_FILE', CONFIG_DIR . 'config.header.inc.php');
  * Filename of custom footer file.
  */
 define('CUSTOM_FOOTER_FILE', CONFIG_DIR . 'config.footer.inc.php');
+
+/**
+ * Default value for check for version upgrades.
+ */
+define('VERSION_CHECK_DEFAULT', true);
 ?>
diff --git a/main.php b/main.php
index 1361391..62fbc04 100644
--- a/main.php
+++ b/main.php
@@ -14,6 +14,7 @@ require_once './libraries/common.inc.php';
 $GLOBALS['js_include'][] = 'colorpicker/js/colorpicker.js';
 $GLOBALS['js_include'][] = 'main_custom_color.js';
 $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js';
+$GLOBALS['js_include'][] = 'jquery/jquery.sprintf.js';
 
 // Handles some variables that may have been sent by the calling script
 $GLOBALS['db'] = '';
@@ -208,7 +209,11 @@ if ($GLOBALS['cfg']['ShowServerInfo'] || $GLOBALS['cfg']['ShowPhpInfo']) {
 echo '<div class="group">';
 echo '<h2>phpMyAdmin</h2>';
 echo '<ul>';
-PMA_printListItem(__('Version information') . ': ' . PMA_VERSION, 'li_pma_version');
+$clas = null;
+if ($GLOBALS['cfg']['VersionCheck']) {
+    $class = 'jsversioncheck';
+}
+PMA_printListItem(__('Version information') . ': ' . PMA_VERSION, 'li_pma_version', null, null, null, null, $class);
 PMA_printListItem(__('Documentation'), 'li_pma_docs', 'Documentation.html', null, '_blank');
 PMA_printListItem(__('Wiki'), 'li_pma_wiki', PMA_linkURL('http://wiki.phpmyadmin.net/'), null, '_blank');
 
@@ -356,9 +361,13 @@ if ($cfg['SuhosinDisableWarning'] == false && @ini_get('suhosin.request.max_valu
  * @param   string  $target special target for $url
  * @param   string  $a_id   id for the anchor, used for jQuery to hook in functions
  */
-function PMA_printListItem($name, $id = null, $url = null, $mysql_help_page = null, $target = null, $a_id = null)
+function PMA_printListItem($name, $id = null, $url = null, $mysql_help_page = null, $target = null, $a_id = null, $class = null)
 {
-    echo '<li id="' . $id . '">';
+    echo '<li id="' . $id . '"';
+    if (null !== $class) {
+        echo ' class="' . $class . '"';
+    }
+    echo '>';
     if (null !== $url) {
         echo '<a href="' . $url . '"';
         if (null !== $target) {


hooks/post-receive
-- 
phpMyAdmin




More information about the Git mailing list