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