Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1427228
CiteParserTagHooks.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
CiteParserTagHooks.php
View Options
<?php
namespace
Cite\Hooks
;
use
Cite\Cite
;
use
MediaWiki\Config\Config
;
use
MediaWiki\Parser\Parser
;
use
MediaWiki\Parser\PPFrame
;
/**
* @license GPL-2.0-or-later
*/
class
CiteParserTagHooks
{
private
Config
$config
;
public
function
__construct
(
Config
$config
)
{
$this
->
config
=
$config
;
}
/**
* Enables the two <ref> and <references> tags.
*/
public
function
register
(
Parser
$parser
):
void
{
$parser
->
setHook
(
'ref'
,
[
$this
,
'ref'
]
);
$parser
->
setHook
(
'references'
,
[
$this
,
'references'
]
);
}
/**
* Parser hook for the <ref> tag.
*
* @param ?string $text Raw, untrimmed wikitext content of the <ref> tag, if any
* @param string[] $argv
* @param Parser $parser
* @param PPFrame $frame
*
* @return string HTML
*/
public
function
ref
(
?
string
$text
,
array
$argv
,
Parser
$parser
,
PPFrame
$frame
):
string
{
$cite
=
$this
->
citeForParser
(
$parser
);
$result
=
$cite
->
ref
(
$parser
,
$text
,
$argv
);
if
(
$result
===
null
)
{
return
htmlspecialchars
(
"<ref>$text</ref>"
);
}
$parserOutput
=
$parser
->
getOutput
();
$parserOutput
->
addModules
(
[
'ext.cite.ux-enhancements'
]
);
$parserOutput
->
addModuleStyles
(
[
'ext.cite.styles'
]
);
$frame
->
setVolatile
();
return
$result
;
}
/**
* Parser hook for the <references> tag.
*
* @param ?string $text Raw, untrimmed wikitext content of the <references> tag, if any
* @param string[] $argv
* @param Parser $parser
* @param PPFrame $frame
*
* @return string HTML
*/
public
function
references
(
?
string
$text
,
array
$argv
,
Parser
$parser
,
PPFrame
$frame
):
string
{
$cite
=
$this
->
citeForParser
(
$parser
);
$result
=
$cite
->
references
(
$parser
,
$text
,
$argv
);
if
(
$result
===
null
)
{
return
htmlspecialchars
(
$text
===
null
?
"<references/>"
:
"<references>$text</references>"
);
}
$frame
->
setVolatile
();
return
$result
;
}
/**
* Get or create Cite state for this parser.
*/
private
function
citeForParser
(
Parser
$parser
):
Cite
{
$parser
->
extCite
??=
new
Cite
(
$parser
,
$this
->
config
);
return
$parser
->
extCite
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 14:22 (1 d, 7 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
90/79/4417bce67ac667f13977134f606a
Default Alt Text
CiteParserTagHooks.php (2 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment