]> git.joonet.de Git - adminer.git/commitdiff
Plugins: Allow providing description
authorJakub Vrana <jakub@vrana.cz>
Mon, 7 Apr 2025 13:54:31 +0000 (15:54 +0200)
committerJakub Vrana <jakub@vrana.cz>
Mon, 7 Apr 2025 13:54:31 +0000 (15:54 +0200)
adminer/include/connect.inc.php
adminer/include/plugin.inc.php

index a4aa655037213e5c8f8c8abffaff7f1706cac9a6..884acdb22808d78e0b203e12ad62bcf0ed4b184e 100644 (file)
@@ -93,8 +93,14 @@ if (
                        echo "<div class='plugins'>\n";
                        echo "<h3>" . lang('Loaded plugins') . "</h3>\n<ul>\n";
                        foreach (adminer()->plugins as $plugin) {
-                               $reflection = new \ReflectionObject($plugin);
-                               echo "<li><b>" . get_class($plugin) . "</b>" . h(preg_match('~^/[\s*]+(.+)~', $reflection->getDocComment(), $match) ? ": $match[1]" : "") . "\n";
+                               $description = (method_exists($plugin, 'description') ? $plugin->description() : "");
+                               if (!$description) {
+                                       $reflection = new \ReflectionObject($plugin);
+                                       if (preg_match('~^/[\s*]+(.+)~', $reflection->getDocComment(), $match)) {
+                                               $description = $match[1];
+                                       }
+                               }
+                               echo "<li><b>" . get_class($plugin) . "</b>" . h($description ? ": $description" : "") . "\n";
                        }
                        echo "</ul>\n";
                        echo "</div>\n";
index 7b78b5d2fbc47ce8fa67d49165d6a97c75be6d55..98f76b4b959942ea92ddae9eb65a513528c8b467 100644 (file)
@@ -1,14 +1,22 @@
 <?php
 namespace Adminer;
 
+// the overridable methods don't use return type declarations so that plugins can be compatible with PHP 5
 abstract class Plugin {
        /** @var array<literal-string, string|list<string>>[] */ protected static $translations = array(); // key is language code
 
+       /** Get plain text plugin description; empty string means to use the first line of class doc-comment
+       * @return string
+       */
+       function description() {
+               return '';
+       }
+
        /** 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) {
+       protected function lang(string $idf, $number = null): string {
                $args = func_get_args();
                $args[0] = idx(static::$translations[LANG], $idf) ?: $idf;
                return call_user_func_array('Adminer\lang_format', $args);