ILIAS  trunk Revision v11.0_alpha-1689-g66c127b4ae8
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
class.ilMathJaxConfigCheckedObjective.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
21 use ILIAS\Setup;
22 
23 class ilMathJaxConfigCheckedObjective implements Setup\Objective
24 {
26 
27  public function __construct(?\ilMathJaxSetupConfig $setup_config = null)
28  {
29  $this->setup_config = $setup_config;
30  }
31 
32  public function getHash(): string
33  {
34  return hash("sha256", self::class);
35  }
36 
37  public function getLabel(): string
38  {
39  return "Check configuration of Services/MathJax";
40  }
41 
42  public function isNotable(): bool
43  {
44  return false;
45  }
46 
47  public function getPreconditions(Setup\Environment $environment): array
48  {
49  return [
50  new \ilSettingsFactoryExistsObjective()
51  ];
52  }
53 
54  public function achieve(Setup\Environment $environment): Setup\Environment
55  {
57  $factory = $environment->getResource(Setup\Environment::RESOURCE_SETTINGS_FACTORY);
58  $interaction = $environment->getResource(Setup\Environment::RESOURCE_ADMIN_INTERACTION);
59 
60  $repo = new ilMathJaxConfigSettingsRepository($factory->settingsFor('MathJax'));
61  if (!empty($new_config = $this->checkClientScriptUrl($repo->getConfig(), $interaction))) {
62  $repo->updateConfig($new_config);
63  }
64 
65  return $environment;
66  }
67 
68  public function isApplicable(Setup\Environment $environment): bool
69  {
70  return true;
71  }
72 
81  protected function checkClientScriptUrl(ilMathJaxConfig $config, Setup\AdminInteraction $interaction): ?ilMathJaxConfig
82  {
83  $change = false;
84  $recommended = 'https://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML,Safe';
85  $outdated = [
86  'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
87  'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML,Safe',
88  'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
89  'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML,Safe',
90  'https://cdn.jsdelivr.net/npm/mathjax@2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML',
91  'https://cdn.jsdelivr.net/npm/mathjax@2.7.9/MathJax.js?config=TeX-AMS-MML_HTMLorMML'
92  ];
93 
94  if (in_array($config->getClientScriptUrl(), $outdated)) {
95  if ($config->isClientEnabled()) {
96  $change = $interaction->confirmOrDeny("Replace outdated or unsave MathJax URL with $recommended ?");
97  } else {
98  $interaction->inform("Replaced inactive outdated MathJax URL with $recommended");
99  $change = true;
100  }
101  }
102  if ($change
103  && $this->setup_config !== null
104  && in_array($this->setup_config->getConfig()->getClientScriptUrl(), $outdated)
105  ) {
106  $interaction->inform("Please change the URL in the setup.json to avoid this message in the next update.");
107  }
108 
109  if ($change) {
110  return $config->withClientScriptUrl($recommended);
111  }
112  return null;
113  }
114 }
withClientScriptUrl(string $client_async_url)
Set the url of Mathjax script to be embedded on the page (for MathJax 3)
Global Mathjax configuration.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
__construct(?\ilMathJaxSetupConfig $setup_config=null)
getClientScriptUrl()
Url of Mathjax script to be embedded with script tag on the page.
isClientEnabled()
Should latex code be rendered in the browser.
checkClientScriptUrl(ilMathJaxConfig $config, Setup\AdminInteraction $interaction)
Check if an outdated script URL is used and try to correct it.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
An environment holds resources to be used in the setup process.
Definition: Environment.php:27
updateConfig(ilMathJaxConfig $config)
Update the MathNax Configuration.
Repository for storing and loading the MathJax configuration.