1328870da1980a3ed0b605815c016181401c5950
[lhc/web/wiklou.git] / includes / skins / SkinTemplate.php
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 /**
22 * Base class for template-based skins.
23 *
24 * Template-filler skin base class
25 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
26 * Based on Brion's smarty skin
27 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
28 *
29 * @todo Needs some serious refactoring into functions that correspond
30 * to the computations individual esi snippets need. Most importantly no body
31 * parsing for most of those of course.
32 *
33 * @ingroup Skins
34 */
35 class SkinTemplate extends Skin {
36 /**
37 * @var string Name of our skin, it probably needs to be all lower case.
38 * Child classes should override the default.
39 */
40 public $skinname = 'monobook';
41
42 /**
43 * @var string For QuickTemplate, the name of the subclass which will
44 * actually fill the template. Child classes should override the default.
45 */
46 public $template = 'QuickTemplate';
47
48 /**
49 * Add specific styles for this skin
50 *
51 * @param OutputPage $out
52 */
53 function setupSkinUserCss( OutputPage $out ) {
54 $moduleStyles = array(
55 'mediawiki.legacy.shared',
56 'mediawiki.legacy.commonPrint',
57 'mediawiki.sectionAnchor'
58 );
59 if ( $out->isSyndicated() ) {
60 $moduleStyles[] = 'mediawiki.feedlink';
61 }
62
63 // Deprecated since 1.26: Unconditional loading of mediawiki.ui.button
64 // on every page is deprecated. Express a dependency instead.
65 if ( strpos( $out->getHTML(), 'mw-ui-button' ) !== false ) {
66 $moduleStyles[] = 'mediawiki.ui.button';
67 }
68
69 $out->addModuleStyles( $moduleStyles );
70 }
71
72 /**
73 * Create the template engine object; we feed it a bunch of data
74 * and eventually it spits out some HTML. Should have interface
75 * roughly equivalent to PHPTAL 0.7.
76 *
77 * @param string $classname
78 * @param bool|string $repository Subdirectory where we keep template files
79 * @param bool|string $cache_dir
80 * @return QuickTemplate
81 * @private
82 */
83 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
84 return new $classname( $this->getConfig() );
85 }
86
87 /**
88 * Generates array of language links for the current page
89 *
90 * @return array
91 */
92 public function getLanguages() {
93 global $wgHideInterlanguageLinks;
94 if ( $wgHideInterlanguageLinks ) {
95 return array();
96 }
97
98 $userLang = $this->getLanguage();
99 $languageLinks = array();
100
101 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
102 $languageLinkParts = explode( ':', $languageLinkText, 2 );
103 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
104 unset( $languageLinkParts );
105
106 $languageLinkTitle = Title::newFromText( $languageLinkText );
107 if ( $languageLinkTitle ) {
108 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
109 $ilLangName = Language::fetchLanguageName( $ilInterwikiCode );
110
111 if ( strval( $ilLangName ) === '' ) {
112 $ilDisplayTextMsg = wfMessage( "interlanguage-link-$ilInterwikiCode" );
113 if ( !$ilDisplayTextMsg->isDisabled() ) {
114 // Use custom MW message for the display text
115 $ilLangName = $ilDisplayTextMsg->text();
116 } else {
117 // Last resort: fallback to the language link target
118 $ilLangName = $languageLinkText;
119 }
120 } else {
121 // Use the language autonym as display text
122 $ilLangName = $this->formatLanguageName( $ilLangName );
123 }
124
125 // CLDR extension or similar is required to localize the language name;
126 // otherwise we'll end up with the autonym again.
127 $ilLangLocalName = Language::fetchLanguageName(
128 $ilInterwikiCode,
129 $userLang->getCode()
130 );
131
132 $languageLinkTitleText = $languageLinkTitle->getText();
133 if ( $ilLangLocalName === '' ) {
134 $ilFriendlySiteName = wfMessage( "interlanguage-link-sitename-$ilInterwikiCode" );
135 if ( !$ilFriendlySiteName->isDisabled() ) {
136 if ( $languageLinkTitleText === '' ) {
137 $ilTitle = wfMessage(
138 'interlanguage-link-title-nonlangonly',
139 $ilFriendlySiteName->text()
140 )->text();
141 } else {
142 $ilTitle = wfMessage(
143 'interlanguage-link-title-nonlang',
144 $languageLinkTitleText,
145 $ilFriendlySiteName->text()
146 )->text();
147 }
148 } else {
149 // we have nothing friendly to put in the title, so fall back to
150 // displaying the interlanguage link itself in the title text
151 // (similar to what is done in page content)
152 $ilTitle = $languageLinkTitle->getInterwiki() .
153 ":$languageLinkTitleText";
154 }
155 } elseif ( $languageLinkTitleText === '' ) {
156 $ilTitle = wfMessage(
157 'interlanguage-link-title-langonly',
158 $ilLangLocalName
159 )->text();
160 } else {
161 $ilTitle = wfMessage(
162 'interlanguage-link-title',
163 $languageLinkTitleText,
164 $ilLangLocalName
165 )->text();
166 }
167
168 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
169 $languageLink = array(
170 'href' => $languageLinkTitle->getFullURL(),
171 'text' => $ilLangName,
172 'title' => $ilTitle,
173 'class' => $class,
174 'lang' => $ilInterwikiCodeBCP47,
175 'hreflang' => $ilInterwikiCodeBCP47,
176 );
177 Hooks::run(
178 'SkinTemplateGetLanguageLink',
179 array( &$languageLink, $languageLinkTitle, $this->getTitle(), $this->getOutput() )
180 );
181 $languageLinks[] = $languageLink;
182 }
183 }
184
185 return $languageLinks;
186 }
187
188 protected function setupTemplateForOutput() {
189
190 $request = $this->getRequest();
191 $user = $this->getUser();
192 $title = $this->getTitle();
193
194 $tpl = $this->setupTemplate( $this->template, 'skins' );
195
196 $this->thispage = $title->getPrefixedDBkey();
197 $this->titletxt = $title->getPrefixedText();
198 $this->userpage = $user->getUserPage()->getPrefixedText();
199 $query = array();
200 if ( !$request->wasPosted() ) {
201 $query = $request->getValues();
202 unset( $query['title'] );
203 unset( $query['returnto'] );
204 unset( $query['returntoquery'] );
205 }
206 $this->thisquery = wfArrayToCgi( $query );
207 $this->loggedin = $user->isLoggedIn();
208 $this->username = $user->getName();
209
210 if ( $this->loggedin ) {
211 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
212 } else {
213 # This won't be used in the standard skins, but we define it to preserve the interface
214 # To save time, we check for existence
215 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
216 }
217
218 return $tpl;
219 }
220
221 /**
222 * initialize various variables and generate the template
223 *
224 * @param OutputPage $out
225 */
226 function outputPage( OutputPage $out = null ) {
227 Profiler::instance()->setTemplated( true );
228
229 $oldContext = null;
230 if ( $out !== null ) {
231 // Deprecated since 1.20, note added in 1.25
232 wfDeprecated( __METHOD__, '1.25' );
233 $oldContext = $this->getContext();
234 $this->setContext( $out->getContext() );
235 }
236
237 $out = $this->getOutput();
238
239 $this->initPage( $out );
240 $tpl = $this->prepareQuickTemplate( $out );
241 // execute template
242 $res = $tpl->execute();
243
244 // result may be an error
245 $this->printOrError( $res );
246
247 if ( $oldContext ) {
248 $this->setContext( $oldContext );
249 }
250
251 }
252
253 /**
254 * initialize various variables and generate the template
255 *
256 * @since 1.23
257 * @return QuickTemplate The template to be executed by outputPage
258 */
259 protected function prepareQuickTemplate() {
260 global $wgContLang, $wgScript, $wgStylePath, $wgMimeType, $wgJsMimeType,
261 $wgSitename, $wgLogo, $wgMaxCredits,
262 $wgShowCreditsIfMax, $wgArticlePath,
263 $wgScriptPath, $wgServer;
264
265 $title = $this->getTitle();
266 $request = $this->getRequest();
267 $out = $this->getOutput();
268 $tpl = $this->setupTemplateForOutput();
269
270 $tpl->set( 'title', $out->getPageTitle() );
271 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
272 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
273
274 $tpl->setRef( 'thispage', $this->thispage );
275 $tpl->setRef( 'titleprefixeddbkey', $this->thispage );
276 $tpl->set( 'titletext', $title->getText() );
277 $tpl->set( 'articleid', $title->getArticleID() );
278
279 $tpl->set( 'isarticle', $out->isArticle() );
280
281 $subpagestr = $this->subPageSubtitle();
282 if ( $subpagestr !== '' ) {
283 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
284 }
285 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
286
287 $undelete = $this->getUndeleteLink();
288 if ( $undelete === '' ) {
289 $tpl->set( 'undelete', '' );
290 } else {
291 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
292 }
293
294 $tpl->set( 'catlinks', $this->getCategories() );
295 if ( $out->isSyndicated() ) {
296 $feeds = array();
297 foreach ( $out->getSyndicationLinks() as $format => $link ) {
298 $feeds[$format] = array(
299 // Messages: feed-atom, feed-rss
300 'text' => $this->msg( "feed-$format" )->text(),
301 'href' => $link
302 );
303 }
304 $tpl->setRef( 'feeds', $feeds );
305 } else {
306 $tpl->set( 'feeds', false );
307 }
308
309 $tpl->setRef( 'mimetype', $wgMimeType );
310 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
311 $tpl->set( 'charset', 'UTF-8' );
312 $tpl->setRef( 'wgScript', $wgScript );
313 $tpl->setRef( 'skinname', $this->skinname );
314 $tpl->set( 'skinclass', get_class( $this ) );
315 $tpl->setRef( 'skin', $this );
316 $tpl->setRef( 'stylename', $this->stylename );
317 $tpl->set( 'printable', $out->isPrintable() );
318 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
319 $tpl->setRef( 'loggedin', $this->loggedin );
320 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
321 $tpl->set( 'searchaction', $this->escapeSearchLink() );
322 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey() );
323 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
324 $tpl->setRef( 'stylepath', $wgStylePath );
325 $tpl->setRef( 'articlepath', $wgArticlePath );
326 $tpl->setRef( 'scriptpath', $wgScriptPath );
327 $tpl->setRef( 'serverurl', $wgServer );
328 $tpl->setRef( 'logopath', $wgLogo );
329 $tpl->setRef( 'sitename', $wgSitename );
330
331 $userLang = $this->getLanguage();
332 $userLangCode = $userLang->getHtmlCode();
333 $userLangDir = $userLang->getDir();
334
335 $tpl->set( 'lang', $userLangCode );
336 $tpl->set( 'dir', $userLangDir );
337 $tpl->set( 'rtl', $userLang->isRTL() );
338
339 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
340 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
341 $tpl->set( 'username', $this->loggedin ? $this->username : null );
342 $tpl->setRef( 'userpage', $this->userpage );
343 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
344 $tpl->set( 'userlang', $userLangCode );
345
346 // Users can have their language set differently than the
347 // content of the wiki. For these users, tell the web browser
348 // that interface elements are in a different language.
349 $tpl->set( 'userlangattributes', '' );
350 $tpl->set( 'specialpageattributes', '' ); # obsolete
351 // Used by VectorBeta to insert HTML before content but after the
352 // heading for the page title. Defaults to empty string.
353 $tpl->set( 'prebodyhtml', '' );
354
355 if ( $userLangCode !== $wgContLang->getHtmlCode() || $userLangDir !== $wgContLang->getDir() ) {
356 $escUserlang = htmlspecialchars( $userLangCode );
357 $escUserdir = htmlspecialchars( $userLangDir );
358 // Attributes must be in double quotes because htmlspecialchars() doesn't
359 // escape single quotes
360 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
361 $tpl->set( 'userlangattributes', $attrs );
362 }
363
364 $tpl->set( 'newtalk', $this->getNewtalks() );
365 $tpl->set( 'logo', $this->logoText() );
366
367 $tpl->set( 'copyright', false );
368 // No longer used
369 $tpl->set( 'viewcount', false );
370 $tpl->set( 'lastmod', false );
371 $tpl->set( 'credits', false );
372 $tpl->set( 'numberofwatchingusers', false );
373 if ( $out->isArticle() && $title->exists() ) {
374 if ( $this->isRevisionCurrent() ) {
375 if ( $wgMaxCredits != 0 ) {
376 $tpl->set( 'credits', Action::factory( 'credits', $this->getWikiPage(),
377 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
378 } else {
379 $tpl->set( 'lastmod', $this->lastModified() );
380 }
381 }
382 $tpl->set( 'copyright', $this->getCopyright() );
383 }
384
385 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
386 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
387 $tpl->set( 'disclaimer', $this->disclaimerLink() );
388 $tpl->set( 'privacy', $this->privacyLink() );
389 $tpl->set( 'about', $this->aboutLink() );
390
391 $tpl->set( 'footerlinks', array(
392 'info' => array(
393 'lastmod',
394 'numberofwatchingusers',
395 'credits',
396 'copyright',
397 ),
398 'places' => array(
399 'privacy',
400 'about',
401 'disclaimer',
402 ),
403 ) );
404
405 global $wgFooterIcons;
406 $tpl->set( 'footericons', $wgFooterIcons );
407 foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
408 if ( count( $footerIconsBlock ) > 0 ) {
409 foreach ( $footerIconsBlock as &$footerIcon ) {
410 if ( isset( $footerIcon['src'] ) ) {
411 if ( !isset( $footerIcon['width'] ) ) {
412 $footerIcon['width'] = 88;
413 }
414 if ( !isset( $footerIcon['height'] ) ) {
415 $footerIcon['height'] = 31;
416 }
417 }
418 }
419 } else {
420 unset( $tpl->data['footericons'][$footerIconsKey] );
421 }
422 }
423
424 $tpl->set( 'indicators', $out->getIndicators() );
425
426 $tpl->set( 'sitenotice', $this->getSiteNotice() );
427 $tpl->set( 'bottomscripts', $this->bottomScripts() );
428 $tpl->set( 'printfooter', $this->printSource() );
429
430 # An ID that includes the actual body text; without categories, contentSub, ...
431 $realBodyAttribs = array( 'id' => 'mw-content-text' );
432
433 # Add a mw-content-ltr/rtl class to be able to style based on text direction
434 # when the content is different from the UI language, i.e.:
435 # not for special pages or file pages AND only when viewing
436 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) &&
437 Action::getActionName( $this ) === 'view' ) {
438 $pageLang = $title->getPageViewLanguage();
439 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
440 $realBodyAttribs['dir'] = $pageLang->getDir();
441 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
442 }
443
444 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
445 $tpl->setRef( 'bodytext', $out->mBodytext );
446
447 $language_urls = $this->getLanguages();
448 if ( count( $language_urls ) ) {
449 $tpl->setRef( 'language_urls', $language_urls );
450 } else {
451 $tpl->set( 'language_urls', false );
452 }
453
454 # Personal toolbar
455 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
456 $content_navigation = $this->buildContentNavigationUrls();
457 $content_actions = $this->buildContentActionUrls( $content_navigation );
458 $tpl->setRef( 'content_navigation', $content_navigation );
459 $tpl->setRef( 'content_actions', $content_actions );
460
461 $tpl->set( 'sidebar', $this->buildSidebar() );
462 $tpl->set( 'nav_urls', $this->buildNavUrls() );
463
464 // Set the head scripts near the end, in case the above actions resulted in added scripts
465 $tpl->set( 'headelement', $out->headElement( $this ) );
466
467 $tpl->set( 'debug', '' );
468 $tpl->set( 'debughtml', $this->generateDebugHTML() );
469 $tpl->set( 'reporttime', wfReportTime() );
470
471 // original version by hansm
472 if ( !Hooks::run( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
473 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
474 }
475
476 // Set the bodytext to another key so that skins can just output it on its own
477 // and output printfooter and debughtml separately
478 $tpl->set( 'bodycontent', $tpl->data['bodytext'] );
479
480 // Append printfooter and debughtml onto bodytext so that skins that
481 // were already using bodytext before they were split out don't suddenly
482 // start not outputting information.
483 $tpl->data['bodytext'] .= Html::rawElement(
484 'div',
485 array( 'class' => 'printfooter' ),
486 "\n{$tpl->data['printfooter']}"
487 ) . "\n";
488 $tpl->data['bodytext'] .= $tpl->data['debughtml'];
489
490 // allow extensions adding stuff after the page content.
491 // See Skin::afterContentHook() for further documentation.
492 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
493
494 return $tpl;
495 }
496
497 /**
498 * Get the HTML for the p-personal list
499 * @return string
500 */
501 public function getPersonalToolsList() {
502 $tpl = $this->setupTemplateForOutput();
503 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
504 $html = '';
505 foreach ( $tpl->getPersonalTools() as $key => $item ) {
506 $html .= $tpl->makeListItem( $key, $item );
507 }
508 return $html;
509 }
510
511 /**
512 * Format language name for use in sidebar interlanguage links list.
513 * By default it is capitalized.
514 *
515 * @param string $name Language name, e.g. "English" or "español"
516 * @return string
517 * @private
518 */
519 function formatLanguageName( $name ) {
520 return $this->getLanguage()->ucfirst( $name );
521 }
522
523 /**
524 * Output the string, or print error message if it's
525 * an error object of the appropriate type.
526 * For the base class, assume strings all around.
527 *
528 * @param string $str
529 * @private
530 */
531 function printOrError( $str ) {
532 echo $str;
533 }
534
535 /**
536 * Output a boolean indicating if buildPersonalUrls should output separate
537 * login and create account links or output a combined link
538 * By default we simply return a global config setting that affects most skins
539 * This is setup as a method so that like with $wgLogo and getLogo() a skin
540 * can override this setting and always output one or the other if it has
541 * a reason it can't output one of the two modes.
542 * @return bool
543 */
544 function useCombinedLoginLink() {
545 global $wgUseCombinedLoginLink;
546 return $wgUseCombinedLoginLink;
547 }
548
549 /**
550 * build array of urls for personal toolbar
551 * @return array
552 */
553 protected function buildPersonalUrls() {
554 $title = $this->getTitle();
555 $request = $this->getRequest();
556 $pageurl = $title->getLocalURL();
557
558 /* set up the default links for the personal toolbar */
559 $personal_urls = array();
560
561 # Due to bug 32276, if a user does not have read permissions,
562 # $this->getTitle() will just give Special:Badtitle, which is
563 # not especially useful as a returnto parameter. Use the title
564 # from the request instead, if there was one.
565 if ( $this->getUser()->isAllowed( 'read' ) ) {
566 $page = $this->getTitle();
567 } else {
568 $page = Title::newFromText( $request->getVal( 'title', '' ) );
569 }
570 $page = $request->getVal( 'returnto', $page );
571 $a = array();
572 if ( strval( $page ) !== '' ) {
573 $a['returnto'] = $page;
574 $query = $request->getVal( 'returntoquery', $this->thisquery );
575 if ( $query != '' ) {
576 $a['returntoquery'] = $query;
577 }
578 }
579
580 $returnto = wfArrayToCgi( $a );
581 if ( $this->loggedin ) {
582 $personal_urls['userpage'] = array(
583 'text' => $this->username,
584 'href' => &$this->userpageUrlDetails['href'],
585 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
586 'active' => ( $this->userpageUrlDetails['href'] == $pageurl ),
587 'dir' => 'auto'
588 );
589 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
590 $personal_urls['mytalk'] = array(
591 'text' => $this->msg( 'mytalk' )->text(),
592 'href' => &$usertalkUrlDetails['href'],
593 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
594 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
595 );
596 $href = self::makeSpecialUrl( 'Preferences' );
597 $personal_urls['preferences'] = array(
598 'text' => $this->msg( 'mypreferences' )->text(),
599 'href' => $href,
600 'active' => ( $href == $pageurl )
601 );
602
603 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
604 $href = self::makeSpecialUrl( 'Watchlist' );
605 $personal_urls['watchlist'] = array(
606 'text' => $this->msg( 'mywatchlist' )->text(),
607 'href' => $href,
608 'active' => ( $href == $pageurl )
609 );
610 }
611
612 # We need to do an explicit check for Special:Contributions, as we
613 # have to match both the title, and the target, which could come
614 # from request values (Special:Contributions?target=Jimbo_Wales)
615 # or be specified in "sub page" form
616 # (Special:Contributions/Jimbo_Wales). The plot
617 # thickens, because the Title object is altered for special pages,
618 # so it doesn't contain the original alias-with-subpage.
619 $origTitle = Title::newFromText( $request->getText( 'title' ) );
620 if ( $origTitle instanceof Title && $origTitle->isSpecialPage() ) {
621 list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
622 $active = $spName == 'Contributions'
623 && ( ( $spPar && $spPar == $this->username )
624 || $request->getText( 'target' ) == $this->username );
625 } else {
626 $active = false;
627 }
628
629 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
630 $personal_urls['mycontris'] = array(
631 'text' => $this->msg( 'mycontris' )->text(),
632 'href' => $href,
633 'active' => $active
634 );
635 $personal_urls['logout'] = array(
636 'text' => $this->msg( 'pt-userlogout' )->text(),
637 'href' => self::makeSpecialUrl( 'Userlogout',
638 // userlogout link must always contain an & character, otherwise we might not be able
639 // to detect a buggy precaching proxy (bug 17790)
640 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto
641 ),
642 'active' => false
643 );
644 } else {
645 $useCombinedLoginLink = $this->useCombinedLoginLink();
646 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
647 ? 'nav-login-createaccount'
648 : 'pt-login';
649 $is_signup = $request->getText( 'type' ) == 'signup';
650
651 $login_url = array(
652 'text' => $this->msg( $loginlink )->text(),
653 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
654 'active' => $title->isSpecial( 'Userlogin' )
655 && ( $loginlink == 'nav-login-createaccount' || !$is_signup ),
656 );
657 $createaccount_url = array(
658 'text' => $this->msg( 'pt-createaccount' )->text(),
659 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
660 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
661 );
662
663 // No need to show Talk and Contributions to anons if they can't contribute!
664 if ( User::groupHasPermission( '*', 'edit' ) ) {
665 // Show the text "Not logged in"
666 $personal_urls['anonuserpage'] = array(
667 'text' => $this->msg( 'notloggedin' )->text()
668 );
669
670 // Because of caching, we can't link directly to the IP talk and
671 // contributions pages. Instead we use the special page shortcuts
672 // (which work correctly regardless of caching). This means we can't
673 // determine whether these links are active or not, but since major
674 // skins (MonoBook, Vector) don't use this information, it's not a
675 // huge loss.
676 $personal_urls['anontalk'] = array(
677 'text' => $this->msg( 'anontalk' )->text(),
678 'href' => self::makeSpecialUrlSubpage( 'Mytalk', false ),
679 'active' => false
680 );
681 $personal_urls['anoncontribs'] = array(
682 'text' => $this->msg( 'anoncontribs' )->text(),
683 'href' => self::makeSpecialUrlSubpage( 'Mycontributions', false ),
684 'active' => false
685 );
686 }
687
688 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
689 $personal_urls['createaccount'] = $createaccount_url;
690 }
691
692 $personal_urls['login'] = $login_url;
693 }
694
695 Hooks::run( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
696 return $personal_urls;
697 }
698
699 /**
700 * Builds an array with tab definition
701 *
702 * @param Title $title Page Where the tab links to
703 * @param string|array $message Message key or an array of message keys (will fall back)
704 * @param bool $selected Display the tab as selected
705 * @param string $query Query string attached to tab URL
706 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
707 *
708 * @return array
709 */
710 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
711 $classes = array();
712 if ( $selected ) {
713 $classes[] = 'selected';
714 }
715 if ( $checkEdit && !$title->isKnown() ) {
716 $classes[] = 'new';
717 if ( $query !== '' ) {
718 $query = 'action=edit&redlink=1&' . $query;
719 } else {
720 $query = 'action=edit&redlink=1';
721 }
722 }
723
724 // wfMessageFallback will nicely accept $message as an array of fallbacks
725 // or just a single key
726 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
727 if ( is_array( $message ) ) {
728 // for hook compatibility just keep the last message name
729 $message = end( $message );
730 }
731 if ( $msg->exists() ) {
732 $text = $msg->text();
733 } else {
734 global $wgContLang;
735 $text = $wgContLang->getConverter()->convertNamespace(
736 MWNamespace::getSubject( $title->getNamespace() ) );
737 }
738
739 $result = array();
740 if ( !Hooks::run( 'SkinTemplateTabAction', array( &$this,
741 $title, $message, $selected, $checkEdit,
742 &$classes, &$query, &$text, &$result ) ) ) {
743 return $result;
744 }
745
746 return array(
747 'class' => implode( ' ', $classes ),
748 'text' => $text,
749 'href' => $title->getLocalURL( $query ),
750 'primary' => true );
751 }
752
753 function makeTalkUrlDetails( $name, $urlaction = '' ) {
754 $title = Title::newFromText( $name );
755 if ( !is_object( $title ) ) {
756 throw new MWException( __METHOD__ . " given invalid pagename $name" );
757 }
758 $title = $title->getTalkPage();
759 self::checkTitle( $title, $name );
760 return array(
761 'href' => $title->getLocalURL( $urlaction ),
762 'exists' => $title->isKnown(),
763 );
764 }
765
766 /**
767 * @todo is this even used?
768 */
769 function makeArticleUrlDetails( $name, $urlaction = '' ) {
770 $title = Title::newFromText( $name );
771 $title = $title->getSubjectPage();
772 self::checkTitle( $title, $name );
773 return array(
774 'href' => $title->getLocalURL( $urlaction ),
775 'exists' => $title->exists(),
776 );
777 }
778
779 /**
780 * a structured array of links usually used for the tabs in a skin
781 *
782 * There are 4 standard sections
783 * namespaces: Used for namespace tabs like special, page, and talk namespaces
784 * views: Used for primary page views like read, edit, history
785 * actions: Used for most extra page actions like deletion, protection, etc...
786 * variants: Used to list the language variants for the page
787 *
788 * Each section's value is a key/value array of links for that section.
789 * The links themselves have these common keys:
790 * - class: The css classes to apply to the tab
791 * - text: The text to display on the tab
792 * - href: The href for the tab to point to
793 * - rel: An optional rel= for the tab's link
794 * - redundant: If true the tab will be dropped in skins using content_actions
795 * this is useful for tabs like "Read" which only have meaning in skins that
796 * take special meaning from the grouped structure of content_navigation
797 *
798 * Views also have an extra key which can be used:
799 * - primary: If this is not true skins like vector may try to hide the tab
800 * when the user has limited space in their browser window
801 *
802 * content_navigation using code also expects these ids to be present on the
803 * links, however these are usually automatically generated by SkinTemplate
804 * itself and are not necessary when using a hook. The only things these may
805 * matter to are people modifying content_navigation after it's initial creation:
806 * - id: A "preferred" id, most skins are best off outputting this preferred
807 * id for best compatibility.
808 * - tooltiponly: This is set to true for some tabs in cases where the system
809 * believes that the accesskey should not be added to the tab.
810 *
811 * @return array
812 */
813 protected function buildContentNavigationUrls() {
814 global $wgDisableLangConversion;
815
816 // Display tabs for the relevant title rather than always the title itself
817 $title = $this->getRelevantTitle();
818 $onPage = $title->equals( $this->getTitle() );
819
820 $out = $this->getOutput();
821 $request = $this->getRequest();
822 $user = $this->getUser();
823
824 $content_navigation = array(
825 'namespaces' => array(),
826 'views' => array(),
827 'actions' => array(),
828 'variants' => array()
829 );
830
831 // parameters
832 $action = $request->getVal( 'action', 'view' );
833
834 $userCanRead = $title->quickUserCan( 'read', $user );
835
836 $preventActiveTabs = false;
837 Hooks::run( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
838
839 // Checks if page is some kind of content
840 if ( $title->canExist() ) {
841 // Gets page objects for the related namespaces
842 $subjectPage = $title->getSubjectPage();
843 $talkPage = $title->getTalkPage();
844
845 // Determines if this is a talk page
846 $isTalk = $title->isTalkPage();
847
848 // Generates XML IDs from namespace names
849 $subjectId = $title->getNamespaceKey( '' );
850
851 if ( $subjectId == 'main' ) {
852 $talkId = 'talk';
853 } else {
854 $talkId = "{$subjectId}_talk";
855 }
856
857 $skname = $this->skinname;
858
859 // Adds namespace links
860 $subjectMsg = array( "nstab-$subjectId" );
861 if ( $subjectPage->isMainPage() ) {
862 array_unshift( $subjectMsg, 'mainpage-nstab' );
863 }
864 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
865 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
866 );
867 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
868 $content_navigation['namespaces'][$talkId] = $this->tabAction(
869 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
870 );
871 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
872
873 if ( $userCanRead ) {
874 $isForeignFile = $title->inNamespace( NS_FILE ) && $this->canUseWikiPage() &&
875 $this->getWikiPage() instanceof WikiFilePage && !$this->getWikiPage()->isLocal();
876
877 // Adds view view link
878 if ( $title->exists() || $isForeignFile ) {
879 $content_navigation['views']['view'] = $this->tabAction(
880 $isTalk ? $talkPage : $subjectPage,
881 array( "$skname-view-view", 'view' ),
882 ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true
883 );
884 // signal to hide this from simple content_actions
885 $content_navigation['views']['view']['redundant'] = true;
886 }
887
888 // If it is a non-local file, show a link to the file in its own repository
889 if ( $isForeignFile ) {
890 $file = $this->getWikiPage()->getFile();
891 $content_navigation['views']['view-foreign'] = array(
892 'class' => '',
893 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
894 setContext( $this->getContext() )->
895 params( $file->getRepo()->getDisplayName() )->text(),
896 'href' => $file->getDescriptionUrl(),
897 'primary' => false,
898 );
899 }
900
901 // Checks if user can edit the current page if it exists or create it otherwise
902 if ( $title->quickUserCan( 'edit', $user )
903 && ( $title->exists() || $title->quickUserCan( 'create', $user ) )
904 ) {
905 // Builds CSS class for talk page links
906 $isTalkClass = $isTalk ? ' istalk' : '';
907 // Whether the user is editing the page
908 $isEditing = $onPage && ( $action == 'edit' || $action == 'submit' );
909 // Whether to show the "Add a new section" tab
910 // Checks if this is a current rev of talk page and is not forced to be hidden
911 $showNewSection = !$out->forceHideNewSectionLink()
912 && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
913 $section = $request->getVal( 'section' );
914
915 if ( $title->exists()
916 || ( $title->getNamespace() == NS_MEDIAWIKI
917 && $title->getDefaultMessageText() !== false
918 )
919 ) {
920 $msgKey = $isForeignFile ? 'edit-local' : 'edit';
921 } else {
922 $msgKey = $isForeignFile ? 'create-local' : 'create';
923 }
924 $content_navigation['views']['edit'] = array(
925 'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection )
926 ? 'selected'
927 : ''
928 ) . $isTalkClass,
929 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
930 ->setContext( $this->getContext() )->text(),
931 'href' => $title->getLocalURL( $this->editUrlOptions() ),
932 'primary' => !$isForeignFile, // don't collapse this in vector
933 );
934
935 // section link
936 if ( $showNewSection ) {
937 // Adds new section link
938 // $content_navigation['actions']['addsection']
939 $content_navigation['views']['addsection'] = array(
940 'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false,
941 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
942 ->setContext( $this->getContext() )->text(),
943 'href' => $title->getLocalURL( 'action=edit&section=new' )
944 );
945 }
946 // Checks if the page has some kind of viewable content
947 } elseif ( $title->hasSourceText() ) {
948 // Adds view source view link
949 $content_navigation['views']['viewsource'] = array(
950 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
951 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
952 ->setContext( $this->getContext() )->text(),
953 'href' => $title->getLocalURL( $this->editUrlOptions() ),
954 'primary' => true, // don't collapse this in vector
955 );
956 }
957
958 // Checks if the page exists
959 if ( $title->exists() ) {
960 // Adds history view link
961 $content_navigation['views']['history'] = array(
962 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
963 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
964 ->setContext( $this->getContext() )->text(),
965 'href' => $title->getLocalURL( 'action=history' ),
966 );
967
968 if ( $title->quickUserCan( 'delete', $user ) ) {
969 $content_navigation['actions']['delete'] = array(
970 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
971 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
972 ->setContext( $this->getContext() )->text(),
973 'href' => $title->getLocalURL( 'action=delete' )
974 );
975 }
976
977 if ( $title->quickUserCan( 'move', $user ) ) {
978 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
979 $content_navigation['actions']['move'] = array(
980 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
981 'text' => wfMessageFallback( "$skname-action-move", 'move' )
982 ->setContext( $this->getContext() )->text(),
983 'href' => $moveTitle->getLocalURL()
984 );
985 }
986 } else {
987 // article doesn't exist or is deleted
988 if ( $user->isAllowed( 'deletedhistory' ) ) {
989 $n = $title->isDeleted();
990 if ( $n ) {
991 $undelTitle = SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
992 // If the user can't undelete but can view deleted
993 // history show them a "View .. deleted" tab instead.
994 $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
995 $content_navigation['actions']['undelete'] = array(
996 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
997 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
998 ->setContext( $this->getContext() )->numParams( $n )->text(),
999 'href' => $undelTitle->getLocalURL()
1000 );
1001 }
1002 }
1003 }
1004
1005 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1006 MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1007 ) {
1008 $mode = $title->isProtected() ? 'unprotect' : 'protect';
1009 $content_navigation['actions'][$mode] = array(
1010 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
1011 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1012 ->setContext( $this->getContext() )->text(),
1013 'href' => $title->getLocalURL( "action=$mode" )
1014 );
1015 }
1016
1017 // Checks if the user is logged in
1018 if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1019 /**
1020 * The following actions use messages which, if made particular to
1021 * the any specific skins, would break the Ajax code which makes this
1022 * action happen entirely inline. OutputPage::getJSVars
1023 * defines a set of messages in a javascript object - and these
1024 * messages are assumed to be global for all skins. Without making
1025 * a change to that procedure these messages will have to remain as
1026 * the global versions.
1027 */
1028 $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
1029 $content_navigation['actions'][$mode] = array(
1030 'class' => 'mw-watchlink ' . (
1031 $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : ''
1032 ),
1033 // uses 'watch' or 'unwatch' message
1034 'text' => $this->msg( $mode )->text(),
1035 'href' => $title->getLocalURL( array( 'action' => $mode ) )
1036 );
1037 }
1038 }
1039
1040 Hooks::run( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1041
1042 if ( $userCanRead && !$wgDisableLangConversion ) {
1043 $pageLang = $title->getPageLanguage();
1044 // Gets list of language variants
1045 $variants = $pageLang->getVariants();
1046 // Checks that language conversion is enabled and variants exist
1047 // And if it is not in the special namespace
1048 if ( count( $variants ) > 1 ) {
1049 // Gets preferred variant (note that user preference is
1050 // only possible for wiki content language variant)
1051 $preferred = $pageLang->getPreferredVariant();
1052 if ( Action::getActionName( $this ) === 'view' ) {
1053 $params = $request->getQueryValues();
1054 unset( $params['title'] );
1055 } else {
1056 $params = array();
1057 }
1058 // Loops over each variant
1059 foreach ( $variants as $code ) {
1060 // Gets variant name from language code
1061 $varname = $pageLang->getVariantname( $code );
1062 // Appends variant link
1063 $content_navigation['variants'][] = array(
1064 'class' => ( $code == $preferred ) ? 'selected' : false,
1065 'text' => $varname,
1066 'href' => $title->getLocalURL( array( 'variant' => $code ) + $params ),
1067 'lang' => wfBCP47( $code ),
1068 'hreflang' => wfBCP47( $code ),
1069 );
1070 }
1071 }
1072 }
1073 } else {
1074 // If it's not content, it's got to be a special page
1075 $content_navigation['namespaces']['special'] = array(
1076 'class' => 'selected',
1077 'text' => $this->msg( 'nstab-special' )->text(),
1078 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1079 'context' => 'subject'
1080 );
1081
1082 Hooks::run( 'SkinTemplateNavigation::SpecialPage',
1083 array( &$this, &$content_navigation ) );
1084 }
1085
1086 // Equiv to SkinTemplateContentActions
1087 Hooks::run( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1088
1089 // Setup xml ids and tooltip info
1090 foreach ( $content_navigation as $section => &$links ) {
1091 foreach ( $links as $key => &$link ) {
1092 $xmlID = $key;
1093 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1094 $xmlID = 'ca-nstab-' . $xmlID;
1095 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1096 $xmlID = 'ca-talk';
1097 $link['rel'] = 'discussion';
1098 } elseif ( $section == 'variants' ) {
1099 $xmlID = 'ca-varlang-' . $xmlID;
1100 } else {
1101 $xmlID = 'ca-' . $xmlID;
1102 }
1103 $link['id'] = $xmlID;
1104 }
1105 }
1106
1107 # We don't want to give the watch tab an accesskey if the
1108 # page is being edited, because that conflicts with the
1109 # accesskey on the watch checkbox. We also don't want to
1110 # give the edit tab an accesskey, because that's fairly
1111 # superfluous and conflicts with an accesskey (Ctrl-E) often
1112 # used for editing in Safari.
1113 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1114 if ( isset( $content_navigation['views']['edit'] ) ) {
1115 $content_navigation['views']['edit']['tooltiponly'] = true;
1116 }
1117 if ( isset( $content_navigation['actions']['watch'] ) ) {
1118 $content_navigation['actions']['watch']['tooltiponly'] = true;
1119 }
1120 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1121 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1122 }
1123 }
1124
1125 return $content_navigation;
1126 }
1127
1128 /**
1129 * an array of edit links by default used for the tabs
1130 * @param array $content_navigation
1131 * @return array
1132 */
1133 private function buildContentActionUrls( $content_navigation ) {
1134
1135 // content_actions has been replaced with content_navigation for backwards
1136 // compatibility and also for skins that just want simple tabs content_actions
1137 // is now built by flattening the content_navigation arrays into one
1138
1139 $content_actions = array();
1140
1141 foreach ( $content_navigation as $links ) {
1142 foreach ( $links as $key => $value ) {
1143 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1144 // Redundant tabs are dropped from content_actions
1145 continue;
1146 }
1147
1148 // content_actions used to have ids built using the "ca-$key" pattern
1149 // so the xmlID based id is much closer to the actual $key that we want
1150 // for that reason we'll just strip out the ca- if present and use
1151 // the latter potion of the "id" as the $key
1152 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1153 $key = substr( $value['id'], 3 );
1154 }
1155
1156 if ( isset( $content_actions[$key] ) ) {
1157 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening " .
1158 "content_navigation into content_actions.\n" );
1159 continue;
1160 }
1161
1162 $content_actions[$key] = $value;
1163 }
1164 }
1165
1166 return $content_actions;
1167 }
1168
1169 /**
1170 * build array of common navigation links
1171 * @return array
1172 */
1173 protected function buildNavUrls() {
1174 global $wgUploadNavigationUrl;
1175
1176 $out = $this->getOutput();
1177 $request = $this->getRequest();
1178
1179 $nav_urls = array();
1180 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
1181 if ( $wgUploadNavigationUrl ) {
1182 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1183 } elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
1184 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
1185 } else {
1186 $nav_urls['upload'] = false;
1187 }
1188 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
1189
1190 $nav_urls['print'] = false;
1191 $nav_urls['permalink'] = false;
1192 $nav_urls['info'] = false;
1193 $nav_urls['whatlinkshere'] = false;
1194 $nav_urls['recentchangeslinked'] = false;
1195 $nav_urls['contributions'] = false;
1196 $nav_urls['log'] = false;
1197 $nav_urls['blockip'] = false;
1198 $nav_urls['emailuser'] = false;
1199 $nav_urls['userrights'] = false;
1200
1201 // A print stylesheet is attached to all pages, but nobody ever
1202 // figures that out. :) Add a link...
1203 if ( !$out->isPrintable() && ( $out->isArticle() || $this->getTitle()->isSpecialPage() ) ) {
1204 $nav_urls['print'] = array(
1205 'text' => $this->msg( 'printableversion' )->text(),
1206 'href' => $this->getTitle()->getLocalURL(
1207 $request->appendQueryValue( 'printable', 'yes' ) )
1208 );
1209 }
1210
1211 if ( $out->isArticle() ) {
1212 // Also add a "permalink" while we're at it
1213 $revid = $this->getRevisionId();
1214 if ( $revid ) {
1215 $nav_urls['permalink'] = array(
1216 'text' => $this->msg( 'permalink' )->text(),
1217 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1218 );
1219 }
1220
1221 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1222 Hooks::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1223 array( &$this, &$nav_urls, &$revid, &$revid ) );
1224 }
1225
1226 if ( $out->isArticleRelated() ) {
1227 $nav_urls['whatlinkshere'] = array(
1228 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalURL()
1229 );
1230
1231 $nav_urls['info'] = array(
1232 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1233 'href' => $this->getTitle()->getLocalURL( "action=info" )
1234 );
1235
1236 if ( $this->getTitle()->exists() ) {
1237 $nav_urls['recentchangeslinked'] = array(
1238 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalURL()
1239 );
1240 }
1241 }
1242
1243 $user = $this->getRelevantUser();
1244 if ( $user ) {
1245 $rootUser = $user->getName();
1246
1247 $nav_urls['contributions'] = array(
1248 'text' => $this->msg( 'contributions', $rootUser )->text(),
1249 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser ),
1250 'tooltip-params' => array( $rootUser ),
1251 );
1252
1253 $nav_urls['log'] = array(
1254 'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser )
1255 );
1256
1257 if ( $this->getUser()->isAllowed( 'block' ) ) {
1258 $nav_urls['blockip'] = array(
1259 'text' => $this->msg( 'blockip', $rootUser )->text(),
1260 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1261 );
1262 }
1263
1264 if ( $this->showEmailUser( $user ) ) {
1265 $nav_urls['emailuser'] = array(
1266 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser ),
1267 'tooltip-params' => array( $rootUser ),
1268 );
1269 }
1270
1271 if ( !$user->isAnon() ) {
1272 $sur = new UserrightsPage;
1273 $sur->setContext( $this->getContext() );
1274 if ( $sur->userCanExecute( $this->getUser() ) ) {
1275 $nav_urls['userrights'] = array(
1276 'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1277 );
1278 }
1279 }
1280 }
1281
1282 return $nav_urls;
1283 }
1284
1285 /**
1286 * Generate strings used for xml 'id' names
1287 * @return string
1288 */
1289 protected function getNameSpaceKey() {
1290 return $this->getTitle()->getNamespaceKey();
1291 }
1292 }