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