Index: trunk/extensions/WikiScripts/i18n/Magic.php |
— | — | @@ -3,5 +3,6 @@ |
4 | 4 | $magicWords = array(); |
5 | 5 | |
6 | 6 | $magicWords['en'] = array( |
7 | | - 'i' => array( 0, 'i' ), |
| 7 | + 'invoke' => array( 0, 'invoke' ), |
| 8 | + 's' => array( 0, 's' ), |
8 | 9 | ); |
Index: trunk/extensions/WikiScripts/Hooks.php |
— | — | @@ -42,7 +42,8 @@ |
43 | 43 | * @param $parser Parser |
44 | 44 | */ |
45 | 45 | 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 ); |
47 | 48 | return true; |
48 | 49 | } |
49 | 50 | |
— | — | @@ -67,7 +68,7 @@ |
68 | 69 | } |
69 | 70 | |
70 | 71 | /** |
71 | | - * Handles the {{i:module|func}} construction. |
| 72 | + * Handles the {{#invoke:module|func}} construction. |
72 | 73 | * |
73 | 74 | * @static |
74 | 75 | * @param $parser Parser |
— | — | @@ -76,29 +77,48 @@ |
77 | 78 | * @return string |
78 | 79 | */ |
79 | 80 | 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 ) { |
80 | 105 | wfProfileIn( __METHOD__ ); |
81 | | - $i = self::getInterpreter( $parser ); |
82 | 106 | |
83 | 107 | try { |
84 | | - if( count( $args ) < 2 ) { |
85 | | - throw new WSTransclusionException( 'nofunction' ); |
86 | | - } |
| 108 | + $i = self::getInterpreter( $parser ); |
87 | 109 | |
88 | | - $moduleName = $parser->mStripState->unstripBoth( array_shift( $args ) ); |
89 | | - $funcName = $frame->expand( array_shift( $args ) ); |
90 | 110 | foreach( $args as &$arg ) { |
91 | 111 | $arg = $frame->expand( $arg ); |
92 | 112 | } |
93 | 113 | |
94 | | - $result = $i->invokeUserFunctionFromWikitext( $moduleName, $funcName, $args, $frame ); |
| 114 | + $result = $i->invokeUserFunctionFromWikitext( $module, $function, $args, $frame ); |
| 115 | + |
| 116 | + wfProfileOut( __METHOD__ ); |
| 117 | + return trim( $result ); |
95 | 118 | } catch( WSException $e ) { |
96 | 119 | $msg = $e->getMessage(); |
97 | 120 | wfProfileOut( __METHOD__ ); |
98 | 121 | return "<strong class=\"error\">{$msg}</strong>"; |
99 | 122 | } |
100 | | - |
101 | | - wfProfileOut( __METHOD__ ); |
102 | | - return trim( $result ); |
103 | 123 | } |
104 | 124 | |
105 | 125 | /** |