e3e2e9a3b0401ed629a34c3c5da9df4e4c23a10d
[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 QuickTemplate {
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 if ( is_string($icon) ) {
194 $html = $icon;
195 } else {
196 $url = $icon["url"];
197 unset($icon["url"]);
198 if ( isset($icon["src"]) ) {
199 $html = Html::element( 'img', $icon ); // do this the lazy way, just pass icon data as an attribute array
200 } else {
201 $html = htmlspecialchars($icon["alt"]);
202 }
203 if ( $url ) {
204 $html = Html::rawElement( 'a', array( "href" => $url ), $html );
205 }
206 }
207 echo " $html\n";
208 } ?>
209 </div>
210 <?php }
211
212 // Generate additional footer links
213 $validFooterLinks = array();
214 foreach( $footerlinks as $aLink ) {
215 if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
216 $validFooterLinks[] = $aLink;
217 }
218 }
219 if ( count( $validFooterLinks ) > 0 ) {
220 ?> <ul id="f-list">
221 <?php
222 foreach( $validFooterLinks as $aLink ) {
223 if( isset( $this->data[$aLink] ) && $this->data[$aLink] ) {
224 ?> <li id="<?php echo $aLink ?>"><?php $this->html($aLink) ?></li>
225 <?php }
226 }
227 ?>
228 </ul>
229 <?php }
230 ?>
231 </div>
232 </div>
233 <?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?>
234 <?php $this->html('reporttime') ?>
235 <?php if ( $this->data['debug'] ): ?>
236 <!-- Debug output:
237 <?php $this->text( 'debug' ); ?>
238
239 -->
240 <?php endif;
241
242 echo Html::closeElement( 'body' );
243 echo Html::closeElement( 'html' );
244 wfRestoreWarnings();
245 } // end of execute() method
246
247 /*************************************************************************************************/
248 function searchBox() {
249 global $wgUseTwoButtonsSearchForm;
250 ?>
251 <div id="p-search" class="portlet">
252 <h5><label for="searchInput"><?php $this->msg('search') ?></label></h5>
253 <div id="searchBody" class="pBody">
254 <form action="<?php $this->text('wgScript') ?>" id="searchform">
255 <input type='hidden' name="title" value="<?php $this->text('searchtitle') ?>"/>
256 <?php
257 echo Html::input( 'search',
258 isset( $this->data['search'] ) ? $this->data['search'] : '', 'search',
259 array(
260 'id' => 'searchInput',
261 'title' => $this->skin->titleAttrib( 'search' ),
262 'accesskey' => $this->skin->accesskey( 'search' )
263 ) ); ?>
264
265 <input type='submit' name="go" class="searchButton" id="searchGoButton" value="<?php $this->msg('searcharticle') ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-go' ); ?> /><?php if ($wgUseTwoButtonsSearchForm) { ?>&#160;
266 <input type='submit' name="fulltext" class="searchButton" id="mw-searchButton" value="<?php $this->msg('searchbutton') ?>"<?php echo $this->skin->tooltipAndAccesskey( 'search-fulltext' ); ?> /><?php } else { ?>
267
268 <div><a href="<?php $this->text('searchaction') ?>" rel="search"><?php $this->msg('powersearch-legend') ?></a></div><?php } ?>
269
270 </form>
271 </div>
272 </div>
273 <?php
274 }
275
276 /*************************************************************************************************/
277 function toolbox() {
278 ?>
279 <div class="portlet" id="p-tb">
280 <h5><?php $this->msg('toolbox') ?></h5>
281 <div class="pBody">
282 <ul>
283 <?php
284 if($this->data['notspecialpage']) { ?>
285 <li id="t-whatlinkshere"><a href="<?php
286 echo htmlspecialchars($this->data['nav_urls']['whatlinkshere']['href'])
287 ?>"<?php echo $this->skin->tooltipAndAccesskey('t-whatlinkshere') ?>><?php $this->msg('whatlinkshere') ?></a></li>
288 <?php
289 if( $this->data['nav_urls']['recentchangeslinked'] ) { ?>
290 <li id="t-recentchangeslinked"><a href="<?php
291 echo htmlspecialchars($this->data['nav_urls']['recentchangeslinked']['href'])
292 ?>"<?php echo $this->skin->tooltipAndAccesskey('t-recentchangeslinked') ?>><?php $this->msg('recentchangeslinked-toolbox') ?></a></li>
293 <?php }
294 }
295 if( isset( $this->data['nav_urls']['trackbacklink'] ) && $this->data['nav_urls']['trackbacklink'] ) { ?>
296 <li id="t-trackbacklink"><a href="<?php
297 echo htmlspecialchars($this->data['nav_urls']['trackbacklink']['href'])
298 ?>"<?php echo $this->skin->tooltipAndAccesskey('t-trackbacklink') ?>><?php $this->msg('trackbacklink') ?></a></li>
299 <?php }
300 if($this->data['feeds']) { ?>
301 <li id="feedlinks"><?php foreach($this->data['feeds'] as $key => $feed) {
302 ?><a id="<?php echo Sanitizer::escapeId( "feed-$key" ) ?>" href="<?php
303 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>&#160;
304 <?php } ?></li><?php
305 }
306
307 foreach( array('contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages') as $special ) {
308
309 if($this->data['nav_urls'][$special]) {
310 ?><li id="t-<?php echo $special ?>"><a href="<?php echo htmlspecialchars($this->data['nav_urls'][$special]['href'])
311 ?>"<?php echo $this->skin->tooltipAndAccesskey('t-'.$special) ?>><?php $this->msg($special) ?></a></li>
312 <?php }
313 }
314
315 if(!empty($this->data['nav_urls']['print']['href'])) { ?>
316 <li id="t-print"><a href="<?php echo htmlspecialchars($this->data['nav_urls']['print']['href'])
317 ?>" rel="alternate"<?php echo $this->skin->tooltipAndAccesskey('t-print') ?>><?php $this->msg('printableversion') ?></a></li><?php
318 }
319
320 if(!empty($this->data['nav_urls']['permalink']['href'])) { ?>
321 <li id="t-permalink"><a href="<?php echo htmlspecialchars($this->data['nav_urls']['permalink']['href'])
322 ?>"<?php echo $this->skin->tooltipAndAccesskey('t-permalink') ?>><?php $this->msg('permalink') ?></a></li><?php
323 } elseif ($this->data['nav_urls']['permalink']['href'] === '') { ?>
324 <li id="t-ispermalink"<?php echo $this->skin->tooltip('t-ispermalink') ?>><?php $this->msg('permalink') ?></li><?php
325 }
326
327 wfRunHooks( 'MonoBookTemplateToolboxEnd', array( &$this ) );
328 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this ) );
329 ?>
330 </ul>
331 </div>
332 </div>
333 <?php
334 }
335
336 /*************************************************************************************************/
337 function languageBox() {
338 if( $this->data['language_urls'] ) {
339 ?>
340 <div id="p-lang" class="portlet">
341 <h5<?php $this->html('userlangattributes') ?>><?php $this->msg('otherlanguages') ?></h5>
342 <div class="pBody">
343 <ul>
344 <?php foreach($this->data['language_urls'] as $langlink) { ?>
345 <li class="<?php echo htmlspecialchars($langlink['class'])?>"><?php
346 ?><a href="<?php echo htmlspecialchars($langlink['href']) ?>" title="<?php
347 echo htmlspecialchars($langlink['title']) ?>"><?php echo $langlink['text'] ?></a></li>
348 <?php } ?>
349 </ul>
350 </div>
351 </div>
352 <?php
353 }
354 }
355
356 /*************************************************************************************************/
357 function customBox( $bar, $cont ) {
358 ?>
359 <div class='generated-sidebar portlet' id='<?php echo Sanitizer::escapeId( "p-$bar" ) ?>'<?php echo $this->skin->tooltip('p-'.$bar) ?>>
360 <h5><?php $out = wfMsg( $bar ); if (wfEmptyMsg($bar, $out)) echo htmlspecialchars($bar); else echo htmlspecialchars($out); ?></h5>
361 <div class='pBody'>
362 <?php if ( is_array( $cont ) ) { ?>
363 <ul>
364 <?php foreach($cont as $val) { ?>
365 <li id="<?php echo Sanitizer::escapeId($val['id']) ?>"<?php
366 if ( $val['active'] ) { ?> class="active" <?php }
367 ?>><a href="<?php echo htmlspecialchars($val['href']) ?>"<?php echo $this->skin->tooltipAndAccesskey($val['id']) ?>><?php echo htmlspecialchars($val['text']) ?></a></li>
368 <?php } ?>
369 </ul>
370 <?php } else {
371 # allow raw HTML block to be defined by extensions
372 print $cont;
373 }
374 ?>
375 </div>
376 </div>
377 <?php
378 }
379 } // end of class
380
381