ILIAS  release_8 Revision v8.24
class.ilMathJaxConfigCheckedObjective.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Setup;
22
24{
26
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
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}
checkClientScriptUrl(ilMathJaxConfig $config, Setup\AdminInteraction $interaction)
Check if an outdated script URL is used and try to correct it.
__construct(?\ilMathJaxSetupConfig $setup_config=null)
Repository for storing and loading the MathJax configuration.
Global Mathjax configuration.
This defines ways in which objectives may interact with admins during the setup.
An environment holds resources to be used in the setup process.
Definition: Environment.php:28
An objective is a desired state of the system that is supposed to be created by the setup.
Definition: Objective.php:31
$factory
Definition: metadata.php:75
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...