Skip to content

Commit

Permalink
Chore/kb 53825/moodle warnings
Browse files Browse the repository at this point in the history
* fix: prevent unnecessary LaTeX rendering during editing context

* fix: update comments to pass linting

* fix: refine LaTeX transformation logic to prevent unnecessary rendering for specific cases

* Update subfilters/php.php

Co-authored-by: Jose González <[email protected]>

* Update php.php

* Update php.php

* fix: pass phpbcf moodle-extra

* chore: remove limit

---------

Co-authored-by: Jose González <[email protected]>
  • Loading branch information
usantos-at-wiris and jgonzalez-at-wiris authored Feb 12, 2025
1 parent 0548932 commit e54cfba
Show file tree
Hide file tree
Showing 24 changed files with 26 additions and 75 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/moodle-ci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ jobs:
# 3.3. Code validations
- name: Moodle Code Checker
if: ${{ always() }}
run: moodle-plugin-ci codechecker --max-warnings 50 ./plugin
run: moodle-plugin-ci codechecker ./plugin

- name: Check upgrade savepoints
if: ${{ always() }}
Expand Down
2 changes: 0 additions & 2 deletions classes/accessprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@
* It implements the com_wiris_util_sys_AccessProvider interface.
*/
class filter_wiris_accessprovider implements com_wiris_util_sys_AccessProvider {


/**
* This method is called before all service. We use it as a wrapper to call
* Moodle require_login() method. Any WIRIS service can't be called without a
Expand Down
1 change: 0 additions & 1 deletion classes/configurationupdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_wiris_configurationupdater implements com_wiris_plugin_configuration_ConfigurationUpdater {

/**
* @var mixed $waseditorenabled Indicates whether the WYSIWYG editor was enabled.
*/
Expand Down
3 changes: 0 additions & 3 deletions classes/moodledbcache.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodledbcache {



/**
* @var mixed $cachetable The cache table instance.
*/
Expand Down
3 changes: 0 additions & 3 deletions classes/moodledbjsoncache.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodledbjsoncache {



/**
* @var string The name of the cache table.
*/
Expand Down
1 change: 0 additions & 1 deletion classes/moodlefilecache.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class moodlefilecache {

/**
* @var mixed $cache The cache instance.
*/
Expand Down
3 changes: 0 additions & 3 deletions classes/paramsprovider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_wiris_paramsprovider implements com_wiris_plugin_api_ParamsProvider {



/**
* @var array $parameters The list of parameters.
*/
Expand Down
2 changes: 0 additions & 2 deletions classes/pluginwrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_wiris_pluginwrapper {


/**
* @var bool $isinit Indicates whether the initialization is done.
*/
Expand Down
2 changes: 0 additions & 2 deletions classes/pluginwrapperconfigurationupdater.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_wiris_pluginwrapperconfigurationupdater implements com_wiris_plugin_configuration_ConfigurationUpdater {


/**
* @var mixed $customconfig The custom configuration instance.
*/
Expand Down
3 changes: 0 additions & 3 deletions classes/privacy/provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \core_privacy\local\metadata\null_provider {



/**
* Get the language string identifier with the component's language
* file to explain why this plugin stores no data.
Expand Down
1 change: 0 additions & 1 deletion classes/text_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
* This class extends the moodle_text_filter and provides a method to filter text using the Wiris filter.
*/
class text_filter extends \core_filters\text_filter {

/**
* Filters the given text using the Wiris filter.
*
Expand Down
4 changes: 2 additions & 2 deletions info.php
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ function get_instalation_check($filterenabled, $filterversion, $enabledpluginsve
$enabledplugins['atto'] = ($mtattoenabled) ? $mtattoversion : null;

$existstinylegacy = get_editor_exists_and_enabled('tinymce');
$existsmttinylegacy = get_exists_mt_editor($existstinylegacy, $plugins, 'tinymce');
$mttinylegacyversion = get_mt_editor_version($existsmttinylegacy, $plugins, 'tinymce');
$existsmttinylegacy = get_exists_mt_editor($existstinylegacy, $plugins, 'tinymce');
$mttinylegacyversion = get_mt_editor_version($existsmttinylegacy, $plugins, 'tinymce');
$mttinylegacyenabled = get_mt_editor_enabled($existsmttinylegacy, 'tinymce');
$enabledplugins['tinymce'] = ($mttinylegacyenabled) ? $mttinylegacyversion : null;

Expand Down
2 changes: 0 additions & 2 deletions lang/en/filter_wiris.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,3 @@


$string['yes'] = 'Yes';


1 change: 0 additions & 1 deletion subfilters/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_wiris_client extends \core_filters\text_filter {

/**
* Set any context-specific configuration for this filter.
*
Expand Down
2 changes: 0 additions & 2 deletions subfilters/php.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filter_wiris_php extends \core_filters\text_filter {

/**
* Set any context-specific configuration for this filter.
*
Expand Down Expand Up @@ -91,7 +90,6 @@ public function filter($text, array $options = []) {
// If MathJax doesn't have preference and wiriseditorparselatex = true, parse LateX into MathML.
if (!$this->mathjax_have_preference() && $wirispluginwrapper->wiris_editor_parse_latex()) {
foreach ($matches[0] as $latex) {

// For some reason, strayed `pi` LaTeX expressions are included in some Moodle pages by default.
// This implies our services having to convert them into MathML and then rendering them as an image without the user even interacting with MathType to begin with.
// To avoid this extra requests, which may impact our services, we just hardcoded it´s conversion to MathML.
Expand Down
2 changes: 0 additions & 2 deletions tests/behat/behat_wiris_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_wiris_base extends behat_base {


/**
* Transforms a string to a number.
*
Expand Down
12 changes: 4 additions & 8 deletions tests/behat/behat_wiris_editor.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_wiris_editor extends behat_wiris_base {




/**
* Once the editor has been opened and focused, set the MathType formula to the specified value.
*
Expand Down Expand Up @@ -327,9 +323,9 @@ public function iswitchtodivwithlocator($locator) {
})()";

$this->getSession()->executeScript($javascript);
$div = $this->getSession()->getPage()->find('xpath', '//div[@id="'.$locator.'"]');
$div = $this->getSession()->getPage()->find('xpath', '//div[@id="' . $locator . '"]');
if (empty($div)) {
throw new ExpectationException('div with locator \''.$locator.'\' not found', $this->getSession());
throw new ExpectationException('div with locator \'' . $locator . '\' not found', $this->getSession());
}
$divname = $div->getAttribute("name");
$this->getSession()->getDriver()->switchToDiv($divname);
Expand All @@ -349,9 +345,9 @@ public function iswitchtoiframewithlocator($locator) {
})()";

$this->getSession()->executeScript($javascript);
$iframe = $this->getSession()->getPage()->find('xpath', '//iframe[@id="'.$locator.'"]');
$iframe = $this->getSession()->getPage()->find('xpath', '//iframe[@id="' . $locator . '"]');
if (empty($iframe)) {
throw new ExpectationException('Iframe with locator \''.$locator.'\' not found', $this->getSession());
throw new ExpectationException('Iframe with locator \'' . $locator . '\' not found', $this->getSession());
}
$iframename = $iframe->getAttribute("name");
$this->getSession()->getDriver()->switchToIFrame($iframename);
Expand Down
2 changes: 0 additions & 2 deletions tests/behat/behat_wiris_filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_wiris_filter extends behat_wiris_base {


/**
* Turns MathType filter off in Filter settings
*
Expand Down
6 changes: 2 additions & 4 deletions tests/behat/behat_wiris_formula.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_wiris_formula extends behat_wiris_base {


/**
* Transform /^(\d+)$/
*/
Expand Down Expand Up @@ -161,9 +159,9 @@ public function a_wirisformula_containing_should_exist($value) {
*/
public function a_wirisformula_containing_should_not_exist($value) {
$session = $this->getSession();
$formula = $session->getPage()->find('xpath', '//img[contains(@alt, \''.$value.'\')]');
$formula = $session->getPage()->find('xpath', '//img[contains(@alt, \'' . $value . '\')]');
if (!empty($formula)) {
throw new ExpectationException('Wirisformula with value '.$value.' found.', $this->getSession());
throw new ExpectationException('Wirisformula with value ' . $value . ' found.', $this->getSession());
}
}

Expand Down
36 changes: 17 additions & 19 deletions tests/behat/behat_wiris_page.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class behat_wiris_page extends behat_wiris_base {


/**
* Check the size of the formula in full screen mode
*
Expand Down Expand Up @@ -71,12 +69,12 @@ public function input_value_is_equal_to($field, $value) {
"wipis.net" => "www.wipis.net",
];
if (empty($fieldarray[$field])) {
throw new ExpectationException($field." field not registered.", $this->getSession());
throw new ExpectationException($field . " field not registered.", $this->getSession());
}
$session = $this->getSession();
$component = $session->getPage()->find('xpath', '//input[@id="'.$fieldarray[$field].'" and @value="'.$valuearray[$value].'"]');
$component = $session->getPage()->find('xpath', '//input[@id="' . $fieldarray[$field] . '" and @value="' . $valuearray[$value] . '"]');
if (empty($component)) {
throw new ExpectationException ('"'.$field.'" input value attribute is not equal to "'.$valuearray[$value].'"', $this->getSession());
throw new ExpectationException('"' . $field . '" input value attribute is not equal to "' . $valuearray[$value] . '"', $this->getSession());
}
}

Expand Down Expand Up @@ -117,12 +115,12 @@ public function i_click_on_field_in_tinymce_6($field) {
"Page content" => "id_page",
];
if (empty($fieldarray[$field])) {
throw new ExpectationException($field." field not registered.");
throw new ExpectationException($field . " field not registered.");
}
$session = $this->getSession();
$component = $session->getPage()->find('xpath', '//body[@data-id="'.$fieldarray[$field].'"]');
$component = $session->getPage()->find('xpath', '//body[@data-id="' . $fieldarray[$field] . '"]');
if (empty($component)) {
throw new ExpectationException($field." field not correctly recognized.", $this->getSession());
throw new ExpectationException($field . " field not correctly recognized.", $this->getSession());
}
$component->click();
}
Expand Down Expand Up @@ -207,11 +205,11 @@ public function i_place_caret_at_position_in_field_in_tinymce_6($position, $fiel
$session = $this->getSession();

$script = 'var editor = tinymce.get(\'' . $fieldarray[$field] . '\');'
.'editor.focus();'
.'var body = editor.getBody();'
.'var textNode = body.querySelector(\'p\').firstChild;'
.'var offset = ' . $position . ';'
.'editor.selection.setCursorLocation(textNode, offset);';
. 'editor.focus();'
. 'var body = editor.getBody();'
. 'var textNode = body.querySelector(\'p\').firstChild;'
. 'var offset = ' . $position . ';'
. 'editor.selection.setCursorLocation(textNode, offset);';

$session->executeScript($script);
}
Expand Down Expand Up @@ -290,8 +288,8 @@ public function i_press_in_field_in_tinymce_editor($button, $field) {
throw new ExpectationException($button . " button not registered.", $this->getSession());
}
$session = $this->getSession();
$component = $session->getPage()->find('xpath', '//div[@id="'.$sectionarray[$field].'"]
//*[contains(@title,\''.$buttonarray[$button].'\')]');
$component = $session->getPage()->find('xpath', '//div[@id="' . $sectionarray[$field] . '"]
//*[contains(@title,\'' . $buttonarray[$button] . '\')]');
if (empty($component)) {
throw new ExpectationException('"' . $button . '" button not found in "' . $field . '" field', $this->getSession());
}
Expand Down Expand Up @@ -587,7 +585,7 @@ public function i_check_in_field_in_tinymce_editor($button, $field, $exist) {
throw new ExpectationException($button . " button not registered.", $this->getSession());
}
$session = $this->getSession();
$component = $session->getPage()->find( 'xpath', '//button[@title="'.$buttonarray[$button].'"]');
$component = $session->getPage()->find('xpath', '//button[@title="' . $buttonarray[$button] . '"]');
// From 4.5, the button is not found via id but via data-mce-name //TODO verify if 4.x may always work like this
global $CFG;
if ($button != 'Toggle' && $CFG->version >= 2024092400) {
Expand Down Expand Up @@ -616,16 +614,16 @@ public function i_click_on_in_tinymce_6_editor_toolbar($button) {
"More options" => "More...",
];
if (empty($buttonarray[$button])) {
throw new ExpectationException($button." button not registered.");
throw new ExpectationException($button . " button not registered.");
}
$session = $this->getSession();
$component = $session->getPage()->find('xpath', '//button[@title="'.$buttonarray[$button].'"]');
$component = $session->getPage()->find('xpath', '//button[@title="' . $buttonarray[$button] . '"]');
if ($CFG->version >= 2024042202.02) {
$component = $session->getPage()->find('xpath', '//*[contains(@aria-label,"Reveal or hide")]');
}

if (empty($component)) {
throw new ExpectationException($button." button not correctly recognized.", $this->getSession());
throw new ExpectationException($button . " button not correctly recognized.", $this->getSession());
}
$component->click();
}
Expand Down
2 changes: 0 additions & 2 deletions tests/filter_performance_png_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
* @subpackage MOODLE_39_STABLE/filter/wiris/tests
*/
final class filter_performance_png_test extends advanced_testcase {


/**
* @var mixed $wirisfilter The WIRIS filter instance used for testing.
*/
Expand Down
4 changes: 0 additions & 4 deletions tests/filter_performance_svg_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
* This class contains unit tests for the MathType filter with SVG image format.
*/
final class filter_performance_svg_test extends advanced_testcase {




/**
* @var filter_wiris The WIRIS filter instance.
*/
Expand Down
2 changes: 0 additions & 2 deletions tests/filter_without_performance_png_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
* @package MOODLE_39_STABLE/filter/wiris/tests
*/
final class filter_without_performance_png_test extends advanced_testcase {


/**
* @var filter_wiris The WIRIS filter instance.
*/
Expand Down
3 changes: 0 additions & 3 deletions tests/filter_without_performance_svg_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
*/
final class filter_without_performance_svg_test extends advanced_testcase {



/**
* @var mixed $wirisfilter The WIRIS filter instance used for testing.
*/
Expand Down

0 comments on commit e54cfba

Please sign in to comment.