Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

MDL-25826 integrate HTMLPurifier 4.3.0 and improve performance

The new HTMLPurifier finally caches the schema properly eliminating both extra CPU cycles and disk writes. The repeated dir exists tests might cause problems on NFS shares.
  • Loading branch information...
commit fd8fa6f9d0ee8090b5763612fabd581df5fef6d0 1 parent 8adf19e
Petr Skoda skodak authored
0  lib/simpletest/testpurifier.php
No changes.
2  lib/thirdpartylibs.xml
@@ -67,7 +67,7 @@
67 67 <location>htmlpurifier</location>
68 68 <name>HTML Purifier</name>
69 69 <license>LGPL</license>
70   - <version>4.2.0</version>
  70 + <version>4.3.0</version>
71 71 <licenseversion>2.1+</licenseversion>
72 72 </library>
73 73 <library>
26 lib/weblib.php
@@ -1509,20 +1509,21 @@ function clean_text($text, $format = FORMAT_HTML, $options = array()) {
1509 1509 function purify_html($text, $options = array()) {
1510 1510 global $CFG;
1511 1511
1512   - // this can not be done only once because we sometimes need to reset the cache
1513   - $cachedir = $CFG->dataroot.'/cache/htmlpurifier';
1514   - check_dir_exists($cachedir);
1515   -
1516 1512 $type = !empty($options['allowid']) ? 'allowid' : 'normal';
1517 1513 static $purifiers = array();
1518 1514 if (empty($purifiers[$type])) {
  1515 +
  1516 + // make sure the serializer dir exists, it should be fine if it disappears later during cache reset
  1517 + $cachedir = $CFG->dataroot.'/cache/htmlpurifier';
  1518 + check_dir_exists($cachedir);
  1519 +
1519 1520 require_once $CFG->libdir.'/htmlpurifier/HTMLPurifier.safe-includes.php';
1520 1521 $config = HTMLPurifier_Config::createDefault();
1521 1522
1522 1523 $config->set('HTML.DefinitionID', 'moodlehtml');
1523   - $config->set('HTML.DefinitionRev', 1);
  1524 + $config->set('HTML.DefinitionRev', 2);
1524 1525 $config->set('Cache.SerializerPath', $cachedir);
1525   - //$config->set('Cache.SerializerPermission', $CFG->directorypermissions); // it would be nice to get this upstream
  1526 + $config->set('Cache.SerializerPermissions', $CFG->directorypermissions);
1526 1527 $config->set('Core.NormalizeNewlines', false);
1527 1528 $config->set('Core.ConvertDocumentToFragment', true);
1528 1529 $config->set('Core.Encoding', 'UTF-8');
@@ -1540,12 +1541,13 @@ function purify_html($text, $options = array()) {
1540 1541 $config->set('Attr.EnableID', true);
1541 1542 }
1542 1543
1543   - $def = $config->getHTMLDefinition(true);
1544   - $def->addElement('nolink', 'Block', 'Flow', array()); // skip our filters inside
1545   - $def->addElement('tex', 'Inline', 'Inline', array()); // tex syntax, equivalent to $$xx$$
1546   - $def->addElement('algebra', 'Inline', 'Inline', array()); // algebra syntax, equivalent to @@xx@@
1547   - $def->addElement('lang', 'Block', 'Flow', array(), array('lang'=>'CDATA')); // old anf future style multilang - only our hacked lang attribute
1548   - $def->addAttribute('span', 'xxxlang', 'CDATA'); // current problematic multilang
  1544 + if ($def = $config->maybeGetRawHTMLDefinition()) {
  1545 + $def->addElement('nolink', 'Block', 'Flow', array()); // skip our filters inside
  1546 + $def->addElement('tex', 'Inline', 'Inline', array()); // tex syntax, equivalent to $$xx$$
  1547 + $def->addElement('algebra', 'Inline', 'Inline', array()); // algebra syntax, equivalent to @@xx@@
  1548 + $def->addElement('lang', 'Block', 'Flow', array(), array('lang'=>'CDATA')); // old and future style multilang - only our hacked lang attribute
  1549 + $def->addAttribute('span', 'xxxlang', 'CDATA'); // current problematic multilang
  1550 + }
1549 1551
1550 1552 $purifier = new HTMLPurifier($config);
1551 1553 $purifiers[$type] = $purifier;

0 comments on commit fd8fa6f

Please sign in to comment.
Something went wrong with that request. Please try again.