Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create a new "configpage" hook for those modules that need to inject …
…anything in the configuration page.

This allows us to change the signature of the hook, so that we pass it the \SimpleSAML\XHTML\Template object and then the hook can not only add data to be passed to the twig template, but also add its own translation domain. This was needed because many modules were putting their translations inside "core", and when moving those to the modules themselves, the new translation system cannot perform the translation because only the translations for the current module in use are loaded (in the config page, that's the core module). Therefore, we needed a way to get the Localization instance from the template, and a way to pass that to the hook so that the hook can register the translations for its own module.
  • Loading branch information
jaimeperez committed Nov 23, 2018
1 parent 409862b commit d42f26f
Show file tree
Hide file tree
Showing 41 changed files with 233 additions and 108 deletions.
4 changes: 2 additions & 2 deletions lib/SimpleSAML/Locale/Localization.php
Expand Up @@ -126,7 +126,7 @@ public function getDomainLocaleDir($domain)
}


/*
/**
* Add a new translation domain from a module
* (We're assuming that each domain only exists in one place)
*
Expand All @@ -142,7 +142,7 @@ public function addModuleDomain($module, $localeDir = null)
}


/*
/**
* Add a new translation domain
* (We're assuming that each domain only exists in one place)
*
Expand Down
11 changes: 11 additions & 0 deletions lib/SimpleSAML/XHTML/Template.php
Expand Up @@ -583,6 +583,17 @@ public function getTranslator()
}


/**
* Return the internal localization object used by this template.
*
* @return \SimpleSAML\Locale\Localization The localization object that will be used with this template.
*/
public function getLocalization()
{
return $this->localization;
}


/**
* Get the current instance of Twig in use.
*
Expand Down
Expand Up @@ -58,5 +58,8 @@
},
"consentadmin_purpose": {
"en": "The purpose of the service is"
},
"link_consentAdmin": {
"en": "Consent administration"
}
}
Expand Up @@ -598,5 +598,10 @@
"cs": "\u00da\u010del slu\u017eby je",
"eu": "Zerbitzuaren xedea hau da",
"el": "\u039f \u03c3\u03ba\u03bf\u03c0\u03cc\u03c2 \u03c4\u03b7\u03c2 \u03c5\u03c0\u03b7\u03c1\u03b5\u03c3\u03af\u03b1\u03c2 \u03b5\u03af\u03bd\u03b1\u03b9"
},
"link_consentAdmin": {
"es": "Administración del consentimiento",
"no": "Samtykke administrasjon",
"nn": "Samtykke administrasjon"
}
}
19 changes: 19 additions & 0 deletions modules/consentAdmin/hooks/hook_configpage.php
@@ -0,0 +1,19 @@
<?php
/**
* Hook to add the consentAdmin module to the config page.
*
* @param \SimpleSAML\XHTML\Template The template that we should alter in this hook.
*/

function consentAdmin_hook_configpage(\SimpleSAML\XHTML\Template &$template)
{
$template->data['links_config']['consentAdmin'] = [
'href' => SimpleSAML\Module::getModuleURL('consentAdmin/consentAdmin.php'),
'text' => '{consentAdmin:consentadmin:link_consentAdmin}',
];

$config = \SimpleSAML\Configuration::getInstance();
if ($config->getBoolean('usenewui', false)) {
$template->getLocalization()->addModuleDomain('consentAdmin');
}
}
17 changes: 0 additions & 17 deletions modules/consentAdmin/hooks/hook_frontpage.php

This file was deleted.

18 changes: 0 additions & 18 deletions modules/core/dictionaries/frontpage.definition.json
Expand Up @@ -110,27 +110,9 @@
"link_cleardiscochoices": {
"en": "Delete my choices of IdP in the IdP discovery services"
},
"link_sanitycheck": {
"en": "Sanity check of your SimpleSAMLphp setup"
},
"link_consentAdmin": {
"en": "Consent Administration"
},
"link_memcacheMonitor": {
"en": "MemCache Statistics"
},
"link_oauth": {
"en": "OAuth Consumer Registry"
},
"link_cron": {
"en": "Cron module information page"
},
"link_statistics": {
"en": "Show statistics"
},
"link_statistics_metadata": {
"en": "Show statistics metadata"
},
"link_metarefresh": {
"en": "Metarefresh: fetch metadata"
},
Expand Down
4 changes: 4 additions & 0 deletions modules/core/www/frontpage_config.php
Expand Up @@ -53,6 +53,8 @@
'federation' => &$links_federation,
];
\SimpleSAML\Module::callHooks('frontpage', $allLinks);
\SimpleSAML\Logger::debug('The "frontpage" hook has been deprecated for the configuration page. Implement the '.'
"configpage" hook instead.');

// Check for updates. Store the remote result in the session so we
// don't need to fetch it on every access to this page.
Expand Down Expand Up @@ -197,4 +199,6 @@
$t->data['version'] = $config->getVersion();
$t->data['directory'] = dirname(dirname(dirname(dirname(__FILE__))));

\SimpleSAML\Module::callHooks('configpage', $t);

$t->show();
3 changes: 3 additions & 0 deletions modules/cron/dictionaries/cron.definition.json
Expand Up @@ -22,5 +22,8 @@
},
"cron_report_title": {
"en": "Cron report"
},
"link_cron": {
"en": "Cron module information page"
}
}
5 changes: 5 additions & 0 deletions modules/cron/dictionaries/cron.translation.json
Expand Up @@ -254,5 +254,10 @@
"af": "Cron verslag",
"pt-br": "Relat\u00f3rio do cron",
"el": "\u0391\u03bd\u03b1\u03c6\u03bf\u03c1\u03ac cron"
},
"link_cron": {
"es": "Informe de cron",
"no": "Informasjon om cron",
"nn": "Informasjon om cron"
}
}
19 changes: 19 additions & 0 deletions modules/cron/hooks/hook_configpage.php
@@ -0,0 +1,19 @@
<?php
/**
* Hook to add the cron module to the config page.
*
* @param \SimpleSAML\XHTML\Template &$template The template that we should alter in this hook.
*/

function cron_hook_configpage(\SimpleSAML\XHTML\Template &$template)
{
$template->data['links_config']['cron'] = [
'href' => SimpleSAML\Module::getModuleURL('cron/croninfo.php'),
'text' => '{cron:cron:link_cron}',
];

$config = \SimpleSAML\Configuration::getInstance();
if ($config->getBoolean('usenewui', false)) {
$template->getLocalization()->addModuleDomain('cron');
}
}
17 changes: 0 additions & 17 deletions modules/cron/hooks/hook_frontpage.php

This file was deleted.

2 changes: 2 additions & 0 deletions modules/cron/locales/en/LC_MESSAGES/cron.po
Expand Up @@ -63,3 +63,5 @@ msgstr "Here are the result for the cron job execution:"
msgid "Cron result page"
msgstr "Cron result page"

msgid "{cron:cron:link_cron}"
msgstr "Cron module information page"
2 changes: 2 additions & 0 deletions modules/cron/locales/es/LC_MESSAGES/cron.po
Expand Up @@ -63,3 +63,5 @@ msgstr "Aqui están los resultados de las tareas en la ejecución del cron:"
msgid "Cron result page"
msgstr "Página de resultado del cron"

msgid "{cron:cron:link_cron}"
msgstr "Informe de cron"
2 changes: 2 additions & 0 deletions modules/cron/locales/nb/LC_MESSAGES/cron.po
Expand Up @@ -63,3 +63,5 @@ msgstr "Her er resultatene fra kjøring av cron-jobben:"
msgid "Cron result page"
msgstr "Cron resultatside"

msgid "{cron:cron:link_cron}"
msgstr "Informasjon om cron"
2 changes: 2 additions & 0 deletions modules/cron/locales/nn/LC_MESSAGES/cron.po
Expand Up @@ -63,3 +63,5 @@ msgstr "Her er resultata frå køyring av cron-jobben:"
msgid "Cron result page"
msgstr "Cron resultatside"

msgid "{cron:cron:link_cron}"
msgstr "Informasjon om cron"
Expand Up @@ -142,5 +142,8 @@
},
"reclaimed": {
"en": "Number of times an entry was stored using memory from an expired entry"
},
"link_memcacheMonitor": {
"en": "Memcache statistics"
}
}
Expand Up @@ -549,5 +549,10 @@
"cs": "Celkov\u00e9 dostupn\u00e9 \u00falo\u017ei\u0161t\u011b",
"eu": "Ustiatutako biltegiraketa guztira",
"el": "\u0394\u03b9\u03b1\u03b8\u03ad\u03c3\u03b9\u03bc\u03bf\u03c2 \u03c7\u03ce\u03c1\u03bf\u03c2 \u03b1\u03c0\u03bf\u03b8\u03ae\u03ba\u03b5\u03c5\u03c3\u03b7\u03c2"
},
"link_memcacheMonitor": {
"es": "Estadísticas de memcache",
"no": "Memcache statistikker",
"nn": "Memcache statistikkar"
}
}
19 changes: 19 additions & 0 deletions modules/memcacheMonitor/hooks/hook_configpage.php
@@ -0,0 +1,19 @@
<?php
/**
* Hook to add the memcacheMonitor module to the config page.
*
* @param \SimpleSAML\XHTML\Template &$template The template that we should alter in this hook.
*/

function memcacheMonitor_hook_configpage(\SimpleSAML\XHTML\Template &$template)
{
$template->data['links_config']['memcacheMonitor'] = [
'href' => SimpleSAML\Module::getModuleURL('memcacheMonitor/memcachestat.php'),
'text' => '{memcacheMonitor:memcachestat:link_memcacheMonitor}',
];

$config = \SimpleSAML\Configuration::getInstance();
if ($config->getBoolean('usenewui', false)) {
$template->getLocalization()->addModuleDomain('memcacheMonitor');
}
}
17 changes: 0 additions & 17 deletions modules/memcacheMonitor/hooks/hook_frontpage.php

This file was deleted.

Expand Up @@ -264,3 +264,5 @@ msgstr "CPU Seconds (System)"
msgid "Total connections"
msgstr "Total connections"

msgid "{memcacheMonitor:memcachestat:link_memcacheMonitor}"
msgstr "Memcache statistics"
Expand Up @@ -129,3 +129,5 @@ msgstr "Segundos de CPU (Sistema)"
msgid "Total connections"
msgstr "Total de conexiones"

msgid "{memcacheMonitor:memcachestat:link_memcacheMonitor}"
msgstr "Estadísticas de memcache"
Expand Up @@ -129,3 +129,5 @@ msgstr "CPU Sekunder (system)"
msgid "Total connections"
msgstr "Totalt antall forbindelser"

msgid "{memcacheMonitor:memcachestat:link_memcacheMonitor}"
msgstr "Memcache statistikker"
Expand Up @@ -129,3 +129,5 @@ msgstr "CPU-sekund (system)"
msgid "Total connections"
msgstr "Opne tilkoplingar (totalt)"

msgid "{memcacheMonitor:memcachestat:link_memcacheMonitor}"
msgstr "Memcache statistikkar"
5 changes: 5 additions & 0 deletions modules/sanitycheck/dictionaries/strings.definition.json
@@ -0,0 +1,5 @@
{
"link_sanitycheck": {
"en": "Sanity check of your SimpleSAMLphp setup"
}
}
7 changes: 7 additions & 0 deletions modules/sanitycheck/dictionaries/strings.translation.json
@@ -0,0 +1,7 @@
{
"link_sanitycheck": {
"es": "Comprobaciones básicas de la instalación",
"no": "Sjekk din installasjon",
"nn": "Sjekk din installasjon"
}
}
18 changes: 18 additions & 0 deletions modules/sanitycheck/hooks/hook_configpage.php
@@ -0,0 +1,18 @@
<?php
/**
* Hook to add the sanitycheck link to the config page.
*
* @param \SimpleSAML\XHTML\Template The template that we should alter in this hook.
*/
function sanitycheck_hook_configpage(\SimpleSAML\XHTML\Template &$template)
{
$template->data['links_config']['sanitycheck'] = [
'href' => SimpleSAML\Module::getModuleURL('sanitycheck/index.php'),
'text' => '{sanitycheck:strings:link_sanitycheck}',
];

$config = \SimpleSAML\Configuration::getInstance();
if ($config->getBoolean('usenewui', false)) {
$template->getLocalization()->addModuleDomain('sanitycheck');
}
}
16 changes: 0 additions & 16 deletions modules/sanitycheck/hooks/hook_frontpage.php

This file was deleted.

Expand Up @@ -4,3 +4,5 @@ msgstr "These checks failed:"
msgid "These checks succeeded:"
msgstr "These checks succeeded:"

msgid "{sanitycheck:strings:link_sanitycheck}"
msgstr "Sanity check of your SimpleSAMLphp setup"
8 changes: 8 additions & 0 deletions modules/sanitycheck/locales/es/LC_MESSAGES/sanitycheck.po
@@ -0,0 +1,8 @@
msgid "These checks failed:"
msgstr "Las siguientes comprobaciones han fallado:"

msgid "These checks succeeded:"
msgstr "Las siguientes comprobaciones fueron satisfactorias:"

msgid "{sanitycheck:strings:link_sanitycheck}"
msgstr "Comprobaciones básicas de la instalación"
8 changes: 8 additions & 0 deletions modules/sanitycheck/locales/nb/LC_MESSAGES/sanitycheck.po
@@ -0,0 +1,8 @@
msgid "These checks failed:"
msgstr "Disse sjekkene har feila:"

msgid "These checks succeeded:"
msgstr "Disse sjekkene var suksessfulle:"

msgid "{sanitycheck:strings:link_sanitycheck}"
msgstr "Sjekk din installasjon"
8 changes: 8 additions & 0 deletions modules/sanitycheck/locales/nn/LC_MESSAGES/sanitycheck.po
@@ -0,0 +1,8 @@
msgid "These checks failed:"
msgstr "These checks failed:"

msgid "These checks succeeded:"
msgstr "Desse sjekkane var suksessfulle:"

msgid "{sanitycheck:strings:link_sanitycheck}"
msgstr "Sjekk din installasjon"
8 changes: 8 additions & 0 deletions modules/statistics/dictionaries/statistics.definition.json
@@ -0,0 +1,8 @@
{
"link_statistics": {
"en": "Show statistics"
},
"link_statistics_metadata": {
"en": "Show statistics metadata"
}
}

0 comments on commit d42f26f

Please sign in to comment.