aeef8a9905f605a0adf1060b4a5b33e34b0dd819
[lhc/web/wiklou.git] / skins / monobook / 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 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @todo document
24 * @file
25 * @ingroup Skins
26 */
27
28 if ( !defined( 'MEDIAWIKI' ) ) {
29 die( -1 );
30 }
31
32 /**
33 * Inherit main code from SkinTemplate, set the CSS and template filter.
34 * @todo document
35 * @ingroup Skins
36 */
37 class SkinMonoBook extends SkinTemplate {
38 /** Using monobook. */
39 public $skinname = 'monobook';
40 public $template = 'MonoBookTemplate';
41
42 /**
43 * @param OutputPage $out
44 */
45 function setupSkinUserCss( OutputPage $out ) {
46 parent::setupSkinUserCss( $out );
47
48 $out->addModuleStyles( array( 'mediawiki.skinning.interface', 'skins.monobook.styles' ) );
49
50 // TODO: Migrate all of these
51 $out->addStyle( 'monobook/IE60Fixes.css', 'screen', 'IE 6' );
52 $out->addStyle( 'monobook/IE70Fixes.css', 'screen', 'IE 7' );
53 }
54 }
55
56 /**
57 * @todo document
58 * @ingroup Skins
59 */
60 class MonoBookTemplate extends BaseTemplate {
61
62 /**
63 * Template filter callback for MonoBook skin.
64 * Takes an associative array of data set from a SkinTemplate-based
65 * class, and a wrapper for MediaWiki's localization database, and
66 * outputs a formatted page.
67 *
68 * @access private
69 */
70 function execute() {
71 // Suppress warnings to prevent notices about missing indexes in $this->data
72 wfSuppressWarnings();
73
74 $this->html( 'headelement' );
75 ?><div id="globalWrapper">
76 <div id="column-content">
77 <div id="content" class="mw-body-primary" role="main">
78 <a id="top"></a>
79 <?php
80 if ( $this->data['sitenotice'] ) {
81 ?>
82 <div id="siteNotice"><?php
83 $this->html( 'sitenotice' )
84 ?></div><?php
85 }
86 ?>
87
88 <h1 id="firstHeading" class="firstHeading" lang="<?php
89 $this->data['pageLanguage'] =
90 $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
91 $this->text( 'pageLanguage' );
92 ?>"><span dir="auto"><?php $this->html( 'title' ) ?></span></h1>
93
94 <div id="bodyContent" class="mw-body">
95 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
96 <div id="contentSub"<?php
97 $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' )
98 ?></div>
99 <?php if ( $this->data['undelete'] ) { ?>
100 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
101 <?php
102 }
103 ?><?php
104 if ( $this->data['newtalk'] ) {
105 ?>
106 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
107 <?php
108 }
109 ?>
110 <div id="jump-to-nav" class="mw-jump"><?php
111 $this->msg( 'jumpto' )
112 ?> <a href="#column-one"><?php
113 $this->msg( 'jumptonavigation' )
114 ?></a><?php
115 $this->msg( 'comma-separator' )
116 ?><a href="#searchInput"><?php
117 $this->msg( 'jumptosearch' )
118 ?></a></div>
119
120 <!-- start content -->
121 <?php $this->html( 'bodytext' ) ?>
122 <?php
123 if ( $this->data['catlinks'] ) {
124 $this->html( 'catlinks' );
125 }
126 ?>
127 <!-- end content -->
128 <?php
129 if ( $this->data['dataAfterContent'] ) {
130 $this->html( 'dataAfterContent'
131 );
132 }
133 ?>
134 <div class="visualClear"></div>
135 </div>
136 </div>
137 </div>
138 <div id="column-one"<?php $this->html( 'userlangattributes' ) ?>>
139 <h2><?php $this->msg( 'navigation-heading' ) ?></h2>
140 <?php $this->cactions(); ?>
141 <div class="portlet" id="p-personal" role="navigation">
142 <h3><?php $this->msg( 'personaltools' ) ?></h3>
143
144 <div class="pBody">
145 <ul<?php $this->html( 'userlangattributes' ) ?>>
146 <?php foreach ( $this->getPersonalTools() as $key => $item ) { ?>
147 <?php echo $this->makeListItem( $key, $item ); ?>
148
149 <?php
150 }
151 ?>
152 </ul>
153 </div>
154 </div>
155 <div class="portlet" id="p-logo" role="banner">
156 <?php
157 echo Html::element( 'a', array(
158 'href' => $this->data['nav_urls']['mainpage']['href'],
159 'style' => "background-image: url({$this->data['logopath']});" )
160 + Linker::tooltipAndAccesskeyAttribs( 'p-logo' ) ); ?>
161
162 </div>
163 <?php
164 $this->renderPortals( $this->data['sidebar'] );
165 ?>
166 </div><!-- end of the left (by default at least) column -->
167 <div class="visualClear"></div>
168 <?php
169 $validFooterIcons = $this->getFooterIcons( "icononly" );
170 $validFooterLinks = $this->getFooterLinks( "flat" ); // Additional footer links
171
172 if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) {
173 ?>
174 <div id="footer" role="contentinfo"<?php $this->html( 'userlangattributes' ) ?>>
175 <?php
176 $footerEnd = '</div>';
177 } else {
178 $footerEnd = '';
179 }
180
181 foreach ( $validFooterIcons as $blockName => $footerIcons ) {
182 ?>
183 <div id="f-<?php echo htmlspecialchars( $blockName ); ?>ico">
184 <?php foreach ( $footerIcons as $icon ) { ?>
185 <?php echo $this->getSkin()->makeFooterIcon( $icon ); ?>
186
187 <?php
188 }
189 ?>
190 </div>
191 <?php
192 }
193
194 if ( count( $validFooterLinks ) > 0 ) {
195 ?>
196 <ul id="f-list">
197 <?php
198 foreach ( $validFooterLinks as $aLink ) {
199 ?>
200 <li id="<?php echo $aLink ?>"><?php $this->html( $aLink ) ?></li>
201 <?php
202 }
203 ?>
204 </ul>
205 <?php
206 }
207
208 echo $footerEnd;
209 ?>
210
211 </div>
212 <?php
213 $this->printTrail();
214 echo Html::closeElement( 'body' );
215 echo Html::closeElement( 'html' );
216 wfRestoreWarnings();
217 } // end of execute() method
218
219 /*************************************************************************************************/
220
221 /**
222 * @param array $sidebar
223 */
224 protected function renderPortals( $sidebar ) {
225 if ( !isset( $sidebar['SEARCH'] ) ) {
226 $sidebar['SEARCH'] = true;
227 }
228 if ( !isset( $sidebar['TOOLBOX'] ) ) {
229 $sidebar['TOOLBOX'] = true;
230 }
231 if ( !isset( $sidebar['LANGUAGES'] ) ) {
232 $sidebar['LANGUAGES'] = true;
233 }
234
235 foreach ( $sidebar as $boxName => $content ) {
236 if ( $content === false ) {
237 continue;
238 }
239
240 if ( $boxName == 'SEARCH' ) {
241 $this->searchBox();
242 } elseif ( $boxName == 'TOOLBOX' ) {
243 $this->toolbox();
244 } elseif ( $boxName == 'LANGUAGES' ) {
245 $this->languageBox();
246 } else {
247 $this->customBox( $boxName, $content );
248 }
249 }
250 }
251
252 function searchBox() {
253 global $wgUseTwoButtonsSearchForm;
254 ?>
255 <div id="p-search" class="portlet" role="search">
256 <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
257
258 <div id="searchBody" class="pBody">
259 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
260 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
261 <?php echo $this->makeSearchInput( array( "id" => "searchInput" ) ); ?>
262
263 <?php
264 echo $this->makeSearchButton(
265 "go",
266 array( "id" => "searchGoButton", "class" => "searchButton" )
267 );
268
269 if ( $wgUseTwoButtonsSearchForm ) {
270 ?>&#160;
271 <?php echo $this->makeSearchButton(
272 "fulltext",
273 array( "id" => "mw-searchButton", "class" => "searchButton" )
274 );
275 } else {
276 ?>
277
278 <div><a href="<?php
279 $this->text( 'searchaction' )
280 ?>" rel="search"><?php $this->msg( 'powersearch-legend' ) ?></a></div><?php
281 } ?>
282
283 </form>
284
285 <?php $this->renderAfterPortlet( 'search' ); ?>
286 </div>
287 </div>
288 <?php
289 }
290
291 /**
292 * Prints the cactions bar.
293 * Shared between MonoBook and Modern
294 */
295 function cactions() {
296 ?>
297 <div id="p-cactions" class="portlet" role="navigation">
298 <h3><?php $this->msg( 'views' ) ?></h3>
299
300 <div class="pBody">
301 <ul><?php
302 foreach ( $this->data['content_actions'] as $key => $tab ) {
303 echo '
304 ' . $this->makeListItem( $key, $tab );
305 } ?>
306
307 </ul>
308 <?php $this->renderAfterPortlet( 'cactions' ); ?>
309 </div>
310 </div>
311 <?php
312 }
313
314 /*************************************************************************************************/
315 function toolbox() {
316 ?>
317 <div class="portlet" id="p-tb" role="navigation">
318 <h3><?php $this->msg( 'toolbox' ) ?></h3>
319
320 <div class="pBody">
321 <ul>
322 <?php
323 foreach ( $this->getToolbox() as $key => $tbitem ) {
324 ?>
325 <?php echo $this->makeListItem( $key, $tbitem ); ?>
326
327 <?php
328 }
329 wfRunHooks( 'MonoBookTemplateToolboxEnd', array( &$this ) );
330 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
331 ?>
332 </ul>
333 <?php $this->renderAfterPortlet( 'tb' ); ?>
334 </div>
335 </div>
336 <?php
337 }
338
339 /*************************************************************************************************/
340 function languageBox() {
341 if ( $this->data['language_urls'] !== false ) {
342 ?>
343 <div id="p-lang" class="portlet" role="navigation">
344 <h3<?php $this->html( 'userlangattributes' ) ?>><?php $this->msg( 'otherlanguages' ) ?></h3>
345
346 <div class="pBody">
347 <ul>
348 <?php foreach ( $this->data['language_urls'] as $key => $langlink ) { ?>
349 <?php echo $this->makeListItem( $key, $langlink ); ?>
350
351 <?php
352 }
353 ?>
354 </ul>
355
356 <?php $this->renderAfterPortlet( 'lang' ); ?>
357 </div>
358 </div>
359 <?php
360 }
361 }
362
363 /*************************************************************************************************/
364 /**
365 * @param string $bar
366 * @param array|string $cont
367 */
368 function customBox( $bar, $cont ) {
369 $portletAttribs = array(
370 'class' => 'generated-sidebar portlet',
371 'id' => Sanitizer::escapeId( "p-$bar" ),
372 'role' => 'navigation'
373 );
374
375 $tooltip = Linker::titleAttrib( "p-$bar" );
376 if ( $tooltip !== false ) {
377 $portletAttribs['title'] = $tooltip;
378 }
379 echo ' ' . Html::openElement( 'div', $portletAttribs );
380 $msgObj = wfMessage( $bar );
381 ?>
382
383 <h3><?php echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $bar ); ?></h3>
384 <div class='pBody'>
385 <?php
386 if ( is_array( $cont ) ) {
387 ?>
388 <ul>
389 <?php
390 foreach ( $cont as $key => $val ) {
391 ?>
392 <?php echo $this->makeListItem( $key, $val ); ?>
393
394 <?php
395 }
396 ?>
397 </ul>
398 <?php
399 } else {
400 # allow raw HTML block to be defined by extensions
401 print $cont;
402 }
403
404 $this->renderAfterPortlet( $bar );
405 ?>
406 </div>
407 </div>
408 <?php
409 }
410 } // end of class