├── .gitattributes ├── .gitignore ├── .gitmodules ├── LICENSE ├── README.md ├── ScratchBlocks.php ├── ScratchblockHooks.php ├── extension.json ├── inline.css └── run_scratchblocks.js /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | *.swp 3 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "scratchblocks"] 2 | path = scratchblocks 3 | url = https://github.com/tjvr/scratchblocks.git 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2013, Tim Radvan 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of 4 | this software and associated documentation files (the "Software"), to deal in 5 | the Software without restriction, including without limitation the rights to 6 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 | the Software, and to permit persons to whom the Software is furnished to do so, 8 | subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | A simple MediaWiki extension for rendering Scratch blocks. 3 | 4 | Transforms `` tags inside wiki articles into `
`
 5 | in the HTML, which are then rendered to scratch blocks using CSS and JS
 6 | included in the page. Inline blocks are rendered with `` tags, and become
 7 | `` tags.
 8 | 
 9 | - Maintained by ErnieParke ([@Choco31415](https://github.com/Choco31415)).
10 | - Authored by tjvr
11 | 
12 | 
13 | Installation
14 | ============
15 | 
16 | This repository uses Git submodules. If you `git clone`, make sure to include the `--recursive` option.
17 | 
18 |     $ cd extensions
19 |     $ git clone --recursive http://github.com/tjvr/wiki-scratchblocks ScratchBlocks
20 | 
21 | Just drop this folder into MediaWiki's "extensions/" folder, and add
22 | 
23 |     require_once( "$IP/extensions/ScratchBlocks/ScratchBlocks.php" );
24 | 
25 | to your "LocalSettings.php". If running Mediawiki 1.25 or greater, you can use
26 | 
27 |     wfLoadExtension( "ScratchBlocks" );
28 | 
29 | instead of the require statement.
30 | 
31 | 


--------------------------------------------------------------------------------
/ScratchBlocks.php:
--------------------------------------------------------------------------------
 1 |  tags to shiny scratch blocks
 5 |  *
 6 |  * Copyright 2013, Tim Radvan
 7 |  * MIT Licensed
 8 |  * http://opensource.org/licenses/MIT
 9 |  *
10 |  * Includes scratchblocks v3
11 |  * https://github.com/tjvr/scratchblocks
12 |  *
13 |  */
14 | 
15 | 
16 | if (!defined('MEDIAWIKI')) {
17 |     die();
18 | }
19 | 
20 | require_once __DIR__ . "/ScratchblockHooks.php";
21 | 
22 | // Hooks
23 | 
24 | $wgExtensionFunctions[] = 'ScratchblockHook::sbSetup';
25 | $wgHooks['ParserFirstCallInit'][] = 'ScratchblockHook::sbParserInit';
26 | 
27 | 
28 | // Define resources
29 | 
30 | $wgResourceModules['ext.scratchBlocks'] = array(
31 |     'scripts' => array(
32 |         'scratchblocks/src/scratchblocks.js',
33 |         'scratchblocks/src/translations.js',
34 |         'run_scratchblocks.js',
35 |     ),
36 | 
37 |     'styles' => '/inline.css',
38 | 
39 |     // jQuery is loaded anyway
40 |     'dependencies' => array(),
41 | 
42 |     // Where the files are
43 |     'localBasePath' => __DIR__,
44 |     'remoteExtPath' => 'ScratchBlocks'
45 | );
46 | 
47 | $wgExtensionCredits['parserhook'][] = array(
48 |     'name' => "Scratchblocks",           // Name of extension - string
49 |     'description' => "This plugin takes text-based Scratch code and renders it in a graphical format.",    // Description of what the extension does - string. Omit in favour of descriptionmsg.
50 |     'version' => 3.1,         // Version number of extension - number or string
51 |     'author' => ["ErnieParke","blob8108"],         // The extension author's name - string or array for multiple
52 |     'url' => "https://github.com/tjvr/wiki-scratchblocks",            // URL of extension (usually instructions) - string
53 |     'license-name' => "MIT",   // Short name of the license, links LICENSE or COPYING file if existing - string, added in 1.23.0
54 | );
55 | 


--------------------------------------------------------------------------------
/ScratchblockHooks.php:
--------------------------------------------------------------------------------
 1 |  tag
 4 | 	
 5 | 	public static function sbParserInit (Parser $parser) {
 6 | 		// Register  and  tag
 7 | 		$parser->setHook('scratchblocks', array( "ScratchblockHook", 'sbRenderTag') );
 8 | 		$parser->setHook('sb', array( "ScratchblockHook", 'sbRenderInlineTag') );
 9 | 		//throw new Exception(var_dump($parser));
10 | 		return true;
11 | 	}
12 | 	
13 | 	public static function sbSetup() {
14 | 		global $wgOut;
15 | 		$wgOut->addModules('ext.scratchBlocks');
16 | 	}
17 | 
18 | 	// Output HTML for  tag
19 | 	public static function sbRenderTag ($input, array $args, Parser $parser, PPFrame $frame) {
20 | 		return '
' . htmlspecialchars($input) . '
'; 21 | } 22 | 23 | // Output HTML for inline tag 24 | public static function sbRenderInlineTag ($input, array $args, Parser $parser, PPFrame $frame) { 25 | return '' . htmlspecialchars($input) . ''; 26 | } 27 | } 28 | ?> 29 | -------------------------------------------------------------------------------- /extension.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "Scratchblocks", 3 | "version": 3.1, 4 | "author": [ 5 | "ErnieParke", 6 | "blob8108" 7 | ], 8 | "url": "https://github.com/tjvr/wiki-scratchblocks", 9 | "description": "This plugin takes text-based Scratch code and renders it in a graphical format.", 10 | "license-name": "MIT", 11 | "type": "parserhook", 12 | "AutoloadClasses": { 13 | "ScratchblockHook": "ScratchblockHooks.php" 14 | }, 15 | "ExtensionFunctions": [ 16 | "ScratchblockHook::sbSetup" 17 | ], 18 | "ResourceModules": { 19 | "ext.scratchBlocks": { 20 | "scripts": [ 21 | "scratchblocks/src/scratchblocks.js", 22 | "scratchblocks/src/translations.js", 23 | "run_scratchblocks.js" 24 | ], 25 | "styles": "/inline.css", 26 | "dependencies": [] 27 | } 28 | }, 29 | "ResourceFileModulePaths": { 30 | "localBasePath": "", 31 | "remoteExtPath": "ScratchBlocks" 32 | }, 33 | "Hooks": { 34 | "ParserFirstCallInit": [ 35 | "ScratchblockHook::sbParserInit" 36 | ] 37 | }, 38 | "manifest_version": 1 39 | } 40 | -------------------------------------------------------------------------------- /inline.css: -------------------------------------------------------------------------------- 1 | code.blocks { 2 | display:inline-block; 3 | } 4 | -------------------------------------------------------------------------------- /run_scratchblocks.js: -------------------------------------------------------------------------------- 1 | scratchblocks.renderMatching("pre.blocks, code.blocks", {languages: ["en", "de", "es", "el", "nl", "pt", "zh_CN", "tr", "nb", "ko", "it", "id", "ru", "ca", "ja", "pl", "he", "fr"],}); 2 | --------------------------------------------------------------------------------