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