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