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