Page MenuHomeWickedGov Phorge

CiteParserTagHooks.php
No OneTemporary

Size
1 KB
Referenced Files
None
Subscribers
None

CiteParserTagHooks.php

<?php
namespace Cite\Hooks;
use Cite\CiteFactory;
use MediaWiki\Parser\Parser;
use MediaWiki\Parser\PPFrame;
/**
* @license GPL-2.0-or-later
*/
class CiteParserTagHooks {
public function __construct(
private readonly CiteFactory $citeFactory,
) {
}
/**
* 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 array<string,?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->citeFactory->getCiteForParser( $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 array<string,?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->citeFactory->getCiteForParser( $parser );
$result = $cite->references( $parser, $text, $argv );
if ( $result === null ) {
return htmlspecialchars( $text === null
? "<references/>"
: "<references>$text</references>"
);
}
$frame->setVolatile();
return $result;
}
}

File Metadata

Mime Type
text/x-php
Expires
Aug 16 2026, 11:52 (15 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
30/f5/0200a711a042963215052780ce42
Default Alt Text
CiteParserTagHooks.php (1 KB)

Event Timeline