Unify MonoBook <head> generation with legacy skins
[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 function initPage( OutputPage $out ) {
24 parent::initPage( $out );
25 $this->skinname = 'monobook';
26 $this->stylename = 'monobook';
27 $this->template = 'MonoBookTemplate';
28
29 }
30
31 function setupSkinUserCss( OutputPage $out ) {
32 global $wgHandheldStyle;
33
34 parent::setupSkinUserCss( $out );
35
36 // Append to the default screen common & print styles...
37 $out->addStyle( 'monobook/main.css', 'screen' );
38 if( $wgHandheldStyle ) {
39 // Currently in testing... try 'chick/main.css'
40 $out->addStyle( $wgHandheldStyle, 'handheld' );
41 }
42
43 $out->addStyle( 'monobook/IE50Fixes.css', 'screen', 'lt IE 5.5000' );
44 $out->addStyle( 'monobook/IE55Fixes.css', 'screen', 'IE 5.5000' );
45 $out->addStyle( 'monobook/IE60Fixes.css', 'screen', 'IE 6' );
46 $out->addStyle( 'monobook/IE70Fixes.css', 'screen', 'IE 7' );
47
48 $out->addStyle( 'monobook/rtl.css', 'screen', '', 'rtl' );
49 }
50 }
51
52 /**
53 * @todo document
54 * @ingroup Skins
55 */
56 class MonoBookTemplate extends QuickTemplate {
57 var $skin;
58 /**
59 * Template filter callback for MonoBook skin.
60 * Takes an associative array of data set from a SkinTemplate-based
61 * class, and a wrapper for MediaWiki's localization database, and
62 * outputs a formatted page.
63 *
64 * @access private
65 */
66 function execute() {
67 global $wgRequest, $wgOut, $wgStyleVersion, $wgJsMimeType, $wgStylePath;
68 $this->skin = $skin = $this->data['skin'];
69 $action = $wgRequest->getText( 'action' );
70
71 // Suppress warnings to prevent notices about missing indexes in $this->data
72 wfSuppressWarnings();
73
74 $path = htmlspecialchars( $wgStylePath );
75 $wgOut->addScript( <<<HTML
76 <!--[if lt IE 7]><script type="$wgJsMimeType" src="$path/common/IEFixes.js?$wgStyleVersion"></script>
77 <meta http-equiv="imagetoolbar" content="no" /><![endif]-->
78 HTML
79 );
80
81 echo $wgOut->headElement( $this->skin );
82
83 ?><body<?php if($this->data['body_ondblclick']) { ?> ondblclick="<?php $this->text('body_ondblclick') ?>"<?php } ?>
84 <?php if($this->data['body_onload']) { ?> onload="<?php $this->text('body_onload') ?>"<?php } ?>
85 class="mediawiki <?php $this->text('dir'); $this->text('capitalizeallnouns') ?> <?php $this->text('pageclass') ?> <?php $this->text('skinnameclass') ?>">
86 <div id="globalWrapper">
87 <div id="column-content">
88 <div id="content">
89 <a name="top" id="top"></a>
90 <?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
91 <h1 id="firstHeading" class="firstHeading"><?php $this->html('title') ?></h1>
92 <div id="bodyContent">
93 <h3 id="siteSub"><?php $this->msg('tagline') ?></h3>
94 <div id="contentSub"><?php $this->html('subtitle') ?></div>
95 <?php if($this->data['undelete']) { ?><div id="contentSub2"><?php $this->html('undelete') ?></div><?php } ?>
96 <?php if($this->data['newtalk'] ) { ?><div class="usermessage"><?php $this->html('newtalk') ?></div><?php } ?>
97 <?php if($this->data['showjumplinks']) { ?><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><?php } ?>
98 <!-- start content -->
99 <?php $this->html('bodytext') ?>
100 <?php if($this->data['catlinks']) { $this->html('catlinks'); } ?>
101 <!-- end content -->
102 <?php if($this->data['dataAfterContent']) { $this->html ('dataAfterContent'); } ?>
103 <div class="visualClear"></div>
104 </div>
105 </div>
106 </div>
107 <div id="column-one">
108 <div id="p-cactions" class="portlet">
109 <h5><?php $this->msg('views') ?></h5>
110 <div class="pBody">
111 <ul <?php $this->html('userlangattributes') ?>>
112 <?php foreach($this->data['content_actions'] as $key => $tab) {
113 echo '
114 <li id="' . Sanitizer::escapeId( "ca-$key" ) . '"';
115 if( $tab['class'] ) {
116 echo ' class="'.htmlspecialchars($tab['class']).'"';
117 }
118 echo '><a href="'.htmlspecialchars($tab['href']).'"';
119 # We don't want to give the watch tab an accesskey if the
120 # page is being edited, because that conflicts with the
121 # accesskey on the watch checkbox. We also don't want to
122 # give the edit tab an accesskey, because that's fairly su-
123 # perfluous and conflicts with an accesskey (Ctrl-E) often
124 # used for editing in Safari.
125 if( in_array( $action, array( 'edit', 'submit' ) )
126 && in_array( $key, array( 'edit', 'watch', 'unwatch' ))) {
127 echo $skin->tooltip( "ca-$key" );
128 } else {
129 echo $skin->tooltipAndAccesskey( "ca-$key" );
130 }
131 echo '>'.htmlspecialchars($tab['text']).'</a></li>';
132 } ?>
133 </ul>
134 </div>
135 </div>
136 <div class="portlet" id="p-personal">
137 <h5><?php $this->msg('personaltools') ?></h5>
138 <div class="pBody">
139 <ul <?php $this->html('userlangattributes') ?>>
140 <?php foreach($this->data['personal_urls'] as $key => $item) { ?>
141 <li id="<?php echo Sanitizer::escapeId( "pt-$key" ) ?>"<?php
142 if ($item['active']) { ?> class="active"<?php } ?>><a href="<?php
143 echo htmlspecialchars($item['href']) ?>"<?php echo $skin->tooltipAndAccesskey('pt-'.$key) ?><?php
144 if(!empty($item['class'])) { ?> class="<?php
145 echo htmlspecialchars($item['class']) ?>"<?php } ?>><?php
146 echo htmlspecialchars($item['text']) ?></a></li>
147 <?php } ?>
148 </ul>
149 </div>
150 </div>
151 <div class="portlet" id="p-logo">
152 <a style="background-image: url(<?php $this->text('logopath') ?>);" <?php
153 ?>href="<?php echo htmlspecialchars($this->data['nav_urls']['mainpage']['href'])?>"<?php
154 echo $skin->tooltipAndAccesskey('p-logo') ?>></a>
155 </div>
156 <script type="<?php $this->text('jsmimetype') ?>"> if (window.isMSIE55) fixalpha(); </script>
157 <?php
158 $sidebar = $this->data['sidebar'];
159 if ( !isset( $sidebar['SEARCH'] ) ) $sidebar['SEARCH'] = true;
160 if ( !isset( $sidebar['TOOLBOX'] ) ) $sidebar['TOOLBOX'] = true;
161 if ( !isset( $sidebar['LANGUAGES'] ) ) $sidebar['LANGUAGES'] = true;
162 foreach ($sidebar as $boxName => $cont) {
163 if ( $boxName == 'SEARCH' ) {
164 $this->searchBox();
165 } elseif ( $boxName == 'TOOLBOX' ) {
166 $this->toolbox();
167 } elseif ( $boxName == 'LANGUAGES' ) {
168 $this->languageBox();
169 } else {
170 $this->customBox( $boxName, $cont );
171 }
172 }
173 ?>
174 </div><!-- end of the left (by default at least) column -->
175 <div class="visualClear"></div>
176 <div id="footer">
177 <?php
178 if($this->data['poweredbyico']) { ?>
179 <div id="f-poweredbyico"><?php $this->html('poweredbyico') ?></div>
180 <?php }
181 if($this->data['copyrightico']) { ?>
182 <div id="f-copyrightico"><?php $this->html('copyrightico') ?></div>
183 <?php }
184
185 // Generate additional footer links
186 $footerlinks = array(
187 'lastmod', 'viewcount', 'numberofwatchingusers', 'credits', 'copyright',
188 'privacy', 'about', 'disclaimer', 'tagline',
189 );
190 $validFooterLinks = array();
191 foreach( $footerlinks as $aLink ) {
192 if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
193 $validFooterLinks[] = $aLink;
194 }
195 }
196 if ( count( $validFooterLinks ) > 0 ) {
197 ?> <ul id="f-list">
198 <?php
199 foreach( $validFooterLinks as $aLink ) {
200 if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
201 ?> <li id="<?php echo $aLink ?>"><?php $this->html($aLink) ?></li>
202 <?php }
203 }
204 ?>
205 </ul>
206 <?php }
207 ?>
208 </div>
209 </div>
210 <?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?>
211 <?php $this->html('reporttime') ?>
212 <?php if ( $this->data['debug'] ): ?>
213 <!-- Debug output:
214 <?php $this->text( 'debug' ); ?>
215
216 -->
217 <?php endif; ?>
218 </body></html>
219 <?php
220 wfRestoreWarnings();
221 } // end of execute() method
222
223 /*************************************************************************************************/
224 function searchBox() {
225 global $wgUseTwoButtonsSearchForm;
226 ?>
227 <div id="p-search" class="portlet">
228 <h5 <?php $this->html('userlangattributes') ?>><label for="searchInput"><?php $this->msg('search') ?></label></h5>
229 <div id="searchBody" class="pBody">
230 <form action="<?php $this->text('wgScript') ?>" id="searchform"><div>
231 <input type='hidden' name="title" value="<?php $this->text('searchtitle') ?>"/>
232 <input id="searchInput" name="search" type="text"<?php echo $this->skin->tooltipAndAccesskey('search');
233 if( isset( $this->data['search'] ) ) {
234 ?> value="<?php $this->text('search') ?>"<?php } ?> />
235 <input type='submit' name="go" class="searchButton" id="searchGoButton" value="<?php $this->msg('searcharticle') ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-go' ); ?> /><?php if ($wgUseTwoButtonsSearchForm) { ?>&nbsp;
236 <input type='submit' name="fulltext" class="searchButton" id="mw-searchButton" value="<?php $this->msg('searchbutton') ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?> /><?php } else { ?>
237
238 <div><a href="<?php $this->text('searchaction') ?>" rel="search"><?php $this->msg('powersearch-legend') ?></a></div><?php } ?>
239
240 </div></form>
241 </div>
242 </div>
243 <?php
244 }
245
246 /*************************************************************************************************/
247 function toolbox() {
248 ?>
249 <div class="portlet" id="p-tb">
250 <h5 <?php $this->html('userlangattributes')?>><?php $this->msg('toolbox') ?></h5>
251 <div class="pBody">
252 <ul>
253 <?php
254 if($this->data['notspecialpage']) { ?>
255 <li id="t-whatlinkshere"><a href="<?php
256 echo htmlspecialchars($this->data['nav_urls']['whatlinkshere']['href'])
257 ?>"<?php echo $this->skin->tooltipAndAccesskey('t-whatlinkshere') ?>><?php $this->msg('whatlinkshere') ?></a></li>
258 <?php
259 if( $this->data['nav_urls']['recentchangeslinked'] ) { ?>
260 <li id="t-recentchangeslinked"><a href="<?php
261 echo htmlspecialchars($this->data['nav_urls']['recentchangeslinked']['href'])
262 ?>"<?php echo $this->skin->tooltipAndAccesskey('t-recentchangeslinked') ?>><?php $this->msg('recentchangeslinked-toolbox') ?></a></li>
263 <?php }
264 }
265 if(isset($this->data['nav_urls']['trackbacklink'])) { ?>
266 <li id="t-trackbacklink"><a href="<?php
267 echo htmlspecialchars($this->data['nav_urls']['trackbacklink']['href'])
268 ?>"<?php echo $this->skin->tooltipAndAccesskey('t-trackbacklink') ?>><?php $this->msg('trackbacklink') ?></a></li>
269 <?php }
270 if($this->data['feeds']) { ?>
271 <li id="feedlinks"><?php foreach($this->data['feeds'] as $key => $feed) {
272 ?><a id="<?php echo Sanitizer::escapeId( "feed-$key" ) ?>" href="<?php
273 echo htmlspecialchars($feed['href']) ?>" rel="alternate" type="application/<?php echo $key ?>+xml" class="feedlink"<?php echo $this->skin->tooltipAndAccesskey('feed-'.$key) ?>><?php echo htmlspecialchars($feed['text'])?></a>&nbsp;
274 <?php } ?></li><?php
275 }
276
277 foreach( array('contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages') as $special ) {
278
279 if($this->data['nav_urls'][$special]) {
280 ?><li id="t-<?php echo $special ?>"><a href="<?php echo htmlspecialchars($this->data['nav_urls'][$special]['href'])
281 ?>"<?php echo $this->skin->tooltipAndAccesskey('t-'.$special) ?>><?php $this->msg($special) ?></a></li>
282 <?php }
283 }
284
285 if(!empty($this->data['nav_urls']['print']['href'])) { ?>
286 <li id="t-print"><a href="<?php echo htmlspecialchars($this->data['nav_urls']['print']['href'])
287 ?>" rel="alternate"<?php echo $this->skin->tooltipAndAccesskey('t-print') ?>><?php $this->msg('printableversion') ?></a></li><?php
288 }
289
290 if(!empty($this->data['nav_urls']['permalink']['href'])) { ?>
291 <li id="t-permalink"><a href="<?php echo htmlspecialchars($this->data['nav_urls']['permalink']['href'])
292 ?>"<?php echo $this->skin->tooltipAndAccesskey('t-permalink') ?>><?php $this->msg('permalink') ?></a></li><?php
293 } elseif ($this->data['nav_urls']['permalink']['href'] === '') { ?>
294 <li id="t-ispermalink"<?php echo $this->skin->tooltip('t-ispermalink') ?>><?php $this->msg('permalink') ?></li><?php
295 }
296
297 wfRunHooks( 'MonoBookTemplateToolboxEnd', array( &$this ) );
298 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this ) );
299 ?>
300 </ul>
301 </div>
302 </div>
303 <?php
304 }
305
306 /*************************************************************************************************/
307 function languageBox() {
308 if( $this->data['language_urls'] ) {
309 ?>
310 <div id="p-lang" class="portlet">
311 <h5 <?php $this->html('userlangattributes') ?>><?php $this->msg('otherlanguages') ?></h5>
312 <div class="pBody">
313 <ul>
314 <?php foreach($this->data['language_urls'] as $langlink) { ?>
315 <li class="<?php echo htmlspecialchars($langlink['class'])?>"><?php
316 ?><a href="<?php echo htmlspecialchars($langlink['href']) ?>"><?php echo $langlink['text'] ?></a></li>
317 <?php } ?>
318 </ul>
319 </div>
320 </div>
321 <?php
322 }
323 }
324
325 /*************************************************************************************************/
326 function customBox( $bar, $cont ) {
327 ?>
328 <div class='generated-sidebar portlet' id='<?php echo Sanitizer::escapeId( "p-$bar" ) ?>'<?php echo $this->skin->tooltip('p-'.$bar) ?>>
329 <h5 <?php $this->html('userlangattributes') ?>><?php $out = wfMsg( $bar ); if (wfEmptyMsg($bar, $out)) echo htmlspecialchars($bar); else echo htmlspecialchars($out); ?></h5>
330 <div class='pBody'>
331 <?php if ( is_array( $cont ) ) { ?>
332 <ul>
333 <?php foreach($cont as $key => $val) { ?>
334 <li id="<?php echo Sanitizer::escapeId($val['id']) ?>"<?php
335 if ( $val['active'] ) { ?> class="active" <?php }
336 ?>><a href="<?php echo htmlspecialchars($val['href']) ?>"<?php echo $this->skin->tooltipAndAccesskey($val['id']) ?>><?php echo htmlspecialchars($val['text']) ?></a></li>
337 <?php } ?>
338 </ul>
339 <?php } else {
340 # allow raw HTML block to be defined by extensions
341 print $cont;
342 }
343 ?>
344 </div>
345 </div>
346 <?php
347 }
348 } // end of class
349
350