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