Index: trunk/extensions/inputbox/InputBox.i18n.php |
— | — | @@ -0,0 +1,27 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Messages file for the InputBox extension |
| 6 | + * |
| 7 | + * @addtogroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +/** |
| 11 | + * Get all extension messages |
| 12 | + * |
| 13 | + * @return array |
| 14 | + */ |
| 15 | +function efInputBoxMessages() { |
| 16 | + $messages = array( |
| 17 | + |
| 18 | +/** |
| 19 | + * English |
| 20 | + */ |
| 21 | +'en' => array( |
| 22 | + 'inputbox-error-no-type' => 'You have not specified the type of input box to create.', |
| 23 | + 'inputbox-error-bad-type' => 'Input box type "$1" not recognised. Please specify "create", "comment", "search" or "search2".', |
| 24 | +), |
| 25 | + |
| 26 | + ); |
| 27 | + return $messages; |
| 28 | +} |
\ No newline at end of file |
Property changes on: trunk/extensions/inputbox/InputBox.i18n.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 29 | + native |
Index: trunk/extensions/inputbox/inputbox.php |
— | — | @@ -15,36 +15,33 @@ |
16 | 16 | * @license Public domain |
17 | 17 | * @version 0.1.1 |
18 | 18 | */ |
19 | | - |
| 19 | + |
20 | 20 | /** |
21 | 21 | * Register the Inputbox extension with MediaWiki |
22 | 22 | */ |
23 | | -$wgExtensionFunctions[] = 'registerInputboxExtension'; |
| 23 | +$wgExtensionFunctions[] = 'efInputBoxSetup'; |
24 | 24 | $wgExtensionCredits['parserhook'][] = array( |
25 | 25 | 'name' => 'Inputbox', |
26 | | - 'author' => 'Erik Moeller', |
| 26 | + 'author' => array( 'Erik Moeller', 'Leonardo Pimenta', 'Rob Church' ), |
27 | 27 | 'url' => 'http://meta.wikimedia.org/wiki/Help:Inputbox', |
28 | 28 | 'description' => 'Allow inclusion of predefined HTML forms.', |
29 | 29 | ); |
30 | 30 | |
31 | 31 | /** |
32 | | - * Sets the tag that this extension looks for and the function by which it |
33 | | - * operates |
| 32 | + * Extension setup function |
34 | 33 | */ |
35 | | -function registerInputboxExtension() |
36 | | -{ |
37 | | - global $wgParser; |
38 | | - $wgParser->setHook('inputbox', 'renderInputbox'); |
| 34 | +function efInputBoxSetup() { |
| 35 | + global $wgMessageCache, $wgParser; |
| 36 | + require_once( dirname( __FILE__ ) . '/InputBox.i18n.php' ); |
| 37 | + foreach( efInputBoxMessages() as $lang => $messages ) |
| 38 | + $wgMessageCache->addMessages( $messages, $lang ); |
| 39 | + $wgParser->setHook( 'inputbox', 'efInputBoxRender' ); |
39 | 40 | } |
40 | 41 | |
41 | | -function renderInputbox( $input, $params, $parser ) { |
| 42 | +function efInputBoxRender( $input, $params, $parser ) { |
42 | 43 | $inputbox = new Inputbox( $parser ); |
43 | 44 | $inputbox->extractOptions( $parser->replaceVariables( $input ) ); |
44 | | - $html = $inputbox->render(); |
45 | | - // FIXME: Won't somebody please think of the i18n people!? |
46 | | - return $html |
47 | | - ? $html |
48 | | - : '<div><strong class="error">Input box: Type not defined.</strong></div>'; |
| 45 | + return $inputbox->render(); |
49 | 46 | } |
50 | 47 | |
51 | 48 | class Inputbox { |
— | — | @@ -57,16 +54,22 @@ |
58 | 55 | } |
59 | 56 | |
60 | 57 | function render() { |
61 | | - if($this->type=='create' || $this->type=='comment') { |
62 | | - return $this->getCreateForm(); |
63 | | - } elseif($this->type=='search') { |
64 | | - return $this->getSearchForm(); |
65 | | - } elseif($this->type=='search2') { |
66 | | - return $this->getSearchForm2(); |
67 | | - } else { |
68 | | - return false; |
69 | | - } |
| 58 | + switch( $this->type ) { |
| 59 | + case 'create': |
| 60 | + case 'comment': |
| 61 | + return $this->getCreateForm(); |
| 62 | + case 'search': |
| 63 | + return $this->getSearchForm(); |
| 64 | + case 'search2': |
| 65 | + return $this->getSearchForm2(); |
| 66 | + default: |
| 67 | + $message = strlen( $this->type ) > 0 |
| 68 | + ? htmlspecialchars( wfMsgForContent( 'inputbox-error-bad-type', $this->type ) ) |
| 69 | + : htmlspecialchars( wfMsgForContent( 'inputbox-error-no-type' ) ); |
| 70 | + return "<div><strong class=\"error\">{$message}</strong></div>"; |
| 71 | + } |
70 | 72 | } |
| 73 | + |
71 | 74 | function getSearchForm() { |
72 | 75 | global $wgUser, $wgContLang; |
73 | 76 | |