Merge "Update Special:ChangePassword to use HTMLForm"
[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_id = $this->showIPinHeader() ? 'anonlogin' : 'login';
726 $login_url = array(
727 'text' => $this->msg( $loginlink )->text(),
728 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
729 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' || !$is_signup ),
730 );
731 $createaccount_url = array(
732 'text' => $this->msg( 'createaccount' )->text(),
733 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
734 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
735 );
736
737 if ( $this->showIPinHeader() ) {
738 $href = &$this->userpageUrlDetails['href'];
739 $personal_urls['anonuserpage'] = array(
740 'text' => $this->username,
741 'href' => $href,
742 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
743 'active' => ( $pageurl == $href )
744 );
745 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
746 $href = &$usertalkUrlDetails['href'];
747 $personal_urls['anontalk'] = array(
748 'text' => $this->msg( 'anontalk' )->text(),
749 'href' => $href,
750 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
751 'active' => ( $pageurl == $href )
752 );
753 }
754
755 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
756 $personal_urls['createaccount'] = $createaccount_url;
757 }
758
759 $personal_urls[$login_id] = $login_url;
760 }
761
762 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
763 wfProfileOut( __METHOD__ );
764 return $personal_urls;
765 }
766
767 /**
768 * Builds an array with tab definition
769 *
770 * @param Title $title page where the tab links to
771 * @param string|array $message message key or an array of message keys (will fall back)
772 * @param boolean $selected display the tab as selected
773 * @param string $query query string attached to tab URL
774 * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
775 *
776 * @return array
777 */
778 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
779 $classes = array();
780 if ( $selected ) {
781 $classes[] = 'selected';
782 }
783 if ( $checkEdit && !$title->isKnown() ) {
784 $classes[] = 'new';
785 if ( $query !== '' ) {
786 $query = 'action=edit&redlink=1&' . $query;
787 } else {
788 $query = 'action=edit&redlink=1';
789 }
790 }
791
792 // wfMessageFallback will nicely accept $message as an array of fallbacks
793 // or just a single key
794 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
795 if ( is_array( $message ) ) {
796 // for hook compatibility just keep the last message name
797 $message = end( $message );
798 }
799 if ( $msg->exists() ) {
800 $text = $msg->text();
801 } else {
802 global $wgContLang;
803 $text = $wgContLang->getFormattedNsText(
804 MWNamespace::getSubject( $title->getNamespace() ) );
805 }
806
807 $result = array();
808 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
809 $title, $message, $selected, $checkEdit,
810 &$classes, &$query, &$text, &$result ) ) ) {
811 return $result;
812 }
813
814 return array(
815 'class' => implode( ' ', $classes ),
816 'text' => $text,
817 'href' => $title->getLocalURL( $query ),
818 'primary' => true );
819 }
820
821 function makeTalkUrlDetails( $name, $urlaction = '' ) {
822 $title = Title::newFromText( $name );
823 if ( !is_object( $title ) ) {
824 throw new MWException( __METHOD__ . " given invalid pagename $name" );
825 }
826 $title = $title->getTalkPage();
827 self::checkTitle( $title, $name );
828 return array(
829 'href' => $title->getLocalURL( $urlaction ),
830 'exists' => $title->getArticleID() != 0,
831 );
832 }
833
834 function makeArticleUrlDetails( $name, $urlaction = '' ) {
835 $title = Title::newFromText( $name );
836 $title = $title->getSubjectPage();
837 self::checkTitle( $title, $name );
838 return array(
839 'href' => $title->getLocalURL( $urlaction ),
840 'exists' => $title->getArticleID() != 0,
841 );
842 }
843
844 /**
845 * a structured array of links usually used for the tabs in a skin
846 *
847 * There are 4 standard sections
848 * namespaces: Used for namespace tabs like special, page, and talk namespaces
849 * views: Used for primary page views like read, edit, history
850 * actions: Used for most extra page actions like deletion, protection, etc...
851 * variants: Used to list the language variants for the page
852 *
853 * Each section's value is a key/value array of links for that section.
854 * The links themselves have these common keys:
855 * - class: The css classes to apply to the tab
856 * - text: The text to display on the tab
857 * - href: The href for the tab to point to
858 * - rel: An optional rel= for the tab's link
859 * - redundant: If true the tab will be dropped in skins using content_actions
860 * this is useful for tabs like "Read" which only have meaning in skins that
861 * take special meaning from the grouped structure of content_navigation
862 *
863 * Views also have an extra key which can be used:
864 * - primary: If this is not true skins like vector may try to hide the tab
865 * when the user has limited space in their browser window
866 *
867 * content_navigation using code also expects these ids to be present on the
868 * links, however these are usually automatically generated by SkinTemplate
869 * itself and are not necessary when using a hook. The only things these may
870 * matter to are people modifying content_navigation after it's initial creation:
871 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
872 * - tooltiponly: This is set to true for some tabs in cases where the system
873 * believes that the accesskey should not be added to the tab.
874 *
875 * @return array
876 */
877 protected function buildContentNavigationUrls() {
878 global $wgDisableLangConversion;
879
880 wfProfileIn( __METHOD__ );
881
882 // Display tabs for the relevant title rather than always the title itself
883 $title = $this->getRelevantTitle();
884 $onPage = $title->equals( $this->getTitle() );
885
886 $out = $this->getOutput();
887 $request = $this->getRequest();
888 $user = $this->getUser();
889
890 $content_navigation = array(
891 'namespaces' => array(),
892 'views' => array(),
893 'actions' => array(),
894 'variants' => array()
895 );
896
897 // parameters
898 $action = $request->getVal( 'action', 'view' );
899
900 $userCanRead = $title->quickUserCan( 'read', $user );
901
902 $preventActiveTabs = false;
903 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
904
905 // Checks if page is some kind of content
906 if ( $title->canExist() ) {
907 // Gets page objects for the related namespaces
908 $subjectPage = $title->getSubjectPage();
909 $talkPage = $title->getTalkPage();
910
911 // Determines if this is a talk page
912 $isTalk = $title->isTalkPage();
913
914 // Generates XML IDs from namespace names
915 $subjectId = $title->getNamespaceKey( '' );
916
917 if ( $subjectId == 'main' ) {
918 $talkId = 'talk';
919 } else {
920 $talkId = "{$subjectId}_talk";
921 }
922
923 $skname = $this->skinname;
924
925 // Adds namespace links
926 $subjectMsg = array( "nstab-$subjectId" );
927 if ( $subjectPage->isMainPage() ) {
928 array_unshift( $subjectMsg, 'mainpage-nstab' );
929 }
930 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
931 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
932 );
933 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
934 $content_navigation['namespaces'][$talkId] = $this->tabAction(
935 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
936 );
937 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
938
939 if ( $userCanRead ) {
940 // Adds view view link
941 if ( $title->exists() ) {
942 $content_navigation['views']['view'] = $this->tabAction(
943 $isTalk ? $talkPage : $subjectPage,
944 array( "$skname-view-view", 'view' ),
945 ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true
946 );
947 // signal to hide this from simple content_actions
948 $content_navigation['views']['view']['redundant'] = true;
949 }
950
951 wfProfileIn( __METHOD__ . '-edit' );
952
953 // Checks if user can edit the current page if it exists or create it otherwise
954 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() || $title->quickUserCan( 'create', $user ) ) ) {
955 // Builds CSS class for talk page links
956 $isTalkClass = $isTalk ? ' istalk' : '';
957 // Whether the user is editing the page
958 $isEditing = $onPage && ( $action == 'edit' || $action == 'submit' );
959 // Whether to show the "Add a new section" tab
960 // Checks if this is a current rev of talk page and is not forced to be hidden
961 $showNewSection = !$out->forceHideNewSectionLink()
962 && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
963 $section = $request->getVal( 'section' );
964
965 $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ?
966 'edit' : 'create';
967 $content_navigation['views']['edit'] = array(
968 'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection ) ? 'selected' : '' ) . $isTalkClass,
969 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
970 'href' => $title->getLocalURL( $this->editUrlOptions() ),
971 'primary' => true, // don't collapse this in vector
972 );
973
974 // section link
975 if ( $showNewSection ) {
976 // Adds new section link
977 //$content_navigation['actions']['addsection']
978 $content_navigation['views']['addsection'] = array(
979 'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false,
980 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
981 'href' => $title->getLocalURL( 'action=edit&section=new' )
982 );
983 }
984 // Checks if the page has some kind of viewable content
985 } elseif ( $title->hasSourceText() ) {
986 // Adds view source view link
987 $content_navigation['views']['viewsource'] = array(
988 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
989 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
990 'href' => $title->getLocalURL( $this->editUrlOptions() ),
991 'primary' => true, // don't collapse this in vector
992 );
993 }
994 wfProfileOut( __METHOD__ . '-edit' );
995
996 wfProfileIn( __METHOD__ . '-live' );
997 // Checks if the page exists
998 if ( $title->exists() ) {
999 // Adds history view link
1000 $content_navigation['views']['history'] = array(
1001 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
1002 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
1003 'href' => $title->getLocalURL( 'action=history' ),
1004 'rel' => 'archives',
1005 );
1006
1007 if ( $title->quickUserCan( 'delete', $user ) ) {
1008 $content_navigation['actions']['delete'] = array(
1009 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
1010 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
1011 'href' => $title->getLocalURL( 'action=delete' )
1012 );
1013 }
1014
1015 if ( $title->quickUserCan( 'move', $user ) ) {
1016 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1017 $content_navigation['actions']['move'] = array(
1018 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
1019 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
1020 'href' => $moveTitle->getLocalURL()
1021 );
1022 }
1023 } else {
1024 // article doesn't exist or is deleted
1025 if ( $user->isAllowed( 'deletedhistory' ) ) {
1026 $n = $title->isDeleted();
1027 if ( $n ) {
1028 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
1029 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
1030 $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
1031 $content_navigation['actions']['undelete'] = array(
1032 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
1033 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1034 ->setContext( $this->getContext() )->numParams( $n )->text(),
1035 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1036 );
1037 }
1038 }
1039 }
1040
1041 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1042 MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1043 ) {
1044 $mode = $title->isProtected() ? 'unprotect' : 'protect';
1045 $content_navigation['actions'][$mode] = array(
1046 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
1047 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
1048 'href' => $title->getLocalURL( "action=$mode" )
1049 );
1050 }
1051
1052 wfProfileOut( __METHOD__ . '-live' );
1053
1054 // Checks if the user is logged in
1055 if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1056 /**
1057 * The following actions use messages which, if made particular to
1058 * the any specific skins, would break the Ajax code which makes this
1059 * action happen entirely inline. Skin::makeGlobalVariablesScript
1060 * defines a set of messages in a javascript object - and these
1061 * messages are assumed to be global for all skins. Without making
1062 * a change to that procedure these messages will have to remain as
1063 * the global versions.
1064 */
1065 $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
1066 $token = WatchAction::getWatchToken( $title, $user, $mode );
1067 $content_navigation['actions'][$mode] = array(
1068 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
1069 // uses 'watch' or 'unwatch' message
1070 'text' => $this->msg( $mode )->text(),
1071 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1072 );
1073 }
1074 }
1075
1076 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1077
1078 if ( $userCanRead && !$wgDisableLangConversion ) {
1079 $pageLang = $title->getPageLanguage();
1080 // Gets list of language variants
1081 $variants = $pageLang->getVariants();
1082 // Checks that language conversion is enabled and variants exist
1083 // And if it is not in the special namespace
1084 if ( count( $variants ) > 1 ) {
1085 // Gets preferred variant (note that user preference is
1086 // only possible for wiki content language variant)
1087 $preferred = $pageLang->getPreferredVariant();
1088 if ( Action::getActionName( $this ) === 'view' ) {
1089 $params = $request->getQueryValues();
1090 unset( $params['title'] );
1091 } else {
1092 $params = array();
1093 }
1094 // Loops over each variant
1095 foreach ( $variants as $code ) {
1096 // Gets variant name from language code
1097 $varname = $pageLang->getVariantname( $code );
1098 // Appends variant link
1099 $content_navigation['variants'][] = array(
1100 'class' => ( $code == $preferred ) ? 'selected' : false,
1101 'text' => $varname,
1102 'href' => $title->getLocalURL( array( 'variant' => $code ) + $params ),
1103 'lang' => wfBCP47( $code ),
1104 'hreflang' => wfBCP47( $code ),
1105 );
1106 }
1107 }
1108 }
1109 } else {
1110 // If it's not content, it's got to be a special page
1111 $content_navigation['namespaces']['special'] = array(
1112 'class' => 'selected',
1113 'text' => $this->msg( 'nstab-special' )->text(),
1114 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1115 'context' => 'subject'
1116 );
1117
1118 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1119 array( &$this, &$content_navigation ) );
1120 }
1121
1122 // Equiv to SkinTemplateContentActions
1123 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1124
1125 // Setup xml ids and tooltip info
1126 foreach ( $content_navigation as $section => &$links ) {
1127 foreach ( $links as $key => &$link ) {
1128 $xmlID = $key;
1129 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1130 $xmlID = 'ca-nstab-' . $xmlID;
1131 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1132 $xmlID = 'ca-talk';
1133 } elseif ( $section == 'variants' ) {
1134 $xmlID = 'ca-varlang-' . $xmlID;
1135 } else {
1136 $xmlID = 'ca-' . $xmlID;
1137 }
1138 $link['id'] = $xmlID;
1139 }
1140 }
1141
1142 # We don't want to give the watch tab an accesskey if the
1143 # page is being edited, because that conflicts with the
1144 # accesskey on the watch checkbox. We also don't want to
1145 # give the edit tab an accesskey, because that's fairly
1146 # superfluous and conflicts with an accesskey (Ctrl-E) often
1147 # used for editing in Safari.
1148 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1149 if ( isset( $content_navigation['views']['edit'] ) ) {
1150 $content_navigation['views']['edit']['tooltiponly'] = true;
1151 }
1152 if ( isset( $content_navigation['actions']['watch'] ) ) {
1153 $content_navigation['actions']['watch']['tooltiponly'] = true;
1154 }
1155 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1156 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1157 }
1158 }
1159
1160 wfProfileOut( __METHOD__ );
1161
1162 return $content_navigation;
1163 }
1164
1165 /**
1166 * an array of edit links by default used for the tabs
1167 * @return array
1168 * @private
1169 */
1170 function buildContentActionUrls( $content_navigation ) {
1171
1172 wfProfileIn( __METHOD__ );
1173
1174 // content_actions has been replaced with content_navigation for backwards
1175 // compatibility and also for skins that just want simple tabs content_actions
1176 // is now built by flattening the content_navigation arrays into one
1177
1178 $content_actions = array();
1179
1180 foreach ( $content_navigation as $links ) {
1181
1182 foreach ( $links as $key => $value ) {
1183
1184 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1185 // Redundant tabs are dropped from content_actions
1186 continue;
1187 }
1188
1189 // content_actions used to have ids built using the "ca-$key" pattern
1190 // so the xmlID based id is much closer to the actual $key that we want
1191 // for that reason we'll just strip out the ca- if present and use
1192 // the latter potion of the "id" as the $key
1193 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1194 $key = substr( $value['id'], 3 );
1195 }
1196
1197 if ( isset( $content_actions[$key] ) ) {
1198 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1199 continue;
1200 }
1201
1202 $content_actions[$key] = $value;
1203
1204 }
1205
1206 }
1207
1208 wfProfileOut( __METHOD__ );
1209
1210 return $content_actions;
1211 }
1212
1213 /**
1214 * build array of common navigation links
1215 * @return array
1216 * @private
1217 */
1218 protected function buildNavUrls() {
1219 global $wgUploadNavigationUrl;
1220
1221 wfProfileIn( __METHOD__ );
1222
1223 $out = $this->getOutput();
1224 $request = $this->getRequest();
1225
1226 $nav_urls = array();
1227 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
1228 if ( $wgUploadNavigationUrl ) {
1229 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1230 } elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
1231 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
1232 } else {
1233 $nav_urls['upload'] = false;
1234 }
1235 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
1236
1237 $nav_urls['print'] = false;
1238 $nav_urls['permalink'] = false;
1239 $nav_urls['info'] = false;
1240 $nav_urls['whatlinkshere'] = false;
1241 $nav_urls['recentchangeslinked'] = false;
1242 $nav_urls['contributions'] = false;
1243 $nav_urls['log'] = false;
1244 $nav_urls['blockip'] = false;
1245 $nav_urls['emailuser'] = false;
1246 $nav_urls['userrights'] = false;
1247
1248 // A print stylesheet is attached to all pages, but nobody ever
1249 // figures that out. :) Add a link...
1250 if ( !$out->isPrintable() && ( $out->isArticle() || $this->getTitle()->isSpecialPage() ) ) {
1251 $nav_urls['print'] = array(
1252 'text' => $this->msg( 'printableversion' )->text(),
1253 'href' => $this->getTitle()->getLocalURL(
1254 $request->appendQueryValue( 'printable', 'yes', true ) )
1255 );
1256 }
1257
1258 if ( $out->isArticle() ) {
1259 // Also add a "permalink" while we're at it
1260 $revid = $this->getRevisionId();
1261 if ( $revid ) {
1262 $nav_urls['permalink'] = array(
1263 'text' => $this->msg( 'permalink' )->text(),
1264 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1265 );
1266 }
1267
1268 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1269 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1270 array( &$this, &$nav_urls, &$revid, &$revid ) );
1271 }
1272
1273 if ( $out->isArticleRelated() ) {
1274 $nav_urls['whatlinkshere'] = array(
1275 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalURL()
1276 );
1277
1278 $nav_urls['info'] = array(
1279 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1280 'href' => $this->getTitle()->getLocalURL( "action=info" )
1281 );
1282
1283 if ( $this->getTitle()->getArticleID() ) {
1284 $nav_urls['recentchangeslinked'] = array(
1285 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalURL()
1286 );
1287 }
1288 }
1289
1290 $user = $this->getRelevantUser();
1291 if ( $user ) {
1292 $rootUser = $user->getName();
1293
1294 $nav_urls['contributions'] = array(
1295 'text' => $this->msg( 'contributions', $rootUser )->text(),
1296 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1297 );
1298
1299 $nav_urls['log'] = array(
1300 'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser )
1301 );
1302
1303 if ( $this->getUser()->isAllowed( 'block' ) ) {
1304 $nav_urls['blockip'] = array(
1305 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1306 );
1307 }
1308
1309 if ( $this->showEmailUser( $user ) ) {
1310 $nav_urls['emailuser'] = array(
1311 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1312 );
1313 }
1314
1315 if ( !$user->isAnon() ) {
1316 $sur = new UserrightsPage;
1317 $sur->setContext( $this->getContext() );
1318 if ( $sur->userCanExecute( $this->getUser() ) ) {
1319 $nav_urls['userrights'] = array(
1320 'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1321 );
1322 }
1323 }
1324 }
1325
1326 wfProfileOut( __METHOD__ );
1327 return $nav_urls;
1328 }
1329
1330 /**
1331 * Generate strings used for xml 'id' names
1332 * @return string
1333 * @private
1334 */
1335 function getNameSpaceKey() {
1336 return $this->getTitle()->getNamespaceKey();
1337 }
1338 }
1339
1340 /**
1341 * Generic wrapper for template functions, with interface
1342 * compatible with what we use of PHPTAL 0.7.
1343 * @ingroup Skins
1344 */
1345 abstract class QuickTemplate {
1346 /**
1347 * Constructor
1348 */
1349 function __construct() {
1350 $this->data = array();
1351 $this->translator = new MediaWiki_I18N();
1352 }
1353
1354 /**
1355 * Sets the value $value to $name
1356 * @param $name
1357 * @param $value
1358 */
1359 public function set( $name, $value ) {
1360 $this->data[$name] = $value;
1361 }
1362
1363 /**
1364 * Gets the template data requested
1365 * @since 1.22
1366 * @param string $name Key for the data
1367 * @param mixed $default Optional default (or null)
1368 * @return mixed The value of the data requested or the deafult
1369 */
1370 public function get( $name, $default = null ) {
1371 if ( isset( $this->data[$name] ) ) {
1372 return $this->data[$name];
1373 } else {
1374 return $default;
1375 }
1376 }
1377
1378 /**
1379 * @param $name
1380 * @param $value
1381 */
1382 public function setRef( $name, &$value ) {
1383 $this->data[$name] =& $value;
1384 }
1385
1386 /**
1387 * @param $t
1388 */
1389 public function setTranslator( &$t ) {
1390 $this->translator = &$t;
1391 }
1392
1393 /**
1394 * Main function, used by classes that subclass QuickTemplate
1395 * to show the actual HTML output
1396 */
1397 abstract public function execute();
1398
1399 /**
1400 * @private
1401 */
1402 function text( $str ) {
1403 echo htmlspecialchars( $this->data[$str] );
1404 }
1405
1406 /**
1407 * @private
1408 */
1409 function html( $str ) {
1410 echo $this->data[$str];
1411 }
1412
1413 /**
1414 * @private
1415 */
1416 function msg( $str ) {
1417 echo htmlspecialchars( $this->translator->translate( $str ) );
1418 }
1419
1420 /**
1421 * @private
1422 */
1423 function msgHtml( $str ) {
1424 echo $this->translator->translate( $str );
1425 }
1426
1427 /**
1428 * An ugly, ugly hack.
1429 * @private
1430 */
1431 function msgWiki( $str ) {
1432 global $wgOut;
1433
1434 $text = $this->translator->translate( $str );
1435 echo $wgOut->parse( $text );
1436 }
1437
1438 /**
1439 * @private
1440 * @return bool
1441 */
1442 function haveData( $str ) {
1443 return isset( $this->data[$str] );
1444 }
1445
1446 /**
1447 * @private
1448 *
1449 * @return bool
1450 */
1451 function haveMsg( $str ) {
1452 $msg = $this->translator->translate( $str );
1453 return ( $msg != '-' ) && ( $msg != '' ); # ????
1454 }
1455
1456 /**
1457 * Get the Skin object related to this object
1458 *
1459 * @return Skin object
1460 */
1461 public function getSkin() {
1462 return $this->data['skin'];
1463 }
1464
1465 /**
1466 * Fetch the output of a QuickTemplate and return it
1467 *
1468 * @since 1.23
1469 * @return String
1470 */
1471 public function getHTML() {
1472 ob_start();
1473 $this->execute();
1474 $html = ob_get_contents();
1475 ob_end_clean();
1476 return $html;
1477 }
1478 }
1479
1480 /**
1481 * New base template for a skin's template extended from QuickTemplate
1482 * this class features helper methods that provide common ways of interacting
1483 * with the data stored in the QuickTemplate
1484 */
1485 abstract class BaseTemplate extends QuickTemplate {
1486
1487 /**
1488 * Get a Message object with its context set
1489 *
1490 * @param string $name message name
1491 * @return Message
1492 */
1493 public function getMsg( $name ) {
1494 return $this->getSkin()->msg( $name );
1495 }
1496
1497 function msg( $str ) {
1498 echo $this->getMsg( $str )->escaped();
1499 }
1500
1501 function msgHtml( $str ) {
1502 echo $this->getMsg( $str )->text();
1503 }
1504
1505 function msgWiki( $str ) {
1506 echo $this->getMsg( $str )->parseAsBlock();
1507 }
1508
1509 /**
1510 * Create an array of common toolbox items from the data in the quicktemplate
1511 * stored by SkinTemplate.
1512 * The resulting array is built according to a format intended to be passed
1513 * through makeListItem to generate the html.
1514 * @return array
1515 */
1516 function getToolbox() {
1517 wfProfileIn( __METHOD__ );
1518
1519 $toolbox = array();
1520 if ( isset( $this->data['nav_urls']['whatlinkshere'] ) && $this->data['nav_urls']['whatlinkshere'] ) {
1521 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
1522 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1523 }
1524 if ( isset( $this->data['nav_urls']['recentchangeslinked'] ) && $this->data['nav_urls']['recentchangeslinked'] ) {
1525 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
1526 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1527 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1528 }
1529 if ( isset( $this->data['feeds'] ) && $this->data['feeds'] ) {
1530 $toolbox['feeds']['id'] = 'feedlinks';
1531 $toolbox['feeds']['links'] = array();
1532 foreach ( $this->data['feeds'] as $key => $feed ) {
1533 $toolbox['feeds']['links'][$key] = $feed;
1534 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1535 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1536 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1537 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1538 }
1539 }
1540 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) {
1541 if ( isset( $this->data['nav_urls'][$special] ) && $this->data['nav_urls'][$special] ) {
1542 $toolbox[$special] = $this->data['nav_urls'][$special];
1543 $toolbox[$special]['id'] = "t-$special";
1544 }
1545 }
1546 if ( isset( $this->data['nav_urls']['print'] ) && $this->data['nav_urls']['print'] ) {
1547 $toolbox['print'] = $this->data['nav_urls']['print'];
1548 $toolbox['print']['id'] = 't-print';
1549 $toolbox['print']['rel'] = 'alternate';
1550 $toolbox['print']['msg'] = 'printableversion';
1551 }
1552 if ( isset( $this->data['nav_urls']['permalink'] ) && $this->data['nav_urls']['permalink'] ) {
1553 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1554 if ( $toolbox['permalink']['href'] === '' ) {
1555 unset( $toolbox['permalink']['href'] );
1556 $toolbox['ispermalink']['tooltiponly'] = true;
1557 $toolbox['ispermalink']['id'] = 't-ispermalink';
1558 $toolbox['ispermalink']['msg'] = 'permalink';
1559 } else {
1560 $toolbox['permalink']['id'] = 't-permalink';
1561 }
1562 }
1563 if ( isset( $this->data['nav_urls']['info'] ) && $this->data['nav_urls']['info'] ) {
1564 $toolbox['info'] = $this->data['nav_urls']['info'];
1565 $toolbox['info']['id'] = 't-info';
1566 }
1567
1568 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1569 wfProfileOut( __METHOD__ );
1570 return $toolbox;
1571 }
1572
1573 /**
1574 * Create an array of personal tools items from the data in the quicktemplate
1575 * stored by SkinTemplate.
1576 * The resulting array is built according to a format intended to be passed
1577 * through makeListItem to generate the html.
1578 * This is in reality the same list as already stored in personal_urls
1579 * however it is reformatted so that you can just pass the individual items
1580 * to makeListItem instead of hardcoding the element creation boilerplate.
1581 * @return array
1582 */
1583 function getPersonalTools() {
1584 $personal_tools = array();
1585 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1586 # The class on a personal_urls item is meant to go on the <a> instead
1587 # of the <li> so we have to use a single item "links" array instead
1588 # of using most of the personal_url's keys directly.
1589 $ptool = array(
1590 'links' => array(
1591 array( 'single-id' => "pt-$key" ),
1592 ),
1593 'id' => "pt-$key",
1594 );
1595 if ( isset( $plink['active'] ) ) {
1596 $ptool['active'] = $plink['active'];
1597 }
1598 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1599 if ( isset( $plink[$k] ) ) {
1600 $ptool['links'][0][$k] = $plink[$k];
1601 }
1602 }
1603 $personal_tools[$key] = $ptool;
1604 }
1605 return $personal_tools;
1606 }
1607
1608 function getSidebar( $options = array() ) {
1609 // Force the rendering of the following portals
1610 $sidebar = $this->data['sidebar'];
1611 if ( !isset( $sidebar['SEARCH'] ) ) {
1612 $sidebar['SEARCH'] = true;
1613 }
1614 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1615 $sidebar['TOOLBOX'] = true;
1616 }
1617 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1618 $sidebar['LANGUAGES'] = true;
1619 }
1620
1621 if ( !isset( $options['search'] ) || $options['search'] !== true ) {
1622 unset( $sidebar['SEARCH'] );
1623 }
1624 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1625 unset( $sidebar['TOOLBOX'] );
1626 }
1627 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1628 unset( $sidebar['LANGUAGES'] );
1629 }
1630
1631 $boxes = array();
1632 foreach ( $sidebar as $boxName => $content ) {
1633 if ( $content === false ) {
1634 continue;
1635 }
1636 switch ( $boxName ) {
1637 case 'SEARCH':
1638 // Search is a special case, skins should custom implement this
1639 $boxes[$boxName] = array(
1640 'id' => 'p-search',
1641 'header' => $this->getMsg( 'search' )->text(),
1642 'generated' => false,
1643 'content' => true,
1644 );
1645 break;
1646 case 'TOOLBOX':
1647 $msgObj = $this->getMsg( 'toolbox' );
1648 $boxes[$boxName] = array(
1649 'id' => 'p-tb',
1650 'header' => $msgObj->exists() ? $msgObj->text() : 'toolbox',
1651 'generated' => false,
1652 'content' => $this->getToolbox(),
1653 );
1654 break;
1655 case 'LANGUAGES':
1656 if ( $this->data['language_urls'] ) {
1657 $msgObj = $this->getMsg( 'otherlanguages' );
1658 $boxes[$boxName] = array(
1659 'id' => 'p-lang',
1660 'header' => $msgObj->exists() ? $msgObj->text() : 'otherlanguages',
1661 'generated' => false,
1662 'content' => $this->data['language_urls'],
1663 );
1664 }
1665 break;
1666 default:
1667 $msgObj = $this->getMsg( $boxName );
1668 $boxes[$boxName] = array(
1669 'id' => "p-$boxName",
1670 'header' => $msgObj->exists() ? $msgObj->text() : $boxName,
1671 'generated' => true,
1672 'content' => $content,
1673 );
1674 break;
1675 }
1676 }
1677
1678 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1679 $hookContents = null;
1680 if ( isset( $boxes['TOOLBOX'] ) ) {
1681 ob_start();
1682 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1683 // can abort and avoid outputting double toolbox links
1684 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1685 $hookContents = ob_get_contents();
1686 ob_end_clean();
1687 if ( !trim( $hookContents ) ) {
1688 $hookContents = null;
1689 }
1690 }
1691 // END hack
1692
1693 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1694 foreach ( $boxes as $boxName => $box ) {
1695 if ( is_array( $box['content'] ) ) {
1696 $content = '<ul>';
1697 foreach ( $box['content'] as $key => $val ) {
1698 $content .= "\n " . $this->makeListItem( $key, $val );
1699 }
1700 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1701 if ( $hookContents ) {
1702 $content .= "\n $hookContents";
1703 }
1704 // END hack
1705 $content .= "\n</ul>\n";
1706 $boxes[$boxName]['content'] = $content;
1707 }
1708 }
1709 } else {
1710 if ( $hookContents ) {
1711 $boxes['TOOLBOXEND'] = array(
1712 'id' => 'p-toolboxend',
1713 'header' => $boxes['TOOLBOX']['header'],
1714 'generated' => false,
1715 'content' => "<ul>{$hookContents}</ul>",
1716 );
1717 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1718 $boxes2 = array();
1719 foreach ( $boxes as $key => $box ) {
1720 if ( $key === 'TOOLBOXEND' ) {
1721 continue;
1722 }
1723 $boxes2[$key] = $box;
1724 if ( $key === 'TOOLBOX' ) {
1725 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1726 }
1727 }
1728 $boxes = $boxes2;
1729 // END hack
1730 }
1731 }
1732
1733 return $boxes;
1734 }
1735
1736 /**
1737 * Makes a link, usually used by makeListItem to generate a link for an item
1738 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1739 *
1740 * @param string $key usually a key from the list you are generating this
1741 * link from.
1742 * @param array $item contains some of a specific set of keys.
1743 *
1744 * The text of the link will be generated either from the contents of the
1745 * "text" key in the $item array, if a "msg" key is present a message by
1746 * that name will be used, and if neither of those are set the $key will be
1747 * used as a message name.
1748 *
1749 * If a "href" key is not present makeLink will just output htmlescaped text.
1750 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1751 * for the link if present.
1752 *
1753 * If an "id" or "single-id" (if you don't want the actual id to be output
1754 * on the link) is present it will be used to generate a tooltip and
1755 * accesskey for the link.
1756 *
1757 * The keys "context" and "primary" are ignored; these keys are used
1758 * internally by skins and are not supposed to be included in the HTML
1759 * output.
1760 *
1761 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1762 *
1763 * @param array $options can be used to affect the output of a link.
1764 * Possible options are:
1765 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1766 * a link in. This should be an array of arrays containing a 'tag' and
1767 * optionally an 'attributes' key. If you only have one element you don't
1768 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1769 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1770 * for your options.
1771 * - 'link-class' key can be used to specify additional classes to apply
1772 * to all links.
1773 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1774 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1775 * any non-link will output a "<span>" instead of just text.
1776 *
1777 * @return string
1778 */
1779 function makeLink( $key, $item, $options = array() ) {
1780 if ( isset( $item['text'] ) ) {
1781 $text = $item['text'];
1782 } else {
1783 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
1784 }
1785
1786 $html = htmlspecialchars( $text );
1787
1788 if ( isset( $options['text-wrapper'] ) ) {
1789 $wrapper = $options['text-wrapper'];
1790 if ( isset( $wrapper['tag'] ) ) {
1791 $wrapper = array( $wrapper );
1792 }
1793 while ( count( $wrapper ) > 0 ) {
1794 $element = array_pop( $wrapper );
1795 $html = Html::rawElement( $element['tag'], isset( $element['attributes'] ) ? $element['attributes'] : null, $html );
1796 }
1797 }
1798
1799 if ( isset( $item['href'] ) || isset( $options['link-fallback'] ) ) {
1800 $attrs = $item;
1801 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1802 unset( $attrs[$k] );
1803 }
1804
1805 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1806 $item['single-id'] = $item['id'];
1807 }
1808 if ( isset( $item['single-id'] ) ) {
1809 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1810 $title = Linker::titleAttrib( $item['single-id'] );
1811 if ( $title !== false ) {
1812 $attrs['title'] = $title;
1813 }
1814 } else {
1815 $tip = Linker::tooltipAndAccesskeyAttribs( $item['single-id'] );
1816 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1817 $attrs['title'] = $tip['title'];
1818 }
1819 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1820 $attrs['accesskey'] = $tip['accesskey'];
1821 }
1822 }
1823 }
1824 if ( isset( $options['link-class'] ) ) {
1825 if ( isset( $attrs['class'] ) ) {
1826 $attrs['class'] .= " {$options['link-class']}";
1827 } else {
1828 $attrs['class'] = $options['link-class'];
1829 }
1830 }
1831 $html = Html::rawElement( isset( $attrs['href'] ) ? 'a' : $options['link-fallback'], $attrs, $html );
1832 }
1833
1834 return $html;
1835 }
1836
1837 /**
1838 * Generates a list item for a navigation, portlet, portal, sidebar... list
1839 *
1840 * @param $key string, usually a key from the list you are generating this link from.
1841 * @param $item array, of list item data containing some of a specific set of keys.
1842 * The "id" and "class" keys will be used as attributes for the list item,
1843 * if "active" contains a value of true a "active" class will also be appended to class.
1844 *
1845 * @param $options array
1846 *
1847 * If you want something other than a "<li>" you can pass a tag name such as
1848 * "tag" => "span" in the $options array to change the tag used.
1849 * link/content data for the list item may come in one of two forms
1850 * A "links" key may be used, in which case it should contain an array with
1851 * a list of links to include inside the list item, see makeLink for the
1852 * format of individual links array items.
1853 *
1854 * Otherwise the relevant keys from the list item $item array will be passed
1855 * to makeLink instead. Note however that "id" and "class" are used by the
1856 * list item directly so they will not be passed to makeLink
1857 * (however the link will still support a tooltip and accesskey from it)
1858 * If you need an id or class on a single link you should include a "links"
1859 * array with just one link item inside of it.
1860 * $options is also passed on to makeLink calls
1861 *
1862 * @return string
1863 */
1864 function makeListItem( $key, $item, $options = array() ) {
1865 if ( isset( $item['links'] ) ) {
1866 $html = '';
1867 foreach ( $item['links'] as $linkKey => $link ) {
1868 $html .= $this->makeLink( $linkKey, $link, $options );
1869 }
1870 } else {
1871 $link = $item;
1872 // These keys are used by makeListItem and shouldn't be passed on to the link
1873 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1874 unset( $link[$k] );
1875 }
1876 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1877 // The id goes on the <li> not on the <a> for single links
1878 // but makeSidebarLink still needs to know what id to use when
1879 // generating tooltips and accesskeys.
1880 $link['single-id'] = $item['id'];
1881 }
1882 $html = $this->makeLink( $key, $link, $options );
1883 }
1884
1885 $attrs = array();
1886 foreach ( array( 'id', 'class' ) as $attr ) {
1887 if ( isset( $item[$attr] ) ) {
1888 $attrs[$attr] = $item[$attr];
1889 }
1890 }
1891 if ( isset( $item['active'] ) && $item['active'] ) {
1892 if ( !isset( $attrs['class'] ) ) {
1893 $attrs['class'] = '';
1894 }
1895 $attrs['class'] .= ' active';
1896 $attrs['class'] = trim( $attrs['class'] );
1897 }
1898 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
1899 }
1900
1901 function makeSearchInput( $attrs = array() ) {
1902 $realAttrs = array(
1903 'type' => 'search',
1904 'name' => 'search',
1905 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1906 'value' => $this->get( 'search', '' ),
1907 );
1908 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1909 return Html::element( 'input', $realAttrs );
1910 }
1911
1912 function makeSearchButton( $mode, $attrs = array() ) {
1913 switch ( $mode ) {
1914 case 'go':
1915 case 'fulltext':
1916 $realAttrs = array(
1917 'type' => 'submit',
1918 'name' => $mode,
1919 'value' => $this->translator->translate(
1920 $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
1921 );
1922 $realAttrs = array_merge(
1923 $realAttrs,
1924 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
1925 $attrs
1926 );
1927 return Html::element( 'input', $realAttrs );
1928 case 'image':
1929 $buttonAttrs = array(
1930 'type' => 'submit',
1931 'name' => 'button',
1932 );
1933 $buttonAttrs = array_merge(
1934 $buttonAttrs,
1935 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1936 $attrs
1937 );
1938 unset( $buttonAttrs['src'] );
1939 unset( $buttonAttrs['alt'] );
1940 unset( $buttonAttrs['width'] );
1941 unset( $buttonAttrs['height'] );
1942 $imgAttrs = array(
1943 'src' => $attrs['src'],
1944 'alt' => isset( $attrs['alt'] )
1945 ? $attrs['alt']
1946 : $this->translator->translate( 'searchbutton' ),
1947 'width' => isset( $attrs['width'] ) ? $attrs['width'] : null,
1948 'height' => isset( $attrs['height'] ) ? $attrs['height'] : null,
1949 );
1950 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
1951 default:
1952 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1953 }
1954 }
1955
1956 /**
1957 * Returns an array of footerlinks trimmed down to only those footer links that
1958 * are valid.
1959 * If you pass "flat" as an option then the returned array will be a flat array
1960 * of footer icons instead of a key/value array of footerlinks arrays broken
1961 * up into categories.
1962 * @return array|mixed
1963 */
1964 function getFooterLinks( $option = null ) {
1965 $footerlinks = $this->get( 'footerlinks' );
1966
1967 // Reduce footer links down to only those which are being used
1968 $validFooterLinks = array();
1969 foreach ( $footerlinks as $category => $links ) {
1970 $validFooterLinks[$category] = array();
1971 foreach ( $links as $link ) {
1972 if ( isset( $this->data[$link] ) && $this->data[$link] ) {
1973 $validFooterLinks[$category][] = $link;
1974 }
1975 }
1976 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1977 unset( $validFooterLinks[$category] );
1978 }
1979 }
1980
1981 if ( $option == 'flat' ) {
1982 // fold footerlinks into a single array using a bit of trickery
1983 $validFooterLinks = call_user_func_array(
1984 'array_merge',
1985 array_values( $validFooterLinks )
1986 );
1987 }
1988
1989 return $validFooterLinks;
1990 }
1991
1992 /**
1993 * Returns an array of footer icons filtered down by options relevant to how
1994 * the skin wishes to display them.
1995 * If you pass "icononly" as the option all footer icons which do not have an
1996 * image icon set will be filtered out.
1997 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1998 * in the list of footer icons. This is mostly useful for skins which only
1999 * display the text from footericons instead of the images and don't want a
2000 * duplicate copyright statement because footerlinks already rendered one.
2001 * @return
2002 */
2003 function getFooterIcons( $option = null ) {
2004 // Generate additional footer icons
2005 $footericons = $this->get( 'footericons' );
2006
2007 if ( $option == 'icononly' ) {
2008 // Unset any icons which don't have an image
2009 foreach ( $footericons as &$footerIconsBlock ) {
2010 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
2011 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
2012 unset( $footerIconsBlock[$footerIconKey] );
2013 }
2014 }
2015 }
2016 // Redo removal of any empty blocks
2017 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
2018 if ( count( $footerIconsBlock ) <= 0 ) {
2019 unset( $footericons[$footerIconsKey] );
2020 }
2021 }
2022 } elseif ( $option == 'nocopyright' ) {
2023 unset( $footericons['copyright']['copyright'] );
2024 if ( count( $footericons['copyright'] ) <= 0 ) {
2025 unset( $footericons['copyright'] );
2026 }
2027 }
2028
2029 return $footericons;
2030 }
2031
2032 /**
2033 * Output the basic end-page trail including bottomscripts, reporttime, and
2034 * debug stuff. This should be called right before outputting the closing
2035 * body and html tags.
2036 */
2037 function printTrail() { ?>
2038 <?php echo MWDebug::getDebugHTML( $this->getSkin()->getContext() ); ?>
2039 <?php $this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?>
2040 <?php $this->html( 'reporttime' ) ?>
2041 <?php
2042 }
2043
2044 }