-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTMLPurifierHooks.php
More file actions
40 lines (31 loc) · 994 Bytes
/
Copy pathHTMLPurifierHooks.php
File metadata and controls
40 lines (31 loc) · 994 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
use MediaWiki\MediaWikiServices;
class HTMLPurifierHooks {
/**
* @param Parser $parser
*/
public static function onParserFirstCallInit( Parser $parser ) {
$parser->setHook( 'html', [ self::class, 'onHTML' ] );
}
/**
* @param string $input Dirty HTML
* @return Purified HTML
*/
public static function onHTML( $input ) {
global $wgHTMLPurifierConfig;
// Set the config
$config = HTMLPurifier_Config::createDefault();
foreach ( $wgHTMLPurifierConfig as $key => $value ) {
$config->set( $key, $value );
}
$hookContainer = MediaWikiServices::getInstance()->getHookContainer();
// Allow others to do more complex configurations
$hookContainer->run( 'HTMLPurifierBeforePurify', [ &$config ] );
// Purify the HTML
$purifier = new HTMLPurifier( $config );
$html = $purifier->purify( $input );
// Allow others to further transform the purified HTML
$hookContainer->run( 'HTMLPurifierAfterPurify', [ &$html, $purifier ] );
return $html;
}
}