Merge "Add tests for WikiMap and WikiReference"
[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 || $this->showIPinHeader() ) {
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 if ( $this->showIPinHeader() ) {
664 $href = &$this->userpageUrlDetails['href'];
665 $personal_urls['anonuserpage'] = array(
666 'text' => $this->username,
667 'href' => $href,
668 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
669 'active' => ( $pageurl == $href )
670 );
671 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
672 $href = &$usertalkUrlDetails['href'];
673 $personal_urls['anontalk'] = array(
674 'text' => $this->msg( 'anontalk' )->text(),
675 'href' => $href,
676 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
677 'active' => ( $pageurl == $href )
678 );
679 }
680
681 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
682 $personal_urls['createaccount'] = $createaccount_url;
683 }
684
685 $personal_urls['login'] = $login_url;
686 }
687
688 Hooks::run( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
689 return $personal_urls;
690 }
691
692 /**
693 * Builds an array with tab definition
694 *
695 * @param Title $title Page Where the tab links to
696 * @param string|array $message Message key or an array of message keys (will fall back)
697 * @param bool $selected Display the tab as selected
698 * @param string $query Query string attached to tab URL
699 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
700 *
701 * @return array
702 */
703 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
704 $classes = array();
705 if ( $selected ) {
706 $classes[] = 'selected';
707 }
708 if ( $checkEdit && !$title->isKnown() ) {
709 $classes[] = 'new';
710 if ( $query !== '' ) {
711 $query = 'action=edit&redlink=1&' . $query;
712 } else {
713 $query = 'action=edit&redlink=1';
714 }
715 }
716
717 // wfMessageFallback will nicely accept $message as an array of fallbacks
718 // or just a single key
719 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
720 if ( is_array( $message ) ) {
721 // for hook compatibility just keep the last message name
722 $message = end( $message );
723 }
724 if ( $msg->exists() ) {
725 $text = $msg->text();
726 } else {
727 global $wgContLang;
728 $text = $wgContLang->getConverter()->convertNamespace(
729 MWNamespace::getSubject( $title->getNamespace() ) );
730 }
731
732 $result = array();
733 if ( !Hooks::run( 'SkinTemplateTabAction', array( &$this,
734 $title, $message, $selected, $checkEdit,
735 &$classes, &$query, &$text, &$result ) ) ) {
736 return $result;
737 }
738
739 return array(
740 'class' => implode( ' ', $classes ),
741 'text' => $text,
742 'href' => $title->getLocalURL( $query ),
743 'primary' => true );
744 }
745
746 function makeTalkUrlDetails( $name, $urlaction = '' ) {
747 $title = Title::newFromText( $name );
748 if ( !is_object( $title ) ) {
749 throw new MWException( __METHOD__ . " given invalid pagename $name" );
750 }
751 $title = $title->getTalkPage();
752 self::checkTitle( $title, $name );
753 return array(
754 'href' => $title->getLocalURL( $urlaction ),
755 'exists' => $title->isKnown(),
756 );
757 }
758
759 /**
760 * @todo is this even used?
761 */
762 function makeArticleUrlDetails( $name, $urlaction = '' ) {
763 $title = Title::newFromText( $name );
764 $title = $title->getSubjectPage();
765 self::checkTitle( $title, $name );
766 return array(
767 'href' => $title->getLocalURL( $urlaction ),
768 'exists' => $title->exists(),
769 );
770 }
771
772 /**
773 * a structured array of links usually used for the tabs in a skin
774 *
775 * There are 4 standard sections
776 * namespaces: Used for namespace tabs like special, page, and talk namespaces
777 * views: Used for primary page views like read, edit, history
778 * actions: Used for most extra page actions like deletion, protection, etc...
779 * variants: Used to list the language variants for the page
780 *
781 * Each section's value is a key/value array of links for that section.
782 * The links themselves have these common keys:
783 * - class: The css classes to apply to the tab
784 * - text: The text to display on the tab
785 * - href: The href for the tab to point to
786 * - rel: An optional rel= for the tab's link
787 * - redundant: If true the tab will be dropped in skins using content_actions
788 * this is useful for tabs like "Read" which only have meaning in skins that
789 * take special meaning from the grouped structure of content_navigation
790 *
791 * Views also have an extra key which can be used:
792 * - primary: If this is not true skins like vector may try to hide the tab
793 * when the user has limited space in their browser window
794 *
795 * content_navigation using code also expects these ids to be present on the
796 * links, however these are usually automatically generated by SkinTemplate
797 * itself and are not necessary when using a hook. The only things these may
798 * matter to are people modifying content_navigation after it's initial creation:
799 * - id: A "preferred" id, most skins are best off outputting this preferred
800 * id for best compatibility.
801 * - tooltiponly: This is set to true for some tabs in cases where the system
802 * believes that the accesskey should not be added to the tab.
803 *
804 * @return array
805 */
806 protected function buildContentNavigationUrls() {
807 global $wgDisableLangConversion;
808
809 // Display tabs for the relevant title rather than always the title itself
810 $title = $this->getRelevantTitle();
811 $onPage = $title->equals( $this->getTitle() );
812
813 $out = $this->getOutput();
814 $request = $this->getRequest();
815 $user = $this->getUser();
816
817 $content_navigation = array(
818 'namespaces' => array(),
819 'views' => array(),
820 'actions' => array(),
821 'variants' => array()
822 );
823
824 // parameters
825 $action = $request->getVal( 'action', 'view' );
826
827 $userCanRead = $title->quickUserCan( 'read', $user );
828
829 $preventActiveTabs = false;
830 Hooks::run( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
831
832 // Checks if page is some kind of content
833 if ( $title->canExist() ) {
834 // Gets page objects for the related namespaces
835 $subjectPage = $title->getSubjectPage();
836 $talkPage = $title->getTalkPage();
837
838 // Determines if this is a talk page
839 $isTalk = $title->isTalkPage();
840
841 // Generates XML IDs from namespace names
842 $subjectId = $title->getNamespaceKey( '' );
843
844 if ( $subjectId == 'main' ) {
845 $talkId = 'talk';
846 } else {
847 $talkId = "{$subjectId}_talk";
848 }
849
850 $skname = $this->skinname;
851
852 // Adds namespace links
853 $subjectMsg = array( "nstab-$subjectId" );
854 if ( $subjectPage->isMainPage() ) {
855 array_unshift( $subjectMsg, 'mainpage-nstab' );
856 }
857 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
858 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
859 );
860 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
861 $content_navigation['namespaces'][$talkId] = $this->tabAction(
862 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
863 );
864 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
865
866 if ( $userCanRead ) {
867 $isForeignFile = $title->inNamespace( NS_FILE ) && $this->canUseWikiPage() &&
868 $this->getWikiPage() instanceof WikiFilePage && !$this->getWikiPage()->isLocal();
869
870 // Adds view view link
871 if ( $title->exists() || $isForeignFile ) {
872 $content_navigation['views']['view'] = $this->tabAction(
873 $isTalk ? $talkPage : $subjectPage,
874 array( "$skname-view-view", 'view' ),
875 ( $onPage && ( $action == 'view' || $action == 'purge' ) ), '', true
876 );
877 // signal to hide this from simple content_actions
878 $content_navigation['views']['view']['redundant'] = true;
879 }
880
881 // If it is a non-local file, show a link to the file in its own repository
882 if ( $isForeignFile ) {
883 $file = $this->getWikiPage()->getFile();
884 $content_navigation['views']['view-foreign'] = array(
885 'class' => '',
886 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
887 setContext( $this->getContext() )->
888 params( $file->getRepo()->getDisplayName() )->text(),
889 'href' => $file->getDescriptionUrl(),
890 'primary' => false,
891 );
892 }
893
894 // Checks if user can edit the current page if it exists or create it otherwise
895 if ( $title->quickUserCan( 'edit', $user )
896 && ( $title->exists() || $title->quickUserCan( 'create', $user ) )
897 ) {
898 // Builds CSS class for talk page links
899 $isTalkClass = $isTalk ? ' istalk' : '';
900 // Whether the user is editing the page
901 $isEditing = $onPage && ( $action == 'edit' || $action == 'submit' );
902 // Whether to show the "Add a new section" tab
903 // Checks if this is a current rev of talk page and is not forced to be hidden
904 $showNewSection = !$out->forceHideNewSectionLink()
905 && ( ( $isTalk && $this->isRevisionCurrent() ) || $out->showNewSectionLink() );
906 $section = $request->getVal( 'section' );
907
908 if ( $title->exists()
909 || ( $title->getNamespace() == NS_MEDIAWIKI
910 && $title->getDefaultMessageText() !== false
911 )
912 ) {
913 $msgKey = $isForeignFile ? 'edit-local' : 'edit';
914 } else {
915 $msgKey = $isForeignFile ? 'create-local' : 'create';
916 }
917 $content_navigation['views']['edit'] = array(
918 'class' => ( $isEditing && ( $section !== 'new' || !$showNewSection )
919 ? 'selected'
920 : ''
921 ) . $isTalkClass,
922 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
923 ->setContext( $this->getContext() )->text(),
924 'href' => $title->getLocalURL( $this->editUrlOptions() ),
925 'primary' => !$isForeignFile, // don't collapse this in vector
926 );
927
928 // section link
929 if ( $showNewSection ) {
930 // Adds new section link
931 //$content_navigation['actions']['addsection']
932 $content_navigation['views']['addsection'] = array(
933 'class' => ( $isEditing && $section == 'new' ) ? 'selected' : false,
934 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
935 ->setContext( $this->getContext() )->text(),
936 'href' => $title->getLocalURL( 'action=edit&section=new' )
937 );
938 }
939 // Checks if the page has some kind of viewable content
940 } elseif ( $title->hasSourceText() ) {
941 // Adds view source view link
942 $content_navigation['views']['viewsource'] = array(
943 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
944 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
945 ->setContext( $this->getContext() )->text(),
946 'href' => $title->getLocalURL( $this->editUrlOptions() ),
947 'primary' => true, // don't collapse this in vector
948 );
949 }
950
951 // Checks if the page exists
952 if ( $title->exists() ) {
953 // Adds history view link
954 $content_navigation['views']['history'] = array(
955 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
956 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
957 ->setContext( $this->getContext() )->text(),
958 'href' => $title->getLocalURL( 'action=history' ),
959 );
960
961 if ( $title->quickUserCan( 'delete', $user ) ) {
962 $content_navigation['actions']['delete'] = array(
963 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
964 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
965 ->setContext( $this->getContext() )->text(),
966 'href' => $title->getLocalURL( 'action=delete' )
967 );
968 }
969
970 if ( $title->quickUserCan( 'move', $user ) ) {
971 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
972 $content_navigation['actions']['move'] = array(
973 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
974 'text' => wfMessageFallback( "$skname-action-move", 'move' )
975 ->setContext( $this->getContext() )->text(),
976 'href' => $moveTitle->getLocalURL()
977 );
978 }
979 } else {
980 // article doesn't exist or is deleted
981 if ( $user->isAllowed( 'deletedhistory' ) ) {
982 $n = $title->isDeleted();
983 if ( $n ) {
984 $undelTitle = SpecialPage::getTitleFor( 'Undelete', $title->getPrefixedDBkey() );
985 // If the user can't undelete but can view deleted
986 // history show them a "View .. deleted" tab instead.
987 $msgKey = $user->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
988 $content_navigation['actions']['undelete'] = array(
989 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
990 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
991 ->setContext( $this->getContext() )->numParams( $n )->text(),
992 'href' => $undelTitle->getLocalURL()
993 );
994 }
995 }
996 }
997
998 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
999 MWNamespace::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1000 ) {
1001 $mode = $title->isProtected() ? 'unprotect' : 'protect';
1002 $content_navigation['actions'][$mode] = array(
1003 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
1004 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1005 ->setContext( $this->getContext() )->text(),
1006 'href' => $title->getLocalURL( "action=$mode" )
1007 );
1008 }
1009
1010 // Checks if the user is logged in
1011 if ( $this->loggedin && $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1012 /**
1013 * The following actions use messages which, if made particular to
1014 * the any specific skins, would break the Ajax code which makes this
1015 * action happen entirely inline. OutputPage::getJSVars
1016 * defines a set of messages in a javascript object - and these
1017 * messages are assumed to be global for all skins. Without making
1018 * a change to that procedure these messages will have to remain as
1019 * the global versions.
1020 */
1021 $mode = $user->isWatched( $title ) ? 'unwatch' : 'watch';
1022 $token = WatchAction::getWatchToken( $title, $user, $mode );
1023 $content_navigation['actions'][$mode] = array(
1024 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
1025 // uses 'watch' or 'unwatch' message
1026 'text' => $this->msg( $mode )->text(),
1027 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1028 );
1029 }
1030 }
1031
1032 Hooks::run( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1033
1034 if ( $userCanRead && !$wgDisableLangConversion ) {
1035 $pageLang = $title->getPageLanguage();
1036 // Gets list of language variants
1037 $variants = $pageLang->getVariants();
1038 // Checks that language conversion is enabled and variants exist
1039 // And if it is not in the special namespace
1040 if ( count( $variants ) > 1 ) {
1041 // Gets preferred variant (note that user preference is
1042 // only possible for wiki content language variant)
1043 $preferred = $pageLang->getPreferredVariant();
1044 if ( Action::getActionName( $this ) === 'view' ) {
1045 $params = $request->getQueryValues();
1046 unset( $params['title'] );
1047 } else {
1048 $params = array();
1049 }
1050 // Loops over each variant
1051 foreach ( $variants as $code ) {
1052 // Gets variant name from language code
1053 $varname = $pageLang->getVariantname( $code );
1054 // Appends variant link
1055 $content_navigation['variants'][] = array(
1056 'class' => ( $code == $preferred ) ? 'selected' : false,
1057 'text' => $varname,
1058 'href' => $title->getLocalURL( array( 'variant' => $code ) + $params ),
1059 'lang' => wfBCP47( $code ),
1060 'hreflang' => wfBCP47( $code ),
1061 );
1062 }
1063 }
1064 }
1065 } else {
1066 // If it's not content, it's got to be a special page
1067 $content_navigation['namespaces']['special'] = array(
1068 'class' => 'selected',
1069 'text' => $this->msg( 'nstab-special' )->text(),
1070 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1071 'context' => 'subject'
1072 );
1073
1074 Hooks::run( 'SkinTemplateNavigation::SpecialPage',
1075 array( &$this, &$content_navigation ) );
1076 }
1077
1078 // Equiv to SkinTemplateContentActions
1079 Hooks::run( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1080
1081 // Setup xml ids and tooltip info
1082 foreach ( $content_navigation as $section => &$links ) {
1083 foreach ( $links as $key => &$link ) {
1084 $xmlID = $key;
1085 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1086 $xmlID = 'ca-nstab-' . $xmlID;
1087 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1088 $xmlID = 'ca-talk';
1089 $link['rel'] = 'discussion';
1090 } elseif ( $section == 'variants' ) {
1091 $xmlID = 'ca-varlang-' . $xmlID;
1092 } else {
1093 $xmlID = 'ca-' . $xmlID;
1094 }
1095 $link['id'] = $xmlID;
1096 }
1097 }
1098
1099 # We don't want to give the watch tab an accesskey if the
1100 # page is being edited, because that conflicts with the
1101 # accesskey on the watch checkbox. We also don't want to
1102 # give the edit tab an accesskey, because that's fairly
1103 # superfluous and conflicts with an accesskey (Ctrl-E) often
1104 # used for editing in Safari.
1105 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1106 if ( isset( $content_navigation['views']['edit'] ) ) {
1107 $content_navigation['views']['edit']['tooltiponly'] = true;
1108 }
1109 if ( isset( $content_navigation['actions']['watch'] ) ) {
1110 $content_navigation['actions']['watch']['tooltiponly'] = true;
1111 }
1112 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1113 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1114 }
1115 }
1116
1117 return $content_navigation;
1118 }
1119
1120 /**
1121 * an array of edit links by default used for the tabs
1122 * @param array $content_navigation
1123 * @return array
1124 */
1125 private function buildContentActionUrls( $content_navigation ) {
1126
1127 // content_actions has been replaced with content_navigation for backwards
1128 // compatibility and also for skins that just want simple tabs content_actions
1129 // is now built by flattening the content_navigation arrays into one
1130
1131 $content_actions = array();
1132
1133 foreach ( $content_navigation as $links ) {
1134 foreach ( $links as $key => $value ) {
1135 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1136 // Redundant tabs are dropped from content_actions
1137 continue;
1138 }
1139
1140 // content_actions used to have ids built using the "ca-$key" pattern
1141 // so the xmlID based id is much closer to the actual $key that we want
1142 // for that reason we'll just strip out the ca- if present and use
1143 // the latter potion of the "id" as the $key
1144 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1145 $key = substr( $value['id'], 3 );
1146 }
1147
1148 if ( isset( $content_actions[$key] ) ) {
1149 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening " .
1150 "content_navigation into content_actions.\n" );
1151 continue;
1152 }
1153
1154 $content_actions[$key] = $value;
1155 }
1156 }
1157
1158 return $content_actions;
1159 }
1160
1161 /**
1162 * build array of common navigation links
1163 * @return array
1164 */
1165 protected function buildNavUrls() {
1166 global $wgUploadNavigationUrl;
1167
1168 $out = $this->getOutput();
1169 $request = $this->getRequest();
1170
1171 $nav_urls = array();
1172 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
1173 if ( $wgUploadNavigationUrl ) {
1174 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1175 } elseif ( UploadBase::isEnabled() && UploadBase::isAllowed( $this->getUser() ) === true ) {
1176 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
1177 } else {
1178 $nav_urls['upload'] = false;
1179 }
1180 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
1181
1182 $nav_urls['print'] = false;
1183 $nav_urls['permalink'] = false;
1184 $nav_urls['info'] = false;
1185 $nav_urls['whatlinkshere'] = false;
1186 $nav_urls['recentchangeslinked'] = false;
1187 $nav_urls['contributions'] = false;
1188 $nav_urls['log'] = false;
1189 $nav_urls['blockip'] = false;
1190 $nav_urls['emailuser'] = false;
1191 $nav_urls['userrights'] = false;
1192
1193 // A print stylesheet is attached to all pages, but nobody ever
1194 // figures that out. :) Add a link...
1195 if ( !$out->isPrintable() && ( $out->isArticle() || $this->getTitle()->isSpecialPage() ) ) {
1196 $nav_urls['print'] = array(
1197 'text' => $this->msg( 'printableversion' )->text(),
1198 'href' => $this->getTitle()->getLocalURL(
1199 $request->appendQueryValue( 'printable', 'yes', true ) )
1200 );
1201 }
1202
1203 if ( $out->isArticle() ) {
1204 // Also add a "permalink" while we're at it
1205 $revid = $this->getRevisionId();
1206 if ( $revid ) {
1207 $nav_urls['permalink'] = array(
1208 'text' => $this->msg( 'permalink' )->text(),
1209 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1210 );
1211 }
1212
1213 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1214 Hooks::run( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1215 array( &$this, &$nav_urls, &$revid, &$revid ) );
1216 }
1217
1218 if ( $out->isArticleRelated() ) {
1219 $nav_urls['whatlinkshere'] = array(
1220 'href' => SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage )->getLocalURL()
1221 );
1222
1223 $nav_urls['info'] = array(
1224 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1225 'href' => $this->getTitle()->getLocalURL( "action=info" )
1226 );
1227
1228 if ( $this->getTitle()->exists() ) {
1229 $nav_urls['recentchangeslinked'] = array(
1230 'href' => SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage )->getLocalURL()
1231 );
1232 }
1233 }
1234
1235 $user = $this->getRelevantUser();
1236 if ( $user ) {
1237 $rootUser = $user->getName();
1238
1239 $nav_urls['contributions'] = array(
1240 'text' => $this->msg( 'contributions', $rootUser )->text(),
1241 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1242 );
1243
1244 $nav_urls['log'] = array(
1245 'href' => self::makeSpecialUrlSubpage( 'Log', $rootUser )
1246 );
1247
1248 if ( $this->getUser()->isAllowed( 'block' ) ) {
1249 $nav_urls['blockip'] = array(
1250 'text' => $this->msg( 'blockip', $rootUser )->text(),
1251 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1252 );
1253 }
1254
1255 if ( $this->showEmailUser( $user ) ) {
1256 $nav_urls['emailuser'] = array(
1257 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1258 );
1259 }
1260
1261 if ( !$user->isAnon() ) {
1262 $sur = new UserrightsPage;
1263 $sur->setContext( $this->getContext() );
1264 if ( $sur->userCanExecute( $this->getUser() ) ) {
1265 $nav_urls['userrights'] = array(
1266 'href' => self::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1267 );
1268 }
1269 }
1270 }
1271
1272 return $nav_urls;
1273 }
1274
1275 /**
1276 * Generate strings used for xml 'id' names
1277 * @return string
1278 */
1279 protected function getNameSpaceKey() {
1280 return $this->getTitle()->getNamespaceKey();
1281 }
1282 }