-
Notifications
You must be signed in to change notification settings - Fork 0
/
Lyrics.php
49 lines (41 loc) · 1.44 KB
/
Lyrics.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
<?php
/**
* Lyrics - Adds a <lyrics> tag to automatically turn line breaks into <br/>
* tags so lyrics display as intended.
*
* @file
* @ingroup Extensions
* @version 1.0
* @author Richard Cook <[email protected]>
* @copyright Copyright © 2014 Richard Cook
* @license http:https://www.gnu.org/copyleft/gpl.html GNU General Public License 3.0 or later
*/
// Check we're in MediaWiki
if ( !defined( 'MEDIAWIKI' ) ) {
die( "This is not a valid entry point.\n" );
}
// Extension credits that will show up on Special:Version
$wgExtensionCredits['parserhook'][] = array(
'name' => 'Lyrics',
'version' => '1.0',
'author' => '[http:https://www.shoutwiki.com/wiki/User:Cook879 Richard Cook]',
'url' => 'http:https://www.shoutwiki.com/wiki/Help:Lyrics',
'description' => 'Adds a <code><lyrics></code> tag to allow simple lyrics formatting'
);
// Create lyrics tag
$wgHooks['ParserFirstCallInit'][] = 'wfLyricsSetup';
function wfLyricsSetup( Parser $parser ) {
// Pair up the tag and the function
$parser->setHook( 'lyrics', 'wfLyricsRender' );
return true;
}
function wfLyricsRender( $text, array $args, Parser $parser, PPFrame $frame ) {
// For security reasons, user input needs to be put through here
$text = htmlspecialchars( $text );
// Replace new lines with <br/>
$text = str_replace( "\n", '<br/>', $text );
// Parse the wikitext
$output = $parser->recursiveTagParse( $text, $frame );
// Return the generated output to the page
return $output;
}