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