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