From 61e35c35347bc7b9e089398f6d76270e137a0709 Mon Sep 17 00:00:00 2001
From: Andreas Gohr <andi@splitbrain.org>
Date: Sat, 13 May 2017 09:03:34 +0200
Subject: [PATCH] fix error in config manager caused by changes visibility

The internal lang and localized variables of a plugin are no longer
accessible from the outside. This adds a proper setter and also fixes
the type hinting in the config plugin.
---
 lib/plugins/config/admin.php                 | 43 ++++++++++++--------
 lib/plugins/config/settings/config.class.php | 34 ++++++++--------
 lib/plugins/config/settings/extra.class.php  | 35 ++++++++--------
 3 files changed, 62 insertions(+), 50 deletions(-)

diff --git a/lib/plugins/config/admin.php b/lib/plugins/config/admin.php
index e760a41c1..262ff46d9 100644
--- a/lib/plugins/config/admin.php
+++ b/lib/plugins/config/admin.php
@@ -24,23 +24,23 @@ require_once(PLUGIN_SELF.'settings/extra.class.php');   // settings classes spec
  */
 class admin_plugin_config extends DokuWiki_Admin_Plugin {
 
-    var $_file = PLUGIN_METADATA;
-    var $_config = null;
-    var $_input = null;
-    var $_changed = false;          // set to true if configuration has altered
-    var $_error = false;
-    var $_session_started = false;
-    var $_localised_prompts = false;
+    protected $_file = PLUGIN_METADATA;
+    protected $_config = null;
+    protected $_input = null;
+    protected $_changed = false;          // set to true if configuration has altered
+    protected $_error = false;
+    protected $_session_started = false;
+    protected $_localised_prompts = false;
 
     /**
      * @return int
      */
-    function getMenuSort() { return 100; }
+    public function getMenuSort() { return 100; }
 
     /**
      * handle user request
      */
-    function handle() {
+    public function handle() {
         global $ID, $INPUT;
 
         if(!$this->_restore_session() || $INPUT->int('save') != 1 || !checkSecurityToken()) {
@@ -86,7 +86,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin {
     /**
      * output appropriate html
      */
-    function html() {
+    public function html() {
         $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here.
         global $lang;
         global $ID;
@@ -225,7 +225,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin {
     /**
      * @return boolean   true - proceed with handle, false - don't proceed
      */
-    function _restore_session() {
+    protected function _restore_session() {
 
         // dokuwiki closes the session before act_dispatch. $_SESSION variables are all set,
         // however they can't be changed without starting the session again
@@ -251,14 +251,14 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin {
         return true;
     }
 
-    function _close_session() {
+    protected function _close_session() {
       if ($this->_session_started) session_write_close();
     }
 
     /**
      * @param bool $prompts
      */
-    function setupLocale($prompts=false) {
+    public function setupLocale($prompts=false) {
 
         parent::setupLocale();
         if (!$prompts || $this->_localised_prompts) return;
@@ -271,7 +271,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin {
     /**
      * @return bool
      */
-    function _setup_localised_plugin_prompts() {
+    protected function _setup_localised_plugin_prompts() {
         global $conf;
 
         $langfile   = '/lang/'.$conf['lang'].'/settings.php';
@@ -328,7 +328,7 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin {
      *
      * @return array
      */
-    function getTOC() {
+    public function getTOC() {
         if (is_null($this->_config)) { $this->_config = new configuration($this->_file); }
         $this->setupLocale(true);
 
@@ -387,9 +387,18 @@ class admin_plugin_config extends DokuWiki_Admin_Plugin {
      * @param string $id
      * @param string $text
      */
-    function _print_h1($id, $text) {
+    protected function _print_h1($id, $text) {
         ptln('<h1 id="'.$id.'">'.$text.'</h1>');
     }
 
-
+    /**
+     * Adds a translation to this plugin's language array
+     *
+     * @param string $key
+     * @param string $value
+     */
+    public function addLang($key, $value) {
+        if (!$this->localised) $this->setupLocale();
+        $this->lang[$key] = $value;
+    }
 }
diff --git a/lib/plugins/config/settings/config.class.php b/lib/plugins/config/settings/config.class.php
index 102fc8546..965c2a38c 100644
--- a/lib/plugins/config/settings/config.class.php
+++ b/lib/plugins/config/settings/config.class.php
@@ -513,11 +513,11 @@ if (!class_exists('setting')) {
         /**
          * Build html for label and input of setting
          *
-         * @param DokuWiki_Plugin $plugin object of config plugin
-         * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
+         * @param admin_plugin_config $plugin object of config plugin
+         * @param bool $echo true: show inputted value, when error occurred, otherwise the stored setting
          * @return string[] with content array(string $label_html, string $input_html)
          */
-        public function html(&$plugin, $echo=false) {
+        public function html(admin_plugin_config $plugin, $echo=false) {
             $disable = '';
 
             if ($this->is_protected()) {
@@ -565,10 +565,10 @@ if (!class_exists('setting')) {
         /**
          * Returns the localized prompt
          *
-         * @param DokuWiki_Plugin $plugin object of config plugin
+         * @param admin_plugin_config $plugin object of config plugin
          * @return string text
          */
-        public function prompt(&$plugin) {
+        public function prompt(admin_plugin_config $plugin) {
             $prompt = $plugin->getLang($this->_key);
             if (!$prompt) $prompt = htmlspecialchars(str_replace(array('____','_'),' ',$this->_key));
             return $prompt;
@@ -738,11 +738,11 @@ if (!class_exists('setting_array')) {
         /**
          * Build html for label and input of setting
          *
-         * @param DokuWiki_Plugin $plugin object of config plugin
+         * @param admin_plugin_config $plugin object of config plugin
          * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
          * @return string[] with content array(string $label_html, string $input_html)
          */
-        function html(&$plugin, $echo=false) {
+        function html(admin_plugin_config $plugin, $echo=false) {
             $disable = '';
 
             if ($this->is_protected()) {
@@ -774,11 +774,11 @@ if (!class_exists('setting_string')) {
         /**
          * Build html for label and input of setting
          *
-         * @param DokuWiki_Plugin $plugin object of config plugin
+         * @param admin_plugin_config $plugin object of config plugin
          * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
          * @return string[] with content array(string $label_html, string $input_html)
          */
-        function html(&$plugin, $echo=false) {
+        function html(admin_plugin_config $plugin, $echo=false) {
             $disable = '';
 
             if ($this->is_protected()) {
@@ -835,11 +835,11 @@ if (!class_exists('setting_password')) {
         /**
          * Build html for label and input of setting
          *
-         * @param DokuWiki_Plugin $plugin object of config plugin
+         * @param admin_plugin_config $plugin object of config plugin
          * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
          * @return string[] with content array(string $label_html, string $input_html)
          */
-        function html(&$plugin, $echo=false) {
+        function html(admin_plugin_config $plugin, $echo=false) {
 
             $disable = $this->is_protected() ? 'disabled="disabled"' : '';
 
@@ -993,11 +993,11 @@ if (!class_exists('setting_onoff')) {
         /**
          * Build html for label and input of setting
          *
-         * @param DokuWiki_Plugin $plugin object of config plugin
+         * @param admin_plugin_config $plugin object of config plugin
          * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
          * @return string[] with content array(string $label_html, string $input_html)
          */
-        function html(&$plugin, $echo = false) {
+        function html(admin_plugin_config $plugin, $echo = false) {
             $disable = '';
 
             if ($this->is_protected()) {
@@ -1047,11 +1047,11 @@ if (!class_exists('setting_multichoice')) {
         /**
          * Build html for label and input of setting
          *
-         * @param DokuWiki_Plugin $plugin object of config plugin
+         * @param admin_plugin_config $plugin object of config plugin
          * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
          * @return string[] with content array(string $label_html, string $input_html)
          */
-        function html(&$plugin, $echo = false) {
+        function html(admin_plugin_config $plugin, $echo = false) {
             $disable = '';
             $nochoice = '';
 
@@ -1247,11 +1247,11 @@ if (!class_exists('setting_multicheckbox')) {
         /**
          * Build html for label and input of setting
          *
-         * @param DokuWiki_Plugin $plugin object of config plugin
+         * @param admin_plugin_config $plugin object of config plugin
          * @param bool            $echo   true: show input value, when error occurred, otherwise the stored setting
          * @return string[] with content array(string $label_html, string $input_html)
          */
-        function html(&$plugin, $echo=false) {
+        function html(admin_plugin_config $plugin, $echo=false) {
 
             $disable = '';
 
diff --git a/lib/plugins/config/settings/extra.class.php b/lib/plugins/config/settings/extra.class.php
index 2445577d1..41af42247 100644
--- a/lib/plugins/config/settings/extra.class.php
+++ b/lib/plugins/config/settings/extra.class.php
@@ -172,20 +172,19 @@ if (!class_exists('setting_disableactions')) {
         /**
          * Build html for label and input of setting
          *
-         * @param DokuWiki_Plugin $plugin object of config plugin
+         * @param admin_plugin_config $plugin object of config plugin
          * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
          * @return array with content array(string $label_html, string $input_html)
          */
-        function html(&$plugin, $echo=false) {
+        function html(admin_plugin_config $plugin, $echo=false) {
             global $lang;
 
             // make some language adjustments (there must be a better way)
             // transfer some DokuWiki language strings to the plugin
-            if (!$plugin->localised) $plugin->setupLocale();
-            $plugin->lang[$this->_key.'_revisions'] = $lang['btn_revs'];
-
-            foreach ($this->_choices as $choice)
-              if (isset($lang['btn_'.$choice])) $plugin->lang[$this->_key.'_'.$choice] = $lang['btn_'.$choice];
+            $plugin->addLang($this->_key.'_revisions', $lang['btn_revs']);
+            foreach ($this->_choices as $choice) {
+              if (isset($lang['btn_'.$choice])) $plugin->addLang($this->_key.'_'.$choice, $lang['btn_'.$choice]);
+            }
 
             return parent::html($plugin, $echo);
         }
@@ -281,22 +280,26 @@ if (!class_exists('setting_renderer')) {
         /**
          * Build html for label and input of setting
          *
-         * @param DokuWiki_Plugin $plugin object of config plugin
+         * @param admin_plugin_config $plugin object of config plugin
          * @param bool            $echo   true: show inputted value, when error occurred, otherwise the stored setting
          * @return array with content array(string $label_html, string $input_html)
          */
-        function html(&$plugin, $echo=false) {
+        function html(admin_plugin_config $plugin, $echo=false) {
 
             // make some language adjustments (there must be a better way)
             // transfer some plugin names to the config plugin
-            if (!$plugin->localised) $plugin->setupLocale();
-
-            foreach ($this->_choices as $choice) {
-                if (!isset($plugin->lang[$this->_key.'_o_'.$choice])) {
-                    if (!isset($this->_prompts[$choice])) {
-                        $plugin->lang[$this->_key.'_o_'.$choice] = sprintf($plugin->lang['renderer__core'],$choice);
+            foreach($this->_choices as $choice) {
+                if(!$plugin->getLang($this->_key . '_o_' . $choice)) {
+                    if(!isset($this->_prompts[$choice])) {
+                        $plugin->addLang(
+                            $this->_key . '_o_' . $choice,
+                            sprintf($plugin->getLang('renderer__core'), $choice)
+                        );
                     } else {
-                        $plugin->lang[$this->_key.'_o_'.$choice] = sprintf($plugin->lang['renderer__plugin'],$this->_prompts[$choice]);
+                        $plugin->addLang(
+                            $this->_key . '_o_' . $choice,
+                            sprintf($plugin->getLang('renderer__plugin'), $this->_prompts[$choice])
+                        );
                     }
                 }
             }
-- 
GitLab