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