forked from gilluminate/FancyBoxThumbs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FancyBoxThumbs.php
87 lines (79 loc) · 2.72 KB
/
FancyBoxThumbs.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
78
79
80
81
82
83
84
85
86
87
<?php
/**
* FancyBoxThumbs MediaWiki Extension
* @version 2.2
* @example at http://gilluminate.com/mediawiki/
* @author [http://www.gilluminate.com Jason Gill]
* @license [http://www.gnu.org/licenses/gpl.html GPLv3]
*/
/**
* fancyBox - jQuery Plugin
* @version: 2.1.4 (Thu, 17 Jan 2013)
* @example at http://fancyapps.com/fancybox/
* @license www.fancyapps.com/fancybox/#license
* @copyright Copyright 2012 Janis Skarnelis - janis@fancyapps.com
*/
if ( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is part of an extension to the MediaWiki software and cannot be used standalone.\n" );
die( 1 );
}
$fbtFancyBoxOptions = "{}";
//Register Credits
$wgExtensionCredits['media'][] = array(
'name' => 'FancyBoxThumbs',
'url' => 'http://www.mediawiki.org/wiki/Extension:FancyBoxThumbs',
'author' => '[http://www.gilluminate.com Jason Gill]',
'description' => 'Displays thumbnailed images in a Mac-style "lightbox" that floats overtop of web page. A simple and fancy lightbox alternative',
'version' => '2.2'
);
$wgResourceModules['ext.FancyBoxThumbs'] = array(
'scripts' => array('fancyBox/source/jquery.fancybox.js','ext.FancyBoxThumbs.js'),
'styles' => 'fancyBox/source/jquery.fancybox.css',
'localBasePath' => dirname( __FILE__ ).'/modules',
'remoteExtPath' => 'FancyBoxThumbs/modules',
);
$wgHooks['BeforePageDisplay'][] = 'fbtBeforePageDisplay';
$wgAjaxExportList[] = 'efFBTGetImageSizes';
function fbtBeforePageDisplay(&$out){
global $fbtFancyBoxOptions;
$out->addModules( 'ext.FancyBoxThumbs' );
$out->addInlineScript('var fbtFancyBoxOptions = '.$fbtFancyBoxOptions.';');
return true;
}
// Ajax handler to get image sizes
function efFBTGetImageSizes( $names ) {
$result = array();
$user = RequestContext::getMain()->getUser();
foreach ( explode( ':', $names ) as $name ) {
if ( !isset( $result[$name] ) ) {
$title = Title::makeTitle( NS_FILE, $name );
if ( $title ) {
if ( class_exists( 'MediaWiki\Permissions\PermissionManager' ) ) {
// MW 1.33+
$userCan = \MediaWiki\MediaWikiServices::getInstance()
->getPermissionManager()
->userCan( 'read', $user, $title );
} else {
$userCan = $title->userCan( 'read' );
}
if ( $userCan ) {
if ( method_exists( MediaWikiServices::class, 'getRepoGroup' ) ) {
// MediaWiki 1.34+
$file = MediaWikiServices::getInstance()->getRepoGroup()->findFile( $title );
} else {
$file = wfFindFile( $title );
}
if ( $file && $file->getWidth() ) {
$result[ $name ] = array(
'width' => $file->getWidth(),
'height' => $file->getHeight(),
'url' => $file->getFullUrl(),
'local' => $file->isLocal(),
);
}
}
}
}
}
return json_encode( $result );
}