-
Notifications
You must be signed in to change notification settings - Fork 7
/
MpdfHooks.php
87 lines (72 loc) · 2.01 KB
/
MpdfHooks.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
use MediaWiki\MediaWikiServices;
class MpdfHooks {
/**
* @param Parser &$parser
*/
public static function onParserFirstCallInit( Parser &$parser ) {
$parser->setFunctionHook( 'mpdftags', 'MpdfHooks::mpdftags_Render' );
}
/**
* Add "PDF Export" link to the toolbox
* Called with the SidebarBeforeOutput hook.
*
* @param Skin $skin
* @param array &$sidebar
* @return bool
*/
public static function onSidebarBeforeOutput( Skin $skin, array &$sidebar ) {
global $wgMpdfToolboxLink;
if ( !$wgMpdfToolboxLink ) {
return true;
}
$title = $skin->getTitle();
if ( $title->isSpecialPage() ) {
return true;
}
$sidebar['TOOLBOX']['mpdf'] = [
'msg' => 'mpdf-action',
'href' => $title->getLocalUrl( [ 'action' => 'mpdf' ] ),
'id' => 't-mpdf',
'rel' => 'mpdf'
];
return true;
}
/**
* Adds a "PDF Export" link to the set of tabs/actions, if one was
* specified.
* Called with the SkinTemplateNavigation::Universal hook.
*
* @param SkinTemplate $sktemplate
* @param array &$links
*/
public static function onSkinTemplateNavigationUniversal( SkinTemplate $sktemplate, array &$links ) {
$mpdfTab = MediaWikiServices::getInstance()->getMainConfig()->get( 'MpdfTab' );
if ( $mpdfTab ) {
$links['views']['mpdf'] = [
'class' => false,
'text' => wfMessage( 'mpdf-action' )->text(),
'href' => $sktemplate->getTitle()->getLocalURL( 'action=mpdf' ),
];
}
}
/**
* @param Parser &$parser
* @return mixed
*/
public static function mpdftags_Render( &$parser ) {
// Get the parameters that were passed to this function
$params = func_get_args();
array_shift( $params );
// Replace open and close tag for security reason
$values = str_replace( [ '<', '>' ], [ '<', '>' ], $params );
// Insert mpdf tags between <!--mpdf ... mpdf-->
$return = '<!--mpdf';
foreach ( $values as $val ) {
$return .= "<" . $val . " />\n";
}
$return .= "mpdf-->\n";
// Return mpdf tags as raw html
return $parser->insertStripItem( $return );
}
}