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