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