From 0bae338a280606d43a4e7e15460c4e345d69de97 Mon Sep 17 00:00:00 2001
From: chris <chris@teacherscpd.co.uk>
Date: Thu, 8 Sep 2005 02:03:05 +0200
Subject: [PATCH] update admin plugin base class, remove plugin_ prefix from
 main methods, leaving original functions in deprecated form. provide plugin
 name if no menutext is found

darcs-hash:20050908000305-50fdc-0d5fe129ac9ab6a39e2e0ae28b5dbcce83faa70a.gz
---
 lib/plugins/admin.php | 101 +++++++++++++++++++++++++++++-------------
 1 file changed, 69 insertions(+), 32 deletions(-)

diff --git a/lib/plugins/admin.php b/lib/plugins/admin.php
index 339f465a7..a5a8bd940 100644
--- a/lib/plugins/admin.php
+++ b/lib/plugins/admin.php
@@ -14,8 +14,8 @@ if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/');
  */
 class DokuWiki_Admin_Plugin {
 
-  var $localised = false;
-  var $lang = array();
+  var $localised = false;        // set to true by setupLocale() after loading language dependent strings
+  var $lang = array();          // array to hold language dependent strings, best accessed via ->getLang()
 
   /**
    * General Info
@@ -34,7 +34,12 @@ class DokuWiki_Admin_Plugin {
   }
 
   function getMenuText($language) {
-      return $this->getLang('menu');
+      $menutext = $this->getLang('menu');
+      if (!$menutext) {
+        $info = $this->getInfo();
+        $menutext = $info['name'].' ...';
+      }
+      return $menutext;
   }
 
   function getMenuSort() {
@@ -54,25 +59,45 @@ class DokuWiki_Admin_Plugin {
   // plugin introspection methods
   // extract from class name, format = <plugin type>_plugin_<name>[_<component name>]
   function getPluginType() { list($t) = explode('_', get_class($this), 2); return $t;  }
+
   function getPluginName() { list($t, $p, $n) = explode('_', get_class($this), 4); return $n; }
   function getPluginComponent() { list($t, $p, $n, $c) = explode('_', get_class($this), 4); return (isset($c)?$c:''); }
-  
-  function setupLocale() {
-  	if ($this->localised) return;
-  
-    global $conf;            // definitely don't invoke "global $lang"
-    $path = DOKU_PLUGIN.$this->getPluginName().'/lang/';
-    
-    // don't include once, in case several plugin components require the same language file
-    @include($path.'en/lang.php');    
-    if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
+
+  // localisation methods
+  /**
+   * getLang($id)
+   * use this function to access plugin language strings
+   * to try to minimise unnecessary loading of the strings when the plugin doesn't require them
+   * e.g. when info plugin is querying plugins for information about themselves.
+   *
+   * @param   $id     id of the string to be retrieved
+   * @return  string  string in appropriate language or english if not available
+   */
+  function getLang($id) {
+    if (!$this->localised) $this->setupLocale();
     
-    $this->lang = $lang;
-    $this->localised = true;
+    return (isset($this->lang[$id]) ? $this->lang[$id] : '');
   }
   
-  // plugin equivalent of localFN()
-  function plugin_localFN($id) {
+  /**
+   * locale_xhtml($id)
+   *
+   * retrieve a language dependent file and pass to xhtml renderer for display
+   * plugin equivalent of p_locale_xhtml()
+   *
+   * @param   $id     id of language dependent wiki page
+   * @return  string  parsed contents of the wiki page in xhtml format
+   */
+  function locale_xhtml($id) {
+    return p_cached_xhtml($this->localFN($id));
+  }
+  
+  /**
+   * localFN($id)
+   * prepends appropriate path for a language dependent filename
+   * plugin equivalent of localFN()
+   */
+  function localFN($id) {
     global $conf;
     $plugin = $this->getPluginName();
     $file = DOKU_PLUGIN.$plugin.'/lang/'.$conf['lang'].'/'.$id.'.txt';
@@ -83,23 +108,28 @@ class DokuWiki_Admin_Plugin {
     return $file;
   }
   
-  // use this function to access plugin language strings
-  // to try to minimise unnecessary loading of the strings when the plugin doesn't require them
-  // e.g. when info plugin is querying plugins for information about themselves.
-  function getLang($id) {
-    if (!$this->localised) $this->setupLocale();
-    
-    return (isset($this->lang[$id]) ? $this->lang[$id] : '');
-  }
+  /**
+   *  setupLocale() 
+   *  reads all the plugins language dependent strings into $this->lang
+   *  this function is automatically called by getLang()
+   */
+  function setupLocale() {
+      if ($this->localised) return;
   
-  // plugin equivalent of p_locale_xhtml()
-  function plugin_locale_xhtml($id) {
-    return p_cached_xhtml($this->plugin_localFN($id));
+    global $conf;            // definitely don't invoke "global $lang"
+    $path = DOKU_PLUGIN.$this->getPluginName().'/lang/';
+    
+    // don't include once, in case several plugin components require the same language file
+    @include($path.'en/lang.php');    
+    if ($conf['lang'] != 'en') @include($path.$conf['lang'].'/lang.php');
+    
+    $this->lang = $lang;
+    $this->localised = true;
   }
   
   // standard functions for outputing email addresses and links
   // use these to avoid having to duplicate code to produce links in line with the installation configuration
-  function plugin_email($email, $name='', $class='', $more='') {
+  function email($email, $name='', $class='', $more='') {
     if (!$email) return $name;
     $email = obfuscate($email);
     if (!$name) $name = $email;
@@ -107,7 +137,7 @@ class DokuWiki_Admin_Plugin {
     return "<a href='mailto:$email' $class title='$email' $more>$name</a>";
   }
   
-  function plugin_link($link, $title='', $class='', $target='', $more='') {
+  function external_link($link, $title='', $class='', $target='', $more='') {
     global $conf;
     
     $link = htmlentities($link);
@@ -124,9 +154,16 @@ class DokuWiki_Admin_Plugin {
                 
   // output text string through the parser, allows dokuwiki markup to be used
   // very ineffecient for small pieces of data - try not to use
-  function plugin_render($text, $format='xhtml') {
+  function render($text, $format='xhtml') {
     return p_render($format, p_get_instructions($text),$info); 
   }
   
+  // deprecated functions
+  function plugin_localFN($id) { return $this->localFN($id); }
+  function plugin_locale_xhtml($id) { return $this->locale_xhtml($id); }
+  function plugin_email($e, $n='', $c='', $m='') { return $this->email($e, $n, $c, $m); }
+  function plugin_link($l, $t='', $c='', $to='', $m='') { return $this->external_link($l, $t, $c, $to, $m); }
+  function plugin_render($t, $f='xhtml') { return $this->render($t, $f); }
+  
 }
-//Setup VIM: ex: et ts=4 enc=utf-8 :
+//Setup VIM: ex: et ts=4 enc=utf-8 :
\ No newline at end of file
-- 
GitLab