Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F7463432
MixinController.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
MixinController.php
View Options
<?php
use
MediaWiki\Context\IContextSource
;
class
MixinController
{
/** @var array */
private
$mixins
;
/** @var array */
private
$magicWords
=
[];
/** @var IContextSource */
private
$uiContext
;
/**
* @param IContextSource $uiContext
* @param array $mixins
*/
public
function
__construct
(
IContextSource
$uiContext
,
$mixins
)
{
$this
->
uiContext
=
$uiContext
;
$this
->
mixins
=
$mixins
;
$this
->
loadPhp
();
}
public
function
getContext
():
IContextSource
{
return
$this
->
uiContext
;
}
/**
* @return string[]
*/
public
function
getMagicWords
()
{
$words
=
array_keys
(
$this
->
magicWords
);
sort
(
$words
);
return
$words
;
}
/**
* Initialize php modules.
*
* @throws MixinNotFoundException
*/
public
function
loadPhp
()
{
foreach
(
$this
->
mixins
as
$name
=>
$info
)
{
if
(
!
empty
(
$info
[
'php'
]
)
)
{
// The module must register itself with this controller.
$php_module_path
=
$info
[
'localBasePath'
]
.
DIRECTORY_SEPARATOR
.
$info
[
'php'
];
// Strip the file extension and assume the mixin class is eponymous.
// TODO: maybe they should be registered using hooks instead...
$php_module_name
=
preg_replace
(
"/[.].+$/"
,
""
,
$info
[
'php'
]
);
require_once
$php_module_path
;
$mod
=
new
$php_module_name
();
if
(
!(
$mod
instanceof
IBannerMixin
)
)
{
throw
new
MixinNotFoundException
(
$name
);
}
$mod
->
register
(
$this
);
}
}
}
/**
* @throws MixinNotFoundException
*/
public
function
getPreloadJsSnippets
():
array
{
$snippets
=
[];
foreach
(
$this
->
mixins
as
$name
=>
$info
)
{
if
(
!
empty
(
$info
[
'preloadJs'
]
)
)
{
$filename
=
$info
[
'localBasePath'
]
.
DIRECTORY_SEPARATOR
.
$info
[
'preloadJs'
];
$snippet
=
file_get_contents
(
$filename
);
if
(
!
$snippet
)
{
throw
new
MixinNotFoundException
(
$name
);
}
$snippets
[
$name
]
=
$snippet
;
}
}
return
$snippets
;
}
public
function
getResourceLoaderModules
():
array
{
$modules
=
[];
foreach
(
$this
->
mixins
as
$name
=>
$info
)
{
if
(
!
empty
(
$info
[
'resourceLoader'
]
)
)
{
$modules
[
$name
]
=
$info
[
'resourceLoader'
];
}
}
return
$modules
;
}
/**
* @param string $word
* @param callable $callback
*/
public
function
registerMagicWord
(
$word
,
$callback
)
{
$this
->
magicWords
[
$word
]
=
$callback
;
}
/**
* @param string $word
* @param array $params
* @return mixed
*/
public
function
renderMagicWord
(
$word
,
$params
=
[]
)
{
if
(
array_key_exists
(
$word
,
$this
->
magicWords
)
)
{
$callback
=
$this
->
magicWords
[
$word
];
if
(
is_callable
(
$callback
)
)
{
return
$callback
(
...
$params
);
}
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Nov 23, 04:05 (3 d, 5 h ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
b0/15/80c3d31fec03c1a3ffdc55d84a34
Default Alt Text
MixinController.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment