Commit getFooterLinks and getFooterIcons helpers to abstract the common code used...
[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 icons
74 $footericons = $this->data["footericons"];
75 // Unset any icons which don't have an image
76 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
77 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
78 if ( !is_string($footerIcon) && !isset($footerIcon["src"]) ) {
79 unset($footerIconsBlock[$footerIconKey]);
80 }
81 }
82 }
83 // Redo removal of any empty blocks
84 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
85 if ( count($footerIconsBlock) <= 0 ) {
86 unset($footericons[$footerIconsKey]);
87 }
88 }
89
90 $this->html( 'headelement' );
91 ?><div id="globalWrapper">
92 <div id="column-content"><div id="content"<?php $this->html("specialpageattributes") ?>>
93 <a id="top"></a>
94 <?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
95
96 <h1 id="firstHeading" class="firstHeading"><?php $this->html('title') ?></h1>
97 <div id="bodyContent">
98 <div id="siteSub"><?php $this->msg('tagline') ?></div>
99 <div id="contentSub"<?php $this->html('userlangattributes') ?>><?php $this->html('subtitle') ?></div>
100 <?php if($this->data['undelete']) { ?>
101 <div id="contentSub2"><?php $this->html('undelete') ?></div>
102 <?php } ?><?php if($this->data['newtalk'] ) { ?>
103 <div class="usermessage"><?php $this->html('newtalk') ?></div>
104 <?php } ?><?php if($this->data['showjumplinks']) { ?>
105 <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>
106 <?php } ?>
107 <!-- start content -->
108 <?php $this->html('bodytext') ?>
109 <?php if($this->data['catlinks']) { $this->html('catlinks'); } ?>
110 <!-- end content -->
111 <?php if($this->data['dataAfterContent']) { $this->html ('dataAfterContent'); } ?>
112 <div class="visualClear"></div>
113 </div>
114 </div></div>
115 <div id="column-one"<?php $this->html('userlangattributes') ?>>
116 <div id="p-cactions" class="portlet">
117 <h5><?php $this->msg('views') ?></h5>
118 <div class="pBody">
119 <ul><?php
120 foreach($this->data['content_actions'] as $key => $tab) {
121 echo '
122 <li id="' . Sanitizer::escapeId( "ca-$key" ) . '"';
123 if( $tab['class'] ) {
124 echo ' class="'.htmlspecialchars($tab['class']).'"';
125 }
126 echo '><a href="'.htmlspecialchars($tab['href']).'"';
127 # We don't want to give the watch tab an accesskey if the
128 # page is being edited, because that conflicts with the
129 # accesskey on the watch checkbox. We also don't want to
130 # give the edit tab an accesskey, because that's fairly su-
131 # perfluous and conflicts with an accesskey (Ctrl-E) often
132 # used for editing in Safari.
133 if( in_array( $action, array( 'edit', 'submit' ) )
134 && in_array( $key, array( 'edit', 'watch', 'unwatch' ))) {
135 echo $skin->tooltip( "ca-$key" );
136 } else {
137 echo $skin->tooltipAndAccesskey( "ca-$key" );
138 }
139 echo '>'.htmlspecialchars($tab['text']).'</a></li>';
140 } ?>
141
142 </ul>
143 </div>
144 </div>
145 <div class="portlet" id="p-personal">
146 <h5><?php $this->msg('personaltools') ?></h5>
147 <div class="pBody">
148 <ul<?php $this->html('userlangattributes') ?>>
149 <?php foreach($this->data['personal_urls'] as $key => $item) { ?>
150 <li id="<?php echo Sanitizer::escapeId( "pt-$key" ) ?>"<?php
151 if ($item['active']) { ?> class="active"<?php } ?>><a href="<?php
152 echo htmlspecialchars($item['href']) ?>"<?php echo $skin->tooltipAndAccesskey('pt-'.$key) ?><?php
153 if(!empty($item['class'])) { ?> class="<?php
154 echo htmlspecialchars($item['class']) ?>"<?php } ?>><?php
155 echo htmlspecialchars($item['text']) ?></a></li>
156 <?php } ?>
157 </ul>
158 </div>
159 </div>
160 <div class="portlet" id="p-logo">
161 <a style="background-image: url(<?php $this->text('logopath') ?>);" <?php
162 ?>href="<?php echo htmlspecialchars($this->data['nav_urls']['mainpage']['href'])?>"<?php
163 echo $skin->tooltipAndAccesskey('p-logo') ?>></a>
164 </div>
165 <script type="<?php $this->text('jsmimetype') ?>"> if (window.isMSIE55) fixalpha(); </script>
166 <?php
167 $sidebar = $this->data['sidebar'];
168 if ( !isset( $sidebar['SEARCH'] ) ) $sidebar['SEARCH'] = true;
169 if ( !isset( $sidebar['TOOLBOX'] ) ) $sidebar['TOOLBOX'] = true;
170 if ( !isset( $sidebar['LANGUAGES'] ) ) $sidebar['LANGUAGES'] = true;
171 foreach ($sidebar as $boxName => $cont) {
172 if ( $boxName == 'SEARCH' ) {
173 $this->searchBox();
174 } elseif ( $boxName == 'TOOLBOX' ) {
175 $this->toolbox();
176 } elseif ( $boxName == 'LANGUAGES' ) {
177 $this->languageBox();
178 } else {
179 $this->customBox( $boxName, $cont );
180 }
181 }
182 ?>
183 </div><!-- end of the left (by default at least) column -->
184 <div class="visualClear"></div>
185 <div id="footer"<?php $this->html('userlangattributes') ?>>
186 <?php foreach ( $footericons as $blockName => $footerIcons ) { ?>
187 <div id="f-<?php echo htmlspecialchars($blockName); ?>ico">
188 <?php foreach ( $footerIcons as $icon ) { ?>
189 <?php echo $this->skin->makeFooterIcon( $icon ); ?>
190
191 <?php }
192 ?>
193 </div>
194 <?php }
195
196 // Generate additional footer links
197 $validFooterLinks = $this->getFooterLinks("flat");
198 if ( count( $validFooterLinks ) > 0 ) {
199 ?> <ul id="f-list">
200 <?php
201 foreach( $validFooterLinks as $aLink ) { ?>
202 <li id="<?php echo $aLink ?>"><?php $this->html($aLink) ?></li>
203
204 <?php
205 }
206 ?>
207 </ul>
208 <?php }
209 ?>
210 </div>
211 </div>
212 <?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?>
213 <?php $this->html('reporttime') ?>
214 <?php if ( $this->data['debug'] ): ?>
215 <!-- Debug output:
216 <?php $this->text( 'debug' ); ?>
217
218 -->
219 <?php endif;
220
221 echo Html::closeElement( 'body' );
222 echo Html::closeElement( 'html' );
223 wfRestoreWarnings();
224 } // end of execute() method
225
226 /*************************************************************************************************/
227 function searchBox() {
228 global $wgUseTwoButtonsSearchForm;
229 ?>
230 <div id="p-search" class="portlet">
231 <h5><label for="searchInput"><?php $this->msg('search') ?></label></h5>
232 <div id="searchBody" class="pBody">
233 <form action="<?php $this->text('wgScript') ?>" id="searchform">
234 <input type='hidden' name="title" value="<?php $this->text('searchtitle') ?>"/>
235 <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
236
237 <?php echo $this->makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" ));
238 if ($wgUseTwoButtonsSearchForm): ?>&#160;
239 <?php echo $this->makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" ));
240 else: ?>
241
242 <div><a href="<?php $this->text('searchaction') ?>" rel="search"><?php $this->msg('powersearch-legend') ?></a></div><?php
243 endif; ?>
244
245 </form>
246 </div>
247 </div>
248 <?php
249 }
250
251 /*************************************************************************************************/
252 function toolbox() {
253 ?>
254 <div class="portlet" id="p-tb">
255 <h5><?php $this->msg('toolbox') ?></h5>
256 <div class="pBody">
257 <ul>
258 <?php
259 foreach ( $this->getToolbox() as $key => $tbitem ) { ?>
260 <?php echo $this->makeListItem($key, $tbitem); ?>
261
262 <?php
263 }
264 wfRunHooks( 'MonoBookTemplateToolboxEnd', array( &$this ) );
265 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this ) );
266 ?>
267 </ul>
268 </div>
269 </div>
270 <?php
271 }
272
273 /*************************************************************************************************/
274 function languageBox() {
275 if( $this->data['language_urls'] ) {
276 ?>
277 <div id="p-lang" class="portlet">
278 <h5<?php $this->html('userlangattributes') ?>><?php $this->msg('otherlanguages') ?></h5>
279 <div class="pBody">
280 <ul>
281 <?php foreach($this->data['language_urls'] as $key => $langlink) { ?>
282 <?php echo $this->makeListItem($key, $langlink); ?>
283
284 <?php } ?>
285 </ul>
286 </div>
287 </div>
288 <?php
289 }
290 }
291
292 /*************************************************************************************************/
293 function customBox( $bar, $cont ) {
294 ?>
295 <div class='generated-sidebar portlet' id='<?php echo Sanitizer::escapeId( "p-$bar" ) ?>'<?php echo $this->skin->tooltip('p-'.$bar) ?>>
296 <h5><?php $out = wfMsg( $bar ); if (wfEmptyMsg($bar, $out)) echo htmlspecialchars($bar); else echo htmlspecialchars($out); ?></h5>
297 <div class='pBody'>
298 <?php if ( is_array( $cont ) ) { ?>
299 <ul>
300 <?php foreach($cont as $key => $val) { ?>
301 <?php echo $this->makeListItem($key, $val); ?>
302
303 <?php } ?>
304 </ul>
305 <?php } else {
306 # allow raw HTML block to be defined by extensions
307 print $cont;
308 }
309 ?>
310 </div>
311 </div>
312 <?php
313 }
314 } // end of class
315
316