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