forked from tjvr/wiki-scratchblocks
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ScratchBlocks2.php
78 lines (54 loc) · 1.63 KB
/
ScratchBlocks2.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/*
* ScratchBlocks extension for MediaWiki
* Renders <scratchblocks> tags to shiny scratch blocks
*
* Copyright 2013, Tim Radvan
* MIT Licensed
* http://opensource.org/licenses/MIT
*
* Includes scratchblocks2
* http://github.com/blob8108/scratchblocks2
*
*/
if (!defined('MEDIAWIKI')) {
die();
}
// Hooks
$wgExtensionFunctions[] = 'sbSetup';
$wgHooks['ParserFirstCallInit'][] = 'sbParserInit';
// Hook callback function into parser
function sbParserInit (Parser $parser) {
// Register <scratchblocks> tag
$parser->setHook('scratchblocks', 'sbRenderTag');
$parser->setHook('sb', 'sbRenderInlineTag');
return true;
}
// Output HTML for <scratchblocks> tag
function sbRenderTag ($input, array $args, Parser $parser, PPFrame $frame) {
return '<pre class="blocks">' . htmlspecialchars($input) . '</pre>';
}
// Output HTML for <scratchblocks> tag
function sbRenderInlineTag ($input, array $args, Parser $parser,
PPFrame $frame) {
return '<code class="blocks">' . htmlspecialchars($input) . '</code>';
}
// Make wiki load resources
function sbSetup () {
global $wgOut;
$wgOut->addModules('ext.scratchBlocks');
}
// Define resources
$wgResourceModules['ext.scratchBlocks'] = array(
'scripts' => array(
'scratchblocks2/build/scratchblocks2.js',
'scratchblocks2/src/translations.js',
'run_scratchblocks2.js',
),
'styles' => 'scratchblocks2/build/scratchblocks2.css',
// jQuery is loaded anyway
'dependencies' => array(),
// Where the files are
'localBasePath' => __DIR__,
'remoteExtPath' => 'mw-ScratchBlocks2'
);