From 0c55a0b6a4e5527dbbf263d5f7687cab39298db6 Mon Sep 17 00:00:00 2001
From: Tim van Dijen <tvdijen@gmail.com>
Date: Wed, 19 Feb 2020 10:05:49 +0100
Subject: [PATCH] Remove references to old templates

---
 lib/SimpleSAML/Error/MetadataNotFound.php          |  2 +-
 lib/SimpleSAML/Error/NoState.php                   |  2 +-
 lib/SimpleSAML/XHTML/Template.php                  | 12 ------------
 lib/SimpleSAML/XHTML/TemplateLoader.php            |  4 ----
 modules/core/www/authenticate.php                  |  2 +-
 modules/core/www/cardinality_error.php             |  2 +-
 modules/core/www/frontpage_auth.php                |  2 +-
 modules/core/www/frontpage_config.php              |  2 +-
 modules/core/www/frontpage_federation.php          |  2 +-
 modules/core/www/frontpage_welcome.php             |  2 +-
 modules/core/www/idp/logout-iframe.php             |  4 ++--
 modules/core/www/loginuserpass.php                 |  2 +-
 modules/core/www/loginuserpassorg.php              |  2 +-
 modules/core/www/no_cookie.php                     |  2 +-
 modules/core/www/short_sso_interval.php            |  2 +-
 modules/core/www/show_metadata.php                 |  2 +-
 modules/exampleauth/www/authpage.php               |  2 +-
 modules/multiauth/www/selectsource.php             |  2 +-
 modules/saml/www/proxy/invalid_session.php         |  2 +-
 modules/saml/www/sp/metadata.php                   |  2 +-
 modules/saml/www/sp/wrong_authncontextclassref.php |  2 +-
 21 files changed, 20 insertions(+), 36 deletions(-)

diff --git a/lib/SimpleSAML/Error/MetadataNotFound.php b/lib/SimpleSAML/Error/MetadataNotFound.php
index 5065a7568..fe730ff38 100644
--- a/lib/SimpleSAML/Error/MetadataNotFound.php
+++ b/lib/SimpleSAML/Error/MetadataNotFound.php
@@ -21,7 +21,7 @@ class MetadataNotFound extends Error
      */
     public function __construct(string $entityId)
     {
-        $this->includeTemplate = 'core:no_metadata.tpl.php';
+        $this->includeTemplate = 'core:no_metadata.twig';
         parent::__construct([
                 'METADATANOTFOUND',
                 '%ENTITYID%' => htmlspecialchars(var_export($entityId, true))
diff --git a/lib/SimpleSAML/Error/NoState.php b/lib/SimpleSAML/Error/NoState.php
index 599bd1cb2..8071d84c7 100644
--- a/lib/SimpleSAML/Error/NoState.php
+++ b/lib/SimpleSAML/Error/NoState.php
@@ -18,7 +18,7 @@ class NoState extends Error
      */
     public function __construct()
     {
-        $this->includeTemplate = 'core:no_state.tpl.php';
+        $this->includeTemplate = 'core:no_state.twig';
         parent::__construct('NOSTATE');
     }
 }
diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php
index bc30e11df..76b5f2131 100644
--- a/lib/SimpleSAML/XHTML/Template.php
+++ b/lib/SimpleSAML/XHTML/Template.php
@@ -545,8 +545,6 @@ class Template extends Response
      */
     private function findTemplatePath(string $template, bool $throw_exception = true): ?string
     {
-        $extensions = ['.tpl.php', '.php'];
-
         list($templateModule, $templateName) = $this->findModuleAndTemplateName($template);
         $templateModule = ($templateModule !== null) ? $templateModule : 'default';
 
@@ -566,11 +564,6 @@ class Template extends Response
         }
 
         $filename = $this->normalizeTemplateName($filename);
-        foreach ($extensions as $extension) {
-            if (file_exists($filename . $extension)) {
-                return $filename . $extension;
-            }
-        }
 
         // not found in current theme
         Logger::debug(
@@ -589,11 +582,6 @@ class Template extends Response
         }
 
         $filename = $this->normalizeTemplateName($filename);
-        foreach ($extensions as $extension) {
-            if (file_exists($filename . $extension)) {
-                return $filename . $extension;
-            }
-        }
 
         // not found in default template
         if ($throw_exception) {
diff --git a/lib/SimpleSAML/XHTML/TemplateLoader.php b/lib/SimpleSAML/XHTML/TemplateLoader.php
index 919ded5d9..f48ae7c54 100644
--- a/lib/SimpleSAML/XHTML/TemplateLoader.php
+++ b/lib/SimpleSAML/XHTML/TemplateLoader.php
@@ -51,10 +51,6 @@ class TemplateLoader extends \Twig\Loader\FilesystemLoader
         if (strpos($name, ':')) {
             // we have our old SSP format
             list($namespace, $shortname) = explode(':', $name, 2);
-            $shortname = strtr($shortname, [
-                '.tpl.php' => '.twig',
-                '.php' => '.twig',
-            ]);
             return [$namespace, $shortname];
         }
         return [$default, $name];
diff --git a/modules/core/www/authenticate.php b/modules/core/www/authenticate.php
index 680ece576..d46da93e3 100644
--- a/modules/core/www/authenticate.php
+++ b/modules/core/www/authenticate.php
@@ -5,7 +5,7 @@ use Webmozart\Assert\Assert;
 $config = \SimpleSAML\Configuration::getInstance();
 
 if (!array_key_exists('as', $_REQUEST)) {
-    $t = new \SimpleSAML\XHTML\Template($config, 'core:authsource_list.tpl.php');
+    $t = new \SimpleSAML\XHTML\Template($config, 'core:authsource_list.twig');
 
     $t->data['sources'] = \SimpleSAML\Auth\Source::getSources();
     $t->send();
diff --git a/modules/core/www/cardinality_error.php b/modules/core/www/cardinality_error.php
index 135493d50..cae3cbf4e 100644
--- a/modules/core/www/cardinality_error.php
+++ b/modules/core/www/cardinality_error.php
@@ -18,7 +18,7 @@ $session = \SimpleSAML\Session::getSessionFromRequest();
     . ' ' . $state['saml:sp:IdP'] . ' ' . implode(',', array_keys($state['core:cardinality:errorAttributes'])));
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:cardinality_error.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:cardinality_error.twig');
 $t->data['cardinalityErrorAttributes'] = $state['core:cardinality:errorAttributes'];
 if (isset($state['Source']['auth'])) {
     $t->data['LogoutURL'] = \SimpleSAML\Module::getModuleURL(
diff --git a/modules/core/www/frontpage_auth.php b/modules/core/www/frontpage_auth.php
index cd6546f13..859bc5a53 100644
--- a/modules/core/www/frontpage_auth.php
+++ b/modules/core/www/frontpage_auth.php
@@ -32,7 +32,7 @@ $allLinks = [
 ];
 \SimpleSAML\Module::callHooks('frontpage', $allLinks);
 
-$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_auth.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_auth.twig');
 $t->data['pageid'] = 'frontpage_auth';
 $t->data['isadmin'] = $isadmin;
 $t->data['loginurl'] = $loginurl;
diff --git a/modules/core/www/frontpage_config.php b/modules/core/www/frontpage_config.php
index 8243fae64..bfd2cf6ad 100644
--- a/modules/core/www/frontpage_config.php
+++ b/modules/core/www/frontpage_config.php
@@ -164,7 +164,7 @@ $funcmatrix[] = [
     'enabled' => $password_ok
 ];
 
-$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_config.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_config.twig');
 $translator = $t->getTranslator();
 $t->data['pageid'] = 'frontpage_config';
 $t->data['header'] = $translator->t('{core:frontpage:page_title}');
diff --git a/modules/core/www/frontpage_federation.php b/modules/core/www/frontpage_federation.php
index 66e896841..8ab6ac092 100644
--- a/modules/core/www/frontpage_federation.php
+++ b/modules/core/www/frontpage_federation.php
@@ -86,7 +86,7 @@ foreach ($metaentries['remote'] as $key => $value) {
     }
 }
 
-$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_federation.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_federation.twig');
 $translator = $t->getTranslator();
 
 $language = $translator->getLanguage()->getLanguage();
diff --git a/modules/core/www/frontpage_welcome.php b/modules/core/www/frontpage_welcome.php
index 22dc2d9f3..9a662dafa 100644
--- a/modules/core/www/frontpage_welcome.php
+++ b/modules/core/www/frontpage_welcome.php
@@ -33,7 +33,7 @@ $links_welcome[] = [
 
 \SimpleSAML\Module::callHooks('frontpage', $allLinks);
 
-$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_welcome.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'core:frontpage_welcome.twig');
 $t->data['pageid'] = 'frontpage_welcome';
 $t->data['isadmin'] = $isadmin;
 $t->data['loginurl'] = $loginurl;
diff --git a/modules/core/www/idp/logout-iframe.php b/modules/core/www/idp/logout-iframe.php
index 442b26bd0..0145a9aa7 100644
--- a/modules/core/www/idp/logout-iframe.php
+++ b/modules/core/www/idp/logout-iframe.php
@@ -122,9 +122,9 @@ foreach ($state['core:Logout-IFrame:Associations'] as $association) {
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
 if ($type === 'nojs') {
-    $t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:logout-iframe-wrapper.tpl.php');
+    $t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:logout-iframe-wrapper.twig');
 } else {
-    $t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:logout-iframe.tpl.php');
+    $t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:logout-iframe.twig');
 }
 
 /**
diff --git a/modules/core/www/loginuserpass.php b/modules/core/www/loginuserpass.php
index 27e432716..ec9faec0a 100644
--- a/modules/core/www/loginuserpass.php
+++ b/modules/core/www/loginuserpass.php
@@ -99,7 +99,7 @@ if (!empty($_REQUEST['username']) || !empty($password)) {
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:loginuserpass.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:loginuserpass.twig');
 $t->data['stateparams'] = ['AuthState' => $authStateId];
 if (array_key_exists('forcedUsername', $state)) {
     $t->data['username'] = $state['forcedUsername'];
diff --git a/modules/core/www/loginuserpassorg.php b/modules/core/www/loginuserpassorg.php
index be63c72bb..2130fd4ac 100644
--- a/modules/core/www/loginuserpassorg.php
+++ b/modules/core/www/loginuserpassorg.php
@@ -128,7 +128,7 @@ if ($organizations === null || !empty($organization)) {
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:loginuserpass.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:loginuserpass.twig');
 $t->data['stateparams'] = ['AuthState' => $authStateId];
 $t->data['username'] = $username;
 $t->data['forceUsername'] = false;
diff --git a/modules/core/www/no_cookie.php b/modules/core/www/no_cookie.php
index c2ff054fa..f5dd285ed 100644
--- a/modules/core/www/no_cookie.php
+++ b/modules/core/www/no_cookie.php
@@ -8,7 +8,7 @@ if (isset($_REQUEST['retryURL'])) {
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:no_cookie.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:no_cookie.twig');
 $translator = $t->getTranslator();
 
 /** @var string $header */
diff --git a/modules/core/www/short_sso_interval.php b/modules/core/www/short_sso_interval.php
index 2659471c1..2d1de11d8 100644
--- a/modules/core/www/short_sso_interval.php
+++ b/modules/core/www/short_sso_interval.php
@@ -23,7 +23,7 @@ if (array_key_exists('continue', $_REQUEST)) {
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:short_sso_interval.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'core:short_sso_interval.twig');
 $translator = $t->getTranslator();
 $t->data['target'] = \SimpleSAML\Module::getModuleURL('core/short_sso_interval.php');
 $t->data['params'] = ['StateId' => $id];
diff --git a/modules/core/www/show_metadata.php b/modules/core/www/show_metadata.php
index d9dd9ffdc..6c9e444be 100644
--- a/modules/core/www/show_metadata.php
+++ b/modules/core/www/show_metadata.php
@@ -26,7 +26,7 @@ $metadata = \SimpleSAML\Metadata\MetaDataStorageHandler::getMetadataHandler();
 
 $m = $metadata->getMetaData($_REQUEST['entityid'], $_REQUEST['set']);
 
-$t = new \SimpleSAML\XHTML\Template($config, 'core:show_metadata.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'core:show_metadata.twig');
 $t->data['clipboard.js'] = true;
 $t->data['pageid'] = 'show_metadata';
 $t->data['header'] = 'SimpleSAMLphp Show Metadata';
diff --git a/modules/exampleauth/www/authpage.php b/modules/exampleauth/www/authpage.php
index b4b4b4458..085b486c2 100644
--- a/modules/exampleauth/www/authpage.php
+++ b/modules/exampleauth/www/authpage.php
@@ -80,7 +80,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
 
 // if we get this far, we need to show the login page to the user
 $config = \SimpleSAML\Configuration::getInstance();
-$t = new \SimpleSAML\XHTML\Template($config, 'exampleauth:authenticate.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($config, 'exampleauth:authenticate.twig');
 $t->data['badUserPass'] = $badUserPass;
 $t->data['returnTo'] = $returnTo;
 $t->send();
diff --git a/modules/multiauth/www/selectsource.php b/modules/multiauth/www/selectsource.php
index 6d7e5d97d..f635521b6 100644
--- a/modules/multiauth/www/selectsource.php
+++ b/modules/multiauth/www/selectsource.php
@@ -51,7 +51,7 @@ if (array_key_exists('multiauth:preselect', $state)) {
 }
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new \SimpleSAML\XHTML\Template($globalConfig, 'multiauth:selectsource.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'multiauth:selectsource.twig');
 
 $defaultLanguage = $globalConfig->getString('language.default', 'en');
 $language = $t->getTranslator()->getLanguage()->getLanguage();
diff --git a/modules/saml/www/proxy/invalid_session.php b/modules/saml/www/proxy/invalid_session.php
index 3a3d3b886..ef0885887 100644
--- a/modules/saml/www/proxy/invalid_session.php
+++ b/modules/saml/www/proxy/invalid_session.php
@@ -48,7 +48,7 @@ if (isset($_POST['continue'])) {
 }
 
 $cfg = \SimpleSAML\Configuration::getInstance();
-$template = new \SimpleSAML\XHTML\Template($cfg, 'saml:proxy/invalid_session.tpl.php');
+$template = new \SimpleSAML\XHTML\Template($cfg, 'saml:proxy/invalid_session.twig');
 $translator = $template->getTranslator();
 $template->data['AuthState'] = (string) $_REQUEST['AuthState'];
 
diff --git a/modules/saml/www/sp/metadata.php b/modules/saml/www/sp/metadata.php
index e32b1d34b..c2e58ee43 100644
--- a/modules/saml/www/sp/metadata.php
+++ b/modules/saml/www/sp/metadata.php
@@ -272,7 +272,7 @@ if (isset($metaArray20['attributes']) && is_array($metaArray20['attributes'])) {
 $xml = \SimpleSAML\Metadata\Signer::sign($xml, $spconfig->toArray(), 'SAML 2 SP');
 
 if (array_key_exists('output', $_REQUEST) && $_REQUEST['output'] == 'xhtml') {
-    $t = new \SimpleSAML\XHTML\Template($config, 'metadata.tpl.php', 'admin');
+    $t = new \SimpleSAML\XHTML\Template($config, 'metadata.twig', 'admin');
 
     $t->data['clipboard.js'] = true;
     $t->data['header'] = 'saml20-sp'; // TODO: Replace with headerString in 2.0
diff --git a/modules/saml/www/sp/wrong_authncontextclassref.php b/modules/saml/www/sp/wrong_authncontextclassref.php
index 5c81d73e5..15c08cd9a 100644
--- a/modules/saml/www/sp/wrong_authncontextclassref.php
+++ b/modules/saml/www/sp/wrong_authncontextclassref.php
@@ -1,5 +1,5 @@
 <?php
 
 $globalConfig = \SimpleSAML\Configuration::getInstance();
-$t = new \SimpleSAML\XHTML\Template($globalConfig, 'saml:sp/wrong_authncontextclassref.tpl.php');
+$t = new \SimpleSAML\XHTML\Template($globalConfig, 'saml:sp/wrong_authncontextclassref.twig');
 $t->send();
-- 
GitLab