Index: trunk/extensions/ShoutBox/ShoutBox.php |
— | — | @@ -6,16 +6,16 @@ |
7 | 7 | * @ingroup Extensions |
8 | 8 | * @author Jim R. Wilson |
9 | 9 | * @author Jack Phoenix <jack@countervandalism.net> |
10 | | - * @version 0.2 |
| 10 | + * @version 0.2.1 |
11 | 11 | * @copyright Copyright © 2007 Jim R. Wilson |
12 | | - * @copyright Copyright © 2010 Jack Phoenix |
| 12 | + * @copyright Copyright © 2010-2011 Jack Phoenix |
13 | 13 | * @license The MIT License - http://www.opensource.org/licenses/mit-license.php |
14 | 14 | * ----------------------------------------------------------------------- |
15 | 15 | * Description: |
16 | 16 | * This is a MediaWiki extension which adds a parser function for embedding |
17 | 17 | * your own shoutbox into a page. |
18 | 18 | * Requirements: |
19 | | - * MediaWiki 1.12+ |
| 19 | + * MediaWiki 1.16+ |
20 | 20 | * Installation: |
21 | 21 | * 1. Drop the files in $IP/extensions/ShoutBox |
22 | 22 | * Note: $IP is your MediaWiki install dir. |
— | — | @@ -56,12 +56,25 @@ |
57 | 57 | # Credits |
58 | 58 | $wgExtensionCredits['parserhook'][] = array( |
59 | 59 | 'name' => 'ShoutBox', |
60 | | - 'version' => '0.2', |
| 60 | + 'version' => '0.2.1', |
61 | 61 | 'author' => array( 'Jim R. Wilson', 'Jack Phoenix' ), |
62 | 62 | 'url' => 'http://www.mediawiki.org/wiki/Extension:ShoutBox', |
63 | 63 | 'description' => 'Adds a parser function for embedding your own shoutbox', |
64 | 64 | ); |
65 | 65 | |
| 66 | +// Configuration settings |
| 67 | +$wgShoutBoxMinWidth = 100; |
| 68 | + |
| 69 | +$wgShoutBoxMaxWidth = 600; |
| 70 | + |
| 71 | +$wgShoutBoxMinHeight = 100; |
| 72 | + |
| 73 | +$wgShoutBoxMaxHeight = 1024; |
| 74 | + |
| 75 | +$wgShoutBoxDefaultId = false; |
| 76 | + |
| 77 | +$wgShoutBoxCSS = false; |
| 78 | + |
66 | 79 | // Internationalization file |
67 | 80 | $dir = dirname( __FILE__ ) . '/'; |
68 | 81 | $wgExtensionMessagesFiles['ShoutBox'] = $dir . 'ShoutBox.i18n.php'; |
— | — | @@ -78,8 +91,9 @@ |
79 | 92 | |
80 | 93 | /** |
81 | 94 | * Sets up parser functions. |
| 95 | + * |
82 | 96 | * @param $parser Object: instance of running Parser. |
83 | | - * @return true |
| 97 | + * @return Boolean: true |
84 | 98 | */ |
85 | 99 | public static function setup( &$parser ) { |
86 | 100 | # Setup parser hook |
— | — | @@ -89,9 +103,10 @@ |
90 | 104 | |
91 | 105 | /** |
92 | 106 | * Adds magic words for parser functions. |
| 107 | + * |
93 | 108 | * @param $magicWords Array: available magic words |
94 | 109 | * @param $langCode String: language code |
95 | | - * @return Boolean Always true |
| 110 | + * @return Boolean: always true |
96 | 111 | */ |
97 | 112 | public static function parserFunctionMagic( &$magicWords, $langCode = 'en' ) { |
98 | 113 | $magicWords['shoutbox'] = array( 0, 'shoutbox' ); |
— | — | @@ -100,11 +115,12 @@ |
101 | 116 | |
102 | 117 | /** |
103 | 118 | * Embeds ShoutBox |
| 119 | + * |
104 | 120 | * @param $parser Object: Instance of running Parser. |
105 | 121 | * @param $id Integer: Identifier of the ShoutBox (optional - if global default is available) |
106 | 122 | * @param $width Integer: Width of box (optional) |
107 | 123 | * @param $height Integer: Height of box (optional) |
108 | | - * @return String Encoded representation of input params (to be processed later) |
| 124 | + * @return String: encoded representation of input params (to be processed later) |
109 | 125 | */ |
110 | 126 | public static function parserFunction( $parser, $id = null, $width = null, $height = null ) { |
111 | 127 | $params = array( |
— | — | @@ -116,10 +132,12 @@ |
117 | 133 | } |
118 | 134 | |
119 | 135 | /** |
120 | | - * Performs placeholder corrections to bypass MW parser function output restraints. |
| 136 | + * Performs placeholder corrections to bypass MW parser function output |
| 137 | + * restraints. |
| 138 | + * |
121 | 139 | * @param $parser Object: Instance of running Parser. |
122 | 140 | * @param $text String: Text of nearly fully rendered wikitext. |
123 | | - * @return Boolean Always true |
| 141 | + * @return Boolean: always true |
124 | 142 | */ |
125 | 143 | public static function placeholderCorrections( $parser, $text ) { |
126 | 144 | $text = preg_replace_callback( |
— | — | @@ -131,42 +149,32 @@ |
132 | 150 | } |
133 | 151 | |
134 | 152 | /** |
135 | | - * Performs placeholder corrections to bypass MW parser function output restraints. |
| 153 | + * Performs placeholder corrections to bypass MW parser function output |
| 154 | + * restraints. |
| 155 | + * |
136 | 156 | * @param $matches Array: An array of matches to the placeholder regular expression. |
137 | | - * @return String Embedded video frame if params are sane|error message |
| 157 | + * @return String: embedded shoutbox if params are sane|error message |
138 | 158 | */ |
139 | 159 | public static function processShoutBoxParams( $matches ) { |
140 | | - wfLoadExtensionMessages( 'ShoutBox' ); |
| 160 | + global $wgShoutBoxMinWidth, $wgShoutBoxMaxWidth; |
| 161 | + global $wgShoutBoxMinHeight, $wgShoutBoxMaxHeight; |
| 162 | + global $wgShoutBoxDefaultId, $wgShoutBoxCSS; |
| 163 | + |
141 | 164 | $params = @unserialize( @base64_decode( $matches[1] ) ); |
142 | 165 | if( !$params ) { |
143 | | - return '<div class="errorbox">' |
144 | | - . wfMsg( 'shoutbox-unparsable-param-string', @htmlspecialchars( $matches[1] ) ) . |
| 166 | + return '<div class="errorbox">' . |
| 167 | + wfMsg( 'shoutbox-unparsable-param-string', @htmlspecialchars( $matches[1] ) ) . |
145 | 168 | '</div>'; |
146 | 169 | } |
147 | 170 | |
148 | | - global $wgShoutBoxMinWidth, $wgShoutBoxMaxWidth; |
149 | | - global $wgShoutBoxMinHeight, $wgShoutBoxMaxHeight; |
150 | | - if( !is_numeric( $wgShoutBoxMinWidth ) || $wgShoutBoxMinWidth < 100 ) { |
151 | | - $wgShoutBoxMinWidth = 100; |
152 | | - } |
153 | | - if( !is_numeric( $wgShoutBoxMaxWidth ) || $wgShoutBoxMaxWidth > 600 ) { |
154 | | - $wgShoutBoxMaxWidth = 600; |
155 | | - } |
156 | | - if( !is_numeric( $wgShoutBoxMinHeight ) || $wgShoutBoxMinHeight < 100 ) { |
157 | | - $wgShoutBoxMinHeight = 100; |
158 | | - } |
159 | | - if( !is_numeric( $wgShoutBoxMaxHeight ) || $wgShoutBoxMaxHeight > 1024 ) { |
160 | | - $wgShoutBoxMaxHeight = 1024; |
161 | | - } |
162 | | - |
163 | | - global $wgShoutBoxDefaultId; |
164 | 171 | $id = $params['id']; |
165 | 172 | if( $id === null ) { |
166 | 173 | $id = $wgShoutBoxDefaultId; |
167 | 174 | } |
| 175 | + |
168 | 176 | if( $id == null || !is_numeric( $id ) ) { |
169 | | - return '<div class="errorbox">' |
170 | | - . wfMsg( 'shoutbox-bad-id', @htmlspecialchars( $id ) ) . |
| 177 | + return '<div class="errorbox">' . |
| 178 | + wfMsg( 'shoutbox-bad-id', @htmlspecialchars( $id ) ) . |
171 | 179 | '</div>'; |
172 | 180 | } |
173 | 181 | |
— | — | @@ -194,22 +202,23 @@ |
195 | 203 | !is_numeric( $params['height'] ) || |
196 | 204 | $params['height'] < $wgShoutBoxMinWidth || |
197 | 205 | $params['height'] > $wgShoutBoxMaxWidth |
198 | | - ) { |
| 206 | + ) |
| 207 | + { |
199 | 208 | return '<div class="errorbox">' . |
200 | | - wfMsg( 'shoutbox-illegal-height', @htmlspecialchars( $params['height'] ) ) . |
| 209 | + wfMsg( 'shoutbox-illegal-height', @htmlspecialchars( $params['height'] ) ) . |
201 | 210 | '</div>'; |
202 | 211 | } |
203 | 212 | $height = $params['height']; |
204 | 213 | } |
205 | 214 | |
206 | | - global $wgShoutBoxCSS; |
207 | 215 | if( $wgShoutBoxCSS ) { |
208 | 216 | $url = wfMsgForContent( 'shoutbox-url-with-css', $id, urlencode( $wgShoutBoxCSS ) ); |
209 | 217 | } else { |
210 | 218 | $url = wfMsgForContent( 'shoutbox-url', $id ); |
211 | 219 | } |
212 | 220 | |
213 | | - return '<iframe src="' . $url . '" width="' . $width . '" height="' . $height . '" frameborder="0" allowTransparency="true"></iframe>'; |
| 221 | + return '<iframe src="' . $url . '" width="' . $width . '" height="' . |
| 222 | + $height . '" frameborder="0" allowTransparency="true"></iframe>'; |
214 | 223 | } |
215 | 224 | |
216 | 225 | } |
\ No newline at end of file |