Index: trunk/extensions/ShoutBox/ShoutBox.i18n.php |
— | — | @@ -0,0 +1,23 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Internationalization file for ShoutBox extension. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +$messages = array(); |
| 11 | + |
| 12 | +/** English |
| 13 | + * @author Jim R. Wilson |
| 14 | + */ |
| 15 | +$messages['en'] = array( |
| 16 | + 'shoutbox-missing-params' => 'ShoutBox is missing a required parameter.', |
| 17 | + 'shoutbox-bad-params' => 'ShoutBox received a bad parameter.', |
| 18 | + 'shoutbox-unparsable-param-string' => 'ShoutBox received the unparsable parameter string "<tt>$1</tt>".', |
| 19 | + 'shoutbox-bad-id' => 'ShoutBox received the bad id "<tt>$1</tt>"', |
| 20 | + 'shoutbox-illegal-width' => 'ShoutBox received the illegal width parameter "$1".', |
| 21 | + 'shoutbox-illegal-height' => 'ShoutBox received the illegal height parameter "$1".', |
| 22 | + 'shoutbox-url' => 'http://$1.shoutbox.us/?LANG=US', |
| 23 | + 'shoutbox-url-with-css' => 'http://$1.shoutbox.us/?LANG=US&extcss=$2', |
| 24 | +); |
\ No newline at end of file |
Property changes on: trunk/extensions/ShoutBox/ShoutBox.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 25 | + native |
Index: trunk/extensions/ShoutBox/ShoutBox.php |
— | — | @@ -0,0 +1,215 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * ShoutBox - Adds a parser function for embedding your own shoutbox. |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + * @author Jim R. Wilson |
| 9 | + * @author Jack Phoenix <jack@countervandalism.net> |
| 10 | + * @version 0.2 |
| 11 | + * @copyright Copyright © 2007 Jim R. Wilson |
| 12 | + * @copyright Copyright © 2010 Jack Phoenix |
| 13 | + * @license The MIT License - http://www.opensource.org/licenses/mit-license.php |
| 14 | + * ----------------------------------------------------------------------- |
| 15 | + * Description: |
| 16 | + * This is a MediaWiki extension which adds a parser function for embedding |
| 17 | + * your own shoutbox into a page. |
| 18 | + * Requirements: |
| 19 | + * MediaWiki 1.12+ |
| 20 | + * Installation: |
| 21 | + * 1. Drop the files in $IP/extensions/ShoutBox |
| 22 | + * Note: $IP is your MediaWiki install dir. |
| 23 | + * 2. Enable the extension by adding this line to your LocalSettings.php: |
| 24 | + * require_once( $IP . '/extensions/ShoutBox/ShoutBox.php' ); |
| 25 | + * Version Notes: |
| 26 | + * version 0.1: |
| 27 | + * Initial release. |
| 28 | + * ----------------------------------------------------------------------- |
| 29 | + * Copyright © 2007 Jim R. Wilson |
| 30 | + * |
| 31 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 32 | + * of this software and associated documentation files (the "Software"), to deal |
| 33 | + * in the Software without restriction, including without limitation the rights to |
| 34 | + * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
| 35 | + * the Software, and to permit persons to whom the Software is furnished to do |
| 36 | + * so, subject to the following conditions: |
| 37 | + * |
| 38 | + * The above copyright notice and this permission notice shall be included in all |
| 39 | + * copies or substantial portions of the Software. |
| 40 | + * |
| 41 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 42 | + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES |
| 43 | + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 44 | + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
| 45 | + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, |
| 46 | + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 47 | + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 48 | + * OTHER DEALINGS IN THE SOFTWARE. |
| 49 | + * ----------------------------------------------------------------------- |
| 50 | + */ |
| 51 | + |
| 52 | +# Confirm MW environment |
| 53 | +if( !defined( 'MEDIAWIKI' ) ) { |
| 54 | + die( "This is an extension to the MediaWiki package and cannot be run standalone." ); |
| 55 | +} |
| 56 | + |
| 57 | +# Credits |
| 58 | +$wgExtensionCredits['parserhook'][] = array( |
| 59 | + 'name' => 'ShoutBox', |
| 60 | + 'version' => '0.2', |
| 61 | + 'author' => array( 'Jim R. Wilson', 'Jack Phoenix' ), |
| 62 | + 'url' => 'http://www.mediawiki.org/wiki/Extension:ShoutBox', |
| 63 | + 'description' => 'Adds a parser function for embedding your own shoutbox', |
| 64 | +); |
| 65 | + |
| 66 | +// Internationalization file |
| 67 | +$dir = dirname( __FILE__ ) . '/'; |
| 68 | +$wgExtensionMessagesFiles['ShoutBox'] = $dir . 'ShoutBox.i18n.php'; |
| 69 | + |
| 70 | +// Hooked functions |
| 71 | +$wgHooks['ParserFirstCallInit'][] = 'ShoutBox::setup'; |
| 72 | +$wgHooks['LanguageGetMagic'][] = 'ShoutBox::parserFunctionMagic'; |
| 73 | +$wgHooks['ParserBeforeTidy'][] = 'ShoutBox::placeholderCorrections'; |
| 74 | + |
| 75 | +/** |
| 76 | + * Wrapper class for encapsulating ShoutBox related parser methods |
| 77 | + */ |
| 78 | +class ShoutBox { |
| 79 | + |
| 80 | + /** |
| 81 | + * Sets up parser functions. |
| 82 | + * @param $parser Object: instance of running Parser. |
| 83 | + * @return true |
| 84 | + */ |
| 85 | + public static function setup( &$parser ) { |
| 86 | + # Setup parser hook |
| 87 | + $parser->setFunctionHook( 'shoutbox', array( 'ShoutBox', 'parserFunction' ) ); |
| 88 | + return true; |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * Adds magic words for parser functions. |
| 93 | + * @param $magicWords Array: available magic words |
| 94 | + * @param $langCode String: language code |
| 95 | + * @return Boolean Always true |
| 96 | + */ |
| 97 | + public static function parserFunctionMagic( &$magicWords, $langCode = 'en' ) { |
| 98 | + $magicWords['shoutbox'] = array( 0, 'shoutbox' ); |
| 99 | + return true; |
| 100 | + } |
| 101 | + |
| 102 | + /** |
| 103 | + * Embeds ShoutBox |
| 104 | + * @param $parser Object: Instance of running Parser. |
| 105 | + * @param $id Integer: Identifier of the ShoutBox (optional - if global default is available) |
| 106 | + * @param $width Integer: Width of box (optional) |
| 107 | + * @param $height Integer: Height of box (optional) |
| 108 | + * @return String Encoded representation of input params (to be processed later) |
| 109 | + */ |
| 110 | + public static function parserFunction( $parser, $id = null, $width = null, $height = null ) { |
| 111 | + $params = array( |
| 112 | + 'id' => trim( $id ), |
| 113 | + 'width' => ( $width === null ? null : trim( $width ) ), |
| 114 | + 'height' => ( $height === null ? null : trim( $height ) ) |
| 115 | + ); |
| 116 | + return '<pre>@SBCONTENT@' . base64_encode( serialize( $params ) ) . '@SBCONTENT@</pre>'; |
| 117 | + } |
| 118 | + |
| 119 | + /** |
| 120 | + * Performs placeholder corrections to bypass MW parser function output restraints. |
| 121 | + * @param $parser Object: Instance of running Parser. |
| 122 | + * @param $text String: Text of nearly fully rendered wikitext. |
| 123 | + * @return Boolean Always true |
| 124 | + */ |
| 125 | + public static function placeholderCorrections( $parser, $text ) { |
| 126 | + $text = preg_replace_callback( |
| 127 | + '|<pre>@SBCONTENT@([0-9a-zA-Z\\+\\/]+=*)@SBCONTENT@</pre>|', |
| 128 | + array( 'ShoutBox', 'processShoutBoxParams' ), |
| 129 | + $text |
| 130 | + ); |
| 131 | + return true; |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Performs placeholder corrections to bypass MW parser function output restraints. |
| 136 | + * @param $matches Array: An array of matches to the placeholder regular expression. |
| 137 | + * @return String Embedded video frame if params are sane|error message |
| 138 | + */ |
| 139 | + public static function processShoutBoxParams( $matches ) { |
| 140 | + wfLoadExtensionMessages( 'ShoutBox' ); |
| 141 | + $params = @unserialize( @base64_decode( $matches[1] ) ); |
| 142 | + if( !$params ) { |
| 143 | + return '<div class="errorbox">' |
| 144 | + . wfMsg( 'shoutbox-unparsable-param-string', @htmlspecialchars( $matches[1] ) ) . |
| 145 | + '</div>'; |
| 146 | + } |
| 147 | + |
| 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 | + $id = $params['id']; |
| 165 | + if( $id === null ) { |
| 166 | + $id = $wgShoutBoxDefaultId; |
| 167 | + } |
| 168 | + if( $id == null || !is_numeric( $id ) ) { |
| 169 | + return '<div class="errorbox">' |
| 170 | + . wfMsg( 'shoutbox-bad-id', @htmlspecialchars( $id ) ) . |
| 171 | + '</div>'; |
| 172 | + } |
| 173 | + |
| 174 | + # Build URL and output embedded iframe |
| 175 | + $width = 150; |
| 176 | + $height = 300; |
| 177 | + |
| 178 | + # Retrieve and check width |
| 179 | + if( $params['width'] !== null ) { |
| 180 | + if ( |
| 181 | + !is_numeric( $params['width'] ) || |
| 182 | + $params['width'] < $wgShoutBoxMinWidth || |
| 183 | + $params['width'] > $wgShoutBoxMaxWidth |
| 184 | + ) { |
| 185 | + return '<div class="errorbox">' . |
| 186 | + wfMsg( 'shoutbox-illegal-width', @htmlspecialchars( $params['width'] ) ) . |
| 187 | + '</div>'; |
| 188 | + } |
| 189 | + $width = $params['width']; |
| 190 | + } |
| 191 | + |
| 192 | + # Retrieve and check height |
| 193 | + if( $params['height'] !== null ) { |
| 194 | + if ( |
| 195 | + !is_numeric( $params['height'] ) || |
| 196 | + $params['height'] < $wgShoutBoxMinWidth || |
| 197 | + $params['height'] > $wgShoutBoxMaxWidth |
| 198 | + ) { |
| 199 | + return '<div class="errorbox">' . |
| 200 | + wfMsg( 'shoutbox-illegal-height', @htmlspecialchars( $params['height'] ) ) . |
| 201 | + '</div>'; |
| 202 | + } |
| 203 | + $height = $params['height']; |
| 204 | + } |
| 205 | + |
| 206 | + global $wgShoutBoxCSS; |
| 207 | + if( $wgShoutBoxCSS ) { |
| 208 | + $url = wfMsgForContent( 'shoutbox-url-with-css', $id, urlencode( $wgShoutBoxCSS ) ); |
| 209 | + } else { |
| 210 | + $url = wfMsgForContent( 'shoutbox-url', $id ); |
| 211 | + } |
| 212 | + |
| 213 | + return '<iframe src="' . $url . '" width="' . $width . '" height="' . $height . '" frameborder="0" allowTransparency="true"></iframe>'; |
| 214 | + } |
| 215 | + |
| 216 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/ShoutBox/ShoutBox.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 217 | + native |