User:Jack Phoenix/patches/WikiTextLoggedInOut

Index: WikiTextLoggedInOut.php

=
====================================================== --- WikiTextLoggedInOut.php	(revision 115) +++ WikiTextLoggedInOut.php	(working copy) @@ -1,35 +1,64 @@ <?php -$wgExtensionFunctions[] = "wfWikiTextLoggedIn"; +/** + * WikiTextLoggedInOut extension + * Defines two new parser hooks, and + * that will display different output depending if the user + * is logged in or not. + * + * @author Wikia, Inc. + * @version 1.0 + * @link http://www.mediawiki.org/wiki/Extension:WikiTextLoggedInOut + */ +//Avoid unstubbing $wgParser on setHook too early on modern (1.12+) MW versions, as per r35980 +if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { +	$wgHooks['ParserFirstCallInit'][] = 'wfWikiTextLoggedIn'; +} else { +	$wgExtensionFunctions[] = 'wfWikiTextLoggedIn'; +} + +$wgExtensionCredits['parserhook'][] = array( +	'name' => 'WikiTextLoggedInOut', +	'version' => '1.0', +	'author' => 'Wikia New York Team', +	'description' => 'Two parser hooks, &lt;loggedin&gt; and &lt;loggedout&gt; to show different text depending on the users\' login state', +	'url' => 'http://www.mediawiki.org/wiki/Extension:WikiTextLoggedInOut' +); + function wfWikiTextLoggedIn { global $wgParser, $wgOut; -	$wgParser->setHook( "loggedin", "OutputLoggedInText" ); +	$wgParser->setHook( 'loggedin', 'OutputLoggedInText' ); +	return true; } -function OutputLoggedInText( $input, $args, &$parser ){ +function OutputLoggedInText( $input, $args, &$parser ) { global $wgUser, $wgTitle, $wgOut; if( $wgUser->isLoggedIn ){ return $parser->recursiveTagParse($input); } -	+ 	return ""; } -$wgExtensionFunctions[] = "wfWikiTextLoggedOut"; +if ( defined( 'MW_SUPPORTS_PARSERFIRSTCALLINIT' ) ) { +	$wgHooks['ParserFirstCallInit'][] = 'wfWikiTextLoggedOut'; +} else { +	$wgExtensionFunctions[] = 'wfWikiTextLoggedOut'; +} function wfWikiTextLoggedOut { global $wgParser, $wgOut; -	$wgParser->setHook( "loggedout", "OutputLoggedOutText" ); +	$wgParser->setHook( 'loggedout', 'OutputLoggedOutText' ); +	return true; } -function OutputLoggedOutText( $input, $args, &$parser ){ +function OutputLoggedOutText( $input, $args, &$parser ) { global $wgUser, $wgTitle, $wgOut; -	-	if( ! $wgUser->isLoggedIn ){ + +	if( !$wgUser->isLoggedIn ){ return $parser->recursiveTagParse($input); } -	+ 	return ""; -} -?> \ No newline at end of file +} \ No newline at end of file