~ubuntu-branches/ubuntu/saucy/mediawiki-extensions/saucy

« back to all changes in this revision

Viewing changes to extensions/inputbox.php

  • Committer: Bazaar Package Importer
  • Author(s): Romain Beauxis
  • Date: 2010-05-04 15:13:35 UTC
  • mfrom: (0.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100504151335-54qeucg3ec108q28
Tags: 2.2
* Added Replaces:/Conflicts: to allow a proper upgrade.
Closes: #580066
* Fixed package descriptions.
Closes: #579667
* Patched mediawiki-extensions-fckeditor to make it work with
  php 5.3. The fix may not be perfect but at least it work.
  Not closing the bug (#579822) for now..

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
 
3
 
/**
4
 
 * This file contains the main include file for the Inputbox extension of 
5
 
 * MediaWiki. 
6
 
 *
7
 
 * Usage: require_once("path/to/inputbox.php"); in LocalSettings.php
8
 
 *
9
 
 * This extension requires MediaWiki 1.5 or higher.
10
 
 *
11
 
 * @author Erik Moeller <moeller@scireview.de>
12
 
 *  namespaces search improvements partially by
13
 
 *  Leonardo Pimenta <leo.lns@gmail.com> 
14
 
 * @copyright Public domain
15
 
 * @license Public domain
16
 
 * @package MediaWikiExtensions
17
 
 * @version 0.1.1
18
 
 */
19
 
 
20
 
/**
21
 
 * Register the Inputbox extension with MediaWiki
22
 
 */ 
23
 
$wgExtensionFunctions[] = 'registerInputboxExtension';
24
 
$wgExtensionCredits['parserhook'][] = array(
25
 
'name' => 'Inputbox',
26
 
'author' => 'Erik Moeller',
27
 
'url' => 'http://meta.wikimedia.org/wiki/Help:Inputbox',
28
 
);
29
 
 
30
 
/**
31
 
 * Sets the tag that this extension looks for and the function by which it
32
 
 * operates
33
 
 */
34
 
function registerInputboxExtension()
35
 
{
36
 
    global $wgParser;
37
 
    $wgParser->setHook('inputbox', 'renderInputbox');
38
 
}
39
 
 
40
 
 
41
 
 
42
 
 
43
 
/**
44
 
 * Renders an inputbox based on information provided by $input.
45
 
 */
46
 
function renderInputbox($input, $params, &$parser)
47
 
{
48
 
        $inputbox=new Inputbox( $parser );
49
 
        getBoxOption($inputbox->type,$input,'type');
50
 
        getBoxOption($inputbox->width,$input,'width',true);     
51
 
        getBoxOption($inputbox->preload,$input,'preload');
52
 
        getBoxOption($inputbox->editintro,$input,'editintro');
53
 
        getBoxOption($inputbox->defaulttext,$input,'default');  
54
 
        getBoxOption($inputbox->bgcolor,$input,'bgcolor');
55
 
        getBoxOption($inputbox->buttonlabel,$input,'buttonlabel');      
56
 
        getBoxOption($inputbox->searchbuttonlabel,$input,'searchbuttonlabel');          
57
 
        getBoxOption($inputbox->namespaces,$input,'namespaces');                
58
 
        getBoxOption($inputbox->id,$input,'id');        
59
 
        getBoxOption($inputbox->labeltext,$input,'labeltext');
60
 
        getBoxOption($inputbox->br, $input, 'break');
61
 
        getBoxOption($inputbox->hidden, $input, 'hidden');
62
 
        $inputbox->lineBreak();
63
 
        $inputbox->checkWidth();
64
 
        
65
 
        $boxhtml=$inputbox->render();
66
 
        # Maybe support other useful magic words here
67
 
        $boxhtml=str_replace("{{PAGENAME}}",$parser->mTitle->getText(),$boxhtml);
68
 
        if($boxhtml) {
69
 
                return $boxhtml;
70
 
        } else {
71
 
                return "<br /> <font color='red'>Input box '{$inputbox->type}' not defined.</font>";
72
 
        }
73
 
}
74
 
 
75
 
 
76
 
function getBoxOption(&$value,&$input,$name,$isNumber=false) {
77
 
 
78
 
      if(preg_match("/^\s*$name\s*=\s*(.*)/mi",$input,$matches)) {
79
 
                if($isNumber) {
80
 
                        $value=intval($matches[1]);
81
 
                } else {
82
 
                        $value=htmlspecialchars($matches[1]);
83
 
                }
84
 
        }
85
 
}
86
 
 
87
 
class Inputbox {
88
 
        var $type,$width,$preload,$editintro, $br;
89
 
        var $defaulttext,$bgcolor,$buttonlabel,$searchbuttonlabel;
90
 
        var $hidden;
91
 
        
92
 
        function InputBox( &$parser ) {
93
 
                $this->parser =& $parser;
94
 
        }
95
 
        
96
 
        function render() {
97
 
                if($this->type=='create' || $this->type=='comment') {
98
 
                        return $this->getCreateForm();          
99
 
                } elseif($this->type=='search') {
100
 
                        return $this->getSearchForm();
101
 
                } elseif($this->type=='search2') {
102
 
                        return $this->getSearchForm2();
103
 
                } else {
104
 
                        return false;
105
 
                }       
106
 
        }
107
 
        function getSearchForm() {
108
 
                global $wgUser, $wgContLang;
109
 
                
110
 
                $sk=$wgUser->getSkin();
111
 
                $searchpath = $sk->escapeSearchLink();          
112
 
                if(!$this->buttonlabel) {
113
 
                        $this->buttonlabel = wfMsgHtml( 'tryexact' );
114
 
                }
115
 
                if(!$this->searchbuttonlabel) {
116
 
                        $this->searchbuttonlabel = wfMsgHtml( 'searchfulltext' );
117
 
                }
118
 
 
119
 
 
120
 
                $type = $this->hidden ? 'hidden' : 'text';
121
 
                $searchform=<<<ENDFORM
122
 
                <table border="0" width="100%" cellspacing="0" cellpadding="0">
123
 
                <tr>
124
 
                <td align="center" bgcolor="{$this->bgcolor}">
125
 
                <form name="searchbox" action="$searchpath" class="searchbox">
126
 
                <input class="searchboxInput" name="search" type="{$type}"
127
 
                value="{$this->defaulttext}" size="{$this->width}" />{$this->br}
128
 
ENDFORM;
129
 
 
130
 
                // disabled when namespace filter active
131
 
                $gobutton=<<<ENDGO
132
 
<input type='submit' name="go" class="searchboxGoButton" value="{$this->buttonlabel}" />&nbsp;
133
 
ENDGO;
134
 
                // Determine namespace checkboxes
135
 
                $namespaces = $wgContLang->getNamespaces();
136
 
                $namespacesarray = explode(",",$this->namespaces);
137
 
 
138
 
                // Test if namespaces requested by user really exist
139
 
                $searchform2 = '';
140
 
                if ($this->namespaces) {
141
 
                        foreach ($namespacesarray as $usernamespace) {
142
 
                                $checked = '';
143
 
                                // Namespace needs to be checked if flagged with "**" or if it's the only one
144
 
                                if (strstr($usernamespace,'**') || count($namespacesarray)==1) {
145
 
                                        $usernamespace = str_replace("**","",$usernamespace);
146
 
                                        $checked =" checked";
147
 
                                }
148
 
                                foreach ( $namespaces as $i => $name ) {
149
 
                                        if ($i < 0){
150
 
                                                continue;
151
 
                                        }elseif($i==0) {
152
 
                                                $name='Main';
153
 
                                        }
154
 
                                        if ($usernamespace == $name) {
155
 
                                                $searchform2 .= "<input type=checkbox name=\"ns{$i}\" value=\"1\"{$checked}>{$usernamespace}";
156
 
                                        }
157
 
                                }
158
 
                        }
159
 
                        //Line feed 
160
 
                        $searchform2 .= $this->br;              
161
 
                        //If namespaces are defined remove the go button 
162
 
                        //because go button doesn't accept namespaces parameters 
163
 
                        $gobutton='';
164
 
                } 
165
 
                $searchform3=<<<ENDFORM2
166
 
                {$gobutton}
167
 
                <input type='submit' name="searchx" class="searchboxSearchButton" value="{$this->searchbuttonlabel}" />
168
 
                </form>
169
 
                </td>
170
 
                </tr>
171
 
                </table>
172
 
ENDFORM2;
173
 
                //Return form values
174
 
                return $searchform . $searchform2 . $searchform3;
175
 
        }
176
 
 
177
 
        function getSearchForm2() {
178
 
                global $wgUser;
179
 
                
180
 
                $sk=$wgUser->getSkin();
181
 
                $searchpath = $sk->escapeSearchLink();          
182
 
                if(!$this->buttonlabel) {
183
 
                        $this->buttonlabel = wfMsgHtml( 'tryexact' );
184
 
                }
185
 
 
186
 
                $output = $this->parser->parse( $this->labeltext,
187
 
                        $this->parser->mTitle, $this->parser->mOptions, false, false );
188
 
                $this->labeltext = $output->getText();
189
 
                $this->labeltext = str_replace('<p>', '', $this->labeltext);
190
 
                $this->labeltext = str_replace('</p>', '', $this->labeltext);
191
 
                
192
 
                $type = $this->hidden ? 'hidden' : 'text';
193
 
                $searchform=<<<ENDFORM
194
 
<form action="$searchpath" class="bodySearch" id="bodySearch{$this->id}"><div class="bodySearchWrap"><label for="bodySearchIput{$this->id}">{$this->labeltext}</label><input type="{$type}" name="search" size="{$this->width}" class="bodySearchIput" id="bodySearchIput{$this->id}" /><input type="submit" name="go" value="{$this->buttonlabel}" class="bodySearchBtnGo" />
195
 
ENDFORM;
196
 
 
197
 
                if ( !empty( $this->fulltextbtn ) ) // this is wrong...
198
 
                        $searchform .= '<input type="submit" name="fulltext" class="bodySearchBtnSearch" value="{$this->searchbuttonlabel}" />';
199
 
 
200
 
                $searchform .= '</div></form>';
201
 
 
202
 
                return $searchform;
203
 
        }
204
 
 
205
 
        
206
 
        function getCreateForm() {
207
 
                global $wgScript;       
208
 
                
209
 
                $action = htmlspecialchars( $wgScript );                
210
 
                if($this->type=="comment") {
211
 
                        $comment='<input type="hidden" name="section" value="new" />';
212
 
                        if(!$this->buttonlabel) {
213
 
                                $this->buttonlabel = wfMsgHtml( "postcomment" );
214
 
                        }
215
 
                } else {
216
 
                        $comment='';
217
 
                        if(!$this->buttonlabel) {                       
218
 
                                $this->buttonlabel = wfMsgHtml( "createarticle" );
219
 
                        }
220
 
                }               
221
 
                $type = $this->hidden ? 'hidden' : 'text';
222
 
                $createform=<<<ENDFORM
223
 
<table border="0" width="100%" cellspacing="0" cellpadding="0">
224
 
<tr>
225
 
<td align="center" bgcolor="{$this->bgcolor}">
226
 
<form name="createbox" action="$action" method="get" class="createbox">
227
 
        <input type='hidden' name="action" value="edit" />
228
 
        <input type="hidden" name="preload" value="{$this->preload}" />
229
 
        <input type="hidden" name="editintro" value="{$this->editintro}" />
230
 
        {$comment}
231
 
        <input class="createboxInput" name="title" type="{$type}"
232
 
        value="{$this->defaulttext}" size="{$this->width}" />{$this->br}
233
 
        <input type='submit' name="create" class="createboxButton"
234
 
        value="{$this->buttonlabel}" />
235
 
</form>
236
 
</td>
237
 
</tr>
238
 
</table>
239
 
ENDFORM;
240
 
                return $createform;
241
 
        }
242
 
 
243
 
        function lineBreak() {
244
 
                # Should we be inserting a <br /> tag?
245
 
                $cond = ( strtolower( $this->br ) == "no" );
246
 
                $this->br = $cond ? '' : '<br />';
247
 
        }
248
 
 
249
 
        /**
250
 
         * If the width is not supplied, set it to 50
251
 
         */
252
 
        function checkWidth() {
253
 
                if( !$this->width || trim( $this->width ) == '' )
254
 
                        $this->width = 50;
255
 
        }       
256
 
}
257
 
?>