Jack Phoenix has uploaded a new change for review. https://gerrit.wikimedia.org/r/254383
Change subject: Version 1.5.0: extension registration support, cleanup & refactoring ...................................................................... Version 1.5.0: extension registration support, cleanup & refactoring Change-Id: I6612652e05cb61feb896d9146e0bdd493071f3a1 --- A WikiTextLoggedInOut.class.php D WikiTextLoggedInOut.i18n.php M WikiTextLoggedInOut.php A extension.json 4 files changed, 75 insertions(+), 63 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/WikiTextLoggedInOut refs/changes/83/254383/1 diff --git a/WikiTextLoggedInOut.class.php b/WikiTextLoggedInOut.class.php new file mode 100644 index 0000000..42e33c8 --- /dev/null +++ b/WikiTextLoggedInOut.class.php @@ -0,0 +1,45 @@ +<?php +/** + * WikiTextLoggedInOut extension + * Defines two new parser hooks, <loggedin> and <loggedout> + * that will display different output depending if the user + * is logged in or not. + * + * @file + * @ingroup Extensions + * @author Aaron Wright + * @author David Pean + * @author Jack Phoenix <[email protected]> + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later + * @link https://www.mediawiki.org/wiki/Extension:WikiTextLoggedInOut Documentation + */ + +class WikiTextLoggedInOut { + + public static function registerTags( &$parser ) { + $parser->setHook( 'loggedin', array( __CLASS__, 'outputLoggedInText' ) ); + $parser->setHook( 'loggedout', array( __CLASS__, 'outputLoggedOutText' ) ); + return true; + } + + public static function outputLoggedInText( $input, $args, $parser, $frame ) { + global $wgUser; + + if ( $wgUser->isLoggedIn() ) { + return $parser->recursiveTagParse( $input, $frame ); + } + + return ''; + } + + public static function outputLoggedOutText( $input, $args, $parser, $frame ) { + global $wgUser; + + if ( !$wgUser->isLoggedIn() ) { + return $parser->recursiveTagParse( $input, $frame ); + } + + return ''; + } + +} \ No newline at end of file diff --git a/WikiTextLoggedInOut.i18n.php b/WikiTextLoggedInOut.i18n.php deleted file mode 100644 index 470ede5..0000000 --- a/WikiTextLoggedInOut.i18n.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php -/** - * This is a backwards-compatibility shim, generated by: - * https://git.wikimedia.org/blob/mediawiki%2Fcore.git/HEAD/maintenance%2FgenerateJsonI18n.php - * - * Beginning with MediaWiki 1.23, translation strings are stored in json files, - * and the EXTENSION.i18n.php file only exists to provide compatibility with - * older releases of MediaWiki. For more information about this migration, see: - * https://www.mediawiki.org/wiki/Requests_for_comment/Localisation_format - * - * This shim maintains compatibility back to MediaWiki 1.17. - */ -$messages = array(); -if ( !function_exists( 'wfJsonI18nShim3fed00dcafae39cb' ) ) { - function wfJsonI18nShim3fed00dcafae39cb( $cache, $code, &$cachedData ) { - $codeSequence = array_merge( array( $code ), $cachedData['fallbackSequence'] ); - foreach ( $codeSequence as $csCode ) { - $fileName = dirname( __FILE__ ) . "/i18n/$csCode.json"; - if ( is_readable( $fileName ) ) { - $data = FormatJson::decode( file_get_contents( $fileName ), true ); - foreach ( array_keys( $data ) as $key ) { - if ( $key === '' || $key[0] === '@' ) { - unset( $data[$key] ); - } - } - $cachedData['messages'] = array_merge( $data, $cachedData['messages'] ); - } - - $cachedData['deps'][] = new FileDependency( $fileName ); - } - return true; - } - - $GLOBALS['wgHooks']['LocalisationCacheRecache'][] = 'wfJsonI18nShim3fed00dcafae39cb'; -} diff --git a/WikiTextLoggedInOut.php b/WikiTextLoggedInOut.php index 8f3ac6f..e185d33 100644 --- a/WikiTextLoggedInOut.php +++ b/WikiTextLoggedInOut.php @@ -18,39 +18,14 @@ $wgExtensionCredits['parserhook'][] = array( 'path' => __FILE__, 'name' => 'WikiTextLoggedInOut', - 'version' => '1.4.0', + 'version' => '1.5.0', 'author' => array( 'Aaron Wright', 'David Pean', 'Jack Phoenix' ), 'url' => 'https://www.mediawiki.org/wiki/Extension:WikiTextLoggedInOut', 'descriptionmsg' => 'wikitextloggedinout-desc' ); -$dir = dirname( __FILE__ ) . '/'; $wgMessagesDirs['WikiTextLoginInOut'] = __DIR__ . '/i18n'; -$wgExtensionMessagesFiles['WikiTextLoginInOut'] = $dir . 'WikiTextLoggedInOut.i18n.php'; -$wgHooks['ParserFirstCallInit'][] = 'efWikiTextLoggedInOut'; -function efWikiTextLoggedInOut( &$parser ) { - $parser->setHook( 'loggedin', 'outputLoggedInText' ); - $parser->setHook( 'loggedout', 'outputLoggedOutText' ); - return true; -} +$wgAutoloadClasses['WikiTextLoggedInOut'] = __DIR__ . '/WikiTextLoggedInOut.class.php'; -function outputLoggedInText( $input, $args, $parser, $frame ) { - global $wgUser; - - if( $wgUser->isLoggedIn() ) { - return $parser->recursiveTagParse( $input, $frame ); - } - - return ''; -} - -function outputLoggedOutText( $input, $args, $parser, $frame ) { - global $wgUser; - - if( !$wgUser->isLoggedIn() ) { - return $parser->recursiveTagParse( $input, $frame ); - } - - return ''; -} +$wgHooks['ParserFirstCallInit'][] = 'WikiTextLoggedInOut::registerTags'; \ No newline at end of file diff --git a/extension.json b/extension.json new file mode 100644 index 0000000..8126e5d --- /dev/null +++ b/extension.json @@ -0,0 +1,27 @@ +{ + "name": "WikiTextLoggedInOut", + "version": "1.5.0", + "author": [ + "Aaron Wright", + "David Pean", + "Jack Phoenix" + ], + "license-name": "GPL-2.0+", + "url": "https://www.mediawiki.org/wiki/Extension:WikiTextLoggedInOut", + "descriptionmsg": "wikitextloggedinout-desc", + "type": "parserhook", + "MessagesDirs": { + "WikiTextLoggedInOut": [ + "i18n" + ] + }, + "AutoloadClasses": { + "WikiTextLoggedInOut": "WikiTextLoggedInOut.class.php" + }, + "Hooks": { + "ParserFirstCallInit": [ + "WikiTextLoggedInOut::registerTags" + ] + }, + "manifest_version": 1 +} -- To view, visit https://gerrit.wikimedia.org/r/254383 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I6612652e05cb61feb896d9146e0bdd493071f3a1 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/WikiTextLoggedInOut Gerrit-Branch: master Gerrit-Owner: Jack Phoenix <[email protected]> _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
