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