Add makeSearchInput and makeSearchButton to BaseTemplate and make use of it in Vector...
[lhc/web/wiklou.git] / skins / MonoBook.php
1 <?php
2 /**
3 * MonoBook nouveau
4 *
5 * Translated from gwicke's previous TAL template version to remove
6 * dependency on PHPTAL.
7 *
8 * @todo document
9 * @file
10 * @ingroup Skins
11 */
12
13 if( !defined( 'MEDIAWIKI' ) )
14 die( -1 );
15
16 /**
17 * Inherit main code from SkinTemplate, set the CSS and template filter.
18 * @todo document
19 * @ingroup Skins
20 */
21 class SkinMonoBook extends SkinTemplate {
22 /** Using monobook. */
23 var $skinname = 'monobook', $stylename = 'monobook',
24 $template = 'MonoBookTemplate', $useHeadElement = true;
25
26 function setupSkinUserCss( OutputPage $out ) {
27 global $wgHandheldStyle;
28 parent::setupSkinUserCss( $out );
29
30 $out->addModuleStyles( 'skins.monobook' );
31
32 // Ugh. Can't do this properly because $wgHandheldStyle may be a URL
33 if( $wgHandheldStyle ) {
34 // Currently in testing... try 'chick/main.css'
35 $out->addStyle( $wgHandheldStyle, 'handheld' );
36 }
37
38 // TODO: Migrate all of these
39 //$out->addStyle( 'monobook/IE50Fixes.css', 'screen', 'lt IE 5.5000' );
40 //$out->addStyle( 'monobook/IE55Fixes.css', 'screen', 'IE 5.5000' );
41 //$out->addStyle( 'monobook/IE60Fixes.css', 'screen', 'IE 6' );
42 //$out->addStyle( 'monobook/IE70Fixes.css', 'screen', 'IE 7' );
43
44 // TODO: migrate
45 //$out->addStyle( 'monobook/rtl.css', 'screen', '', 'rtl' );
46
47 }
48 }
49
50 /**
51 * @todo document
52 * @ingroup Skins
53 */
54 class MonoBookTemplate extends BaseTemplate {
55 var $skin;
56 /**
57 * Template filter callback for MonoBook skin.
58 * Takes an associative array of data set from a SkinTemplate-based
59 * class, and a wrapper for MediaWiki's localization database, and
60 * outputs a formatted page.
61 *
62 * @access private
63 */
64 function execute() {
65 global $wgRequest;
66
67 $this->skin = $skin = $this->data['skin'];
68 $action = $wgRequest->getText( 'action' );
69
70 // Suppress warnings to prevent notices about missing indexes in $this->data
71 wfSuppressWarnings();
72
73 // Generate additional footer links
74 $footerlinks = $this->data["footerlinks"];
75 // fold footerlinks into a single array using a bit of trickery
76 $footerlinks = call_user_func_array('array_merge', array_values($footerlinks));
77 // Generate additional footer icons
78 $footericons = $this->data["footericons"];
79 // Unset any icons which don't have an image
80 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
81 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
82 if ( !is_string($footerIcon) && !isset($footerIcon["src"]) ) {
83 unset($footerIconsBlock[$footerIconKey]);
84 }
85 }
86 }
87 // Redo removal of any empty blocks
88 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
89 if ( count($footerIconsBlock) <= 0 ) {
90 unset($footericons[$footerIconsKey]);
91 }
92 }
93
94 $this->html( 'headelement' );
95 ?><div id="globalWrapper">
96 <div id="column-content"><div id="content"<?php $this->html("specialpageattributes") ?>>
97 <a id="top"></a>
98 <?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
99
100 <h1 id="firstHeading" class="firstHeading"><?php $this->html('title') ?></h1>
101 <div id="bodyContent">
102 <div id="siteSub"><?php $this->msg('tagline') ?></div>
103 <div id="contentSub"<?php $this->html('userlangattributes') ?>><?php $this->html('subtitle') ?></div>
104 <?php if($this->data['undelete']) { ?>
105 <div id="contentSub2"><?php $this->html('undelete') ?></div>
106 <?php } ?><?php if($this->data['newtalk'] ) { ?>
107 <div class="usermessage"><?php $this->html('newtalk') ?></div>
108 <?php } ?><?php if($this->data['showjumplinks']) { ?>
109 <div id="jump-to-nav"><?php $this->msg('jumpto') ?> <a href="#column-one"><?php $this->msg('jumptonavigation') ?></a>, <a href="#searchInput"><?php $this->msg('jumptosearch') ?></a></div>
110 <?php } ?>
111 <!-- start content -->
112 <?php $this->html('bodytext') ?>
113 <?php if($this->data['catlinks']) { $this->html('catlinks'); } ?>
114 <!-- end content -->
115 <?php if($this->data['dataAfterContent']) { $this->html ('dataAfterContent'); } ?>
116 <div class="visualClear"></div>
117 </div>
118 </div></div>
119 <div id="column-one"<?php $this->html('userlangattributes') ?>>
120 <div id="p-cactions" class="portlet">
121 <h5><?php $this->msg('views') ?></h5>
122 <div class="pBody">
123 <ul><?php
124 foreach($this->data['content_actions'] as $key => $tab) {
125 echo '
126 <li id="' . Sanitizer::escapeId( "ca-$key" ) . '"';
127 if( $tab['class'] ) {
128 echo ' class="'.htmlspecialchars($tab['class']).'"';
129 }
130 echo '><a href="'.htmlspecialchars($tab['href']).'"';
131 # We don't want to give the watch tab an accesskey if the
132 # page is being edited, because that conflicts with the
133 # accesskey on the watch checkbox. We also don't want to
134 # give the edit tab an accesskey, because that's fairly su-
135 # perfluous and conflicts with an accesskey (Ctrl-E) often
136 # used for editing in Safari.
137 if( in_array( $action, array( 'edit', 'submit' ) )
138 && in_array( $key, array( 'edit', 'watch', 'unwatch' ))) {
139 echo $skin->tooltip( "ca-$key" );
140 } else {
141 echo $skin->tooltipAndAccesskey( "ca-$key" );
142 }
143 echo '>'.htmlspecialchars($tab['text']).'</a></li>';
144 } ?>
145
146 </ul>
147 </div>
148 </div>
149 <div class="portlet" id="p-personal">
150 <h5><?php $this->msg('personaltools') ?></h5>
151 <div class="pBody">
152 <ul<?php $this->html('userlangattributes') ?>>
153 <?php foreach($this->data['personal_urls'] as $key => $item) { ?>
154 <li id="<?php echo Sanitizer::escapeId( "pt-$key" ) ?>"<?php
155 if ($item['active']) { ?> class="active"<?php } ?>><a href="<?php
156 echo htmlspecialchars($item['href']) ?>"<?php echo $skin->tooltipAndAccesskey('pt-'.$key) ?><?php
157 if(!empty($item['class'])) { ?> class="<?php
158 echo htmlspecialchars($item['class']) ?>"<?php } ?>><?php
159 echo htmlspecialchars($item['text']) ?></a></li>
160 <?php } ?>
161 </ul>
162 </div>
163 </div>
164 <div class="portlet" id="p-logo">
165 <a style="background-image: url(<?php $this->text('logopath') ?>);" <?php
166 ?>href="<?php echo htmlspecialchars($this->data['nav_urls']['mainpage']['href'])?>"<?php
167 echo $skin->tooltipAndAccesskey('p-logo') ?>></a>
168 </div>
169 <script type="<?php $this->text('jsmimetype') ?>"> if (window.isMSIE55) fixalpha(); </script>
170 <?php
171 $sidebar = $this->data['sidebar'];
172 if ( !isset( $sidebar['SEARCH'] ) ) $sidebar['SEARCH'] = true;
173 if ( !isset( $sidebar['TOOLBOX'] ) ) $sidebar['TOOLBOX'] = true;
174 if ( !isset( $sidebar['LANGUAGES'] ) ) $sidebar['LANGUAGES'] = true;
175 foreach ($sidebar as $boxName => $cont) {
176 if ( $boxName == 'SEARCH' ) {
177 $this->searchBox();
178 } elseif ( $boxName == 'TOOLBOX' ) {
179 $this->toolbox();
180 } elseif ( $boxName == 'LANGUAGES' ) {
181 $this->languageBox();
182 } else {
183 $this->customBox( $boxName, $cont );
184 }
185 }
186 ?>
187 </div><!-- end of the left (by default at least) column -->
188 <div class="visualClear"></div>
189 <div id="footer"<?php $this->html('userlangattributes') ?>>
190 <?php foreach ( $footericons as $blockName => $footerIcons ) { ?>
191 <div id="f-<?php echo htmlspecialchars($blockName); ?>ico">
192 <?php foreach ( $footerIcons as $icon ) { ?>
193 <?php echo $this->skin->makeFooterIcon( $icon ); ?>
194
195 <?php }
196 ?>
197 </div>
198 <?php }
199
200 // Generate additional footer links
201 $validFooterLinks = array();
202 foreach( $footerlinks as $aLink ) {
203 if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
204 $validFooterLinks[] = $aLink;
205 }
206 }
207 if ( count( $validFooterLinks ) > 0 ) {
208 ?> <ul id="f-list">
209 <?php
210 foreach( $validFooterLinks as $aLink ) {
211 if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
212 ?> <li id="<?php echo $aLink ?>"><?php $this->html($aLink) ?></li>
213 <?php }
214 }
215 ?>
216 </ul>
217 <?php }
218 ?>
219 </div>
220 </div>
221 <?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?>
222 <?php $this->html('reporttime') ?>
223 <?php if ( $this->data['debug'] ): ?>
224 <!-- Debug output:
225 <?php $this->text( 'debug' ); ?>
226
227 -->
228 <?php endif;
229
230 echo Html::closeElement( 'body' );
231 echo Html::closeElement( 'html' );
232 wfRestoreWarnings();
233 } // end of execute() method
234
235 /*************************************************************************************************/
236 function searchBox() {
237 global $wgUseTwoButtonsSearchForm;
238 ?>
239 <div id="p-search" class="portlet">
240 <h5><label for="searchInput"><?php $this->msg('search') ?></label></h5>
241 <div id="searchBody" class="pBody">
242 <form action="<?php $this->text('wgScript') ?>" id="searchform">
243 <input type='hidden' name="title" value="<?php $this->text('searchtitle') ?>"/>
244 <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
245
246 <?php echo $this->makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" ));
247 if ($wgUseTwoButtonsSearchForm): ?>&#160;
248 <?php echo $this->makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" ));
249 else: ?>
250
251 <div><a href="<?php $this->text('searchaction') ?>" rel="search"><?php $this->msg('powersearch-legend') ?></a></div><?php
252 endif; ?>
253
254 </form>
255 </div>
256 </div>
257 <?php
258 }
259
260 /*************************************************************************************************/
261 function toolbox() {
262 ?>
263 <div class="portlet" id="p-tb">
264 <h5><?php $this->msg('toolbox') ?></h5>
265 <div class="pBody">
266 <ul>
267 <?php
268 foreach ( $this->getToolbox() as $key => $tbitem ) { ?>
269 <?php echo $this->makeListItem($key, $tbitem); ?>
270
271 <?php
272 }
273 wfRunHooks( 'MonoBookTemplateToolboxEnd', array( &$this ) );
274 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this ) );
275 ?>
276 </ul>
277 </div>
278 </div>
279 <?php
280 }
281
282 /*************************************************************************************************/
283 function languageBox() {
284 if( $this->data['language_urls'] ) {
285 ?>
286 <div id="p-lang" class="portlet">
287 <h5<?php $this->html('userlangattributes') ?>><?php $this->msg('otherlanguages') ?></h5>
288 <div class="pBody">
289 <ul>
290 <?php foreach($this->data['language_urls'] as $key => $langlink) { ?>
291 <?php echo $this->makeListItem($key, $langlink); ?>
292
293 <?php } ?>
294 </ul>
295 </div>
296 </div>
297 <?php
298 }
299 }
300
301 /*************************************************************************************************/
302 function customBox( $bar, $cont ) {
303 ?>
304 <div class='generated-sidebar portlet' id='<?php echo Sanitizer::escapeId( "p-$bar" ) ?>'<?php echo $this->skin->tooltip('p-'.$bar) ?>>
305 <h5><?php $out = wfMsg( $bar ); if (wfEmptyMsg($bar, $out)) echo htmlspecialchars($bar); else echo htmlspecialchars($out); ?></h5>
306 <div class='pBody'>
307 <?php if ( is_array( $cont ) ) { ?>
308 <ul>
309 <?php foreach($cont as $key => $val) { ?>
310 <?php echo $this->makeListItem($key, $val); ?>
311
312 <?php } ?>
313 </ul>
314 <?php } else {
315 # allow raw HTML block to be defined by extensions
316 print $cont;
317 }
318 ?>
319 </div>
320 </div>
321 <?php
322 }
323 } // end of class
324
325