Create renderPortals() function for MonoBook (same interface as Vector one).
[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 /**
27 * @param $out OutputPage
28 */
29 function setupSkinUserCss( OutputPage $out ) {
30 global $wgHandheldStyle;
31 parent::setupSkinUserCss( $out );
32
33 $out->addModuleStyles( 'skins.monobook' );
34
35 // Ugh. Can't do this properly because $wgHandheldStyle may be a URL
36 if( $wgHandheldStyle ) {
37 // Currently in testing... try 'chick/main.css'
38 $out->addStyle( $wgHandheldStyle, 'handheld' );
39 }
40
41 // TODO: Migrate all of these
42 //$out->addStyle( 'monobook/IE50Fixes.css', 'screen', 'lt IE 5.5000' );
43 //$out->addStyle( 'monobook/IE55Fixes.css', 'screen', 'IE 5.5000' );
44 //$out->addStyle( 'monobook/IE60Fixes.css', 'screen', 'IE 6' );
45 //$out->addStyle( 'monobook/IE70Fixes.css', 'screen', 'IE 7' );
46
47 // TODO: migrate
48 //$out->addStyle( 'monobook/rtl.css', 'screen', '', 'rtl' );
49
50 }
51 }
52
53 /**
54 * @todo document
55 * @ingroup Skins
56 */
57 class MonoBookTemplate extends BaseTemplate {
58
59 /**
60 * @var Skin
61 */
62 var $skin;
63
64 /**
65 * Template filter callback for MonoBook skin.
66 * Takes an associative array of data set from a SkinTemplate-based
67 * class, and a wrapper for MediaWiki's localization database, and
68 * outputs a formatted page.
69 *
70 * @access private
71 */
72 function execute() {
73 $this->skin = $skin = $this->data['skin'];
74
75 // Suppress warnings to prevent notices about missing indexes in $this->data
76 wfSuppressWarnings();
77
78 $this->html( 'headelement' );
79 ?><div id="globalWrapper">
80 <div id="column-content"><div id="content"<?php $this->html("specialpageattributes") ?>>
81 <a id="top"></a>
82 <?php if($this->data['sitenotice']) { ?><div id="siteNotice"><?php $this->html('sitenotice') ?></div><?php } ?>
83
84 <h1 id="firstHeading" class="firstHeading"><?php $this->html('title') ?></h1>
85 <div id="bodyContent">
86 <div id="siteSub"><?php $this->msg('tagline') ?></div>
87 <div id="contentSub"<?php $this->html('userlangattributes') ?>><?php $this->html('subtitle') ?></div>
88 <?php if($this->data['undelete']) { ?>
89 <div id="contentSub2"><?php $this->html('undelete') ?></div>
90 <?php } ?><?php if($this->data['newtalk'] ) { ?>
91 <div class="usermessage"><?php $this->html('newtalk') ?></div>
92 <?php } ?><?php if($this->data['showjumplinks']) { ?>
93 <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>
94 <?php } ?>
95 <!-- start content -->
96 <?php $this->html('bodytext') ?>
97 <?php if($this->data['printfooter']) { ?><div class="printfooter"><?php $this->html('printfooter'); ?></div><?php } ?>
98 <?php $this->html('debughtml'); ?>
99 <?php if($this->data['catlinks']) { $this->html('catlinks'); } ?>
100 <!-- end content -->
101 <?php if($this->data['dataAfterContent']) { $this->html ('dataAfterContent'); } ?>
102 <div class="visualClear"></div>
103 </div>
104 </div></div>
105 <div id="column-one"<?php $this->html('userlangattributes') ?>>
106 <?php $this->cactions( $skin ); ?>
107 <div class="portlet" id="p-personal">
108 <h5><?php $this->msg('personaltools') ?></h5>
109 <div class="pBody">
110 <ul<?php $this->html('userlangattributes') ?>>
111 <?php foreach($this->getPersonalTools() as $key => $item) { ?>
112 <?php echo $this->makeListItem($key, $item); ?>
113
114 <?php } ?>
115 </ul>
116 </div>
117 </div>
118 <div class="portlet" id="p-logo">
119 <?php
120 $logoAttribs = array() + Linker::tooltipAndAccesskeyAttribs('p-logo');
121 $logoAttribs['style'] = "background-image: url({$this->data['logopath']});";
122 $logoAttribs['href'] = $this->data['nav_urls']['mainpage']['href'];
123 echo Html::element( 'a', $logoAttribs );
124 ?>
125
126 </div>
127 <script type="<?php $this->text('jsmimetype') ?>"> if (window.isMSIE55) fixalpha(); </script>
128 <?php
129 $this->renderPortals( $this->data['sidebar'] );
130 ?>
131 </div><!-- end of the left (by default at least) column -->
132 <div class="visualClear"></div>
133 <?php
134 $validFooterIcons = $this->getFooterIcons( "icononly" );
135 $validFooterLinks = $this->getFooterLinks( "flat" ); // Additional footer links
136
137 if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) { ?>
138 <div id="footer"<?php $this->html('userlangattributes') ?>>
139 <?php
140 $footerEnd = '</div>';
141 } else {
142 $footerEnd = '';
143 }
144 foreach ( $validFooterIcons as $blockName => $footerIcons ) { ?>
145 <div id="f-<?php echo htmlspecialchars($blockName); ?>ico">
146 <?php foreach ( $footerIcons as $icon ) { ?>
147 <?php echo $this->skin->makeFooterIcon( $icon ); ?>
148
149 <?php }
150 ?>
151 </div>
152 <?php }
153
154 if ( count( $validFooterLinks ) > 0 ) {
155 ?> <ul id="f-list">
156 <?php
157 foreach( $validFooterLinks as $aLink ) { ?>
158 <li id="<?php echo $aLink ?>"><?php $this->html($aLink) ?></li>
159 <?php
160 }
161 ?>
162 </ul>
163 <?php }
164 echo $footerEnd;
165 ?>
166
167 </div>
168 <?php
169 $this->printTrail();
170 echo Html::closeElement( 'body' );
171 echo Html::closeElement( 'html' );
172 wfRestoreWarnings();
173 } // end of execute() method
174
175 /*************************************************************************************************/
176
177 protected function renderPortals( $sidebar ) {
178 if ( !isset( $sidebar['SEARCH'] ) ) $sidebar['SEARCH'] = true;
179 if ( !isset( $sidebar['TOOLBOX'] ) ) $sidebar['TOOLBOX'] = true;
180 if ( !isset( $sidebar['LANGUAGES'] ) ) $sidebar['LANGUAGES'] = true;
181
182 foreach ($sidebar as $boxName => $cont) {
183 if ( $boxName == 'SEARCH' ) {
184 $this->searchBox();
185 } elseif ( $boxName == 'TOOLBOX' ) {
186 $this->toolbox();
187 } elseif ( $boxName == 'LANGUAGES' ) {
188 $this->languageBox();
189 } else {
190 $this->customBox( $boxName, $cont );
191 }
192 }
193 }
194
195 function searchBox() {
196 global $wgUseTwoButtonsSearchForm;
197 ?>
198 <div id="p-search" class="portlet">
199 <h5><label for="searchInput"><?php $this->msg('search') ?></label></h5>
200 <div id="searchBody" class="pBody">
201 <form action="<?php $this->text('wgScript') ?>" id="searchform">
202 <input type='hidden' name="title" value="<?php $this->text('searchtitle') ?>"/>
203 <?php echo $this->makeSearchInput(array( "id" => "searchInput" )); ?>
204
205 <?php echo $this->makeSearchButton("go", array( "id" => "searchGoButton", "class" => "searchButton" ));
206 if ($wgUseTwoButtonsSearchForm): ?>&#160;
207 <?php echo $this->makeSearchButton("fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" ));
208 else: ?>
209
210 <div><a href="<?php $this->text('searchaction') ?>" rel="search"><?php $this->msg('powersearch-legend') ?></a></div><?php
211 endif; ?>
212
213 </form>
214 </div>
215 </div>
216 <?php
217 }
218
219 /**
220 * Prints the cactions bar.
221 * Shared between MonoBook and Modern
222 *
223 * @param $skin Skin
224 */
225 function cactions( Skin $skin ) {
226 ?>
227 <div id="p-cactions" class="portlet">
228 <h5><?php $this->msg('views') ?></h5>
229 <div class="pBody">
230 <ul><?php
231 foreach($this->data['content_actions'] as $key => $tab) {
232 $linkAttribs = array( 'href' => $tab['href'] );
233
234 if( isset( $tab["tooltiponly"] ) && $tab["tooltiponly"] ) {
235 $title = Linker::titleAttrib( "ca-$key" );
236 if ( $title !== false ) {
237 $linkAttribs['title'] = $title;
238 }
239 } else {
240 $linkAttribs += Linker::tooltipAndAccesskeyAttribs( "ca-$key" );
241 }
242 $linkHtml = Html::element( 'a', $linkAttribs, $tab['text'] );
243
244 /* Surround with a <li> */
245 $liAttribs = array( 'id' => Sanitizer::escapeId( "ca-$key" ) );
246 if( $tab['class'] ) {
247 $liAttribs['class'] = $tab['class'];
248 }
249 echo '
250 ' . Html::rawElement( 'li', $liAttribs, $linkHtml );
251 } ?>
252
253 </ul>
254 </div>
255 </div>
256 <?php
257 }
258 /*************************************************************************************************/
259 function toolbox() {
260 ?>
261 <div class="portlet" id="p-tb">
262 <h5><?php $this->msg('toolbox') ?></h5>
263 <div class="pBody">
264 <ul>
265 <?php
266 foreach ( $this->getToolbox() as $key => $tbitem ) { ?>
267 <?php echo $this->makeListItem($key, $tbitem); ?>
268
269 <?php
270 }
271 wfRunHooks( 'MonoBookTemplateToolboxEnd', array( &$this ) );
272 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this ) );
273 ?>
274 </ul>
275 </div>
276 </div>
277 <?php
278 }
279
280 /*************************************************************************************************/
281 function languageBox() {
282 if( $this->data['language_urls'] ) {
283 ?>
284 <div id="p-lang" class="portlet">
285 <h5<?php $this->html('userlangattributes') ?>><?php $this->msg('otherlanguages') ?></h5>
286 <div class="pBody">
287 <ul>
288 <?php foreach($this->data['language_urls'] as $key => $langlink) { ?>
289 <?php echo $this->makeListItem($key, $langlink); ?>
290
291 <?php } ?>
292 </ul>
293 </div>
294 </div>
295 <?php
296 }
297 }
298
299 /*************************************************************************************************/
300 function customBox( $bar, $cont ) {
301 $portletAttribs = array( 'class' => 'generated-sidebar portlet', 'id' => Sanitizer::escapeId( "p-$bar" ) );
302 $tooltip = Linker::titleAttrib( "p-$bar" );
303 if ( $tooltip !== false ) {
304 $portletAttribs['title'] = $tooltip;
305 }
306 echo ' ' . Html::openElement( 'div', $portletAttribs );
307 ?>
308
309 <h5><?php $msg = wfMessage( $bar ); echo htmlspecialchars( $msg->exists() ? $msg->text() : $bar ); ?></h5>
310 <div class='pBody'>
311 <?php if ( is_array( $cont ) ) { ?>
312 <ul>
313 <?php foreach($cont as $key => $val) { ?>
314 <?php echo $this->makeListItem($key, $val); ?>
315
316 <?php } ?>
317 </ul>
318 <?php } else {
319 # allow raw HTML block to be defined by extensions
320 print $cont;
321 }
322 ?>
323 </div>
324 </div>
325 <?php
326 }
327 } // end of class
328
329