|
25 | 25 | if (!defined('MEDIAWIKI')) {
|
26 | 26 | die();
|
27 | 27 | }
|
28 |
| -error_reporting(0); |
29 |
| - |
30 |
| -$wgExtensionFunctions[] = 'beginEmbedScratch'; |
31 |
| -$wgHooks['ParserFirstCallInit'][] = 'parserEmbedScratch'; |
32 |
| - |
33 |
| -function parserEmbedScratch (Parser $parser) { |
34 |
| - $parser->setHook('scratch', 'renderEmbedScratch'); |
35 |
| - return true; |
36 |
| -} |
37 |
| - |
38 |
| -function renderEmbedScratch ($input, array $args, Parser $parser, PPFrame $frame) { |
39 |
| - $project = $args["project"]?$args["project"]:""; |
40 |
| - if ($project == ""){ |
41 |
| - return ""; |
42 |
| - } |
43 |
| - $o = '<br>' |
44 |
| - . '<iframe allowtransparency="true" width="485" height="402" allowfullscreen frameborder="0" src="https://scratch.mit.edu/projects/embed/' |
45 |
| - . $project |
46 |
| - . '/?autostart=false"></iframe>'; |
47 |
| - return $o; |
48 |
| -} |
49 |
| -function beginEmbedScratch () { |
50 |
| - global $wgOut; |
51 |
| - $wgOut->addModules('ext.embedScratch'); |
| 28 | +class EmbedScratch{ |
| 29 | + public static function parserEmbedScratch (&$parser) { |
| 30 | + $parser->setHook('scratch', array(__CLASS__,'renderEmbedScratch')); |
| 31 | + return true; |
| 32 | + } |
| 33 | + |
| 34 | + function renderEmbedScratch ($input, $argv, $parser) { |
| 35 | + $project = ''; |
| 36 | + $width = $width_max = 485; |
| 37 | + $height = $height_max = 402; |
| 38 | + |
| 39 | + |
| 40 | + if ( !empty( $argv['project'] ) ){ |
| 41 | + $project=$argv['project']; |
| 42 | + } elseif (!empty($input)){ |
| 43 | + $project=$input; |
| 44 | + } |
| 45 | + if ( |
| 46 | + !empty( $argv['width'] ) && |
| 47 | + settype( $argv['width'], 'integer' ) && |
| 48 | + ( $width_max >= $argv['width'] ) |
| 49 | + ) |
| 50 | + { |
| 51 | + $width = $argv['width']; |
| 52 | + } |
| 53 | + if ( |
| 54 | + !empty( $argv['height'] ) && |
| 55 | + settype( $argv['height'], 'integer' ) && |
| 56 | + ( $height_max >= $argv['height'] ) |
| 57 | + ) |
| 58 | + { |
| 59 | + $height = $argv['height']; |
| 60 | + } |
| 61 | + if (!empty($project)) { |
| 62 | + return "<iframe allowtransparency=\"true\" width=\"{$width}\" height=\"{$height}\" src=\"https://scratch.mit.edu/projects/embed/{$project}/?autostart=false\" frameborder=\"0\" allowfullscreen></iframe>"; |
| 63 | + } else { |
| 64 | + return ""; |
| 65 | + } |
| 66 | + } |
52 | 67 | }
|
53 |
| - |
|
0 commit comments