ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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  $this->checkClientScriptUrl($repo->getConfig(), $interaction);
62 
63  return $environment;
64  }
65 
66  public function isApplicable(Setup\Environment $environment): bool
67  {
68  return true;
69  }
70 
74  protected function checkClientScriptUrl(ilMathJaxConfig $config, Setup\AdminInteraction $interaction): void
75  {
76  $recommended = 'https://YOUR_ILIAS_URL/assets/js/cdn-mathjax2-tex-mml-chtml-safe.js';
77 
78  if (str_contains($config->getClientScriptUrl(), '?')) {
79  $interaction->inform("ILIAS 10 cuts query params of javascript URLs that are added to the page."
80  . " Please replace your MathJax URL with $recommended or a similar script that sets the save mode of MathJax!");
81 
82  if ($this->setup_config !== null && str_contains($this->setup_config->getConfig()->getClientScriptUrl(), '?')) {
83  $interaction->inform("Change the URL in the setup.json to avoid this message in the next update.");
84  }
85  }
86  }
87 }
Global Mathjax configuration.
__construct(?\ilMathJaxSetupConfig $setup_config=null)
getClientScriptUrl()
Url of Mathjax script to be embedded with script tag on the page.
checkClientScriptUrl(ilMathJaxConfig $config, Setup\AdminInteraction $interaction)
Check if an outdated script URL is used.
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
Repository for storing and loading the MathJax configuration.