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