Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
apple502j authored Mar 30, 2018
1 parent f75dc87 commit bb1d9d0
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 30 deletions.
64 changes: 39 additions & 25 deletions EmbedScratch.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,43 @@
if (!defined('MEDIAWIKI')) {
die();
}
error_reporting(0);

$wgExtensionFunctions[] = 'beginEmbedScratch';
$wgHooks['ParserFirstCallInit'][] = 'parserEmbedScratch';

function parserEmbedScratch (Parser $parser) {
$parser->setHook('scratch', 'renderEmbedScratch');
return true;
}

function renderEmbedScratch ($input, array $args, Parser $parser, PPFrame $frame) {
$project = $args["project"]?$args["project"]:"";
if ($project == ""){
return "";
}
$o = '<br>'
. '<iframe allowtransparency="true" width="485" height="402" allowfullscreen frameborder="0" src="https://scratch.mit.edu/projects/embed/'
. $project
. '/?autostart=false"></iframe>';
return $o;
}
function beginEmbedScratch () {
global $wgOut;
$wgOut->addModules('ext.embedScratch');
class EmbedScratch{
public static function parserEmbedScratch (&$parser) {
$parser->setHook('scratch', array(__CLASS__,'renderEmbedScratch'));
return true;
}

function renderEmbedScratch ($input, $argv, $parser) {
$project = '';
$width = $width_max = 485;
$height = $height_max = 402;


if ( !empty( $argv['project'] ) ){
$project=$argv['project'];
} elseif (!empty($input)){
$project=$input;
}
if (
!empty( $argv['width'] ) &&
settype( $argv['width'], 'integer' ) &&
( $width_max >= $argv['width'] )
)
{
$width = $argv['width'];
}
if (
!empty( $argv['height'] ) &&
settype( $argv['height'], 'integer' ) &&
( $height_max >= $argv['height'] )
)
{
$height = $argv['height'];
}
if (!empty($project)) {
return "<iframe allowtransparency=\"true\" width=\"{$width}\" height=\"{$height}\" src=\"https://scratch.mit.edu/projects/embed/{$project}/?autostart=false\" frameborder=\"0\" allowfullscreen></iframe>";
} else {
return "";
}
}
}

8 changes: 4 additions & 4 deletions extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "embedScratch",
"version": "1.0.0",
"name": "EmbedScratch",
"version": "2.0.0",
"author": [
"Apple502j"
],
Expand All @@ -15,10 +15,10 @@
"ContentHandlers": {},
"ExtensionMessagesFiles": {},
"Hooks": {
"ParserFirstCallInit": "EmbedScratch::parserEmbedScratch"
"ParserFirstCallInit": ["EmbedScratch::parserEmbedScratch"]
},
"MessagesDirs": {
"embedScratch": [
"EmbedScratch": [
"i18n"
]
},
Expand Down
2 changes: 1 addition & 1 deletion i18n/ja.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"author": "apple502j"
},
"embedscratch-desc": "Scratchを埋め込もう!"
}
}
6 changes: 6 additions & 0 deletions i18n/qqq.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"@metadata": {
"author": "apple502j"
},
"embedscratch-desc": "Description of this extension"
}

0 comments on commit bb1d9d0

Please sign in to comment.