]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - skins/monobook/MonoBookTemplate.php
MediaWiki 1.30.2-scripts
[autoinstallsdev/mediawiki.git] / skins / monobook / MonoBookTemplate.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  * @file
24  * @ingroup Skins
25  */
26
27 /**
28  * @ingroup Skins
29  */
30 class MonoBookTemplate extends BaseTemplate {
31
32         /**
33          * Template filter callback for MonoBook skin.
34          * Takes an associative array of data set from a SkinTemplate-based
35          * class, and a wrapper for MediaWiki's localization database, and
36          * outputs a formatted page.
37          */
38         public function execute() {
39                 $this->html( 'headelement' );
40                 ?><div id="globalWrapper">
41                 <div id="column-content">
42                         <div id="content" class="mw-body" role="main">
43                                 <a id="top"></a>
44                                 <?php
45                                 if ( $this->data['sitenotice'] ) {
46                                         ?>
47                                         <div id="siteNotice" class="mw-body-content"><?php
48                                         $this->html( 'sitenotice' )
49                                         ?></div><?php
50                                 }
51                                 ?>
52
53                                 <?php
54                                 echo $this->getIndicators();
55                                 // Loose comparison with '!=' is intentional, to catch null and false too, but not '0'
56                                 if ( $this->data['title'] != '' ) {
57                                 ?>
58                                 <h1 id="firstHeading" class="firstHeading" lang="<?php
59                                 $this->data['pageLanguage'] =
60                                         $this->getSkin()->getTitle()->getPageViewLanguage()->getHtmlCode();
61                                 $this->text( 'pageLanguage' );
62                                 ?>"><?php $this->html( 'title' ) ?></h1>
63                                 <?php
64                                 }
65                                 ?>
66
67                                 <div id="bodyContent" class="mw-body-content">
68                                         <div id="siteSub"><?php $this->msg( 'tagline' ) ?></div>
69                                         <div id="contentSub"<?php
70                                         $this->html( 'userlangattributes' ) ?>><?php $this->html( 'subtitle' )
71                                                 ?></div>
72                                         <?php if ( $this->data['undelete'] ) { ?>
73                                                 <div id="contentSub2"><?php $this->html( 'undelete' ) ?></div>
74                                         <?php
75                                         }
76                                         ?><?php
77                                         if ( $this->data['newtalk'] ) {
78                                                 ?>
79                                                 <div class="usermessage"><?php $this->html( 'newtalk' ) ?></div>
80                                         <?php
81                                         }
82                                         ?>
83                                         <div id="jump-to-nav" class="mw-jump"><?php
84                                                 $this->msg( 'jumpto' )
85                                                 ?> <a href="#column-one"><?php
86                                                         $this->msg( 'jumptonavigation' )
87                                                         ?></a><?php
88                                                 $this->msg( 'comma-separator' )
89                                                 ?><a href="#searchInput"><?php
90                                                         $this->msg( 'jumptosearch' )
91                                                         ?></a></div>
92
93                                         <!-- start content -->
94                                         <?php $this->html( 'bodytext' ) ?>
95                                         <?php
96                                         if ( $this->data['catlinks'] ) {
97                                                 $this->html( 'catlinks' );
98                                         }
99                                         ?>
100                                         <!-- end content -->
101                                         <?php
102                                         if ( $this->data['dataAfterContent'] ) {
103                                                 $this->html( 'dataAfterContent' );
104                                         }
105                                         ?>
106                                         <div class="visualClear"></div>
107                                 </div>
108                         </div>
109                         <?php Hooks::run( 'MonoBookAfterContent' ); ?>
110                 </div>
111                 <div id="column-one"<?php $this->html( 'userlangattributes' ) ?>>
112                         <h2><?php $this->msg( 'navigation-heading' ) ?></h2>
113                         <?php $this->cactions(); ?>
114                         <div class="portlet" id="p-personal" role="navigation">
115                                 <h3><?php $this->msg( 'personaltools' ) ?></h3>
116
117                                 <div class="pBody">
118                                         <ul<?php $this->html( 'userlangattributes' ) ?>>
119                                                 <?php
120                                                 $personalTools = $this->getPersonalTools();
121
122                                                 if ( array_key_exists( 'uls', $personalTools ) ) {
123                                                         echo $this->makeListItem( 'uls', $personalTools['uls'] );
124                                                         unset( $personalTools['uls'] );
125                                                 }
126
127                                                 if ( !$this->getSkin()->getUser()->isLoggedIn() &&
128                                                         User::groupHasPermission( '*', 'edit' )
129                                                 ) {
130                                                         echo Html::rawElement( 'li', [
131                                                                 'id' => 'pt-anonuserpage'
132                                                         ], $this->getMsg( 'notloggedin' )->escaped() );
133                                                 }
134
135                                                 foreach ( $personalTools as $key => $item ) { ?>
136                                                         <?php echo $this->makeListItem( $key, $item ); ?>
137
138                                                 <?php
139                                                 }
140                                                 ?>
141                                         </ul>
142                                 </div>
143                         </div>
144                         <div class="portlet" id="p-logo" role="banner">
145                                 <?php
146                                 echo Html::element( 'a', [
147                                                 'href' => $this->data['nav_urls']['mainpage']['href'],
148                                                 'class' => 'mw-wiki-logo',
149                                         ]
150                                         + Linker::tooltipAndAccesskeyAttribs( 'p-logo' )
151                                 ); ?>
152
153                         </div>
154                         <?php
155                         $this->renderPortals( $this->data['sidebar'] );
156                         ?>
157                 </div><!-- end of the left (by default at least) column -->
158                 <div class="visualClear"></div>
159                 <?php
160                 $validFooterIcons = $this->getFooterIcons( 'icononly' );
161                 // Additional footer links
162                 $validFooterLinks = $this->getFooterLinks( 'flat' );
163
164                 if ( count( $validFooterIcons ) + count( $validFooterLinks ) > 0 ) {
165                         ?>
166                         <div id="footer" role="contentinfo"<?php $this->html( 'userlangattributes' ) ?>>
167                         <?php
168                         $footerEnd = '</div>';
169                 } else {
170                         $footerEnd = '';
171                 }
172
173                 foreach ( $validFooterIcons as $blockName => $footerIcons ) {
174                         ?>
175                         <div id="f-<?php echo htmlspecialchars( $blockName ); ?>ico">
176                                 <?php foreach ( $footerIcons as $icon ) { ?>
177                                         <?php echo $this->getSkin()->makeFooterIcon( $icon ); ?>
178
179                                 <?php
180                                 }
181                                 ?>
182                         </div>
183                 <?php
184                 }
185
186                 if ( count( $validFooterLinks ) > 0 ) {
187                         ?>
188                         <ul id="f-list">
189                                 <?php
190                                 foreach ( $validFooterLinks as $aLink ) {
191                                         ?>
192                                         <li id="<?php echo $aLink ?>"><?php $this->html( $aLink ) ?></li>
193                                 <?php
194                                 }
195                                 ?>
196                         </ul>
197                 <?php
198                 }
199
200                 echo $footerEnd;
201                 ?>
202
203                 </div>
204                 <?php
205                 $this->printTrail();
206                 echo Html::closeElement( 'body' );
207                 echo Html::closeElement( 'html' );
208                 echo "\n";
209         }
210
211         /**
212          * @param array $sidebar
213          */
214         protected function renderPortals( $sidebar ) {
215                 if ( !isset( $sidebar['SEARCH'] ) ) {
216                         $sidebar['SEARCH'] = true;
217                 }
218                 if ( !isset( $sidebar['TOOLBOX'] ) ) {
219                         $sidebar['TOOLBOX'] = true;
220                 }
221                 if ( !isset( $sidebar['LANGUAGES'] ) ) {
222                         $sidebar['LANGUAGES'] = true;
223                 }
224
225                 foreach ( $sidebar as $boxName => $content ) {
226                         if ( $content === false ) {
227                                 continue;
228                         }
229
230                         // Numeric strings gets an integer when set as key, cast back - T73639
231                         $boxName = (string)$boxName;
232
233                         if ( $boxName == 'SEARCH' ) {
234                                 $this->searchBox();
235                         } elseif ( $boxName == 'TOOLBOX' ) {
236                                 $this->toolbox();
237                         } elseif ( $boxName == 'LANGUAGES' ) {
238                                 $this->languageBox();
239                         } else {
240                                 $this->customBox( $boxName, $content );
241                         }
242                 }
243         }
244
245         function searchBox() {
246                 ?>
247                 <div id="p-search" class="portlet" role="search">
248                         <h3><label for="searchInput"><?php $this->msg( 'search' ) ?></label></h3>
249
250                         <div id="searchBody" class="pBody">
251                                 <form action="<?php $this->text( 'wgScript' ) ?>" id="searchform">
252                                         <input type="hidden" name="title" value="<?php $this->text( 'searchtitle' ) ?>"/>
253                                         <?php echo $this->makeSearchInput( [ 'id' => 'searchInput' ] ); ?>
254
255                                         <?php
256                                         echo $this->makeSearchButton(
257                                                 'go',
258                                                 [ 'id' => 'searchGoButton', 'class' => 'searchButton' ]
259                                         );
260
261                                         if ( $this->config->get( 'UseTwoButtonsSearchForm' ) ) {
262                                                 ?>&#160;
263                                                 <?php echo $this->makeSearchButton(
264                                                         'fulltext',
265                                                         [ 'id' => 'mw-searchButton', 'class' => 'searchButton' ]
266                                                 );
267                                         } else {
268                                                 ?>
269
270                                                 <div><a href="<?php
271                                                 $this->text( 'searchaction' )
272                                                 ?>" rel="search"><?php $this->msg( 'powersearch-legend' ) ?></a></div><?php
273                                         } ?>
274
275                                 </form>
276
277                                 <?php $this->renderAfterPortlet( 'search' ); ?>
278                         </div>
279                 </div>
280         <?php
281         }
282
283         /**
284          * Prints the content actions (cactions) bar.
285          * Shared between MonoBook and Modern
286          */
287         function cactions() {
288                 ?>
289                 <div id="p-cactions" class="portlet" role="navigation">
290                         <h3><?php $this->msg( 'views' ) ?></h3>
291
292                         <div class="pBody">
293                                 <ul><?php
294                                         foreach ( $this->data['content_actions'] as $key => $tab ) {
295                                                 echo '
296                                 ' . $this->makeListItem( $key, $tab );
297                                         } ?>
298
299                                 </ul>
300                                 <?php $this->renderAfterPortlet( 'cactions' ); ?>
301                         </div>
302                 </div>
303         <?php
304         }
305
306         function toolbox() {
307                 ?>
308                 <div class="portlet" id="p-tb" role="navigation">
309                         <h3><?php $this->msg( 'toolbox' ) ?></h3>
310
311                         <div class="pBody">
312                                 <ul>
313                                         <?php
314                                         foreach ( $this->getToolbox() as $key => $tbitem ) {
315                                                 ?>
316                                                 <?php echo $this->makeListItem( $key, $tbitem ); ?>
317
318                                         <?php
319                                         }
320                                         // Avoid PHP 7.1 warnings
321                                         $skin = $this;
322                                         Hooks::run( 'MonoBookTemplateToolboxEnd', [ &$skin ] );
323                                         Hooks::run( 'SkinTemplateToolboxEnd', [ &$skin, true ] );
324                                         ?>
325                                 </ul>
326                                 <?php $this->renderAfterPortlet( 'tb' ); ?>
327                         </div>
328                 </div>
329         <?php
330                 Hooks::run( 'MonoBookAfterToolbox' );
331         }
332
333         function languageBox() {
334                 if ( $this->data['language_urls'] !== false ) {
335                         ?>
336                         <div id="p-lang" class="portlet" role="navigation">
337                                 <h3<?php $this->html( 'userlangattributes' ) ?>><?php $this->msg( 'otherlanguages' ) ?></h3>
338
339                                 <div class="pBody">
340                                         <ul>
341                                                 <?php foreach ( $this->data['language_urls'] as $key => $langLink ) { ?>
342                                                         <?php echo $this->makeListItem( $key, $langLink ); ?>
343
344                                                 <?php
345                                                 }
346                                                 ?>
347                                         </ul>
348
349                                         <?php $this->renderAfterPortlet( 'lang' ); ?>
350                                 </div>
351                         </div>
352                 <?php
353                 }
354         }
355
356         /**
357          * @param string $bar
358          * @param array|string $cont
359          */
360         function customBox( $bar, $cont ) {
361                 $portletAttribs = [
362                         'class' => 'generated-sidebar portlet',
363                         'id' => Sanitizer::escapeId( "p-$bar" ),
364                         'role' => 'navigation'
365                 ];
366
367                 $tooltip = Linker::titleAttrib( "p-$bar" );
368                 if ( $tooltip !== false ) {
369                         $portletAttribs['title'] = $tooltip;
370                 }
371                 echo '  ' . Html::openElement( 'div', $portletAttribs );
372                 $msgObj = wfMessage( $bar );
373                 ?>
374
375                 <h3><?php echo htmlspecialchars( $msgObj->exists() ? $msgObj->text() : $bar ); ?></h3>
376                 <div class="pBody">
377                         <?php
378                         if ( is_array( $cont ) ) {
379                                 ?>
380                                 <ul>
381                                         <?php
382                                         foreach ( $cont as $key => $val ) {
383                                                 ?>
384                                                 <?php echo $this->makeListItem( $key, $val ); ?>
385
386                                         <?php
387                                         }
388                                         ?>
389                                 </ul>
390                         <?php
391                         } else {
392                                 # allow raw HTML block to be defined by extensions
393                                 print $cont;
394                         }
395
396                         $this->renderAfterPortlet( $bar );
397                         ?>
398                 </div>
399                 </div>
400         <?php
401         }
402 }