]> git.joonet.de Git - adminer.git/commitdiff
Plugins: Move lang() to Adminer\Plugin
authorJakub Vrana <jakub@vrana.cz>
Sun, 6 Apr 2025 04:43:26 +0000 (06:43 +0200)
committerJakub Vrana <jakub@vrana.cz>
Sun, 6 Apr 2025 05:29:23 +0000 (07:29 +0200)
CHANGELOG.md
adminer/include/bootstrap.inc.php
adminer/include/plugin.inc.php [new file with mode: 0644]
adminer/include/version.inc.php
plugins/config.php
plugins/menu-links.php
plugins/select-email.php
plugins/sql-gemini.php

index bbd56273c6f9af31f08e9c0da1a7e7959949cd8f..0288b6d0da212cc61143af9498ec531aa06384d3 100644 (file)
@@ -7,7 +7,7 @@
 - MS SQL: Limit one INSERT in export to 1000 rows (bug #983)
 - CSS: Add logo
 - Editor: Move mass sending e-mails to a plugin
-- Plugins: Allow formatting translations using Adminer\lang_format()
+- Plugins: Support translations by extending Adminer\Plugin
 - New plugin: Configure options by end-users and store them to a cookie
 - New plugin: Configure menu table links
 - New plugin: Set up driver, server and database in Adminer Editor
index fbd21d4108bac9489c4d95ea67140c293238364f..4b8511376b15cf513fd8a03cfd882a45fff40416 100644 (file)
@@ -79,14 +79,13 @@ include "../adminer/drivers/oracle.inc.php";
 include "../adminer/drivers/mssql.inc.php";
 include "./include/adminer.inc.php";
 include "../adminer/include/plugins.inc.php";
+include "../adminer/include/plugin.inc.php";
 
-if (function_exists('adminer_object')) {
-       Adminer::$instance = adminer_object();
-} elseif (is_dir("adminer-plugins") || file_exists("adminer-plugins.php")) {
-       Adminer::$instance = new Plugins(null);
-} else {
-       Adminer::$instance = new Adminer;
-}
+Adminer::$instance =
+       (function_exists('adminer_object') ? adminer_object() :
+       (is_dir("adminer-plugins") || file_exists("adminer-plugins.php") ? new Plugins(null) :
+       new Adminer
+));
 
 // this is matched by compile.php
 include "../adminer/drivers/mysql.inc.php"; // must be included as last driver
diff --git a/adminer/include/plugin.inc.php b/adminer/include/plugin.inc.php
new file mode 100644 (file)
index 0000000..7b78b5d
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+namespace Adminer;
+
+abstract class Plugin {
+       /** @var array<literal-string, string|list<string>>[] */ protected static $translations = array(); // key is language code
+
+       /** Translate a string from static::$translations; use Adminer\lang() for strings used by Adminer
+       * @param literal-string $idf
+       * @param float|string $number
+       */
+       protected function lang(string $idf, $number = null) {
+               $args = func_get_args();
+               $args[0] = idx(static::$translations[LANG], $idf) ?: $idf;
+               return call_user_func_array('Adminer\lang_format', $args);
+       }
+}
index bc354f40382d03cc67932574aab489b263d46a27..4415f8e34136331f8c3d826b9fb4eb6bf25c9a61 100644 (file)
@@ -1,4 +1,4 @@
 <?php
 namespace Adminer;
 
-const VERSION = "5.1.2-dev";
+const VERSION = "5.2.0-dev";
index a0c060f3ae6076f1e5dc9593111938fe2d0d8266..bd5a7b8d46fd22dbe4344ed8445b88810760d976 100644 (file)
@@ -6,7 +6,7 @@
 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
 * @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
 */
-class AdminerConfig {
+class AdminerConfig extends Adminer\Plugin {
 
        function headers() {
                static $called; // this function is called from page_header() and it also calls page_header()
@@ -53,10 +53,6 @@ class AdminerConfig {
                }
        }
 
-       protected function lang($idf, $number = null) {
-               return Adminer\lang_format(Adminer\idx(self::$translations[Adminer\LANG], $idf) ?: $idf, $number);
-       }
-
        protected static $translations = array(
                'cs' => array(
                        'Configuration' => 'Konfigurace',
index 4ba89f0dc8c10962a1470536556d7d61541b9461..e9b53580d90f021ddc026cfdf5a430172807d0b7 100644 (file)
@@ -6,7 +6,7 @@
 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
 * @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
 */
-class AdminerMenuLinks {
+class AdminerMenuLinks extends Adminer\Plugin {
        private $menu;
 
        /** @param ''|'table'|'select'|'auto' $menu see config() for explanation */
@@ -65,10 +65,6 @@ class AdminerMenuLinks {
                return true;
        }
 
-       protected function lang($idf, $number = null) {
-               return Adminer\lang_format(Adminer\idx(self::$translations[Adminer\LANG], $idf) ?: $idf, $number);
-       }
-
        protected static $translations = array(
                'cs' => array(
                        'Menu table links' => 'Odkazy na tabulky v menu',
index 6a908a2849f38c1acfe7570e437ff0fc804ce661..acef4676841696e354306832945068a26ff0492f 100644 (file)
@@ -6,7 +6,7 @@
 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
 * @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
 */
-class AdminerSelectEmail {
+class AdminerSelectEmail extends Adminer\Plugin {
 
        function selectEmailPrint($emailFields, $columns) {
                if ($emailFields) {
@@ -100,11 +100,7 @@ class AdminerSelectEmail {
                return mail($email, $this->emailHeader($subject), $beginning . $message . $attachments, $headers);
        }
 
-       private function lang($idf, $number = null) {
-               return Adminer\lang_format(Adminer\idx(self::$translations[Adminer\LANG], $idf) ?: $idf, $number);
-       }
-
-       private static $translations = array(
+       protected static $translations = array(
                'ar' => array('E-mail' => 'البريد الإلكتروني', 'From' => 'من', 'Subject' => 'الموضوع', 'Send' => 'إرسال', '%d e-mail(s) have been sent.' => 'تم إرسال %d رسالة.', 'Attachments' => 'ملفات مرفقة'),
                'bg' => array('E-mail' => 'E-mail', 'From' => 'От', 'Subject' => 'Тема', 'Attachments' => 'Прикачени', 'Send' => 'Изпращане', '%d e-mail(s) have been sent.' => array('%d писмо беше изпратено.', '%d писма бяха изпратени.')),
                'bn' => array('E-mail' => '​​ই-মেইল', 'From' => 'থেকে', 'Subject' => 'বিষয়', 'Send' => 'পাঠান', '%d e-mail(s) have been sent.' => array('%d ইমেইল(গুলি) পাঠানো হয়েছে।', '%d ইমেইল(গুলি) পাঠানো হয়েছে।'), 'Attachments' => 'সংযুক্তিগুলো'),
index 23cd27ed740cbd00347d4b84070df6cb841ce24b..6ec113d76f12ed7d066975a29be3e820ff62ff8e 100644 (file)
@@ -9,7 +9,7 @@
 * @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
 * @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other)
 */
-class AdminerSqlGemini {
+class AdminerSqlGemini extends Adminer\Plugin {
        private $apiKey;
        private $model;
 
@@ -92,11 +92,7 @@ geminiText.onkeydown = event => {
 <?php
        }
 
-       private function lang($idf, $number = null) {
-               return Adminer\lang_format(Adminer\idx(self::$translations[Adminer\LANG], $idf) ?: $idf, $number);
-       }
-
-       private static $translations = array(
+       protected static $translations = array(
                'cs' => array(
                        'Ask Gemini' => 'Zeptat se Gemini',
                        'Just a sec...' => 'Chviličku...',