about summary refs log tree commit diff stats
path: root/wiki/lib/plugins/config/admin.php
blob: 76ecae24ccc86201f256be36c4153e5747d1ef3a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
---

18:17 < Biolunar> when i change my resolution in dwm (to a smaller one) and then back to the native, the top bar is not repainted. that's since 5.7.2, in 5.6 it worked fine
18:19 < Biolunar> is it just happening to me or a (known) bug?
18:24 < Biolunar> and in addition, mplayers fullscreen is limited to the small resolution after i changed it back to the native

reproducible with xrandr -s but not with --output and --mode, strange

---

yet another corner case:
open a terminal, focus another monitor, but without moving the mouse
pointer there
if there is no client on the other monitor to get the focus, then the
terminal will be unfocused but it will accept input

---

Donald Allen reported this:

starting emacs from dmenu in archlinux results in missing configure of emacs, but mod1-space or mod1-shift-space fix this problem. this problem is new and did not happen in 1.6 xorg servers

---

voltaic reports this:

When I use two monitors, one larger in resolution than the other, the
bar is drawn using the smaller x-dimension on both screens. I think
what's happening is that there are two bars drawn, but the short bar
is always on top of the long bar such that I can't see the information
under the short bar. If I switch to the small screen, hide the short
bar, and then switch to the large screen, the long bar is drawn
correctly.

A similar problem occurs when I have started dwm on a small resolution
monitor (laptop screen) and then I switch to a large external display.
When I do this, the bar itself is drawn for the original smaller
resolution, but the information to be printed on the bar is
right-aligned for a longer bar. So what I see is a bar that has the
right hand side of it cut-off. See attached screenshot.

I am using standard options for xrandr such as --output VGA1 --auto, etc.
<?php
/**
 * Configuration Manager admin plugin
 *
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
 * @author     Christopher Smith <chris@jalakai.co.uk>
 * @author     Ben Coburn <btcoburn@silicodon.net>
 */
// must be run within Dokuwiki
if(!defined('DOKU_INC')) die();

define('CM_KEYMARKER','____');            // used for settings with multiple dimensions of array indices

define('PLUGIN_SELF',dirname(__FILE__).'/');
define('PLUGIN_METADATA',PLUGIN_SELF.'settings/config.metadata.php');
if(!defined('DOKU_PLUGIN_IMAGES')) define('DOKU_PLUGIN_IMAGES',DOKU_BASE.'lib/plugins/config/images/');

require_once(PLUGIN_SELF.'settings/config.class.php');  // main configuration class and generic settings classes
require_once(PLUGIN_SELF.'settings/extra.class.php');   // settings classes specific to these settings

/**
 * All DokuWiki plugins to extend the admin function
 * need to inherit from this class
 */
class admin_plugin_config extends DokuWiki_Admin_Plugin {

    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
     */
    public function getMenuSort() { return 100; }

    /**
     * handle user request
     */
    public function handle() {
        global $ID, $INPUT;

        if(!$this->_restore_session() || $INPUT->int('save') != 1 || !checkSecurityToken()) {
            $this->_close_session();
            return;
        }

        if(is_null($this->_config)) {
            $this->_config = new configuration($this->_file);
        }

        // don't go any further if the configuration is locked
        if($this->_config->locked) {
            $this->_close_session();
            return;
        }

        $this->_input = $INPUT->arr('config');

        foreach ($this->_config->setting as $key => $value){
            $input = isset($this->_input[$key]) ? $this->_input[$key] : null;
            if ($this->_config->setting[$key]->update($input)) {
                $this->_changed = true;
            }
            if ($this->_config->setting[$key]->error()) $this->_error = true;
        }

        if ($this->_changed  && !$this->_error) {
            $this->_config->save_settings($this->getPluginName());

            // save state & force a page reload to get the new settings to take effect
            $_SESSION['PLUGIN_CONFIG'] = array('state' => 'updated', 'time' => time());
            $this->_close_session();
            send_redirect(wl($ID,array('do'=>'admin','page'=>'config'),true,'&'));
            exit();
        } elseif(!$this->_error) {
            $this->_config->touch_settings(); // just touch to refresh cache
        }

        $this->_close_session();
    }

    /**
     * output appropriate html
     */
    public function html() {
        $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here.
        global $lang;
        global $ID;

        if (is_null($this->_config)) { $this->_config = new configuration($this->_file); }
        $this->setupLocale(true);

        print $this->locale_xhtml('intro');

        ptln('<div id="config__manager">');

        if ($this->_config->locked)
            ptln('<div class="info">'.$this->getLang('locked').'</div>');
        elseif ($this->_error)
            ptln('<div class="error">'.$this->getLang('error').'</div>');
        elseif ($this->_changed)
            ptln('<div class="success">'.$this->getLang('updated').'</div>');

        // POST to script() instead of wl($ID) so config manager still works if
        // rewrite config is broken. Add $ID as hidden field to remember
        // current ID in most cases.
        ptln('<form action="'.script().'" method="post">');
        ptln('<div class="no"><input type="hidden" name="id" value="'.$ID.'" /></div>');
        formSecurityToken();
        $this->_print_h1('dokuwiki_settings', $this->getLang('_header_dokuwiki'));

        /** @var setting[] $undefined_settings */
        $undefined_settings = array();
        $in_fieldset = false;
        $first_plugin_fieldset = true;
        $first_template_fieldset = true;
        foreach($this->_config->setting as $setting) {
            if (is_a($setting, 'setting_hidden')) {
                // skip hidden (and undefined) settings
                if ($allow_debug && is_a($setting, 'setting_undefined')) {
                    $undefined_settings[] = $setting;
                } else {
                    continue;
                }
            } else if (is_a($setting, 'setting_fieldset')) {
                // config setting group
                if ($in_fieldset) {
                    ptln('  </table>');
                    ptln('  </div>');
                    ptln('  </fieldset>');
                } else {
                    $in_fieldset = true;
                }
                if ($first_plugin_fieldset && substr($setting->_key, 0, 10)=='plugin'.CM_KEYMARKER) {
                    $this->_print_h1('plugin_settings', $this->getLang('_header_plugin'));
                    $first_plugin_fieldset = false;
                } else if ($first_template_fieldset && substr($setting->_key, 0, 7)=='tpl'.CM_KEYMARKER) {
                    $this->_print_h1('template_settings', $this->getLang('_header_template'));
                    $first_template_fieldset = false;
                }
                ptln('  <fieldset id="'.$setting->_key.'">');
                ptln('  <legend>'.$setting->prompt($this).'</legend>');
                ptln('  <div class="table">');
                ptln('  <table class="inline">');
            } else {
                // config settings
                list($label,$input) = $setting->html($this, $this->_error);

                $class = $setting->is_default() ? ' class="default"' : ($setting->is_protected() ? ' class="protected"' : '');
                $error = $setting->error() ? ' class="value error"' : ' class="value"';
                $icon = $setting->caution() ? '<img src="'.DOKU_PLUGIN_IMAGES.$setting->caution().'.png" alt="'.$setting->caution().'" title="'.$this->getLang($setting->caution()).'" />' : '';

                ptln('    <tr'.$class.'>');
                ptln('      <td class="label">');
                ptln('        <span class="outkey">'.$setting->_out_key(true, true).'</span>');
                ptln('        '.$icon.$label);
                ptln('      </td>');
                ptln('      <td'.$error.'>'.$input.'</td>');
                ptln('    </tr>');
            }
        }

        ptln('  </table>');
        ptln('  </div>');
        if ($in_fieldset) {
            ptln('  </fieldset>');
        }

        // show undefined settings list
        if ($allow_debug && !empty($undefined_settings)) {
            /**
             * Callback for sorting settings
             *
             * @param setting $a
             * @param setting $b
             * @return int if $a is lower/equal/higher than $b
             */
            function _setting_natural_comparison($a, $b) {
                return strnatcmp($a->_key, $b->_key);
            }

            usort($undefined_settings, '_setting_natural_comparison');
            $this->_print_h1('undefined_settings', $this->getLang('_header_undefined'));
            ptln('<fieldset>');
            ptln('<div class="table">');
            ptln('<table class="inline">');
            $undefined_setting_match = array();
            foreach($undefined_settings as $setting) {
                if (preg_match('/^(?:plugin|tpl)'.CM_KEYMARKER.'.*?'.CM_KEYMARKER.'(.*)$/', $setting->_key, $undefined_setting_match)) {
                    $undefined_setting_key = $undefined_setting_match[1];
                } else {
                    $undefined_setting_key = $setting->_key;
                }
                ptln('  <tr>');
                ptln('    <td class="label"><span title="$meta[\''.$undefined_setting_key.'\']">$'.$this->_config->_name.'[\''.$setting->_out_key().'\']</span></td>');
                ptln('    <td>'.$this->getLang('_msg_'.get_class($setting)).'</td>');
                ptln('  </tr>');
            }
            ptln('</table>');
            ptln('</div>');
            ptln('</fieldset>');
        }

        // finish up form
        ptln('<p>');
        ptln('  <input type="hidden" name="do"     value="admin" />');
        ptln('  <input type="hidden" name="page"   value="config" />');

        if (!$this->_config->locked) {
            ptln('  <input type="hidden" name="save"   value="1" />');
            ptln('  <button type="submit" name="submit" accesskey="s">'.$lang['btn_save'].'</button>');
            ptln('  <button type="reset">'.$lang['btn_reset'].'</button>');
        }

        ptln('</p>');

        ptln('</form>');
        ptln('</div>');
    }

    /**
     * @return boolean   true - proceed with handle, false - don't proceed
     */
    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
        if (!headers_sent()) {
            session_start();
            $this->_session_started = true;
        }

        if (!isset($_SESSION['PLUGIN_CONFIG'])) return true;

        $session = $_SESSION['PLUGIN_CONFIG'];
        unset($_SESSION['PLUGIN_CONFIG']);

        // still valid?
        if (time() - $session['time'] > 120) return true;

        switch ($session['state']) {
            case 'updated' :
                $this->_changed = true;
                return false;
        }

        return true;
    }

    protected function _close_session() {
      if ($this->_session_started) session_write_close();
    }

    /**
     * @param bool $prompts
     */
    public function setupLocale($prompts=false) {

        parent::setupLocale();
        if (!$prompts || $this->_localised_prompts) return;

        $this->_setup_localised_plugin_prompts();
        $this->_localised_prompts = true;

    }

    /**
     * @return bool
     */
    protected function _setup_localised_plugin_prompts() {
        global $conf;

        $langfile   = '/lang/'.$conf['lang'].'/settings.php';
        $enlangfile = '/lang/en/settings.php';

        if ($dh = opendir(DOKU_PLUGIN)) {
            while (false !== ($plugin = readdir($dh))) {
                if ($plugin == '.' || $plugin == '..' || $plugin == 'tmp' || $plugin == 'config') continue;
                if (is_file(DOKU_PLUGIN.$plugin)) continue;

                if (file_exists(DOKU_PLUGIN.$plugin.$enlangfile)){
                    $lang = array();
                    @include(DOKU_PLUGIN.$plugin.$enlangfile);
                    if ($conf['lang'] != 'en') @include(DOKU_PLUGIN.$plugin.$langfile);
                    foreach ($lang as $key => $value){
                        $this->lang['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.$key] = $value;
                    }
                }

                // fill in the plugin name if missing (should exist for plugins with settings)
                if (!isset($this->lang['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.'plugin_settings_name'])) {
                    $this->lang['plugin'.CM_KEYMARKER.$plugin.CM_KEYMARKER.'plugin_settings_name'] =
                      ucwords(str_replace('_', ' ', $plugin));
                }
            }
            closedir($dh);
      }

        // the same for the active template
        $tpl = $conf['template'];

        if (file_exists(tpl_incdir().$enlangfile)){
            $lang = array();
            @include(tpl_incdir().$enlangfile);
            if ($conf['lang'] != 'en') @include(tpl_incdir().$langfile);
            foreach ($lang as $key => $value){
                $this->lang['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.$key] = $value;
            }
        }

        // fill in the template name if missing (should exist for templates with settings)
        if (!isset($this->lang['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.'template_settings_name'])) {
            $this->lang['tpl'.CM_KEYMARKER.$tpl.CM_KEYMARKER.'template_settings_name'] =
              ucwords(str_replace('_', ' ', $tpl));
        }

        return true;
    }

    /**
     * Generates a two-level table of contents for the config plugin.
     *
     * @author Ben Coburn <btcoburn@silicodon.net>
     *
     * @return array
     */
    public function getTOC() {
        if (is_null($this->_config)) { $this->_config = new configuration($this->_file); }
        $this->setupLocale(true);

        $allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here.

        // gather toc data
        $has_undefined = false;
        $toc = array('conf'=>array(), 'plugin'=>array(), 'template'=>null);
        foreach($this->_config->setting as $setting) {
            if (is_a($setting, 'setting_fieldset')) {
                if (substr($setting->_key, 0, 10)=='plugin'.CM_KEYMARKER) {
                    $toc['plugin'][] = $setting;
                } else if (substr($setting->_key, 0, 7)=='tpl'.CM_KEYMARKER) {
                    $toc['template'] = $setting;
                } else {
                    $toc['conf'][] = $setting;
                }
            } else if (!$has_undefined && is_a($setting, 'setting_undefined')) {
                $has_undefined = true;
            }
        }

        // build toc
        $t = array();

        $check = false;
        $title = $this->getLang('_configuration_manager');
        $t[] = html_mktocitem(sectionID($title, $check), $title, 1);
        $t[] = html_mktocitem('dokuwiki_settings', $this->getLang('_header_dokuwiki'), 1);
        /** @var setting $setting */
        foreach($toc['conf'] as $setting) {
            $name = $setting->prompt($this);
            $t[] = html_mktocitem($setting->_key, $name, 2);
        }
        if (!empty($toc['plugin'])) {
            $t[] = html_mktocitem('plugin_settings', $this->getLang('_header_plugin'), 1);
        }
        foreach($toc['plugin'] as $setting) {
            $name = $setting->prompt($this);
            $t[] = html_mktocitem($setting->_key, $name, 2);
        }
        if (isset($toc['template'])) {
            $t[] = html_mktocitem('template_settings', $this->getLang('_header_template'), 1);
            $setting = $toc['template'];
            $name = $setting->prompt($this);
            $t[] = html_mktocitem($setting->_key, $name, 2);
        }
        if ($has_undefined && $allow_debug) {
            $t[] = html_mktocitem('undefined_settings', $this->getLang('_header_undefined'), 1);
        }

        return $t;
    }

    /**
     * @param string $id
     * @param string $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;
    }
}