mirror of
https://github.com/scratchfoundation/mw-ScratchSig2.git
synced 2024-11-24 08:18:01 -05:00
Initial
This commit is contained in:
commit
ae6e477cc7
3 changed files with 111 additions and 0 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
.DS_Store
|
||||
*.swp
|
100
ScratchSig2.php
Normal file
100
ScratchSig2.php
Normal file
|
@ -0,0 +1,100 @@
|
|||
<?php
|
||||
|
||||
if (!defined('MEDIAWIKI')) {
|
||||
die();
|
||||
}
|
||||
|
||||
|
||||
// Don't dump DOM errors onto page
|
||||
|
||||
error_reporting(0);
|
||||
|
||||
|
||||
// Hooks
|
||||
|
||||
$wgExtensionFunctions[] = 'sigSetup';
|
||||
$wgHooks['ParserFirstCallInit'][] = 'sigParserInit';
|
||||
|
||||
|
||||
// Temporary cache of avatar image URLs
|
||||
|
||||
global $sig_imageUrls;
|
||||
$sig_imageUrls = array();
|
||||
|
||||
|
||||
// Hook callback function into parser
|
||||
|
||||
function sigParserInit (Parser $parser) {
|
||||
// Register <scratchsig> tag
|
||||
$parser->setHook('scratchsig', 'sigRenderTag');
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Fetch avatar thumbnail url for user from site api
|
||||
|
||||
function sigFetchProfile ($username) {
|
||||
// Fetch page
|
||||
$data = file_get_contents("http://scratch.mit.edu/site-api/users/all/$username/");
|
||||
$json = json_decode($data, $assoc=true);
|
||||
return $json['thumbnail_url'];
|
||||
}
|
||||
|
||||
|
||||
// Return the url of the avatar's profile image
|
||||
// Fetches it if not cached in database
|
||||
|
||||
function sigGetAvatarUrl ($username) {
|
||||
global $sig_imageUrls;
|
||||
if (!isset($sig_imageUrls[$username])) {
|
||||
$sig_imageUrls[$username] = sigFetchProfile($username);
|
||||
}
|
||||
return $sig_imageUrls[$username];
|
||||
}
|
||||
|
||||
|
||||
// Called to output HTML for <scratchsig> tag
|
||||
|
||||
function sigRenderTag ($input, array $args, Parser $parser, PPFrame $frame) {
|
||||
$username = $input;
|
||||
|
||||
$img_url = sigGetAvatarUrl($username);
|
||||
|
||||
$o = '<br>'
|
||||
. '<span class="scratch-sig">'
|
||||
. '<a href="/wiki/User:'.$username.'">'
|
||||
. '<img src="' . $img_url . '" width="21">'
|
||||
. '</a>'
|
||||
. ' '
|
||||
. '<a href="/wiki/User:'.$username.'">'
|
||||
. '<b>'.$username.'</b>'
|
||||
. '</a>'
|
||||
. ' '
|
||||
. '('
|
||||
. '<a href="/wiki/User_Talk:'.$username.'">talk</a>'
|
||||
. ' | '
|
||||
. '<a href="/wiki/Special:Contributions/'.$username.'">contribs</a>'
|
||||
. ')'
|
||||
. '</span>';
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
// Make wiki load resources
|
||||
|
||||
function sigSetup () {
|
||||
global $wgOut;
|
||||
$wgOut->addModules('ext.scratchSig');
|
||||
}
|
||||
|
||||
|
||||
// Define resources
|
||||
|
||||
$wgResourceModules['ext.scratchSig'] = array(
|
||||
'styles' => 'scratchsig.css',
|
||||
|
||||
'localBasePath' => __DIR__,
|
||||
'remoteExtPath' => 'ScratchSig2'
|
||||
);
|
||||
|
9
scratchsig.css
Normal file
9
scratchsig.css
Normal file
|
@ -0,0 +1,9 @@
|
|||
.scratch-sig {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.scratch-sig img {
|
||||
width: 1.25em;
|
||||
height: 1.25em;
|
||||
border: 1px solid #aaa;
|
||||
}
|
Loading…
Reference in a new issue