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