Merge "Separate language generation from outputPage"
[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 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 * http://www.gnu.org/copyleft/gpl.html
22 *
23 * @todo document
24 * @file
25 * @ingroup Skins
26 */
27
28 if ( !defined( 'MEDIAWIKI' ) ) {
29 die( -1 );
30 }
31
32 /**
33 * Inherit main code from SkinTemplate, set the CSS and template filter.
34 * @todo document
35 * @ingroup Skins
36 */
37 class SkinMonoBook extends SkinTemplate {
38 /** Using monobook. */
39 var $skinname = 'monobook', $stylename = 'monobook',
40 $template = 'MonoBookTemplate', $useHeadElement = true;
41
42 /**
43 * @param $out OutputPage
44 */
45 function setupSkinUserCss( OutputPage $out ) {
46 global $wgHandheldStyle;
47 parent::setupSkinUserCss( $out );
48
49 $out->addModuleStyles( 'skins.monobook' );
50
51 // Ugh. Can't do this properly because $wgHandheldStyle may be a URL
52 if ( $wgHandheldStyle ) {
53 // Currently in testing... try 'chick/main.css'
54 $out->addStyle( $wgHandheldStyle, 'handheld' );
55 }
56
57 // TODO: Migrate all of these
58 $out->addStyle( 'monobook/IE60Fixes.css', 'screen', 'IE 6' );
59 $out->addStyle( 'monobook/IE70Fixes.css', 'screen', 'IE 7' );
60
61 }
62 }
63
64 /**
65 * @todo document
66 * @ingroup Skins
67 */
68 class MonoBookTemplate extends BaseTemplate {
69
70 /**
71 * Template filter callback for MonoBook skin.
72 * Takes an associative array of data set from a SkinTemplate-based
73 * class, and a wrapper for MediaWiki's localization database, and
74 * outputs a formatted page.
75 *
76 * @access private
77 */
78 function execute() {
79 // Suppress warnings to prevent notices about missing indexes in $this->data
80 wfSuppressWarnings();
81
82 $this->html( 'headelement' );
83 ?><div id="globalWrapper">
84 <div id="column-content"><div id="content" class="mw-body-primary" role="main">
85 <a id="top"></a>
86 <?php if ( $this->data['sitenotice'] ) { ?><div id="siteNotice"><?php $this->html( 'sitenotice' ) ?></div><?php } ?>
87
88 <h1 id="firstHeading" class="firstHeading" lang="<?php
89 $this->data['pageLanguage'] = $this->getSkin()->getTitle()->getPageViewLanguage()->getCode();
90 $this->html( 'pageLanguage' );
91 ?>"><span dir="auto"><?php $this->html( 'title' ) ?></span></h1>
92 <div id="bodyContent" class="mw-body">
93 <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
94 <div id="contentSub"<?php $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' ) ?></div>
95 <?php if ( $this->data['undelete'] ) { ?>
96 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
97 <?php } ?><?php if ( $this->data['newtalk'] ) { ?>
98 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
99 <?php } ?><?php if ( $this->data['showjumplinks'] ) { ?>
100 <div id="jump-to-nav" class="mw-jump"><?php $this->msg( 'jumpto' ) ?> <a href="#column-one"><?php $this->msg( 'jumptonavigation' ) ?></a><?php $this->msg( 'comma-separator' ) ?><a href="#searchInput"><?php $this->msg( 'jumptosearch' ) ?></a></div>
101 <?php } ?>
102 <!-- start content -->
103 <?php $this->html( 'bodytext' ) ?>
104 <?php if ( $this->data['catlinks'] ) { $this->html( 'catlinks' ); } ?>
105 <!-- end content -->
106 <?php if ( $this->data['dataAfterContent'] ) { $this->html( 'dataAfterContent' ); } ?>
107 <div class="visualClear"></div>
108 </div>
109 </div></div>
110 <div id="column-one"<?php $this->html( 'userlangattributes' ) ?>>
111 <h2><?php $this->msg( 'navigation-heading' ) ?></h2>
112 <?php $this->cactions(); ?>
113 <div class="portlet" id="p-personal" role="navigation">
114 <h3><?php $this->msg( 'personaltools' ) ?></h3>
115 <div class="pBody">
116 <ul<?php $this->html( 'userlangattributes' ) ?>>
117 <?php foreach ( $this->getPersonalTools() as $key => $item ) { ?>
118 <?php echo $this->makeListItem( $key, $item ); ?>
119
120 <?php } ?>
121 </ul>
122 </div>
123 </div>
124 <div class="portlet" id="p-logo" role="banner">
125 <?php
126 echo Html::element( 'a', array(
127 'href' => $this->data['nav_urls']['mainpage']['href'],
128 'style' => "background-image: url({$this->data['logopath']});" )
129 + Linker::tooltipAndAccesskeyAttribs( 'p-logo' ) ); ?>
130
131 </div>
132 <?php
133 $this->renderPortals( $this->data['sidebar'] );
134 ?>
135 </div><!-- end of the left (by default at least) column -->
136 <div class="visualClear"></div>
137 <?php
138 $validFooterIcons = $this->getFooterIcons( "icononly" );
139 $validFooterLinks = $this->getFooterLinks( "flat" ); // Additional footer links
140
141 if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) { ?>
142 <div id="footer" role="contentinfo"<?php $this->html( 'userlangattributes' ) ?>>
143 <?php
144 $footerEnd = '</div>';
145 } else {
146 $footerEnd = '';
147 }
148 foreach ( $validFooterIcons as $blockName => $footerIcons ) { ?>
149 <div id="f-<?php echo htmlspecialchars($blockName); ?>ico">
150 <?php foreach ( $footerIcons as $icon ) { ?>
151 <?php echo $this->getSkin()->makeFooterIcon( $icon ); ?>
152
153 <?php }
154 ?>
155 </div>
156 <?php }
157
158 if ( count( $validFooterLinks ) > 0 ) {
159 ?> <ul id="f-list">
160 <?php
161 foreach ( $validFooterLinks as $aLink ) { ?>
162 <li id="<?php echo $aLink ?>"><?php $this->html($aLink) ?></li>
163 <?php
164 }
165 ?>
166 </ul>
167 <?php }
168 echo $footerEnd;
169 ?>
170
171 </div>
172 <?php
173 $this->printTrail();
174 echo Html::closeElement( 'body' );
175 echo Html::closeElement( 'html' );
176 wfRestoreWarnings();
177 } // end of execute() method
178
179 /*************************************************************************************************/
180
181 /**
182 * @param $sidebar array
183 */
184 protected function renderPortals( $sidebar ) {
185 if ( !isset( $sidebar['SEARCH'] ) ) {
186 $sidebar['SEARCH'] = true;
187 }
188 if ( !isset( $sidebar['TOOLBOX'] ) ) {
189 $sidebar['TOOLBOX'] = true;
190 }
191 if ( !isset( $sidebar['LANGUAGES'] ) ) {
192 $sidebar['LANGUAGES'] = true;
193 }
194
195 foreach ( $sidebar as $boxName => $content ) {
196 if ( $content === false ) {
197 continue;
198 }
199
200 if ( $boxName == 'SEARCH' ) {
201 $this->searchBox();
202 } elseif ( $boxName == 'TOOLBOX' ) {
203 $this->toolbox();
204 } elseif ( $boxName == 'LANGUAGES' ) {
205 $this->languageBox();
206 } else {
207 $this->customBox( $boxName, $content );
208 }
209 }
210 }
211
212 function searchBox() {
213 global $wgUseTwoButtonsSearchForm;
214 ?>
215 <div id="p-search" class="portlet" role="search">
216 <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
217 <div id="searchBody" class="pBody">
218 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
219 <input type='hidden' name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
220 <?php echo $this->makeSearchInput( array( "id" => "searchInput" ) ); ?>
221
222 <?php echo $this->makeSearchButton( "go", array( "id" => "searchGoButton", "class" => "searchButton" ) );
223 if ( $wgUseTwoButtonsSearchForm ) { ?>&#160;
224 <?php echo $this->makeSearchButton( "fulltext", array( "id" => "mw-searchButton", "class" => "searchButton" ) );
225 } else { ?>
226
227 <div><a href="<?php $this->text( 'searchaction' ) ?>" rel="search"><?php $this->msg( 'powersearch-legend' ) ?></a></div><?php
228 } ?>
229
230 </form>
231 </div>
232 </div>
233 <?php
234 }
235
236 /**
237 * Prints the cactions bar.
238 * Shared between MonoBook and Modern
239 */
240 function cactions() {
241 ?>
242 <div id="p-cactions" class="portlet" role="navigation">
243 <h3><?php $this->msg( 'views' ) ?></h3>
244 <div class="pBody">
245 <ul><?php
246 foreach ( $this->data['content_actions'] as $key => $tab ) {
247 echo '
248 ' . $this->makeListItem( $key, $tab );
249 } ?>
250
251 </ul>
252 </div>
253 </div>
254 <?php
255 }
256 /*************************************************************************************************/
257 function toolbox() {
258 ?>
259 <div class="portlet" id="p-tb" role="navigation">
260 <h3><?php $this->msg( 'toolbox' ) ?></h3>
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, true ) );
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" role="navigation">
283 <h3<?php $this->html( 'userlangattributes' ) ?>><?php $this->msg( 'otherlanguages' ) ?></h3>
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 /**
299 * @param $bar string
300 * @param $cont array|string
301 */
302 function customBox( $bar, $cont ) {
303 $portletAttribs = array( 'class' => 'generated-sidebar portlet', 'id' => Sanitizer::escapeId( "p-$bar" ), 'role' => 'navigation' );
304 $tooltip = Linker::titleAttrib( "p-$bar" );
305 if ( $tooltip !== false ) {
306 $portletAttribs['title'] = $tooltip;
307 }
308 echo ' ' . Html::openElement( 'div', $portletAttribs );
309 ?>
310
311 <h3><?php $msg = wfMessage( $bar ); echo htmlspecialchars( $msg->exists() ? $msg->text() : $bar ); ?></h3>
312 <div class='pBody'>
313 <?php if ( is_array( $cont ) ) { ?>
314 <ul>
315 <?php foreach ( $cont as $key => $val ) { ?>
316 <?php echo $this->makeListItem( $key, $val ); ?>
317
318 <?php } ?>
319 </ul>
320 <?php } else {
321 # allow raw HTML block to be defined by extensions
322 print $cont;
323 }
324 ?>
325 </div>
326 </div>
327 <?php
328 }
329 } // end of class
330
331