r24581 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24580‎ | r24581 | r24582 >
Date:14:30, 4 August 2007
Author:robchurch
Status:old
Tags:
Comment:
* Move error output to Inputbox::render()
* Split error condition into "no type" and "bad type"
* Appease the i18n team with a messages file
* Update credits per comments
Modified paths:
  • /trunk/extensions/inputbox/InputBox.i18n.php (added) (history)
  • /trunk/extensions/inputbox/inputbox.php (modified) (history)

Diff [purge]

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
129 + native
Index: trunk/extensions/inputbox/inputbox.php
@@ -15,36 +15,33 @@
1616 * @license Public domain
1717 * @version 0.1.1
1818 */
19 -
 19+
2020 /**
2121 * Register the Inputbox extension with MediaWiki
2222 */
23 -$wgExtensionFunctions[] = 'registerInputboxExtension';
 23+$wgExtensionFunctions[] = 'efInputBoxSetup';
2424 $wgExtensionCredits['parserhook'][] = array(
2525 'name' => 'Inputbox',
26 - 'author' => 'Erik Moeller',
 26+ 'author' => array( 'Erik Moeller', 'Leonardo Pimenta', 'Rob Church' ),
2727 'url' => 'http://meta.wikimedia.org/wiki/Help:Inputbox',
2828 'description' => 'Allow inclusion of predefined HTML forms.',
2929 );
3030
3131 /**
32 - * Sets the tag that this extension looks for and the function by which it
33 - * operates
 32+ * Extension setup function
3433 */
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' );
3940 }
4041
41 -function renderInputbox( $input, $params, $parser ) {
 42+function efInputBoxRender( $input, $params, $parser ) {
4243 $inputbox = new Inputbox( $parser );
4344 $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();
4946 }
5047
5148 class Inputbox {
@@ -57,16 +54,22 @@
5855 }
5956
6057 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+ }
7072 }
 73+
7174 function getSearchForm() {
7275 global $wgUser, $wgContLang;
7376

Status & tagging log