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