Skip to content

Commit

Permalink
fix language and TOC handling
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain committed May 25, 2018
1 parent 303ffdf commit d6fc72e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 36 deletions.
2 changes: 2 additions & 0 deletions lib/plugins/config/_test/LoaderTest.php
Expand Up @@ -68,6 +68,8 @@ public function testLangs() {
$this->assertArrayNotHasKey('title', $lang);

// plugin strings
$this->assertArrayHasKey('plugin____testing____plugin_settings_name', $lang);
$this->assertEquals('Testing', $lang['plugin____testing____plugin_settings_name']);
$this->assertArrayHasKey('plugin____testing____schnibble', $lang);
$this->assertEquals(
'Turns on the schnibble before the frobble is used',
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/config/_test/Setting/AbstractSettingTest.php
Expand Up @@ -64,10 +64,10 @@ public function testPrettyKey() {
public function testType() {
/** @var Setting $setting */
$setting = new $this->class('test');
$this->assertEquals('conf', $setting->getType());
$this->assertEquals('dokuwiki', $setting->getType());

$setting = new $this->class('test_foo');
$this->assertEquals('conf', $setting->getType());
$this->assertEquals('dokuwiki', $setting->getType());

$setting = new $this->class('plugin____test');
$this->assertEquals('plugin', $setting->getType());
Expand Down
62 changes: 31 additions & 31 deletions lib/plugins/config/admin.php
Expand Up @@ -187,8 +187,7 @@ function settingNaturalComparison($a, $b) {
echo '<tr>';
echo
'<td class="label"><span title="$meta[\'' . $undefined_setting_key . '\']">$' .
'conf' . '[\'' . $setting->getArrayKey() . '\']</span></td>'
;
'conf' . '[\'' . $setting->getArrayKey() . '\']</span></td>';
echo '<td>' . $this->getLang('_msg_' . get_class($setting)) . '</td>';
echo '</tr>';
}
Expand Down Expand Up @@ -220,7 +219,7 @@ function settingNaturalComparison($a, $b) {
public function setupLocale($prompts = false) {
parent::setupLocale();
if(!$prompts || $this->promptsLocalized) return;
$this->configuration->getLangs();
$this->lang = array_merge($this->lang, $this->configuration->getLangs());
$this->promptsLocalized = true;
}

Expand All @@ -235,45 +234,46 @@ public function getTOC() {
$this->setupLocale(true);

$allow_debug = $GLOBALS['conf']['allowdebug']; // avoid global $conf; here.
$toc = array();
$check = false;

// gather settings data into three sub arrays
$toc = array('conf' => array(), 'plugin' => array(), 'template' => null);
$labels = ['dokuwiki' => [], 'plugin' => [], 'template' => []];
foreach($this->configuration->getSettings() as $setting) {
if(is_a($setting, 'setting_fieldset')) {
$toc[$setting->getType()][] = $setting;
if(is_a($setting, SettingFieldset::class)) {
$labels[$setting->getType()][] = $setting;
}
}

// build toc
$t = array();

$check = false;
// top header
$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->getKey(), $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->getKey(), $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->getKey(), $name, 2);
$toc[] = html_mktocitem(sectionID($title, $check), $title, 1);

// main entries
foreach(['dokuwiki', 'plugin', 'template'] as $section) {
if(empty($labels[$section])) continue; // no entries, skip

// create main header
$toc[] = html_mktocitem(
$section . '_settings',
$this->getLang('_header_'.$section),
1
);

// create sub headers
foreach($labels[$section] as $setting) {
/** @var SettingFieldset $setting */
$name = $setting->prompt($this);
$toc[] = html_mktocitem($setting->getKey(), $name, 2);
}
}

// undefined settings if allowed
if(count($this->configuration->getUndefined()) && $allow_debug) {
$t[] = html_mktocitem('undefined_settings', $this->getLang('_header_undefined'), 1);
$toc[] = html_mktocitem('undefined_settings', $this->getLang('_header_undefined'), 1);
}

return $t;
return $toc;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/config/core/Loader.php
Expand Up @@ -257,7 +257,7 @@ protected function loadExtensionLang($dir, $type, $extname) {
}

// add fieldset key
$strings[$prefix . $type . '_settings_name'] = ucwords(str_replace('_', ' ', $type));
$strings[$prefix . $type . '_settings_name'] = ucwords(str_replace('_', ' ', $extname));

return $strings;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/plugins/config/core/Setting/Setting.php
Expand Up @@ -143,7 +143,7 @@ public function getArrayKey() {
*
* 'plugin' for plugin configuration
* 'template' for template configuration
* 'conf' for core configuration
* 'dokuwiki' for core configuration
*
* @return string
*/
Expand All @@ -153,7 +153,7 @@ public function getType() {
} else if(substr($this->getKey(), 0, 7) == 'tpl' . Configuration::KEYMARKER) {
return 'template';
} else {
return 'conf';
return 'dokuwiki';
}
}

Expand Down

0 comments on commit d6fc72e

Please sign in to comment.