r94768 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94767‎ | r94768 | r94769 >
Date:15:37, 17 August 2011
Author:vasilievvv
Status:deferred
Tags:
Comment:
* Rename {{i:}} to {{#invoke:}}
* Make a {{s:}} instruction which allows user to transclude the script directly.
Modified paths:
  • /trunk/extensions/WikiScripts/Hooks.php (modified) (history)
  • /trunk/extensions/WikiScripts/i18n/Magic.php (modified) (history)

Diff [purge]

Index: trunk/extensions/WikiScripts/i18n/Magic.php
@@ -3,5 +3,6 @@
44 $magicWords = array();
55
66 $magicWords['en'] = array(
7 - 'i' => array( 0, 'i' ),
 7+ 'invoke' => array( 0, 'invoke' ),
 8+ 's' => array( 0, 's' ),
89 );
Index: trunk/extensions/WikiScripts/Hooks.php
@@ -42,7 +42,8 @@
4343 * @param $parser Parser
4444 */
4545 public static function setupParserHook( &$parser ) {
46 - $parser->setFunctionHook( 'i', 'WSHooks::callHook', SFH_NO_HASH | SFH_OBJECT_ARGS );
 46+ $parser->setFunctionHook( 'invoke', 'WSHooks::callHook', SFH_OBJECT_ARGS );
 47+ $parser->setFunctionHook( 's', 'WSHooks::transcludeHook', SFH_NO_HASH | SFH_OBJECT_ARGS );
4748 return true;
4849 }
4950
@@ -67,7 +68,7 @@
6869 }
6970
7071 /**
71 - * Handles the {{i:module|func}} construction.
 72+ * Handles the {{#invoke:module|func}} construction.
7273 *
7374 * @static
7475 * @param $parser Parser
@@ -76,29 +77,48 @@
7778 * @return string
7879 */
7980 public static function callHook( &$parser, $frame, $args ) {
 81+ if( count( $args ) < 2 ) {
 82+ throw new WSTransclusionException( 'nofunction' );
 83+ }
 84+
 85+ $module = $parser->mStripState->unstripBoth( array_shift( $args ) );
 86+ $function = $frame->expand( array_shift( $args ) );
 87+ return self::doRunHook( $parser, $frame, $module, $function, $args );
 88+ }
 89+
 90+ /**
 91+ * Handles the transclusion of the script ({{s:module}} hook).
 92+ *
 93+ * @static
 94+ * @param $parser Parser
 95+ * @param $frame
 96+ * @param $args
 97+ * @return string
 98+ */
 99+ public static function transcludeHook( &$parser, $frame, $args ) {
 100+ $module = $parser->mStripState->unstripBoth( array_shift( $args ) );
 101+ return self::doRunHook( $parser, $frame, $module, 'main', $args );
 102+ }
 103+
 104+ private static function doRunHook( &$parser, $frame, $module, $function, $args ) {
80105 wfProfileIn( __METHOD__ );
81 - $i = self::getInterpreter( $parser );
82106
83107 try {
84 - if( count( $args ) < 2 ) {
85 - throw new WSTransclusionException( 'nofunction' );
86 - }
 108+ $i = self::getInterpreter( $parser );
87109
88 - $moduleName = $parser->mStripState->unstripBoth( array_shift( $args ) );
89 - $funcName = $frame->expand( array_shift( $args ) );
90110 foreach( $args as &$arg ) {
91111 $arg = $frame->expand( $arg );
92112 }
93113
94 - $result = $i->invokeUserFunctionFromWikitext( $moduleName, $funcName, $args, $frame );
 114+ $result = $i->invokeUserFunctionFromWikitext( $module, $function, $args, $frame );
 115+
 116+ wfProfileOut( __METHOD__ );
 117+ return trim( $result );
95118 } catch( WSException $e ) {
96119 $msg = $e->getMessage();
97120 wfProfileOut( __METHOD__ );
98121 return "<strong class=\"error\">{$msg}</strong>";
99122 }
100 -
101 - wfProfileOut( __METHOD__ );
102 - return trim( $result );
103123 }
104124
105125 /**

Status & tagging log