r95181 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r95180‎ | r95181 | r95182 >
Date:22:28, 21 August 2011
Author:ashley
Status:deferred
Tags:
Comment:
ShoutBox: cleanup
Modified paths:
  • /trunk/extensions/ShoutBox/ShoutBox.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ShoutBox/ShoutBox.php
@@ -6,16 +6,16 @@
77 * @ingroup Extensions
88 * @author Jim R. Wilson
99 * @author Jack Phoenix <jack@countervandalism.net>
10 - * @version 0.2
 10+ * @version 0.2.1
1111 * @copyright Copyright © 2007 Jim R. Wilson
12 - * @copyright Copyright © 2010 Jack Phoenix
 12+ * @copyright Copyright © 2010-2011 Jack Phoenix
1313 * @license The MIT License - http://www.opensource.org/licenses/mit-license.php
1414 * -----------------------------------------------------------------------
1515 * Description:
1616 * This is a MediaWiki extension which adds a parser function for embedding
1717 * your own shoutbox into a page.
1818 * Requirements:
19 - * MediaWiki 1.12+
 19+ * MediaWiki 1.16+
2020 * Installation:
2121 * 1. Drop the files in $IP/extensions/ShoutBox
2222 * Note: $IP is your MediaWiki install dir.
@@ -56,12 +56,25 @@
5757 # Credits
5858 $wgExtensionCredits['parserhook'][] = array(
5959 'name' => 'ShoutBox',
60 - 'version' => '0.2',
 60+ 'version' => '0.2.1',
6161 'author' => array( 'Jim R. Wilson', 'Jack Phoenix' ),
6262 'url' => 'http://www.mediawiki.org/wiki/Extension:ShoutBox',
6363 'description' => 'Adds a parser function for embedding your own shoutbox',
6464 );
6565
 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+
6679 // Internationalization file
6780 $dir = dirname( __FILE__ ) . '/';
6881 $wgExtensionMessagesFiles['ShoutBox'] = $dir . 'ShoutBox.i18n.php';
@@ -78,8 +91,9 @@
7992
8093 /**
8194 * Sets up parser functions.
 95+ *
8296 * @param $parser Object: instance of running Parser.
83 - * @return true
 97+ * @return Boolean: true
8498 */
8599 public static function setup( &$parser ) {
86100 # Setup parser hook
@@ -89,9 +103,10 @@
90104
91105 /**
92106 * Adds magic words for parser functions.
 107+ *
93108 * @param $magicWords Array: available magic words
94109 * @param $langCode String: language code
95 - * @return Boolean Always true
 110+ * @return Boolean: always true
96111 */
97112 public static function parserFunctionMagic( &$magicWords, $langCode = 'en' ) {
98113 $magicWords['shoutbox'] = array( 0, 'shoutbox' );
@@ -100,11 +115,12 @@
101116
102117 /**
103118 * Embeds ShoutBox
 119+ *
104120 * @param $parser Object: Instance of running Parser.
105121 * @param $id Integer: Identifier of the ShoutBox (optional - if global default is available)
106122 * @param $width Integer: Width of box (optional)
107123 * @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)
109125 */
110126 public static function parserFunction( $parser, $id = null, $width = null, $height = null ) {
111127 $params = array(
@@ -116,10 +132,12 @@
117133 }
118134
119135 /**
120 - * Performs placeholder corrections to bypass MW parser function output restraints.
 136+ * Performs placeholder corrections to bypass MW parser function output
 137+ * restraints.
 138+ *
121139 * @param $parser Object: Instance of running Parser.
122140 * @param $text String: Text of nearly fully rendered wikitext.
123 - * @return Boolean Always true
 141+ * @return Boolean: always true
124142 */
125143 public static function placeholderCorrections( $parser, $text ) {
126144 $text = preg_replace_callback(
@@ -131,42 +149,32 @@
132150 }
133151
134152 /**
135 - * Performs placeholder corrections to bypass MW parser function output restraints.
 153+ * Performs placeholder corrections to bypass MW parser function output
 154+ * restraints.
 155+ *
136156 * @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
138158 */
139159 public static function processShoutBoxParams( $matches ) {
140 - wfLoadExtensionMessages( 'ShoutBox' );
 160+ global $wgShoutBoxMinWidth, $wgShoutBoxMaxWidth;
 161+ global $wgShoutBoxMinHeight, $wgShoutBoxMaxHeight;
 162+ global $wgShoutBoxDefaultId, $wgShoutBoxCSS;
 163+
141164 $params = @unserialize( @base64_decode( $matches[1] ) );
142165 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] ) ) .
145168 '</div>';
146169 }
147170
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;
164171 $id = $params['id'];
165172 if( $id === null ) {
166173 $id = $wgShoutBoxDefaultId;
167174 }
 175+
168176 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 ) ) .
171179 '</div>';
172180 }
173181
@@ -194,22 +202,23 @@
195203 !is_numeric( $params['height'] ) ||
196204 $params['height'] < $wgShoutBoxMinWidth ||
197205 $params['height'] > $wgShoutBoxMaxWidth
198 - ) {
 206+ )
 207+ {
199208 return '<div class="errorbox">' .
200 - wfMsg( 'shoutbox-illegal-height', @htmlspecialchars( $params['height'] ) ) .
 209+ wfMsg( 'shoutbox-illegal-height', @htmlspecialchars( $params['height'] ) ) .
201210 '</div>';
202211 }
203212 $height = $params['height'];
204213 }
205214
206 - global $wgShoutBoxCSS;
207215 if( $wgShoutBoxCSS ) {
208216 $url = wfMsgForContent( 'shoutbox-url-with-css', $id, urlencode( $wgShoutBoxCSS ) );
209217 } else {
210218 $url = wfMsgForContent( 'shoutbox-url', $id );
211219 }
212220
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>';
214223 }
215224
216225 }
\ No newline at end of file

Status & tagging log