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