MediaWiki
fundraising/REL1_35
MediaWikiTwig.php
Go to the documentation of this file.
1
<?php
32
class
MediaWikiTwig
{
34
protected
$mTwig
;
36
protected
$mCallbacks
;
37
43
public
function
__construct
( $templatePath,
IContextSource
$context ) {
44
global $wgTwigCachePath;
45
46
$loader =
new
MediaWikiTwigLoader
( $templatePath, $context );
47
$this->mTwig =
new
Twig_Environment( $loader, [
48
'cache'
=> $wgTwigCachePath .
'/'
. md5( $templatePath ),
49
'auto_reload'
=>
true
,
50
'autoescape'
=>
false
,
51
] );
52
$this->mTwig->addExtension(
new
MediaWikiTwigCallbacks
( $context ) );
53
}
54
63
public
function
render
( $template, $params = [] ) {
64
return
$this->mTwig->render( $template, $params );
65
}
66
}
67
71
class
MediaWikiTwigCallbacks
extends
Twig_Extension {
72
protected
$mContext
;
73
74
public
function
__construct
(
IContextSource
$context ) {
75
$this->mContext = $context;
76
}
77
78
public
function
getName
() {
79
return
'MediaWiki Twig Handler'
;
80
}
81
82
public
function
getFunctions
() {
83
return
[
84
'wfMessage'
=>
new
Twig_Function_Method( $this,
'twig_wfMessage'
),
85
'wfText'
=>
new
Twig_Function_Method( $this,
'twig_wfText'
),
86
'wfWikiText'
=>
new
Twig_Function_Method( $this,
'twig_wfWikiText'
),
87
];
88
}
89
98
public
function
twig_wfMessage
( $message, $params = [] ) {
99
return
wfMessage
( $message, $params )->parse();
100
}
101
110
public
function
twig_wfText
( $message, $params = [] ) {
111
return
wfMessage
( $message, $params )->text();
112
}
113
122
public
function
twig_wfWikiText
( $wikiText ) {
123
return
$this->mContext->getOutput()->parseInlineAsInterface( $wikiText );
124
}
125
}
wfMessage
wfMessage( $key,... $params)
This is the function for getting translated interface messages.
Definition
GlobalFunctions.php:1220
MediaWikiTwigCallbacks
All exposed MW functions to Twig Templates.
Definition
MediaWikiTwig.php:71
MediaWikiTwigCallbacks\__construct
__construct(IContextSource $context)
Definition
MediaWikiTwig.php:74
MediaWikiTwigCallbacks\twig_wfText
twig_wfText( $message, $params=[])
Retrieves non-wiki-parsed MW i18n message.
Definition
MediaWikiTwig.php:110
MediaWikiTwigCallbacks\getName
getName()
Definition
MediaWikiTwig.php:78
MediaWikiTwigCallbacks\twig_wfWikiText
twig_wfWikiText( $wikiText)
Fully parses arbitrary wiki text; use for things like template inclusion.
Definition
MediaWikiTwig.php:122
MediaWikiTwigCallbacks\twig_wfMessage
twig_wfMessage( $message, $params=[])
Fully parses a MW i18n message into HTML.
Definition
MediaWikiTwig.php:98
MediaWikiTwigCallbacks\$mContext
$mContext
Definition
MediaWikiTwig.php:72
MediaWikiTwigCallbacks\getFunctions
getFunctions()
Definition
MediaWikiTwig.php:82
MediaWikiTwigLoader
Provides methods for Twig templates to integrate with Mediawiki.
Definition
MediaWikiTwigLoader.php:33
MediaWikiTwig
Wrapper around the Twig templating engine that allows MW code to easily integrate HTML templates.
Definition
MediaWikiTwig.php:32
MediaWikiTwig\$mTwig
Twig_Environment $mTwig
Definition
MediaWikiTwig.php:34
MediaWikiTwig\render
render( $template, $params=[])
Renders a Twig template and returns the processed HTML data.
Definition
MediaWikiTwig.php:63
MediaWikiTwig\__construct
__construct( $templatePath, IContextSource $context)
Definition
MediaWikiTwig.php:43
MediaWikiTwig\$mCallbacks
array $mCallbacks
Definition
MediaWikiTwig.php:36
IContextSource
Interface for objects which can provide a MediaWiki context on request.
Definition
IContextSource.php:55
extensions
FundraisingEmailUnsubscribe
includes
MediaWikiTwig.php
Generated on Mon Nov 25 2024 16:14:09 for MediaWiki by
1.10.0