Index: trunk/extensions/StringFunctionsEscaped/StringFunctionsEscaped.i18n.php |
— | — | @@ -0,0 +1,12 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +$magicWords = array(); |
| 5 | + |
| 6 | +$magicWords['en'] = array( |
| 7 | + 'pos_e' => array ( 0, 'pos_e' ), |
| 8 | + 'rpos_e' => array ( 0, 'rpos_e' ), |
| 9 | + 'pad_e' => array ( 0, 'pad_e' ), |
| 10 | + 'replace_e' => array ( 0, 'replace_e' ), |
| 11 | + 'explode_e' => array ( 0, 'explode_e' ), |
| 12 | + 'stripnewlines' => array ( 0, 'stripnewlines' ), |
| 13 | +); |
Property changes on: trunk/extensions/StringFunctionsEscaped/StringFunctionsEscaped.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 14 | + native |
Index: trunk/extensions/StringFunctionsEscaped/StringFunctionsEscaped.php |
— | — | @@ -1,9 +1,9 @@ |
2 | 2 | <?php |
3 | 3 | if ( !defined( 'MEDIAWIKI' ) ) |
4 | | - die( 'StringFunctionsEscaped::This file is a MediaWiki extension, it is not a valid entry point' ); |
| 4 | + #die( 'StringFunctionsEscaped::This file is a MediaWiki extension, it is not a valid entry point' ); |
5 | 5 | if ( !class_exists('ExtStringFunctions',false) && |
6 | 6 | !(class_exists('ParserFunctions_HookStub',false) && isset($wgPFEnableStringFunctions) && $wgPFEnableStringFunctions)) |
7 | | - die( 'StringFunctionsEscaped::You must have extension StringFunctions or extension ParserFunctions with string functions enabled' ); |
| 7 | + #die( 'StringFunctionsEscaped::You must have extension StringFunctions or extension ParserFunctions with string functions enabled' ); |
8 | 8 | /* |
9 | 9 | |
10 | 10 | Defines a superset of string parser functions that allow character escaping in the 'search for' and 'replace with' arguments. |
— | — | @@ -67,50 +67,32 @@ |
68 | 68 | ); |
69 | 69 | |
70 | 70 | $dir = dirname( __FILE__ ) . '/'; |
71 | | -# RFU |
72 | | -# $wgExtensionMessagesFiles['StringFunctionsEscaped'] = $dir . 'StringFunctionsEscaped.i18n.php'; |
73 | 71 | |
74 | | -$wgExtensionFunctions[] = 'wfStringFunctionsEscaped'; |
| 72 | +$wgExtensionMessagesFiles['StringFunctionsEscaped'] = $dir . 'StringFunctionsEscaped.i18n.php'; |
75 | 73 | |
76 | | -$wgHooks['LanguageGetMagic'][] = 'wfStringFunctionsEscapedLanguageGetMagic'; |
| 74 | +$wgHooks['ParserFirstCallInit'][] = 'ExtStringFunctionsEscaped::onParserFirstCallInit'; |
77 | 75 | |
78 | | -function wfStringFunctionsEscaped ( ) { |
79 | | - global $wgParser, $wgExtStringFunctionsEscaped; |
| 76 | +class ExtStringFunctionsEscaped { |
80 | 77 | |
81 | | - $wgExtStringFunctionsEscaped = new ExtStringFunctionsEscaped ( ); |
| 78 | + public static function onParserFirstCallInit( $parser ) { |
| 79 | + $parser->setFunctionHook( 'pos_e', array( __CLASS__, 'runPos_e' ) ); |
| 80 | + $parser->setFunctionHook( 'rpos_e', array( __CLASS__, 'runRPos_e' ) ); |
| 81 | + $parser->setFunctionHook( 'pad_e', array( __CLASS__, 'runPad_e' ) ); |
| 82 | + $parser->setFunctionHook( 'replace_e', array( __CLASS__, 'runReplace_e' ) ); |
| 83 | + $parser->setFunctionHook( 'explode_e', array( __CLASS__, 'runExplode_e' ) ); |
| 84 | + $parser->setFunctionHook( 'stripnewlines', array( __CLASS__, 'runStrip_nl' ) ); |
82 | 85 | |
83 | | - $wgParser->setFunctionHook('pos_e', array( &$wgExtStringFunctionsEscaped, 'runPos_e' )); |
84 | | - $wgParser->setFunctionHook('rpos_e', array( &$wgExtStringFunctionsEscaped, 'runRPos_e' )); |
85 | | - $wgParser->setFunctionHook('pad_e', array( &$wgExtStringFunctionsEscaped, 'runPad_e' )); |
86 | | - $wgParser->setFunctionHook('replace_e', array( &$wgExtStringFunctionsEscaped, 'runReplace_e' )); |
87 | | - $wgParser->setFunctionHook('explode_e', array( &$wgExtStringFunctionsEscaped, 'runExplode_e' )); |
88 | | - $wgParser->setFunctionHook('stripnewlines', array( &$wgExtStringFunctionsEscaped, 'runStrip_nl' )); |
89 | | -} |
90 | | - |
91 | | -function wfStringFunctionsEscapedLanguageGetMagic( &$magicWords, $langCode = "en" ) { |
92 | | - switch ( $langCode ) { |
93 | | - default: |
94 | | - $magicWords['pos_e'] = array ( 0, 'pos_e' ); |
95 | | - $magicWords['rpos_e'] = array ( 0, 'rpos_e' ); |
96 | | - $magicWords['pad_e'] = array ( 0, 'pad_e' ); |
97 | | - $magicWords['replace_e'] = array ( 0, 'replace_e' ); |
98 | | - $magicWords['explode_e'] = array ( 0, 'explode_e' ); |
99 | | - $magicWords['stripnewlines'] = array ( 0, 'stripnewlines' ); |
| 86 | + return true; |
100 | 87 | } |
101 | | - return true; |
102 | | -} |
103 | 88 | |
104 | | -class ExtStringFunctionsEscaped { |
105 | | - |
106 | 89 | /** |
107 | 90 | * {{#pos_e:value|key|offset}} |
108 | 91 | * Note: If the needle is an empty string, single space is used instead. |
109 | 92 | * Note: If the needle is not found, empty string is returned. |
110 | 93 | * Note: The needle is limited to specific length. |
111 | 94 | */ |
112 | | - function runPos_e ( &$parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) { |
113 | | - global $wgParser; |
114 | | - list( $callback, $flags ) = $wgParser->mFunctionHooks['pos']; |
| 95 | + public static function runPos_e ( &$parser, $inStr = '', $inNeedle = '', $inOffset = 0 ) { |
| 96 | + list( $callback, $flags ) = $parser->mFunctionHooks['pos']; |
115 | 97 | return @call_user_func_array( $callback, |
116 | 98 | array_merge( array( $parser ), array( $inStr, stripcslashes( $inNeedle ), $inOffset ) ) ); |
117 | 99 | } |
— | — | @@ -121,9 +103,8 @@ |
122 | 104 | * Note: If the needle is not found, -1 is returned. |
123 | 105 | * Note: The needle is limited to specific length. |
124 | 106 | */ |
125 | | - function runRPos_e( &$parser , $inStr = '', $inNeedle = '' ) { |
126 | | - global $wgParser; |
127 | | - list( $callback, $flags ) = $wgParser->mFunctionHooks['rpos']; |
| 107 | + public static function runRPos_e( &$parser , $inStr = '', $inNeedle = '' ) { |
| 108 | + list( $callback, $flags ) = $parser->mFunctionHooks['rpos']; |
128 | 109 | return @call_user_func_array( $callback, |
129 | 110 | array_merge( array( $parser ), array( $inStr, stripcslashes( $inNeedle ) ) ) ); |
130 | 111 | } |
— | — | @@ -132,9 +113,8 @@ |
133 | 114 | * {{#pad_e:value|length|with|direction}} |
134 | 115 | * Note: Length of the resulting string is limited. |
135 | 116 | */ |
136 | | - function runPad_e( &$parser, $inStr = '', $inLen = 0, $inWith = '', $inDirection = '' ) { |
137 | | - global $wgParser; |
138 | | - list( $callback , $flags ) = $wgParser->mFunctionHooks['pad']; |
| 117 | + public static function runPad_e( &$parser, $inStr = '', $inLen = 0, $inWith = '', $inDirection = '' ) { |
| 118 | + list( $callback , $flags ) = $parser->mFunctionHooks['pad']; |
139 | 119 | return @call_user_func_array( $callback, |
140 | 120 | array_merge( array( $parser ), array( $inStr, $inLen, stripcslashes( $inWith ), $inDirection ) ) ); |
141 | 121 | } |
— | — | @@ -145,9 +125,8 @@ |
146 | 126 | * Note: The needle is limited to specific length. |
147 | 127 | * Note: The product is limited to specific length. |
148 | 128 | */ |
149 | | - function runReplace_e( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { |
150 | | - global $wgParser; |
151 | | - list( $callback, $flags ) = $wgParser->mFunctionHooks['replace']; |
| 129 | + public static function runReplace_e( &$parser, $inStr = '', $inReplaceFrom = '', $inReplaceTo = '' ) { |
| 130 | + list( $callback, $flags ) = $parser->mFunctionHooks['replace']; |
152 | 131 | return @call_user_func_array( $callback, |
153 | 132 | array_merge( array( $parser ), array( $inStr, stripcslashes( $inReplaceFrom ), stripcslashes( $inReplaceTo ) ) ) ); |
154 | 133 | } |
— | — | @@ -159,9 +138,8 @@ |
160 | 139 | * Note: The divider is limited to specific length. |
161 | 140 | * Note: Empty string is returned, if there is not enough exploded chunks. |
162 | 141 | */ |
163 | | - function runExplode_e( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) { |
164 | | - global $wgParser; |
165 | | - list( $callback, $flags ) = $wgParser->mFunctionHooks['explode']; |
| 142 | + public static function runExplode_e( &$parser, $inStr = '', $inDiv = '', $inPos = 0 ) { |
| 143 | + list( $callback, $flags ) = $parser->mFunctionHooks['explode']; |
166 | 144 | return @call_user_func_array( $callback, |
167 | 145 | array_merge(array( $parser ), array( $inStr, stripcslashes( $inDiv ), $inPos ) )); |
168 | 146 | } |
— | — | @@ -169,7 +147,7 @@ |
170 | 148 | /** |
171 | 149 | * {{#stripnewlines:value}} |
172 | 150 | */ |
173 | | - function runStrip_nl( &$parser , $inStr = '' ) { |
| 151 | + public static function runStrip_nl( &$parser , $inStr = '' ) { |
174 | 152 | return preg_replace( stripcslashes( '/\n\n+/' ), stripcslashes( '\n' ), $inStr ); |
175 | 153 | } |
176 | 154 | |