Merge "ResourceLoader lint"
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 /**
3 * Base class for template-based skins.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 */
22
23 /**
24 * Wrapper object for MediaWiki's localization functions,
25 * to be passed to the template engine.
26 *
27 * @private
28 * @ingroup Skins
29 */
30 class MediaWiki_I18N {
31 var $_context = array();
32
33 function set( $varName, $value ) {
34 $this->_context[$varName] = $value;
35 }
36
37 function translate( $value ) {
38 wfProfileIn( __METHOD__ );
39
40 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
41 $value = preg_replace( '/^string:/', '', $value );
42
43 $value = wfMessage( $value )->text();
44 // interpolate variables
45 $m = array();
46 while ( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
47 list( $src, $var ) = $m;
48 wfSuppressWarnings();
49 $varValue = $this->_context[$var];
50 wfRestoreWarnings();
51 $value = str_replace( $src, $varValue, $value );
52 }
53 wfProfileOut( __METHOD__ );
54 return $value;
55 }
56 }
57
58 /**
59 * Template-filler skin base class
60 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
61 * Based on Brion's smarty skin
62 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
63 *
64 * @todo Needs some serious refactoring into functions that correspond
65 * to the computations individual esi snippets need. Most importantly no body
66 * parsing for most of those of course.
67 *
68 * @ingroup Skins
69 */
70 class SkinTemplate extends Skin {
71 /**#@+
72 * @private
73 */
74
75 /**
76 * Name of our skin, it probably needs to be all lower case. Child classes
77 * should override the default.
78 */
79 var $skinname = 'monobook';
80
81 /**
82 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
83 * are located. Child classes should override the default.
84 */
85 var $stylename = 'monobook';
86
87 /**
88 * For QuickTemplate, the name of the subclass which will actually fill the
89 * template. Child classes should override the default.
90 */
91 var $template = 'QuickTemplate';
92
93 /**
94 * Whether this skin use OutputPage::headElement() to generate the "<head>"
95 * tag
96 */
97 var $useHeadElement = false;
98
99 /**#@-*/
100
101 /**
102 * Add specific styles for this skin
103 *
104 * @param $out OutputPage
105 */
106 function setupSkinUserCss( OutputPage $out ) {
107 $out->addModuleStyles( array( 'mediawiki.legacy.shared', 'mediawiki.legacy.commonPrint' ) );
108 }
109
110 /**
111 * Create the template engine object; we feed it a bunch of data
112 * and eventually it spits out some HTML. Should have interface
113 * roughly equivalent to PHPTAL 0.7.
114 *
115 * @param $classname String
116 * @param string $repository subdirectory where we keep template files
117 * @param $cache_dir string
118 * @return QuickTemplate
119 * @private
120 */
121 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
122 return new $classname();
123 }
124
125 /**
126 * Generates array of language links for the current page
127 *
128 * @return array
129 * @public
130 */
131 public function getLanguages() {
132 global $wgHideInterlanguageLinks;
133 $out = $this->getOutput();
134
135 # Language links
136 $language_urls = array();
137
138 if ( !$wgHideInterlanguageLinks ) {
139 foreach ( $out->getLanguageLinks() as $languageLinkText ) {
140 $languageLinkParts = explode( ':', $languageLinkText, 2 );
141 $class = 'interwiki-' . $languageLinkParts[0];
142 unset( $languageLinkParts );
143 $languageLinkTitle = Title::newFromText( $languageLinkText );
144 if ( $languageLinkTitle ) {
145 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
146 $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
147
148 if ( strval( $ilLangName ) === '' ) {
149 $ilLangName = $languageLinkText;
150 } else {
151 $ilLangName = $this->formatLanguageName( $ilLangName );
152 }
153
154 $language_urls[] = array(
155 'href' => $languageLinkTitle->getFullURL(),
156 'text' => $ilLangName,
157 'title' => $languageLinkTitle->getText(),
158 'class' => $class,
159 'lang' => wfBCP47( $ilInterwikiCode ),
160 'hreflang' => wfBCP47( $ilInterwikiCode ),
161 );
162 }
163 }
164 }
165 return $language_urls;
166 }
167
168 protected function setupTemplateForOutput() {
169 wfProfileIn( __METHOD__ );
170
171 $request = $this->getRequest();
172 $user = $this->getUser();
173 $title = $this->getTitle();
174
175 wfProfileIn( __METHOD__ . '-init' );
176 $tpl = $this->setupTemplate( $this->template, 'skins' );
177 wfProfileOut( __METHOD__ . '-init' );
178
179 wfProfileIn( __METHOD__ . '-stuff' );
180 $this->thispage = $title->getPrefixedDBkey();
181 $this->titletxt = $title->getPrefixedText();
182 $this->userpage = $user->getUserPage()->getPrefixedText();
183 $query = array();
184 if ( !$request->wasPosted() ) {
185 $query = $request->getValues();
186 unset( $query['title'] );
187 unset( $query['returnto'] );
188 unset( $query['returntoquery'] );
189 }
190 $this->thisquery = wfArrayToCgi( $query );
191 $this->loggedin = $user->isLoggedIn();
192 $this->username = $user->getName();
193
194 if ( $this->loggedin || $this->showIPinHeader() ) {
195 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
196 } else {
197 # This won't be used in the standard skins, but we define it to preserve the interface
198 # To save time, we check for existence
199 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
200 }
201
202 wfProfileOut( __METHOD__ . '-stuff' );
203
204 wfProfileOut( __METHOD__ );
205
206 return $tpl;
207 }
208
209 /**
210 * initialize various variables and generate the template
211 *
212 * @param $out OutputPage
213 */
214 function outputPage( OutputPage $out = null ) {
215 global $wgContLang;
216 global $wgScript, $wgStylePath;
217 global $wgMimeType, $wgJsMimeType;
218 global $wgXhtmlNamespaces, $wgHtml5Version;
219 global $wgDisableCounters, $wgSitename, $wgLogo;
220 global $wgMaxCredits, $wgShowCreditsIfMax;
221 global $wgPageShowWatchingUsers;
222 global $wgArticlePath, $wgScriptPath, $wgServer;
223
224 wfProfileIn( __METHOD__ );
225 Profiler::instance()->setTemplated( true );
226
227 $oldContext = null;
228 if ( $out !== null ) {
229 // @todo Add wfDeprecated in 1.20
230 $oldContext = $this->getContext();
231 $this->setContext( $out->getContext() );
232 }
233
234 $out = $this->getOutput();
235 $request = $this->getRequest();
236 $user = $this->getUser();
237 $title = $this->getTitle();
238
239 wfProfileIn( __METHOD__ . '-init' );
240 $this->initPage( $out );
241 wfProfileOut( __METHOD__ . '-init' );
242
243 $tpl = $this->setupTemplateForOutput();
244
245 wfProfileIn( __METHOD__ . '-stuff-head' );
246 if ( !$this->useHeadElement ) {
247 $tpl->set( 'pagecss', false );
248 $tpl->set( 'usercss', false );
249
250 $tpl->set( 'userjs', false );
251 $tpl->set( 'userjsprev', false );
252
253 $tpl->set( 'jsvarurl', false );
254
255 $tpl->set( 'xhtmldefaultnamespace', 'http://www.w3.org/1999/xhtml' );
256 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
257 $tpl->set( 'html5version', $wgHtml5Version );
258 $tpl->set( 'headlinks', $out->getHeadLinks() );
259 $tpl->set( 'csslinks', $out->buildCssLinks() );
260 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
261 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
262 }
263 wfProfileOut( __METHOD__ . '-stuff-head' );
264
265 wfProfileIn( __METHOD__ . '-stuff2' );
266 $tpl->set( 'title', $out->getPageTitle() );
267 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
268 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
269
270 $tpl->setRef( 'thispage', $this->thispage );
271 $tpl->setRef( 'titleprefixeddbkey', $this->thispage );
272 $tpl->set( 'titletext', $title->getText() );
273 $tpl->set( 'articleid', $title->getArticleID() );
274
275 $tpl->set( 'isarticle', $out->isArticle() );
276
277 $subpagestr = $this->subPageSubtitle();
278 if ( $subpagestr !== '' ) {
279 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
280 }
281 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
282
283 $undelete = $this->getUndeleteLink();
284 if ( $undelete === '' ) {
285 $tpl->set( 'undelete', '' );
286 } else {
287 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
288 }
289
290 $tpl->set( 'catlinks', $this->getCategories() );
291 if ( $out->isSyndicated() ) {
292 $feeds = array();
293 foreach ( $out->getSyndicationLinks() as $format => $link ) {
294 $feeds[$format] = array(
295 'text' => $this->msg( "feed-$format" )->text(),
296 'href' => $link
297 );
298 }
299 $tpl->setRef( 'feeds', $feeds );
300 } else {
301 $tpl->set( 'feeds', false );
302 }
303
304 $tpl->setRef( 'mimetype', $wgMimeType );
305 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
306 $tpl->set( 'charset', 'UTF-8' );
307 $tpl->setRef( 'wgScript', $wgScript );
308 $tpl->setRef( 'skinname', $this->skinname );
309 $tpl->set( 'skinclass', get_class( $this ) );
310 $tpl->setRef( 'skin', $this );
311 $tpl->setRef( 'stylename', $this->stylename );
312 $tpl->set( 'printable', $out->isPrintable() );
313 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
314 $tpl->setRef( 'loggedin', $this->loggedin );
315 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
316 /* XXX currently unused, might get useful later
317 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
318 $tpl->set( 'exists', $title->getArticleID() != 0 );
319 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
320 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
321 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
322 */
323 $tpl->set( 'searchaction', $this->escapeSearchLink() );
324 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey() );
325 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
326 $tpl->setRef( 'stylepath', $wgStylePath );
327 $tpl->setRef( 'articlepath', $wgArticlePath );
328 $tpl->setRef( 'scriptpath', $wgScriptPath );
329 $tpl->setRef( 'serverurl', $wgServer );
330 $tpl->setRef( 'logopath', $wgLogo );
331 $tpl->setRef( 'sitename', $wgSitename );
332
333 $userLang = $this->getLanguage();
334 $userLangCode = $userLang->getHtmlCode();
335 $userLangDir = $userLang->getDir();
336
337 $tpl->set( 'lang', $userLangCode );
338 $tpl->set( 'dir', $userLangDir );
339 $tpl->set( 'rtl', $userLang->isRTL() );
340
341 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
342 $tpl->set( 'showjumplinks', $user->getOption( 'showjumplinks' ) );
343 $tpl->set( 'username', $this->loggedin ? $this->username : null );
344 $tpl->setRef( 'userpage', $this->userpage );
345 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
346 $tpl->set( 'userlang', $userLangCode );
347
348 // Users can have their language set differently than the
349 // content of the wiki. For these users, tell the web browser
350 // that interface elements are in a different language.
351 $tpl->set( 'userlangattributes', '' );
352 $tpl->set( 'specialpageattributes', '' ); # obsolete
353
354 if ( $userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir() ) {
355 $escUserlang = htmlspecialchars( $userLangCode );
356 $escUserdir = htmlspecialchars( $userLangDir );
357 // Attributes must be in double quotes because htmlspecialchars() doesn't
358 // escape single quotes
359 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
360 $tpl->set( 'userlangattributes', $attrs );
361 }
362
363 wfProfileOut( __METHOD__ . '-stuff2' );
364
365 wfProfileIn( __METHOD__ . '-stuff3' );
366 $tpl->set( 'newtalk', $this->getNewtalks() );
367 $tpl->set( 'logo', $this->logoText() );
368
369 $tpl->set( 'copyright', false );
370 $tpl->set( 'viewcount', false );
371 $tpl->set( 'lastmod', false );
372 $tpl->set( 'credits', false );
373 $tpl->set( 'numberofwatchingusers', false );
374 if ( $out->isArticle() && $title->exists() ) {
375 if ( $this->isRevisionCurrent() ) {
376 if ( !$wgDisableCounters ) {
377 $viewcount = $this->getWikiPage()->getCount();
378 if ( $viewcount ) {
379 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
380 }
381 }
382
383 if ( $wgPageShowWatchingUsers ) {
384 $dbr = wfGetDB( DB_SLAVE );
385 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
386 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
387 __METHOD__
388 );
389 if ( $num > 0 ) {
390 $tpl->set( 'numberofwatchingusers',
391 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
392 );
393 }
394 }
395
396 if ( $wgMaxCredits != 0 ) {
397 $tpl->set( 'credits', Action::factory( 'credits', $this->getWikiPage(),
398 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
399 } else {
400 $tpl->set( 'lastmod', $this->lastModified() );
401 }
402 }
403 $tpl->set( 'copyright', $this->getCopyright() );
404 }
405 wfProfileOut( __METHOD__ . '-stuff3' );
406
407 wfProfileIn( __METHOD__ . '-stuff4' );
408 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
409 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
410 $tpl->set( 'disclaimer', $this->disclaimerLink() );
411 $tpl->set( 'privacy', $this->privacyLink() );
412 $tpl->set( 'about', $this->aboutLink() );
413
414 $tpl->set( 'footerlinks', array(
415 'info' => array(
416 'lastmod',
417 'viewcount',
418 'numberofwatchingusers',
419 'credits',
420 'copyright',
421 ),
422 'places' => array(
423 'privacy',
424 'about',
425 'disclaimer',
426 ),
427 ) );
428
429 global $wgFooterIcons;
430 $tpl->set( 'footericons', $wgFooterIcons );
431 foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
432 if ( count( $footerIconsBlock ) > 0 ) {
433 foreach ( $footerIconsBlock as &$footerIcon ) {
434 if ( isset( $footerIcon['src'] ) ) {
435 if ( !isset( $footerIcon['width'] ) ) {
436 $footerIcon['width'] = 88;
437 }
438 if ( !isset( $footerIcon['height'] ) ) {
439 $footerIcon['height'] = 31;
440 }
441 }
442 }
443 } else {
444 unset( $tpl->data['footericons'][$footerIconsKey] );
445 }
446 }
447
448 $tpl->set( 'sitenotice', $this->getSiteNotice() );
449 $tpl->set( 'bottomscripts', $this->bottomScripts() );
450 $tpl->set( 'printfooter', $this->printSource() );
451
452 # An ID that includes the actual body text; without categories, contentSub, ...
453 $realBodyAttribs = array( 'id' => 'mw-content-text' );
454
455 # Add a mw-content-ltr/rtl class to be able to style based on text direction
456 # when the content is different from the UI language, i.e.:
457 # not for special pages or file pages AND only when viewing AND if the page exists
458 # (or is in MW namespace, because that has default content)
459 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) &&
460 Action::getActionName( $this ) === 'view' &&
461 ( $title->exists() || $title->getNamespace() == NS_MEDIAWIKI ) ) {
462 $pageLang = $title->getPageViewLanguage();
463 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
464 $realBodyAttribs['dir'] = $pageLang->getDir();
465 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
466 }
467
468 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
469 $tpl->setRef( 'bodytext', $out->mBodytext );
470
471 $language_urls = $this->getLanguages();
472 if ( count( $language_urls ) ) {
473 $tpl->setRef( 'language_urls', $language_urls );
474 } else {
475 $tpl->set( 'language_urls', false );
476 }
477 wfProfileOut( __METHOD__ . '-stuff4' );
478
479 wfProfileIn( __METHOD__ . '-stuff5' );
480 # Personal toolbar
481 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
482 $content_navigation = $this->buildContentNavigationUrls();
483 $content_actions = $this->buildContentActionUrls( $content_navigation );
484 $tpl->setRef( 'content_navigation', $content_navigation );
485 $tpl->setRef( 'content_actions', $content_actions );
486
487 $tpl->set( 'sidebar', $this->buildSidebar() );
488 $tpl->set( 'nav_urls', $this->buildNavUrls() );
489
490 // Set the head scripts near the end, in case the above actions resulted in added scripts
491 if ( $this->useHeadElement ) {
492 $tpl->set( 'headelement', $out->headElement( $this ) );
493 } else {
494 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
495 }
496
497 $tpl->set( 'debug', '' );
498 $tpl->set( 'debughtml', $this->generateDebugHTML() );
499 $tpl->set( 'reporttime', wfReportTime() );
500
501 // original version by hansm
502 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
503 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
504 }
505
506 // Set the bodytext to another key so that skins can just output it on it's own
507 // and output printfooter and debughtml separately
508 $tpl->set( 'bodycontent', $tpl->data['bodytext'] );
509
510 // Append printfooter and debughtml onto bodytext so that skins that were already
511 // using bodytext before they were split out don't suddenly start not outputting information
512 $tpl->data['bodytext'] .= Html::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
513 $tpl->data['bodytext'] .= $tpl->data['debughtml'];
514
515 // allow extensions adding stuff after the page content.
516 // See Skin::afterContentHook() for further documentation.
517 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
518 wfProfileOut( __METHOD__ . '-stuff5' );
519
520 // execute template
521 wfProfileIn( __METHOD__ . '-execute' );
522 $res = $tpl->execute();
523 wfProfileOut( __METHOD__ . '-execute' );
524
525 // result may be an error
526 $this->printOrError( $res );
527
528 if ( $oldContext ) {
529 $this->setContext( $oldContext );
530 }
531 wfProfileOut( __METHOD__ );
532 }
533
534 /**
535 * Get the HTML for the p-personal list
536 * @return string
537 */
538 public function getPersonalToolsList() {
539 $tpl = $this->setupTemplateForOutput();
540 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
541 $html = '';
542 foreach ( $tpl->getPersonalTools() as $key => $item ) {
543 $html .= $tpl->makeListItem( $key, $item );
544 }
545 return $html;
546 }
547
548 /**
549 * Format language name for use in sidebar interlanguage links list.
550 * By default it is capitalized.
551 *
552 * @param string $name Language name, e.g. "English" or "español"
553 * @return string
554 * @private
555 */
556 function formatLanguageName( $name ) {
557 return $this->getLanguage()->ucfirst( $name );
558 }
559
560 /**
561 * Output the string, or print error message if it's
562 * an error object of the appropriate type.
563 * For the base class, assume strings all around.
564 *
565 * @param $str Mixed
566 * @private
567 */
568 function printOrError( $str ) {
569 echo $str;
570 }
571
572 /**
573 * Output a boolean indicating if buildPersonalUrls should output separate
574 * login and create account links or output a combined link
575 * By default we simply return a global config setting that affects most skins
576 * This is setup as a method so that like with $wgLogo and getLogo() a skin
577 * can override this setting and always output one or the other if it has
578 * a reason it can't output one of the two modes.
579 * @return bool
580 */
581 function useCombinedLoginLink() {
582 global $wgUseCombinedLoginLink;
583 return $wgUseCombinedLoginLink;
584 }
585
586 /**
587 * build array of urls for personal toolbar
588 * @return array
589 */
590 protected function buildPersonalUrls() {
591 global $wgSecureLogin;
592
593 $title = $this->getTitle();
594 $request = $this->getRequest();
595 $pageurl = $title->getLocalURL();
596 wfProfileIn( __METHOD__ );
597
598 /* set up the default links for the personal toolbar */
599 $personal_urls = array();
600
601 # Due to bug 32276, if a user does not have read permissions,
602 # $this->getTitle() will just give Special:Badtitle, which is
603 # not especially useful as a returnto parameter. Use the title
604 # from the request instead, if there was one.
605 if ( $this->getUser()->isAllowed( 'read' ) ) {
606 $page = $this->getTitle();
607 } else {
608 $page = Title::newFromText( $request->getVal( 'title', '' ) );
609 }
610 $page = $request->getVal( 'returnto', $page );
611 $a = array();
612 if ( strval( $page ) !== '' ) {
613 $a['returnto'] = $page;
614 $query = $request->getVal( 'returntoquery', $this->thisquery );
615 if ( $query != '' ) {
616 $a['returntoquery'] = $query;
617 }
618 }
619
620 if ( $wgSecureLogin && $request->detectProtocol() === 'https' ) {
621 $a['wpStickHTTPS'] = true;
622 }
623
624 $returnto = wfArrayToCgi( $a );
625 if ( $this->loggedin ) {
626 $personal_urls['userpage'] = array(
627 'text' => $this->username,
628 'href' => &$this->userpageUrlDetails['href'],
629 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
630 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ),
631 'dir' => 'auto'
632 );
633 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
634 $personal_urls['mytalk'] = array(
635 'text' => $this->msg( 'mytalk' )->text(),
636 'href' => &$usertalkUrlDetails['href'],
637 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
638 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
639 );
640 $href = self::makeSpecialUrl( 'Preferences' );
641 $personal_urls['preferences'] = array(
642 'text' => $this->msg( 'mypreferences' )->text(),
643 'href' => $href,
644 'active' => ( $href == $pageurl )
645 );
646
647 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
648 $href = self::makeSpecialUrl( 'Watchlist' );
649 $personal_urls['watchlist'] = array(
650 'text' => $this->msg( 'mywatchlist' )->text(),
651 'href' => $href,
652 'active' => ( $href == $pageurl )
653 );
654 }
655
656 # We need to do an explicit check for Special:Contributions, as we
657 # have to match both the title, and the target, which could come
658 # from request values (Special:Contributions?target=Jimbo_Wales)
659 # or be specified in "sub page" form
660 # (Special:Contributions/Jimbo_Wales). The plot
661 # thickens, because the Title object is altered for special pages,
662 # so it doesn't contain the original alias-with-subpage.
663 $origTitle = Title::newFromText( $request->getText( 'title' ) );
664 if ( $origTitle instanceof Title && $origTitle->isSpecialPage() ) {
665 list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
666 $active = $spName == 'Contributions'
667 && ( ( $spPar && $spPar == $this->username )
668 || $request->getText( 'target' ) == $this->username );
669 } else {
670 $active = false;
671 }
672
673 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
674 $personal_urls['mycontris'] = array(
675 'text' => $this->msg( 'mycontris' )->text(),
676 'href' => $href,
677 'active' => $active
678 );
679 $personal_urls['logout'] = array(
680 'text' => $this->msg( 'userlogout' )->text(),
681 'href' => self::makeSpecialUrl( 'Userlogout',
682 // userlogout link must always contain an & character, otherwise we might not be able
683 // to detect a buggy precaching proxy (bug 17790)
684 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto
685 ),
686 'active' => false
687 );
688 } else {
689 $useCombinedLoginLink = $this->useCombinedLoginLink();
690 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
691 ? 'nav-login-createaccount'
692 : 'login';
693 $is_signup = $request->getText( 'type' ) == 'signup';
694
695 # anonlogin & login are the same
696 $proto = $wgSecureLogin ? PROTO_HTTPS : null;
697
698 $login_id = $this->showIPinHeader() ? 'anonlogin' : 'login';
699 $login_url = array(
700 'text' => $this->msg( $loginlink )->text(),
701 'href' => self::makeSpecialUrl( 'Userlogin', $returnto, $proto ),
702 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup ),
703 'class' => $wgSecureLogin ? 'link-https' : ''
704 );
705 $createaccount_url = array(
706 'text' => $this->msg( 'createaccount' )->text(),
707 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup", $proto ),
708 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
709 'class' => $wgSecureLogin ? 'link-https' : ''
710 );
711
712 if ( $this->showIPinHeader() ) {
713 $href = &$this->userpageUrlDetails['href'];
714 $personal_urls['anonuserpage'] = array(
715 'text' => $this->username,
716 'href' => $href,
717 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
718 'active' => ( $pageurl == $href )
719 );
720 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
721 $href = &$usertalkUrlDetails['href'];
722 $personal_urls['anontalk'] = array(
723 'text' => $this->msg( 'anontalk' )->text(),
724 'href' => $href,
725 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
726 'active' => ( $pageurl == $href )
727 );
728 }
729
730 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
731 $personal_urls['createaccount'] = $createaccount_url;
732 }
733
734 $personal_urls[$login_id] = $login_url;
735 }
736
737 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
738 wfProfileOut( __METHOD__ );
739 return $personal_urls;
740 }
741
742 /**
743 * Builds an array with tab definition
744 *
745 * @param Title $title page where the tab links to
746 * @param string|array $message message key or an array of message keys (will fall back)
747 * @param boolean $selected display the tab as selected
748 * @param string $query query string attached to tab URL
749 * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
750 *
751 * @return array
752 */
753 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
754 $classes = array();
755 if ( $selected ) {
756 $classes[] = 'selected';
757 }
758 if ( $checkEdit && !$title->isKnown() ) {
759 $classes[] = 'new';
760 if ( $query !== '' ) {
761 $query = 'action=edit&redlink=1&' . $query;
762 } else {
763 $query = 'action=edit&redlink=1';
764 }
765 }
766
767 // wfMessageFallback will nicely accept $message as an array of fallbacks
768 // or just a single key
769 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
770 if ( is_array( $message ) ) {
771 // for hook compatibility just keep the last message name
772 $message = end( $message );
773 }
774 if ( $msg->exists() ) {
775 $text = $msg->text();
776 } else {
777 global $wgContLang;
778 $text = $wgContLang->getFormattedNsText(
779 MWNamespace::getSubject( $title->getNamespace() ) );
780 }
781
782 $result = array();
783 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
784 $title, $message, $selected, $checkEdit,
785 &$classes, &$query, &$text, &$result ) ) ) {
786 return $result;
787 }
788
789 return array(
790 'class' => implode( ' ', $classes ),
791 'text' => $text,
792 'href' => $title->getLocalURL( $query ),
793 'primary' => true );
794 }
795
796 function makeTalkUrlDetails( $name, $urlaction = '' ) {
797 $title = Title::newFromText( $name );
798 if ( !is_object( $title ) ) {
799 throw new MWException( __METHOD__ . " given invalid pagename $name" );
800 }
801 $title = $title->getTalkPage();
802 self::checkTitle( $title, $name );
803 return array(
804 'href' => $title->getLocalURL( $urlaction ),
805 'exists' => $title->getArticleID() != 0,
806 );
807 }
808
809 function makeArticleUrlDetails( $name, $urlaction = '' ) {
810 $title = Title::newFromText( $name );
811 $title = $title->getSubjectPage();
812 self::checkTitle( $title, $name );
813 return array(
814 'href' => $title->getLocalURL( $urlaction ),
815 'exists' => $title->getArticleID() != 0,
816 );
817 }
818
819 /**
820 * a structured array of links usually used for the tabs in a skin
821 *
822 * There are 4 standard sections
823 * namespaces: Used for namespace tabs like special, page, and talk namespaces
824 * views: Used for primary page views like read, edit, history
825 * actions: Used for most extra page actions like deletion, protection, etc...
826 * variants: Used to list the language variants for the page
827 *
828 * Each section's value is a key/value array of links for that section.
829 * The links themselves have these common keys:
830 * - class: The css classes to apply to the tab
831 * - text: The text to display on the tab
832 * - href: The href for the tab to point to
833 * - rel: An optional rel= for the tab's link
834 * - redundant: If true the tab will be dropped in skins using content_actions
835 * this is useful for tabs like "Read" which only have meaning in skins that
836 * take special meaning from the grouped structure of content_navigation
837 *
838 * Views also have an extra key which can be used:
839 * - primary: If this is not true skins like vector may try to hide the tab
840 * when the user has limited space in their browser window
841 *
842 * content_navigation using code also expects these ids to be present on the
843 * links, however these are usually automatically generated by SkinTemplate
844 * itself and are not necessary when using a hook. The only things these may
845 * matter to are people modifying content_navigation after it's initial creation:
846 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
847 * - tooltiponly: This is set to true for some tabs in cases where the system
848 * believes that the accesskey should not be added to the tab.
849 *
850 * @return array
851 */
852 protected function buildContentNavigationUrls() {
853 global $wgDisableLangConversion;
854
855 wfProfileIn( __METHOD__ );
856
857 // Display tabs for the relevant title rather than always the title itself
858 $title = $this->getRelevantTitle();
859 $onPage = $title->equals( $this->getTitle() );
860
861 $out = $this->getOutput();
862 $request = $this->getRequest();
863 $user = $this->getUser();
864
865 $content_navigation = array(
866 'namespaces' => array(),
867 'views' => array(),
868 'actions' => array(),
869 'variants' => array()
870 );
871
872 // parameters
873 $action = $request->getVal( 'action', 'view' );
874
875 $userCanRead = $title->quickUserCan( 'read', $user );
876
877 $preventActiveTabs = false;
878 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
879
880 // Checks if page is some kind of content
881 if ( $title->canExist() ) {
882 // Gets page objects for the related namespaces
883 $subjectPage = $title->getSubjectPage();
884 $talkPage = $title->getTalkPage();
885
886 // Determines if this is a talk page
887 $isTalk = $title->isTalkPage();
888
889 // Generates XML IDs from namespace names
890 $subjectId = $title->getNamespaceKey( '' );
891
892 if ( $subjectId == 'main' ) {
893 $talkId = 'talk';
894 } else {
895 $talkId = "{$subjectId}_talk";
896 }
897
898 $skname = $this->skinname;
899
900 // Adds namespace links
901 $subjectMsg = array( "nstab-$subjectId" );
902 if ( $subjectPage->isMainPage() ) {
903 array_unshift( $subjectMsg, 'mainpage-nstab' );
904 }
905 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
906 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
907 );
908 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
909 $content_navigation['namespaces'][$talkId] = $this->tabAction(
910 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
911 );
912 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
913
914 if ( $userCanRead ) {
915 // Adds view view link
916 if ( $title->exists() ) {
917 $content_navigation['views']['view'] = $this->tabAction(
918 $isTalk ? $talkPage : $subjectPage,
919 array( "$skname-view-view", 'view' ),
920 ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true
921 );
922 // signal to hide this from simple content_actions
923 $content_navigation['views']['view']['redundant'] = true;
924 }
925
926 wfProfileIn( __METHOD__ . '-edit' );
927
928 // Checks if user can edit the current page if it exists or create it otherwise
929 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() || $title->quickUserCan( 'create', $user ) ) ) {
930 // Builds CSS class for talk page links
931 $isTalkClass = $isTalk ? ' istalk' : '';
932 // Whether the user is editing the page
933 $isEditing = $onPage && ( $action == 'edit' || $action == 'submit' );
934 // Whether to show the "Add a new section" tab
935 // Checks if this is a current rev of talk page and is not forced to be hidden
936 $showNewSection = !$out->forceHideNewSectionLink()
937 && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
938 $section = $request->getVal( 'section' );
939
940 $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ?
941 'edit' : 'create';
942 $content_navigation['views']['edit'] = array(
943 'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection ) ? 'selected' : '' ) . $isTalkClass,
944 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
945 'href' => $title->getLocalURL( $this->editUrlOptions() ),
946 'primary' => true, // don't collapse this in vector
947 );
948
949 // section link
950 if ( $showNewSection ) {
951 // Adds new section link
952 //$content_navigation['actions']['addsection']
953 $content_navigation['views']['addsection'] = array(
954 'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false,
955 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
956 'href' => $title->getLocalURL( 'action=edit&section=new' )
957 );
958 }
959 // Checks if the page has some kind of viewable content
960 } elseif ( $title->hasSourceText() ) {
961 // Adds view source view link
962 $content_navigation['views']['viewsource'] = array(
963 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
964 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
965 'href' => $title->getLocalURL( $this->editUrlOptions() ),
966 'primary' => true, // don't collapse this in vector
967 );
968 }
969 wfProfileOut( __METHOD__ . '-edit' );
970
971 wfProfileIn( __METHOD__ . '-live' );
972 // Checks if the page exists
973 if ( $title->exists() ) {
974 // Adds history view link
975 $content_navigation['views']['history'] = array(
976 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
977 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
978 'href' => $title->getLocalURL( 'action=history' ),
979 'rel' => 'archives',
980 );
981
982 if ( $title->quickUserCan( 'delete', $user ) ) {
983 $content_navigation['actions']['delete'] = array(
984 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
985 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
986 'href' => $title->getLocalURL( 'action=delete' )
987 );
988 }
989
990 if ( $title->quickUserCan( 'move', $user ) ) {
991 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
992 $content_navigation['actions']['move'] = array(
993 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
994 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
995 'href' => $moveTitle->getLocalURL()
996 );
997 }
998 } else {
999 // article doesn't exist or is deleted
1000 if ( $user->isAllowed( 'deletedhistory' ) ) {
1001 $n = $title->isDeleted();
1002 if ( $n ) {
1003 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
1004 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
1005 $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
1006 $content_navigation['actions']['undelete'] = array(
1007 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
1008 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1009 ->setContext( $this->getContext() )->numParams( $n )->text(),
1010 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1011 );
1012 }
1013 }
1014 }
1015
1016 if ( $title->getNamespace() !== NS_MEDIAWIKI && $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() ) {
1017 $mode = $title->isProtected() ? 'unprotect' : 'protect';
1018 $content_navigation['actions'][$mode] = array(
1019 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
1020 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
1021 'href' => $title->getLocalURL( "action=$mode" )
1022 );
1023 }
1024
1025 wfProfileOut( __METHOD__ . '-live' );
1026
1027 // Checks if the user is logged in
1028 if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1029 /**
1030 * The following actions use messages which, if made particular to
1031 * the any specific skins, would break the Ajax code which makes this
1032 * action happen entirely inline. Skin::makeGlobalVariablesScript
1033 * defines a set of messages in a javascript object - and these
1034 * messages are assumed to be global for all skins. Without making
1035 * a change to that procedure these messages will have to remain as
1036 * the global versions.
1037 */
1038 $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
1039 $token = WatchAction::getWatchToken( $title, $user, $mode );
1040 $content_navigation['actions'][$mode] = array(
1041 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
1042 // uses 'watch' or 'unwatch' message
1043 'text' => $this->msg( $mode )->text(),
1044 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1045 );
1046 }
1047 }
1048
1049 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1050
1051 if ( $userCanRead && !$wgDisableLangConversion ) {
1052 $pageLang = $title->getPageLanguage();
1053 // Gets list of language variants
1054 $variants = $pageLang->getVariants();
1055 // Checks that language conversion is enabled and variants exist
1056 // And if it is not in the special namespace
1057 if ( count( $variants ) > 1 ) {
1058 // Gets preferred variant (note that user preference is
1059 // only possible for wiki content language variant)
1060 $preferred = $pageLang->getPreferredVariant();
1061 if ( Action::getActionName( $this ) === 'view' ) {
1062 $params = $request->getQueryValues();
1063 unset( $params['title'] );
1064 } else {
1065 $params = array();
1066 }
1067 // Loops over each variant
1068 foreach ( $variants as $code ) {
1069 // Gets variant name from language code
1070 $varname = $pageLang->getVariantname( $code );
1071 // Appends variant link
1072 $content_navigation['variants'][] = array(
1073 'class' => ( $code == $preferred ) ? 'selected' : false,
1074 'text' => $varname,
1075 'href' => $title->getLocalURL( array( 'variant' => $code ) + $params ),
1076 'lang' => wfBCP47( $code ),
1077 'hreflang' => wfBCP47( $code ),
1078 );
1079 }
1080 }
1081 }
1082 } else {
1083 // If it's not content, it's got to be a special page
1084 $content_navigation['namespaces']['special'] = array(
1085 'class' => 'selected',
1086 'text' => $this->msg( 'nstab-special' )->text(),
1087 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1088 'context' => 'subject'
1089 );
1090
1091 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1092 array( &$this, &$content_navigation ) );
1093 }
1094
1095 // Equiv to SkinTemplateContentActions
1096 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1097
1098 // Setup xml ids and tooltip info
1099 foreach ( $content_navigation as $section => &$links ) {
1100 foreach ( $links as $key => &$link ) {
1101 $xmlID = $key;
1102 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1103 $xmlID = 'ca-nstab-' . $xmlID;
1104 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1105 $xmlID = 'ca-talk';
1106 } elseif ( $section == 'variants' ) {
1107 $xmlID = 'ca-varlang-' . $xmlID;
1108 } else {
1109 $xmlID = 'ca-' . $xmlID;
1110 }
1111 $link['id'] = $xmlID;
1112 }
1113 }
1114
1115 # We don't want to give the watch tab an accesskey if the
1116 # page is being edited, because that conflicts with the
1117 # accesskey on the watch checkbox. We also don't want to
1118 # give the edit tab an accesskey, because that's fairly
1119 # superfluous and conflicts with an accesskey (Ctrl-E) often
1120 # used for editing in Safari.
1121 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1122 if ( isset( $content_navigation['views']['edit'] ) ) {
1123 $content_navigation['views']['edit']['tooltiponly'] = true;
1124 }
1125 if ( isset( $content_navigation['actions']['watch'] ) ) {
1126 $content_navigation['actions']['watch']['tooltiponly'] = true;
1127 }
1128 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1129 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1130 }
1131 }
1132
1133 wfProfileOut( __METHOD__ );
1134
1135 return $content_navigation;
1136 }
1137
1138 /**
1139 * an array of edit links by default used for the tabs
1140 * @return array
1141 * @private
1142 */
1143 function buildContentActionUrls( $content_navigation ) {
1144
1145 wfProfileIn( __METHOD__ );
1146
1147 // content_actions has been replaced with content_navigation for backwards
1148 // compatibility and also for skins that just want simple tabs content_actions
1149 // is now built by flattening the content_navigation arrays into one
1150
1151 $content_actions = array();
1152
1153 foreach ( $content_navigation as $links ) {
1154
1155 foreach ( $links as $key => $value ) {
1156
1157 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1158 // Redundant tabs are dropped from content_actions
1159 continue;
1160 }
1161
1162 // content_actions used to have ids built using the "ca-$key" pattern
1163 // so the xmlID based id is much closer to the actual $key that we want
1164 // for that reason we'll just strip out the ca- if present and use
1165 // the latter potion of the "id" as the $key
1166 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1167 $key = substr( $value['id'], 3 );
1168 }
1169
1170 if ( isset( $content_actions[$key] ) ) {
1171 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1172 continue;
1173 }
1174
1175 $content_actions[$key] = $value;
1176
1177 }
1178
1179 }
1180
1181 wfProfileOut( __METHOD__ );
1182
1183 return $content_actions;
1184 }
1185
1186 /**
1187 * build array of common navigation links
1188 * @return array
1189 * @private
1190 */
1191 protected function buildNavUrls() {
1192 global $wgUploadNavigationUrl;
1193
1194 wfProfileIn( __METHOD__ );
1195
1196 $out = $this->getOutput();
1197 $request = $this->getRequest();
1198
1199 $nav_urls = array();
1200 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
1201 if ( $wgUploadNavigationUrl ) {
1202 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1203 } elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
1204 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
1205 } else {
1206 $nav_urls['upload'] = false;
1207 }
1208 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
1209
1210 $nav_urls['print'] = false;
1211 $nav_urls['permalink'] = false;
1212 $nav_urls['info'] = false;
1213 $nav_urls['whatlinkshere'] = false;
1214 $nav_urls['recentchangeslinked'] = false;
1215 $nav_urls['contributions'] = false;
1216 $nav_urls['log'] = false;
1217 $nav_urls['blockip'] = false;
1218 $nav_urls['emailuser'] = false;
1219 $nav_urls['userrights'] = false;
1220
1221 // A print stylesheet is attached to all pages, but nobody ever
1222 // figures that out. :) Add a link...
1223 if ( !$out->isPrintable() && ( $out->isArticle() || $this->getTitle()->isSpecialPage() ) ) {
1224 $nav_urls['print'] = array(
1225 'text' => $this->msg( 'printableversion' )->text(),
1226 'href' => $this->getTitle()->getLocalURL(
1227 $request->appendQueryValue( 'printable', 'yes', true ) )
1228 );
1229 }
1230
1231 if ( $out->isArticle() ) {
1232 // Also add a "permalink" while we're at it
1233 $revid = $this->getRevisionId();
1234 if ( $revid ) {
1235 $nav_urls['permalink'] = array(
1236 'text' => $this->msg( 'permalink' )->text(),
1237 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1238 );
1239 }
1240
1241 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1242 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1243 array( &$this, &$nav_urls, &$revid, &$revid ) );
1244 }
1245
1246 if ( $out->isArticleRelated() ) {
1247 $nav_urls['whatlinkshere'] = array(
1248 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalURL()
1249 );
1250
1251 $nav_urls['info'] = array(
1252 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1253 'href' => $this->getTitle()->getLocalURL( "action=info" )
1254 );
1255
1256 if ( $this->getTitle()->getArticleID() ) {
1257 $nav_urls['recentchangeslinked'] = array(
1258 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalURL()
1259 );
1260 }
1261 }
1262
1263 $user = $this->getRelevantUser();
1264 if ( $user ) {
1265 $rootUser = $user->getName();
1266
1267 $nav_urls['contributions'] = array(
1268 'text' => $this->msg( 'contributions', $rootUser )->text(),
1269 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1270 );
1271
1272 $nav_urls['log'] = array(
1273 'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser )
1274 );
1275
1276 if ( $this->getUser()->isAllowed( 'block' ) ) {
1277 $nav_urls['blockip'] = array(
1278 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1279 );
1280 }
1281
1282 if ( $this->showEmailUser( $user ) ) {
1283 $nav_urls['emailuser'] = array(
1284 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1285 );
1286 }
1287
1288 $sur = new UserrightsPage;
1289 $sur->setContext( $this->getContext() );
1290 if ( $sur->userCanExecute( $this->getUser() ) ) {
1291 $nav_urls['userrights'] = array(
1292 'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1293 );
1294 }
1295 }
1296
1297 wfProfileOut( __METHOD__ );
1298 return $nav_urls;
1299 }
1300
1301 /**
1302 * Generate strings used for xml 'id' names
1303 * @return string
1304 * @private
1305 */
1306 function getNameSpaceKey() {
1307 return $this->getTitle()->getNamespaceKey();
1308 }
1309
1310 public function commonPrintStylesheet() {
1311 return false;
1312 }
1313 }
1314
1315 /**
1316 * Generic wrapper for template functions, with interface
1317 * compatible with what we use of PHPTAL 0.7.
1318 * @ingroup Skins
1319 */
1320 abstract class QuickTemplate {
1321 /**
1322 * Constructor
1323 */
1324 function __construct() {
1325 $this->data = array();
1326 $this->translator = new MediaWiki_I18N();
1327 }
1328
1329 /**
1330 * Sets the value $value to $name
1331 * @param $name
1332 * @param $value
1333 */
1334 public function set( $name, $value ) {
1335 $this->data[$name] = $value;
1336 }
1337
1338 /**
1339 * @param $name
1340 * @param $value
1341 */
1342 public function setRef( $name, &$value ) {
1343 $this->data[$name] =& $value;
1344 }
1345
1346 /**
1347 * @param $t
1348 */
1349 public function setTranslator( &$t ) {
1350 $this->translator = &$t;
1351 }
1352
1353 /**
1354 * Main function, used by classes that subclass QuickTemplate
1355 * to show the actual HTML output
1356 */
1357 abstract public function execute();
1358
1359 /**
1360 * @private
1361 */
1362 function text( $str ) {
1363 echo htmlspecialchars( $this->data[$str] );
1364 }
1365
1366 /**
1367 * @private
1368 * @deprecated since 1.21; use Xml::encodeJsVar() or Xml::encodeJsCall() instead
1369 */
1370 function jstext( $str ) {
1371 wfDeprecated( __METHOD__, '1.21' );
1372 echo Xml::escapeJsString( $this->data[$str] );
1373 }
1374
1375 /**
1376 * @private
1377 */
1378 function html( $str ) {
1379 echo $this->data[$str];
1380 }
1381
1382 /**
1383 * @private
1384 */
1385 function msg( $str ) {
1386 echo htmlspecialchars( $this->translator->translate( $str ) );
1387 }
1388
1389 /**
1390 * @private
1391 */
1392 function msgHtml( $str ) {
1393 echo $this->translator->translate( $str );
1394 }
1395
1396 /**
1397 * An ugly, ugly hack.
1398 * @private
1399 */
1400 function msgWiki( $str ) {
1401 global $wgOut;
1402
1403 $text = $this->translator->translate( $str );
1404 echo $wgOut->parse( $text );
1405 }
1406
1407 /**
1408 * @private
1409 * @return bool
1410 */
1411 function haveData( $str ) {
1412 return isset( $this->data[$str] );
1413 }
1414
1415 /**
1416 * @private
1417 *
1418 * @return bool
1419 */
1420 function haveMsg( $str ) {
1421 $msg = $this->translator->translate( $str );
1422 return ( $msg != '-' ) && ( $msg != '' ); # ????
1423 }
1424
1425 /**
1426 * Get the Skin object related to this object
1427 *
1428 * @return Skin object
1429 */
1430 public function getSkin() {
1431 return $this->data['skin'];
1432 }
1433 }
1434
1435 /**
1436 * New base template for a skin's template extended from QuickTemplate
1437 * this class features helper methods that provide common ways of interacting
1438 * with the data stored in the QuickTemplate
1439 */
1440 abstract class BaseTemplate extends QuickTemplate {
1441
1442 /**
1443 * Get a Message object with its context set
1444 *
1445 * @param string $name message name
1446 * @return Message
1447 */
1448 public function getMsg( $name ) {
1449 return $this->getSkin()->msg( $name );
1450 }
1451
1452 function msg( $str ) {
1453 echo $this->getMsg( $str )->escaped();
1454 }
1455
1456 function msgHtml( $str ) {
1457 echo $this->getMsg( $str )->text();
1458 }
1459
1460 function msgWiki( $str ) {
1461 echo $this->getMsg( $str )->parseAsBlock();
1462 }
1463
1464 /**
1465 * Create an array of common toolbox items from the data in the quicktemplate
1466 * stored by SkinTemplate.
1467 * The resulting array is built according to a format intended to be passed
1468 * through makeListItem to generate the html.
1469 * @return array
1470 */
1471 function getToolbox() {
1472 wfProfileIn( __METHOD__ );
1473
1474 $toolbox = array();
1475 if ( isset( $this->data['nav_urls']['whatlinkshere'] ) && $this->data['nav_urls']['whatlinkshere'] ) {
1476 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
1477 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1478 }
1479 if ( isset( $this->data['nav_urls']['recentchangeslinked'] ) && $this->data['nav_urls']['recentchangeslinked'] ) {
1480 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
1481 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1482 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1483 }
1484 if ( isset( $this->data['feeds'] ) && $this->data['feeds'] ) {
1485 $toolbox['feeds']['id'] = 'feedlinks';
1486 $toolbox['feeds']['links'] = array();
1487 foreach ( $this->data['feeds'] as $key => $feed ) {
1488 $toolbox['feeds']['links'][$key] = $feed;
1489 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1490 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1491 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1492 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1493 }
1494 }
1495 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) {
1496 if ( isset( $this->data['nav_urls'][$special] ) && $this->data['nav_urls'][$special] ) {
1497 $toolbox[$special] = $this->data['nav_urls'][$special];
1498 $toolbox[$special]['id'] = "t-$special";
1499 }
1500 }
1501 if ( isset( $this->data['nav_urls']['print'] ) && $this->data['nav_urls']['print'] ) {
1502 $toolbox['print'] = $this->data['nav_urls']['print'];
1503 $toolbox['print']['id'] = 't-print';
1504 $toolbox['print']['rel'] = 'alternate';
1505 $toolbox['print']['msg'] = 'printableversion';
1506 }
1507 if ( isset( $this->data['nav_urls']['permalink'] ) && $this->data['nav_urls']['permalink'] ) {
1508 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1509 if ( $toolbox['permalink']['href'] === '' ) {
1510 unset( $toolbox['permalink']['href'] );
1511 $toolbox['ispermalink']['tooltiponly'] = true;
1512 $toolbox['ispermalink']['id'] = 't-ispermalink';
1513 $toolbox['ispermalink']['msg'] = 'permalink';
1514 } else {
1515 $toolbox['permalink']['id'] = 't-permalink';
1516 }
1517 }
1518 if ( isset( $this->data['nav_urls']['info'] ) && $this->data['nav_urls']['info'] ) {
1519 $toolbox['info'] = $this->data['nav_urls']['info'];
1520 $toolbox['info']['id'] = 't-info';
1521 }
1522
1523 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1524 wfProfileOut( __METHOD__ );
1525 return $toolbox;
1526 }
1527
1528 /**
1529 * Create an array of personal tools items from the data in the quicktemplate
1530 * stored by SkinTemplate.
1531 * The resulting array is built according to a format intended to be passed
1532 * through makeListItem to generate the html.
1533 * This is in reality the same list as already stored in personal_urls
1534 * however it is reformatted so that you can just pass the individual items
1535 * to makeListItem instead of hardcoding the element creation boilerplate.
1536 * @return array
1537 */
1538 function getPersonalTools() {
1539 $personal_tools = array();
1540 foreach ( $this->data['personal_urls'] as $key => $plink ) {
1541 # The class on a personal_urls item is meant to go on the <a> instead
1542 # of the <li> so we have to use a single item "links" array instead
1543 # of using most of the personal_url's keys directly.
1544 $ptool = array(
1545 'links' => array(
1546 array( 'single-id' => "pt-$key" ),
1547 ),
1548 'id' => "pt-$key",
1549 );
1550 if ( isset( $plink['active'] ) ) {
1551 $ptool['active'] = $plink['active'];
1552 }
1553 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1554 if ( isset( $plink[$k] ) ) {
1555 $ptool['links'][0][$k] = $plink[$k];
1556 }
1557 }
1558 $personal_tools[$key] = $ptool;
1559 }
1560 return $personal_tools;
1561 }
1562
1563 function getSidebar( $options = array() ) {
1564 // Force the rendering of the following portals
1565 $sidebar = $this->data['sidebar'];
1566 if ( !isset( $sidebar['SEARCH'] ) ) {
1567 $sidebar['SEARCH'] = true;
1568 }
1569 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1570 $sidebar['TOOLBOX'] = true;
1571 }
1572 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1573 $sidebar['LANGUAGES'] = true;
1574 }
1575
1576 if ( !isset( $options['search'] ) || $options['search'] !== true ) {
1577 unset( $sidebar['SEARCH'] );
1578 }
1579 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1580 unset( $sidebar['TOOLBOX'] );
1581 }
1582 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1583 unset( $sidebar['LANGUAGES'] );
1584 }
1585
1586 $boxes = array();
1587 foreach ( $sidebar as $boxName => $content ) {
1588 if ( $content === false ) {
1589 continue;
1590 }
1591 switch ( $boxName ) {
1592 case 'SEARCH':
1593 // Search is a special case, skins should custom implement this
1594 $boxes[$boxName] = array(
1595 'id' => 'p-search',
1596 'header' => $this->getMsg( 'search' )->text(),
1597 'generated' => false,
1598 'content' => true,
1599 );
1600 break;
1601 case 'TOOLBOX':
1602 $msgObj = $this->getMsg( 'toolbox' );
1603 $boxes[$boxName] = array(
1604 'id' => 'p-tb',
1605 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox',
1606 'generated' => false,
1607 'content' => $this->getToolbox(),
1608 );
1609 break;
1610 case 'LANGUAGES':
1611 if ( $this->data['language_urls'] ) {
1612 $msgObj = $this->getMsg( 'otherlanguages' );
1613 $boxes[$boxName] = array(
1614 'id' => 'p-lang',
1615 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
1616 'generated' => false,
1617 'content' => $this->data['language_urls'],
1618 );
1619 }
1620 break;
1621 default:
1622 $msgObj = $this->getMsg( $boxName );
1623 $boxes[$boxName] = array(
1624 'id' => "p-$boxName",
1625 'header' => $msgObj->exists() ? $msgObj->text() : $boxName,
1626 'generated' => true,
1627 'content' => $content,
1628 );
1629 break;
1630 }
1631 }
1632
1633 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1634 $hookContents = null;
1635 if ( isset( $boxes['TOOLBOX'] ) ) {
1636 ob_start();
1637 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1638 // can abort and avoid outputting double toolbox links
1639 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1640 $hookContents = ob_get_contents();
1641 ob_end_clean();
1642 if ( !trim( $hookContents ) ) {
1643 $hookContents = null;
1644 }
1645 }
1646 // END hack
1647
1648 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1649 foreach ( $boxes as $boxName => $box ) {
1650 if ( is_array( $box['content'] ) ) {
1651 $content = '<ul>';
1652 foreach ( $box['content'] as $key => $val ) {
1653 $content .= "\n " . $this->makeListItem( $key, $val );
1654 }
1655 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1656 if ( $hookContents ) {
1657 $content .= "\n $hookContents";
1658 }
1659 // END hack
1660 $content .= "\n</ul>\n";
1661 $boxes[$boxName]['content'] = $content;
1662 }
1663 }
1664 } else {
1665 if ( $hookContents ) {
1666 $boxes['TOOLBOXEND'] = array(
1667 'id' => 'p-toolboxend',
1668 'header' => $boxes['TOOLBOX']['header'],
1669 'generated' => false,
1670 'content' => "<ul>{$hookContents}</ul>",
1671 );
1672 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1673 $boxes2 = array();
1674 foreach ( $boxes as $key => $box ) {
1675 if ( $key === 'TOOLBOXEND' ) {
1676 continue;
1677 }
1678 $boxes2[$key] = $box;
1679 if ( $key === 'TOOLBOX' ) {
1680 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1681 }
1682 }
1683 $boxes = $boxes2;
1684 // END hack
1685 }
1686 }
1687
1688 return $boxes;
1689 }
1690
1691 /**
1692 * Makes a link, usually used by makeListItem to generate a link for an item
1693 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1694 *
1695 * @param string $key usually a key from the list you are generating this
1696 * link from.
1697 * @param array $item contains some of a specific set of keys.
1698 *
1699 * The text of the link will be generated either from the contents of the
1700 * "text" key in the $item array, if a "msg" key is present a message by
1701 * that name will be used, and if neither of those are set the $key will be
1702 * used as a message name.
1703 *
1704 * If a "href" key is not present makeLink will just output htmlescaped text.
1705 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1706 * for the link if present.
1707 *
1708 * If an "id" or "single-id" (if you don't want the actual id to be output
1709 * on the link) is present it will be used to generate a tooltip and
1710 * accesskey for the link.
1711 *
1712 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1713 *
1714 * @param array $options can be used to affect the output of a link.
1715 * Possible options are:
1716 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1717 * a link in. This should be an array of arrays containing a 'tag' and
1718 * optionally an 'attributes' key. If you only have one element you don't
1719 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1720 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1721 * for your options.
1722 * - 'link-class' key can be used to specify additional classes to apply
1723 * to all links.
1724 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1725 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1726 * any non-link will output a "<span>" instead of just text.
1727 *
1728 * @return string
1729 */
1730 function makeLink( $key, $item, $options = array() ) {
1731 if ( isset( $item['text'] ) ) {
1732 $text = $item['text'];
1733 } else {
1734 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
1735 }
1736
1737 $html = htmlspecialchars( $text );
1738
1739 if ( isset( $options['text-wrapper'] ) ) {
1740 $wrapper = $options['text-wrapper'];
1741 if ( isset( $wrapper['tag'] ) ) {
1742 $wrapper = array( $wrapper );
1743 }
1744 while ( count( $wrapper ) > 0 ) {
1745 $element = array_pop( $wrapper );
1746 $html = Html::rawElement( $element['tag'], isset( $element['attributes'] ) ? $element['attributes'] : null, $html );
1747 }
1748 }
1749
1750 if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
1751 $attrs = $item;
1752 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly' ) as $k ) {
1753 unset( $attrs[$k] );
1754 }
1755
1756 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1757 $item['single-id'] = $item['id'];
1758 }
1759 if ( isset( $item['single-id'] ) ) {
1760 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1761 $title = Linker::titleAttrib( $item['single-id'] );
1762 if ( $title !== false ) {
1763 $attrs['title'] = $title;
1764 }
1765 } else {
1766 $tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'] );
1767 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1768 $attrs['title'] = $tip['title'];
1769 }
1770 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1771 $attrs['accesskey'] = $tip['accesskey'];
1772 }
1773 }
1774 }
1775 if ( isset( $options['link-class'] ) ) {
1776 if ( isset( $attrs['class'] ) ) {
1777 $attrs['class'] .= " {$options['link-class']}";
1778 } else {
1779 $attrs['class'] = $options['link-class'];
1780 }
1781 }
1782 $html = Html::rawElement( isset( $attrs['href'] ) ? 'a' : $options['link-fallback'], $attrs, $html );
1783 }
1784
1785 return $html;
1786 }
1787
1788 /**
1789 * Generates a list item for a navigation, portlet, portal, sidebar... list
1790 *
1791 * @param $key string, usually a key from the list you are generating this link from.
1792 * @param $item array, of list item data containing some of a specific set of keys.
1793 * The "id" and "class" keys will be used as attributes for the list item,
1794 * if "active" contains a value of true a "active" class will also be appended to class.
1795 *
1796 * @param $options array
1797 *
1798 * If you want something other than a "<li>" you can pass a tag name such as
1799 * "tag" => "span" in the $options array to change the tag used.
1800 * link/content data for the list item may come in one of two forms
1801 * A "links" key may be used, in which case it should contain an array with
1802 * a list of links to include inside the list item, see makeLink for the
1803 * format of individual links array items.
1804 *
1805 * Otherwise the relevant keys from the list item $item array will be passed
1806 * to makeLink instead. Note however that "id" and "class" are used by the
1807 * list item directly so they will not be passed to makeLink
1808 * (however the link will still support a tooltip and accesskey from it)
1809 * If you need an id or class on a single link you should include a "links"
1810 * array with just one link item inside of it.
1811 * $options is also passed on to makeLink calls
1812 *
1813 * @return string
1814 */
1815 function makeListItem( $key, $item, $options = array() ) {
1816 if ( isset( $item['links'] ) ) {
1817 $html = '';
1818 foreach ( $item['links'] as $linkKey => $link ) {
1819 $html .= $this->makeLink( $linkKey, $link, $options );
1820 }
1821 } else {
1822 $link = $item;
1823 // These keys are used by makeListItem and shouldn't be passed on to the link
1824 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1825 unset( $link[$k] );
1826 }
1827 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1828 // The id goes on the <li> not on the <a> for single links
1829 // but makeSidebarLink still needs to know what id to use when
1830 // generating tooltips and accesskeys.
1831 $link['single-id'] = $item['id'];
1832 }
1833 $html = $this->makeLink( $key, $link, $options );
1834 }
1835
1836 $attrs = array();
1837 foreach ( array( 'id', 'class' ) as $attr ) {
1838 if ( isset( $item[$attr] ) ) {
1839 $attrs[$attr] = $item[$attr];
1840 }
1841 }
1842 if ( isset( $item['active'] ) && $item['active'] ) {
1843 if ( !isset( $attrs['class'] ) ) {
1844 $attrs['class'] = '';
1845 }
1846 $attrs['class'] .= ' active';
1847 $attrs['class'] = trim( $attrs['class'] );
1848 }
1849 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
1850 }
1851
1852 function makeSearchInput( $attrs = array() ) {
1853 $realAttrs = array(
1854 'type' => 'search',
1855 'name' => 'search',
1856 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1857 'value' => isset( $this->data['search'] ) ? $this->data['search'] : '',
1858 );
1859 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1860 return Html::element( 'input', $realAttrs );
1861 }
1862
1863 function makeSearchButton( $mode, $attrs = array() ) {
1864 switch ( $mode ) {
1865 case 'go':
1866 case 'fulltext':
1867 $realAttrs = array(
1868 'type' => 'submit',
1869 'name' => $mode,
1870 'value' => $this->translator->translate(
1871 $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
1872 );
1873 $realAttrs = array_merge(
1874 $realAttrs,
1875 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
1876 $attrs
1877 );
1878 return Html::element( 'input', $realAttrs );
1879 case 'image':
1880 $buttonAttrs = array(
1881 'type' => 'submit',
1882 'name' => 'button',
1883 );
1884 $buttonAttrs = array_merge(
1885 $buttonAttrs,
1886 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1887 $attrs
1888 );
1889 unset( $buttonAttrs['src'] );
1890 unset( $buttonAttrs['alt'] );
1891 unset( $buttonAttrs['width'] );
1892 unset( $buttonAttrs['height'] );
1893 $imgAttrs = array(
1894 'src' => $attrs['src'],
1895 'alt' => isset( $attrs['alt'] )
1896 ? $attrs['alt']
1897 : $this->translator->translate( 'searchbutton' ),
1898 'width' => isset( $attrs['width'] ) ? $attrs['width'] : null,
1899 'height' => isset( $attrs['height'] ) ? $attrs['height'] : null,
1900 );
1901 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
1902 default:
1903 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1904 }
1905 }
1906
1907 /**
1908 * Returns an array of footerlinks trimmed down to only those footer links that
1909 * are valid.
1910 * If you pass "flat" as an option then the returned array will be a flat array
1911 * of footer icons instead of a key/value array of footerlinks arrays broken
1912 * up into categories.
1913 * @return array|mixed
1914 */
1915 function getFooterLinks( $option = null ) {
1916 $footerlinks = $this->data['footerlinks'];
1917
1918 // Reduce footer links down to only those which are being used
1919 $validFooterLinks = array();
1920 foreach ( $footerlinks as $category => $links ) {
1921 $validFooterLinks[$category] = array();
1922 foreach ( $links as $link ) {
1923 if ( isset( $this->data[$link] ) && $this->data[$link] ) {
1924 $validFooterLinks[$category][] = $link;
1925 }
1926 }
1927 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1928 unset( $validFooterLinks[$category] );
1929 }
1930 }
1931
1932 if ( $option == 'flat' ) {
1933 // fold footerlinks into a single array using a bit of trickery
1934 $validFooterLinks = call_user_func_array(
1935 'array_merge',
1936 array_values( $validFooterLinks )
1937 );
1938 }
1939
1940 return $validFooterLinks;
1941 }
1942
1943 /**
1944 * Returns an array of footer icons filtered down by options relevant to how
1945 * the skin wishes to display them.
1946 * If you pass "icononly" as the option all footer icons which do not have an
1947 * image icon set will be filtered out.
1948 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1949 * in the list of footer icons. This is mostly useful for skins which only
1950 * display the text from footericons instead of the images and don't want a
1951 * duplicate copyright statement because footerlinks already rendered one.
1952 * @return
1953 */
1954 function getFooterIcons( $option = null ) {
1955 // Generate additional footer icons
1956 $footericons = $this->data['footericons'];
1957
1958 if ( $option == 'icononly' ) {
1959 // Unset any icons which don't have an image
1960 foreach ( $footericons as &$footerIconsBlock ) {
1961 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1962 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1963 unset( $footerIconsBlock[$footerIconKey] );
1964 }
1965 }
1966 }
1967 // Redo removal of any empty blocks
1968 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1969 if ( count( $footerIconsBlock ) <= 0 ) {
1970 unset( $footericons[$footerIconsKey] );
1971 }
1972 }
1973 } elseif ( $option == 'nocopyright' ) {
1974 unset( $footericons['copyright']['copyright'] );
1975 if ( count( $footericons['copyright'] ) <= 0 ) {
1976 unset( $footericons['copyright'] );
1977 }
1978 }
1979
1980 return $footericons;
1981 }
1982
1983 /**
1984 * Output the basic end-page trail including bottomscripts, reporttime, and
1985 * debug stuff. This should be called right before outputting the closing
1986 * body and html tags.
1987 */
1988 function printTrail() { ?>
1989 <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
1990 <?php $this->html( 'reporttime' ) ?>
1991 <?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() );
1992 }
1993
1994 }