3 * Base class for template-based skins.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * Wrapper object for MediaWiki's localization functions,
25 * to be passed to the template engine.
31 private $context = array();
33 function set( $varName, $value ) {
34 $this->context
[$varName] = $value;
37 function translate( $value ) {
38 wfProfileIn( __METHOD__
);
40 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
41 $value = preg_replace( '/^string:/', '', $value );
43 $value = wfMessage( $value )->text();
44 // interpolate variables
46 while ( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
47 list( $src, $var ) = $m;
49 $varValue = $this->context
[$var];
51 $value = str_replace( $src, $varValue, $value );
53 wfProfileOut( __METHOD__
);
59 * Template-filler skin base class
60 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
61 * Based on Brion's smarty skin
62 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
64 * @todo Needs some serious refactoring into functions that correspond
65 * to the computations individual esi snippets need. Most importantly no body
66 * parsing for most of those of course.
70 class SkinTemplate
extends Skin
{
72 * @var string Name of our skin, it probably needs to be all lower case.
73 * Child classes should override the default.
75 public $skinname = 'monobook';
78 * @var string Stylesheets set to use. Subdirectory in skins/ where various
79 * stylesheets are located. Child classes should override the default.
81 public $stylename = 'monobook';
84 * @var string For QuickTemplate, the name of the subclass which will
85 * actually fill the template. Child classes should override the default.
87 public $template = 'QuickTemplate';
90 * @var bool Whether this skin use OutputPage::headElement() to generate
93 public $useHeadElement = false;
96 * Add specific styles for this skin
98 * @param OutputPage $out
100 function setupSkinUserCss( OutputPage
$out ) {
101 $out->addModuleStyles( array(
102 'mediawiki.legacy.shared',
103 'mediawiki.legacy.commonPrint',
104 'mediawiki.ui.button'
109 * Create the template engine object; we feed it a bunch of data
110 * and eventually it spits out some HTML. Should have interface
111 * roughly equivalent to PHPTAL 0.7.
113 * @param string $classname
114 * @param string $repository Subdirectory where we keep template files
115 * @param string $cache_dir
116 * @return QuickTemplate
119 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
120 return new $classname();
124 * Generates array of language links for the current page
129 public function getLanguages() {
130 global $wgHideInterlanguageLinks;
131 if ( $wgHideInterlanguageLinks ) {
135 $userLang = $this->getLanguage();
136 $languageLinks = array();
138 foreach ( $this->getOutput()->getLanguageLinks() as $languageLinkText ) {
139 $languageLinkParts = explode( ':', $languageLinkText, 2 );
140 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
141 unset( $languageLinkParts );
143 $languageLinkTitle = Title
::newFromText( $languageLinkText );
144 if ( $languageLinkTitle ) {
145 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
146 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
148 if ( strval( $ilLangName ) === '' ) {
149 $ilLangName = $languageLinkText;
151 $ilLangName = $this->formatLanguageName( $ilLangName );
154 // CLDR extension or similar is required to localize the language name;
155 // otherwise we'll end up with the autonym again.
156 $ilLangLocalName = Language
::fetchLanguageName(
161 $languageLinkTitleText = $languageLinkTitle->getText();
162 if ( $languageLinkTitleText === '' ) {
163 $ilTitle = wfMessage(
164 'interlanguage-link-title-langonly',
168 $ilTitle = wfMessage(
169 'interlanguage-link-title',
170 $languageLinkTitleText,
175 $ilInterwikiCodeBCP47 = wfBCP47( $ilInterwikiCode );
176 $languageLink = array(
177 'href' => $languageLinkTitle->getFullURL(),
178 'text' => $ilLangName,
181 'lang' => $ilInterwikiCodeBCP47,
182 'hreflang' => $ilInterwikiCodeBCP47,
185 'SkinTemplateGetLanguageLink',
186 array( &$languageLink, $languageLinkTitle, $this->getTitle() )
188 $languageLinks[] = $languageLink;
192 return $languageLinks;
195 protected function setupTemplateForOutput() {
196 wfProfileIn( __METHOD__
);
198 $request = $this->getRequest();
199 $user = $this->getUser();
200 $title = $this->getTitle();
202 wfProfileIn( __METHOD__
. '-init' );
203 $tpl = $this->setupTemplate( $this->template
, 'skins' );
204 wfProfileOut( __METHOD__
. '-init' );
206 wfProfileIn( __METHOD__
. '-stuff' );
207 $this->thispage
= $title->getPrefixedDBkey();
208 $this->titletxt
= $title->getPrefixedText();
209 $this->userpage
= $user->getUserPage()->getPrefixedText();
211 if ( !$request->wasPosted() ) {
212 $query = $request->getValues();
213 unset( $query['title'] );
214 unset( $query['returnto'] );
215 unset( $query['returntoquery'] );
217 $this->thisquery
= wfArrayToCgi( $query );
218 $this->loggedin
= $user->isLoggedIn();
219 $this->username
= $user->getName();
221 if ( $this->loggedin ||
$this->showIPinHeader() ) {
222 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
224 # This won't be used in the standard skins, but we define it to preserve the interface
225 # To save time, we check for existence
226 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
229 wfProfileOut( __METHOD__
. '-stuff' );
231 wfProfileOut( __METHOD__
);
237 * initialize various variables and generate the template
239 * @param OutputPage $out
241 function outputPage( OutputPage
$out = null ) {
242 wfProfileIn( __METHOD__
);
243 Profiler
::instance()->setTemplated( true );
246 if ( $out !== null ) {
247 // @todo Add wfDeprecated in 1.20
248 $oldContext = $this->getContext();
249 $this->setContext( $out->getContext() );
252 $out = $this->getOutput();
254 wfProfileIn( __METHOD__
. '-init' );
255 $this->initPage( $out );
256 wfProfileOut( __METHOD__
. '-init' );
257 $tpl = $this->prepareQuickTemplate( $out );
259 wfProfileIn( __METHOD__
. '-execute' );
260 $res = $tpl->execute();
261 wfProfileOut( __METHOD__
. '-execute' );
263 // result may be an error
264 $this->printOrError( $res );
267 $this->setContext( $oldContext );
270 wfProfileOut( __METHOD__
);
274 * initialize various variables and generate the template
277 * @return QuickTemplate The template to be executed by outputPage
279 protected function prepareQuickTemplate() {
280 global $wgContLang, $wgScript, $wgStylePath,
281 $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
282 $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
283 $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
284 $wgScriptPath, $wgServer;
286 wfProfileIn( __METHOD__
);
288 $title = $this->getTitle();
289 $request = $this->getRequest();
290 $out = $this->getOutput();
291 $tpl = $this->setupTemplateForOutput();
293 wfProfileIn( __METHOD__
. '-stuff-head' );
294 if ( !$this->useHeadElement
) {
295 $tpl->set( 'pagecss', false );
296 $tpl->set( 'usercss', false );
298 $tpl->set( 'userjs', false );
299 $tpl->set( 'userjsprev', false );
301 $tpl->set( 'jsvarurl', false );
303 $tpl->set( 'xhtmldefaultnamespace', 'http://www.w3.org/1999/xhtml' );
304 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
305 $tpl->set( 'html5version', $wgHtml5Version );
306 $tpl->set( 'headlinks', $out->getHeadLinks() );
307 $tpl->set( 'csslinks', $out->buildCssLinks() );
308 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
309 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
311 wfProfileOut( __METHOD__
. '-stuff-head' );
313 wfProfileIn( __METHOD__
. '-stuff2' );
314 $tpl->set( 'title', $out->getPageTitle() );
315 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
316 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
318 $tpl->setRef( 'thispage', $this->thispage
);
319 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
320 $tpl->set( 'titletext', $title->getText() );
321 $tpl->set( 'articleid', $title->getArticleID() );
323 $tpl->set( 'isarticle', $out->isArticle() );
325 $subpagestr = $this->subPageSubtitle();
326 if ( $subpagestr !== '' ) {
327 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
329 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
331 $undelete = $this->getUndeleteLink();
332 if ( $undelete === '' ) {
333 $tpl->set( 'undelete', '' );
335 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
338 $tpl->set( 'catlinks', $this->getCategories() );
339 if ( $out->isSyndicated() ) {
341 foreach ( $out->getSyndicationLinks() as $format => $link ) {
342 $feeds[$format] = array(
343 // Messages: feed-atom, feed-rss
344 'text' => $this->msg( "feed-$format" )->text(),
348 $tpl->setRef( 'feeds', $feeds );
350 $tpl->set( 'feeds', false );
353 $tpl->setRef( 'mimetype', $wgMimeType );
354 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
355 $tpl->set( 'charset', 'UTF-8' );
356 $tpl->setRef( 'wgScript', $wgScript );
357 $tpl->setRef( 'skinname', $this->skinname
);
358 $tpl->set( 'skinclass', get_class( $this ) );
359 $tpl->setRef( 'skin', $this );
360 $tpl->setRef( 'stylename', $this->stylename
);
361 $tpl->set( 'printable', $out->isPrintable() );
362 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
363 $tpl->setRef( 'loggedin', $this->loggedin
);
364 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
365 /* XXX currently unused, might get useful later
366 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
367 $tpl->set( 'exists', $title->getArticleID() != 0 );
368 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
369 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
370 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
372 $tpl->set( 'searchaction', $this->escapeSearchLink() );
373 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
374 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
375 $tpl->setRef( 'stylepath', $wgStylePath );
376 $tpl->setRef( 'articlepath', $wgArticlePath );
377 $tpl->setRef( 'scriptpath', $wgScriptPath );
378 $tpl->setRef( 'serverurl', $wgServer );
379 $tpl->setRef( 'logopath', $wgLogo );
380 $tpl->setRef( 'sitename', $wgSitename );
382 $userLang = $this->getLanguage();
383 $userLangCode = $userLang->getHtmlCode();
384 $userLangDir = $userLang->getDir();
386 $tpl->set( 'lang', $userLangCode );
387 $tpl->set( 'dir', $userLangDir );
388 $tpl->set( 'rtl', $userLang->isRTL() );
390 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
391 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
392 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
393 $tpl->setRef( 'userpage', $this->userpage
);
394 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
395 $tpl->set( 'userlang', $userLangCode );
397 // Users can have their language set differently than the
398 // content of the wiki. For these users, tell the web browser
399 // that interface elements are in a different language.
400 $tpl->set( 'userlangattributes', '' );
401 $tpl->set( 'specialpageattributes', '' ); # obsolete
402 // Used by VectorBeta to insert HTML before content but after the
403 // heading for the page title. Defaults to empty string.
404 $tpl->set( 'prebodyhtml', '' );
406 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
407 $escUserlang = htmlspecialchars( $userLangCode );
408 $escUserdir = htmlspecialchars( $userLangDir );
409 // Attributes must be in double quotes because htmlspecialchars() doesn't
410 // escape single quotes
411 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
412 $tpl->set( 'userlangattributes', $attrs );
415 wfProfileOut( __METHOD__
. '-stuff2' );
417 wfProfileIn( __METHOD__
. '-stuff3' );
418 $tpl->set( 'newtalk', $this->getNewtalks() );
419 $tpl->set( 'logo', $this->logoText() );
421 $tpl->set( 'copyright', false );
422 $tpl->set( 'viewcount', false );
423 $tpl->set( 'lastmod', false );
424 $tpl->set( 'credits', false );
425 $tpl->set( 'numberofwatchingusers', false );
426 if ( $out->isArticle() && $title->exists() ) {
427 if ( $this->isRevisionCurrent() ) {
428 if ( !$wgDisableCounters ) {
429 $viewcount = $this->getWikiPage()->getCount();
431 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
435 if ( $wgPageShowWatchingUsers ) {
436 $dbr = wfGetDB( DB_SLAVE
);
437 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
438 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
442 $tpl->set( 'numberofwatchingusers',
443 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
448 if ( $wgMaxCredits != 0 ) {
449 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
450 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
452 $tpl->set( 'lastmod', $this->lastModified() );
455 $tpl->set( 'copyright', $this->getCopyright() );
457 wfProfileOut( __METHOD__
. '-stuff3' );
459 wfProfileIn( __METHOD__
. '-stuff4' );
460 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
461 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
462 $tpl->set( 'disclaimer', $this->disclaimerLink() );
463 $tpl->set( 'privacy', $this->privacyLink() );
464 $tpl->set( 'about', $this->aboutLink() );
466 $tpl->set( 'footerlinks', array(
470 'numberofwatchingusers',
481 global $wgFooterIcons;
482 $tpl->set( 'footericons', $wgFooterIcons );
483 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
484 if ( count( $footerIconsBlock ) > 0 ) {
485 foreach ( $footerIconsBlock as &$footerIcon ) {
486 if ( isset( $footerIcon['src'] ) ) {
487 if ( !isset( $footerIcon['width'] ) ) {
488 $footerIcon['width'] = 88;
490 if ( !isset( $footerIcon['height'] ) ) {
491 $footerIcon['height'] = 31;
496 unset( $tpl->data
['footericons'][$footerIconsKey] );
500 $tpl->set( 'sitenotice', $this->getSiteNotice() );
501 $tpl->set( 'bottomscripts', $this->bottomScripts() );
502 $tpl->set( 'printfooter', $this->printSource() );
504 # An ID that includes the actual body text; without categories, contentSub, ...
505 $realBodyAttribs = array( 'id' => 'mw-content-text' );
507 # Add a mw-content-ltr/rtl class to be able to style based on text direction
508 # when the content is different from the UI language, i.e.:
509 # not for special pages or file pages AND only when viewing AND if the page exists
510 # (or is in MW namespace, because that has default content)
511 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
512 Action
::getActionName( $this ) === 'view' &&
513 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
514 $pageLang = $title->getPageViewLanguage();
515 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
516 $realBodyAttribs['dir'] = $pageLang->getDir();
517 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
520 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
521 $tpl->setRef( 'bodytext', $out->mBodytext
);
523 $language_urls = $this->getLanguages();
524 if ( count( $language_urls ) ) {
525 $tpl->setRef( 'language_urls', $language_urls );
527 $tpl->set( 'language_urls', false );
529 wfProfileOut( __METHOD__
. '-stuff4' );
531 wfProfileIn( __METHOD__
. '-stuff5' );
533 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
534 $content_navigation = $this->buildContentNavigationUrls();
535 $content_actions = $this->buildContentActionUrls( $content_navigation );
536 $tpl->setRef( 'content_navigation', $content_navigation );
537 $tpl->setRef( 'content_actions', $content_actions );
539 $tpl->set( 'sidebar', $this->buildSidebar() );
540 $tpl->set( 'nav_urls', $this->buildNavUrls() );
542 // Set the head scripts near the end, in case the above actions resulted in added scripts
543 if ( $this->useHeadElement
) {
544 $tpl->set( 'headelement', $out->headElement( $this ) );
546 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
549 $tpl->set( 'debug', '' );
550 $tpl->set( 'debughtml', $this->generateDebugHTML() );
551 $tpl->set( 'reporttime', wfReportTime() );
553 // original version by hansm
554 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
555 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
558 // Set the bodytext to another key so that skins can just output it on it's own
559 // and output printfooter and debughtml separately
560 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
562 // Append printfooter and debughtml onto bodytext so that skins that
563 // were already using bodytext before they were split out don't suddenly
564 // start not outputting information.
565 $tpl->data
['bodytext'] .= Html
::rawElement(
567 array( 'class' => 'printfooter' ),
568 "\n{$tpl->data['printfooter']}"
570 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
572 // allow extensions adding stuff after the page content.
573 // See Skin::afterContentHook() for further documentation.
574 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
575 wfProfileOut( __METHOD__
. '-stuff5' );
577 wfProfileOut( __METHOD__
);
582 * Get the HTML for the p-personal list
585 public function getPersonalToolsList() {
586 $tpl = $this->setupTemplateForOutput();
587 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
589 foreach ( $tpl->getPersonalTools() as $key => $item ) {
590 $html .= $tpl->makeListItem( $key, $item );
596 * Format language name for use in sidebar interlanguage links list.
597 * By default it is capitalized.
599 * @param string $name Language name, e.g. "English" or "español"
603 function formatLanguageName( $name ) {
604 return $this->getLanguage()->ucfirst( $name );
608 * Output the string, or print error message if it's
609 * an error object of the appropriate type.
610 * For the base class, assume strings all around.
615 function printOrError( $str ) {
620 * Output a boolean indicating if buildPersonalUrls should output separate
621 * login and create account links or output a combined link
622 * By default we simply return a global config setting that affects most skins
623 * This is setup as a method so that like with $wgLogo and getLogo() a skin
624 * can override this setting and always output one or the other if it has
625 * a reason it can't output one of the two modes.
628 function useCombinedLoginLink() {
629 global $wgUseCombinedLoginLink;
630 return $wgUseCombinedLoginLink;
634 * build array of urls for personal toolbar
637 protected function buildPersonalUrls() {
638 $title = $this->getTitle();
639 $request = $this->getRequest();
640 $pageurl = $title->getLocalURL();
641 wfProfileIn( __METHOD__
);
643 /* set up the default links for the personal toolbar */
644 $personal_urls = array();
646 # Due to bug 32276, if a user does not have read permissions,
647 # $this->getTitle() will just give Special:Badtitle, which is
648 # not especially useful as a returnto parameter. Use the title
649 # from the request instead, if there was one.
650 if ( $this->getUser()->isAllowed( 'read' ) ) {
651 $page = $this->getTitle();
653 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
655 $page = $request->getVal( 'returnto', $page );
657 if ( strval( $page ) !== '' ) {
658 $a['returnto'] = $page;
659 $query = $request->getVal( 'returntoquery', $this->thisquery
);
660 if ( $query != '' ) {
661 $a['returntoquery'] = $query;
665 $returnto = wfArrayToCgi( $a );
666 if ( $this->loggedin
) {
667 $personal_urls['userpage'] = array(
668 'text' => $this->username
,
669 'href' => &$this->userpageUrlDetails
['href'],
670 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
671 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
674 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
675 $personal_urls['mytalk'] = array(
676 'text' => $this->msg( 'mytalk' )->text(),
677 'href' => &$usertalkUrlDetails['href'],
678 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
679 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
681 $href = self
::makeSpecialUrl( 'Preferences' );
682 $personal_urls['preferences'] = array(
683 'text' => $this->msg( 'mypreferences' )->text(),
685 'active' => ( $href == $pageurl )
688 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
689 $href = self
::makeSpecialUrl( 'Watchlist' );
690 $personal_urls['watchlist'] = array(
691 'text' => $this->msg( 'mywatchlist' )->text(),
693 'active' => ( $href == $pageurl )
697 # We need to do an explicit check for Special:Contributions, as we
698 # have to match both the title, and the target, which could come
699 # from request values (Special:Contributions?target=Jimbo_Wales)
700 # or be specified in "sub page" form
701 # (Special:Contributions/Jimbo_Wales). The plot
702 # thickens, because the Title object is altered for special pages,
703 # so it doesn't contain the original alias-with-subpage.
704 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
705 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
706 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
707 $active = $spName == 'Contributions'
708 && ( ( $spPar && $spPar == $this->username
)
709 ||
$request->getText( 'target' ) == $this->username
);
714 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
715 $personal_urls['mycontris'] = array(
716 'text' => $this->msg( 'mycontris' )->text(),
720 $personal_urls['logout'] = array(
721 'text' => $this->msg( 'pt-userlogout' )->text(),
722 'href' => self
::makeSpecialUrl( 'Userlogout',
723 // userlogout link must always contain an & character, otherwise we might not be able
724 // to detect a buggy precaching proxy (bug 17790)
725 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
730 $useCombinedLoginLink = $this->useCombinedLoginLink();
731 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
732 ?
'nav-login-createaccount'
734 $is_signup = $request->getText( 'type' ) == 'signup';
737 'text' => $this->msg( $loginlink )->text(),
738 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
739 'active' => $title->isSpecial( 'Userlogin' )
740 && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
742 $createaccount_url = array(
743 'text' => $this->msg( 'pt-createaccount' )->text(),
744 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
745 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
748 if ( $this->showIPinHeader() ) {
749 $href = &$this->userpageUrlDetails
['href'];
750 $personal_urls['anonuserpage'] = array(
751 'text' => $this->username
,
753 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
754 'active' => ( $pageurl == $href )
756 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
757 $href = &$usertalkUrlDetails['href'];
758 $personal_urls['anontalk'] = array(
759 'text' => $this->msg( 'anontalk' )->text(),
761 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
762 'active' => ( $pageurl == $href )
766 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
767 $personal_urls['createaccount'] = $createaccount_url;
770 $personal_urls['login'] = $login_url;
773 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
774 wfProfileOut( __METHOD__
);
775 return $personal_urls;
779 * Builds an array with tab definition
781 * @param Title $title page Where the tab links to
782 * @param string|array $message Message key or an array of message keys (will fall back)
783 * @param bool $selected Display the tab as selected
784 * @param string $query Query string attached to tab URL
785 * @param bool $checkEdit Check if $title exists and mark with .new if one doesn't
789 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
792 $classes[] = 'selected';
794 if ( $checkEdit && !$title->isKnown() ) {
796 if ( $query !== '' ) {
797 $query = 'action=edit&redlink=1&' . $query;
799 $query = 'action=edit&redlink=1';
803 // wfMessageFallback will nicely accept $message as an array of fallbacks
804 // or just a single key
805 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
806 if ( is_array( $message ) ) {
807 // for hook compatibility just keep the last message name
808 $message = end( $message );
810 if ( $msg->exists() ) {
811 $text = $msg->text();
814 $text = $wgContLang->getFormattedNsText(
815 MWNamespace
::getSubject( $title->getNamespace() ) );
819 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
820 $title, $message, $selected, $checkEdit,
821 &$classes, &$query, &$text, &$result ) ) ) {
826 'class' => implode( ' ', $classes ),
828 'href' => $title->getLocalURL( $query ),
832 function makeTalkUrlDetails( $name, $urlaction = '' ) {
833 $title = Title
::newFromText( $name );
834 if ( !is_object( $title ) ) {
835 throw new MWException( __METHOD__
. " given invalid pagename $name" );
837 $title = $title->getTalkPage();
838 self
::checkTitle( $title, $name );
840 'href' => $title->getLocalURL( $urlaction ),
841 'exists' => $title->getArticleID() != 0,
845 function makeArticleUrlDetails( $name, $urlaction = '' ) {
846 $title = Title
::newFromText( $name );
847 $title = $title->getSubjectPage();
848 self
::checkTitle( $title, $name );
850 'href' => $title->getLocalURL( $urlaction ),
851 'exists' => $title->getArticleID() != 0,
856 * a structured array of links usually used for the tabs in a skin
858 * There are 4 standard sections
859 * namespaces: Used for namespace tabs like special, page, and talk namespaces
860 * views: Used for primary page views like read, edit, history
861 * actions: Used for most extra page actions like deletion, protection, etc...
862 * variants: Used to list the language variants for the page
864 * Each section's value is a key/value array of links for that section.
865 * The links themselves have these common keys:
866 * - class: The css classes to apply to the tab
867 * - text: The text to display on the tab
868 * - href: The href for the tab to point to
869 * - rel: An optional rel= for the tab's link
870 * - redundant: If true the tab will be dropped in skins using content_actions
871 * this is useful for tabs like "Read" which only have meaning in skins that
872 * take special meaning from the grouped structure of content_navigation
874 * Views also have an extra key which can be used:
875 * - primary: If this is not true skins like vector may try to hide the tab
876 * when the user has limited space in their browser window
878 * content_navigation using code also expects these ids to be present on the
879 * links, however these are usually automatically generated by SkinTemplate
880 * itself and are not necessary when using a hook. The only things these may
881 * matter to are people modifying content_navigation after it's initial creation:
882 * - id: A "preferred" id, most skins are best off outputting this preferred
883 * id for best compatibility.
884 * - tooltiponly: This is set to true for some tabs in cases where the system
885 * believes that the accesskey should not be added to the tab.
889 protected function buildContentNavigationUrls() {
890 global $wgDisableLangConversion;
892 wfProfileIn( __METHOD__
);
894 // Display tabs for the relevant title rather than always the title itself
895 $title = $this->getRelevantTitle();
896 $onPage = $title->equals( $this->getTitle() );
898 $out = $this->getOutput();
899 $request = $this->getRequest();
900 $user = $this->getUser();
902 $content_navigation = array(
903 'namespaces' => array(),
905 'actions' => array(),
906 'variants' => array()
910 $action = $request->getVal( 'action', 'view' );
912 $userCanRead = $title->quickUserCan( 'read', $user );
914 $preventActiveTabs = false;
915 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
917 // Checks if page is some kind of content
918 if ( $title->canExist() ) {
919 // Gets page objects for the related namespaces
920 $subjectPage = $title->getSubjectPage();
921 $talkPage = $title->getTalkPage();
923 // Determines if this is a talk page
924 $isTalk = $title->isTalkPage();
926 // Generates XML IDs from namespace names
927 $subjectId = $title->getNamespaceKey( '' );
929 if ( $subjectId == 'main' ) {
932 $talkId = "{$subjectId}_talk";
935 $skname = $this->skinname
;
937 // Adds namespace links
938 $subjectMsg = array( "nstab-$subjectId" );
939 if ( $subjectPage->isMainPage() ) {
940 array_unshift( $subjectMsg, 'mainpage-nstab' );
942 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
943 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
945 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
946 $content_navigation['namespaces'][$talkId] = $this->tabAction(
947 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
949 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
951 if ( $userCanRead ) {
952 $isForeignFile = $title->inNamespace( NS_FILE
) && $this->canUseWikiPage() &&
953 $this->getWikiPage() instanceof WikiFilePage
&& !$this->getWikiPage()->isLocal();
955 // Adds view view link
956 if ( $title->exists() ||
$isForeignFile ) {
957 $content_navigation['views']['view'] = $this->tabAction(
958 $isTalk ?
$talkPage : $subjectPage,
959 array( "$skname-view-view", 'view' ),
960 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
962 // signal to hide this from simple content_actions
963 $content_navigation['views']['view']['redundant'] = true;
966 // If it is a non-local file, show a link to the file in its own repository
967 if ( $isForeignFile ) {
968 $file = $this->getWikiPage()->getFile();
969 $content_navigation['views']['view-foreign'] = array(
971 'text' => wfMessageFallback( "$skname-view-foreign", 'view-foreign' )->
972 setContext( $this->getContext() )->
973 params( $file->getRepo()->getDisplayName() )->text(),
974 'href' => $file->getDescriptionUrl(),
979 wfProfileIn( __METHOD__
. '-edit' );
981 // Checks if user can edit the current page if it exists or create it otherwise
982 if ( $title->quickUserCan( 'edit', $user )
983 && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) )
985 // Builds CSS class for talk page links
986 $isTalkClass = $isTalk ?
' istalk' : '';
987 // Whether the user is editing the page
988 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
989 // Whether to show the "Add a new section" tab
990 // Checks if this is a current rev of talk page and is not forced to be hidden
991 $showNewSection = !$out->forceHideNewSectionLink()
992 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
993 $section = $request->getVal( 'section' );
995 if ( $title->exists()
996 ||
( $title->getNamespace() == NS_MEDIAWIKI
997 && $title->getDefaultMessageText() !== false
1000 $msgKey = $isForeignFile ?
'edit-local' : 'edit';
1002 $msgKey = $isForeignFile ?
'create-local' : 'create';
1004 $content_navigation['views']['edit'] = array(
1005 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection )
1009 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )
1010 ->setContext( $this->getContext() )->text(),
1011 'href' => $title->getLocalURL( $this->editUrlOptions() ),
1012 'primary' => !$isForeignFile, // don't collapse this in vector
1016 if ( $showNewSection ) {
1017 // Adds new section link
1018 //$content_navigation['actions']['addsection']
1019 $content_navigation['views']['addsection'] = array(
1020 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
1021 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )
1022 ->setContext( $this->getContext() )->text(),
1023 'href' => $title->getLocalURL( 'action=edit§ion=new' )
1026 // Checks if the page has some kind of viewable content
1027 } elseif ( $title->hasSourceText() ) {
1028 // Adds view source view link
1029 $content_navigation['views']['viewsource'] = array(
1030 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
1031 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )
1032 ->setContext( $this->getContext() )->text(),
1033 'href' => $title->getLocalURL( $this->editUrlOptions() ),
1034 'primary' => true, // don't collapse this in vector
1037 wfProfileOut( __METHOD__
. '-edit' );
1039 wfProfileIn( __METHOD__
. '-live' );
1040 // Checks if the page exists
1041 if ( $title->exists() ) {
1042 // Adds history view link
1043 $content_navigation['views']['history'] = array(
1044 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
1045 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )
1046 ->setContext( $this->getContext() )->text(),
1047 'href' => $title->getLocalURL( 'action=history' ),
1048 'rel' => 'archives',
1051 if ( $title->quickUserCan( 'delete', $user ) ) {
1052 $content_navigation['actions']['delete'] = array(
1053 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
1054 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )
1055 ->setContext( $this->getContext() )->text(),
1056 'href' => $title->getLocalURL( 'action=delete' )
1060 if ( $title->quickUserCan( 'move', $user ) ) {
1061 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1062 $content_navigation['actions']['move'] = array(
1063 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
1064 'text' => wfMessageFallback( "$skname-action-move", 'move' )
1065 ->setContext( $this->getContext() )->text(),
1066 'href' => $moveTitle->getLocalURL()
1070 // article doesn't exist or is deleted
1071 if ( $user->isAllowed( 'deletedhistory' ) ) {
1072 $n = $title->isDeleted();
1074 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
1075 // If the user can't undelete but can view deleted
1076 // history show them a "View .. deleted" tab instead.
1077 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1078 $content_navigation['actions']['undelete'] = array(
1079 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1080 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1081 ->setContext( $this->getContext() )->numParams( $n )->text(),
1082 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1088 if ( $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() &&
1089 MWNamespace
::getRestrictionLevels( $title->getNamespace(), $user ) !== array( '' )
1091 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1092 $content_navigation['actions'][$mode] = array(
1093 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1094 'text' => wfMessageFallback( "$skname-action-$mode", $mode )
1095 ->setContext( $this->getContext() )->text(),
1096 'href' => $title->getLocalURL( "action=$mode" )
1100 wfProfileOut( __METHOD__
. '-live' );
1102 // Checks if the user is logged in
1103 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1105 * The following actions use messages which, if made particular to
1106 * the any specific skins, would break the Ajax code which makes this
1107 * action happen entirely inline. Skin::makeGlobalVariablesScript
1108 * defines a set of messages in a javascript object - and these
1109 * messages are assumed to be global for all skins. Without making
1110 * a change to that procedure these messages will have to remain as
1111 * the global versions.
1113 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1114 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1115 $content_navigation['actions'][$mode] = array(
1116 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1117 // uses 'watch' or 'unwatch' message
1118 'text' => $this->msg( $mode )->text(),
1119 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1124 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1126 if ( $userCanRead && !$wgDisableLangConversion ) {
1127 $pageLang = $title->getPageLanguage();
1128 // Gets list of language variants
1129 $variants = $pageLang->getVariants();
1130 // Checks that language conversion is enabled and variants exist
1131 // And if it is not in the special namespace
1132 if ( count( $variants ) > 1 ) {
1133 // Gets preferred variant (note that user preference is
1134 // only possible for wiki content language variant)
1135 $preferred = $pageLang->getPreferredVariant();
1136 if ( Action
::getActionName( $this ) === 'view' ) {
1137 $params = $request->getQueryValues();
1138 unset( $params['title'] );
1142 // Loops over each variant
1143 foreach ( $variants as $code ) {
1144 // Gets variant name from language code
1145 $varname = $pageLang->getVariantname( $code );
1146 // Appends variant link
1147 $content_navigation['variants'][] = array(
1148 'class' => ( $code == $preferred ) ?
'selected' : false,
1150 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1151 'lang' => wfBCP47( $code ),
1152 'hreflang' => wfBCP47( $code ),
1158 // If it's not content, it's got to be a special page
1159 $content_navigation['namespaces']['special'] = array(
1160 'class' => 'selected',
1161 'text' => $this->msg( 'nstab-special' )->text(),
1162 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1163 'context' => 'subject'
1166 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1167 array( &$this, &$content_navigation ) );
1170 // Equiv to SkinTemplateContentActions
1171 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1173 // Setup xml ids and tooltip info
1174 foreach ( $content_navigation as $section => &$links ) {
1175 foreach ( $links as $key => &$link ) {
1177 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1178 $xmlID = 'ca-nstab-' . $xmlID;
1179 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1181 } elseif ( $section == 'variants' ) {
1182 $xmlID = 'ca-varlang-' . $xmlID;
1184 $xmlID = 'ca-' . $xmlID;
1186 $link['id'] = $xmlID;
1190 # We don't want to give the watch tab an accesskey if the
1191 # page is being edited, because that conflicts with the
1192 # accesskey on the watch checkbox. We also don't want to
1193 # give the edit tab an accesskey, because that's fairly
1194 # superfluous and conflicts with an accesskey (Ctrl-E) often
1195 # used for editing in Safari.
1196 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1197 if ( isset( $content_navigation['views']['edit'] ) ) {
1198 $content_navigation['views']['edit']['tooltiponly'] = true;
1200 if ( isset( $content_navigation['actions']['watch'] ) ) {
1201 $content_navigation['actions']['watch']['tooltiponly'] = true;
1203 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1204 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1208 wfProfileOut( __METHOD__
);
1210 return $content_navigation;
1214 * an array of edit links by default used for the tabs
1218 function buildContentActionUrls( $content_navigation ) {
1220 wfProfileIn( __METHOD__
);
1222 // content_actions has been replaced with content_navigation for backwards
1223 // compatibility and also for skins that just want simple tabs content_actions
1224 // is now built by flattening the content_navigation arrays into one
1226 $content_actions = array();
1228 foreach ( $content_navigation as $links ) {
1230 foreach ( $links as $key => $value ) {
1232 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1233 // Redundant tabs are dropped from content_actions
1237 // content_actions used to have ids built using the "ca-$key" pattern
1238 // so the xmlID based id is much closer to the actual $key that we want
1239 // for that reason we'll just strip out the ca- if present and use
1240 // the latter potion of the "id" as the $key
1241 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1242 $key = substr( $value['id'], 3 );
1245 if ( isset( $content_actions[$key] ) ) {
1246 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening " .
1247 "content_navigation into content_actions.\n" );
1251 $content_actions[$key] = $value;
1257 wfProfileOut( __METHOD__
);
1259 return $content_actions;
1263 * build array of common navigation links
1267 protected function buildNavUrls() {
1268 global $wgUploadNavigationUrl;
1270 wfProfileIn( __METHOD__
);
1272 $out = $this->getOutput();
1273 $request = $this->getRequest();
1275 $nav_urls = array();
1276 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1277 if ( $wgUploadNavigationUrl ) {
1278 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1279 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1280 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1282 $nav_urls['upload'] = false;
1284 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1286 $nav_urls['print'] = false;
1287 $nav_urls['permalink'] = false;
1288 $nav_urls['info'] = false;
1289 $nav_urls['whatlinkshere'] = false;
1290 $nav_urls['recentchangeslinked'] = false;
1291 $nav_urls['contributions'] = false;
1292 $nav_urls['log'] = false;
1293 $nav_urls['blockip'] = false;
1294 $nav_urls['emailuser'] = false;
1295 $nav_urls['userrights'] = false;
1297 // A print stylesheet is attached to all pages, but nobody ever
1298 // figures that out. :) Add a link...
1299 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1300 $nav_urls['print'] = array(
1301 'text' => $this->msg( 'printableversion' )->text(),
1302 'href' => $this->getTitle()->getLocalURL(
1303 $request->appendQueryValue( 'printable', 'yes', true ) )
1307 if ( $out->isArticle() ) {
1308 // Also add a "permalink" while we're at it
1309 $revid = $this->getRevisionId();
1311 $nav_urls['permalink'] = array(
1312 'text' => $this->msg( 'permalink' )->text(),
1313 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1317 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1318 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1319 array( &$this, &$nav_urls, &$revid, &$revid ) );
1322 if ( $out->isArticleRelated() ) {
1323 $nav_urls['whatlinkshere'] = array(
1324 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1327 $nav_urls['info'] = array(
1328 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1329 'href' => $this->getTitle()->getLocalURL( "action=info" )
1332 if ( $this->getTitle()->getArticleID() ) {
1333 $nav_urls['recentchangeslinked'] = array(
1334 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1339 $user = $this->getRelevantUser();
1341 $rootUser = $user->getName();
1343 $nav_urls['contributions'] = array(
1344 'text' => $this->msg( 'contributions', $rootUser )->text(),
1345 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1348 $nav_urls['log'] = array(
1349 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1352 if ( $this->getUser()->isAllowed( 'block' ) ) {
1353 $nav_urls['blockip'] = array(
1354 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1358 if ( $this->showEmailUser( $user ) ) {
1359 $nav_urls['emailuser'] = array(
1360 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1364 if ( !$user->isAnon() ) {
1365 $sur = new UserrightsPage
;
1366 $sur->setContext( $this->getContext() );
1367 if ( $sur->userCanExecute( $this->getUser() ) ) {
1368 $nav_urls['userrights'] = array(
1369 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1375 wfProfileOut( __METHOD__
);
1380 * Generate strings used for xml 'id' names
1384 function getNameSpaceKey() {
1385 return $this->getTitle()->getNamespaceKey();
1390 * Generic wrapper for template functions, with interface
1391 * compatible with what we use of PHPTAL 0.7.
1394 abstract class QuickTemplate
{
1398 function __construct() {
1399 $this->data
= array();
1400 $this->translator
= new MediaWikiI18N();
1404 * Sets the value $value to $name
1405 * @param string $name
1406 * @param mixed $value
1408 public function set( $name, $value ) {
1409 $this->data
[$name] = $value;
1413 * Gets the template data requested
1415 * @param string $name Key for the data
1416 * @param mixed $default Optional default (or null)
1417 * @return mixed The value of the data requested or the deafult
1419 public function get( $name, $default = null ) {
1420 if ( isset( $this->data
[$name] ) ) {
1421 return $this->data
[$name];
1428 * @param string $name
1429 * @param mixed $value
1431 public function setRef( $name, &$value ) {
1432 $this->data
[$name] =& $value;
1436 * @param MediaWikiI18N $t
1438 public function setTranslator( &$t ) {
1439 $this->translator
= &$t;
1443 * Main function, used by classes that subclass QuickTemplate
1444 * to show the actual HTML output
1446 abstract public function execute();
1450 * @param string $str
1453 function text( $str ) {
1454 echo htmlspecialchars( $this->data
[$str] );
1459 * @param string $str
1462 function html( $str ) {
1463 echo $this->data
[$str];
1468 * @param string $str
1471 function msg( $str ) {
1472 echo htmlspecialchars( $this->translator
->translate( $str ) );
1477 * @param string $str
1480 function msgHtml( $str ) {
1481 echo $this->translator
->translate( $str );
1485 * An ugly, ugly hack.
1487 * @param string $str
1490 function msgWiki( $str ) {
1493 $text = $this->translator
->translate( $str );
1494 echo $wgOut->parse( $text );
1499 * @param string $str
1502 function haveData( $str ) {
1503 return isset( $this->data
[$str] );
1509 * @param string $str
1512 function haveMsg( $str ) {
1513 $msg = $this->translator
->translate( $str );
1514 return ( $msg != '-' ) && ( $msg != '' ); # ????
1518 * Get the Skin object related to this object
1522 public function getSkin() {
1523 return $this->data
['skin'];
1527 * Fetch the output of a QuickTemplate and return it
1532 public function getHTML() {
1535 $html = ob_get_contents();
1542 * New base template for a skin's template extended from QuickTemplate
1543 * this class features helper methods that provide common ways of interacting
1544 * with the data stored in the QuickTemplate
1546 abstract class BaseTemplate
extends QuickTemplate
{
1549 * Get a Message object with its context set
1551 * @param string $name Message name
1554 public function getMsg( $name ) {
1555 return $this->getSkin()->msg( $name );
1558 function msg( $str ) {
1559 echo $this->getMsg( $str )->escaped();
1562 function msgHtml( $str ) {
1563 echo $this->getMsg( $str )->text();
1566 function msgWiki( $str ) {
1567 echo $this->getMsg( $str )->parseAsBlock();
1571 * Create an array of common toolbox items from the data in the quicktemplate
1572 * stored by SkinTemplate.
1573 * The resulting array is built according to a format intended to be passed
1574 * through makeListItem to generate the html.
1577 function getToolbox() {
1578 wfProfileIn( __METHOD__
);
1581 if ( isset( $this->data
['nav_urls']['whatlinkshere'] )
1582 && $this->data
['nav_urls']['whatlinkshere']
1584 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1585 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1587 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] )
1588 && $this->data
['nav_urls']['recentchangeslinked']
1590 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1591 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1592 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1594 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1595 $toolbox['feeds']['id'] = 'feedlinks';
1596 $toolbox['feeds']['links'] = array();
1597 foreach ( $this->data
['feeds'] as $key => $feed ) {
1598 $toolbox['feeds']['links'][$key] = $feed;
1599 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1600 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1601 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1602 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1605 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser',
1606 'userrights', 'upload', 'specialpages' ) as $special
1608 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1609 $toolbox[$special] = $this->data
['nav_urls'][$special];
1610 $toolbox[$special]['id'] = "t-$special";
1613 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1614 $toolbox['print'] = $this->data
['nav_urls']['print'];
1615 $toolbox['print']['id'] = 't-print';
1616 $toolbox['print']['rel'] = 'alternate';
1617 $toolbox['print']['msg'] = 'printableversion';
1619 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1620 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1621 if ( $toolbox['permalink']['href'] === '' ) {
1622 unset( $toolbox['permalink']['href'] );
1623 $toolbox['ispermalink']['tooltiponly'] = true;
1624 $toolbox['ispermalink']['id'] = 't-ispermalink';
1625 $toolbox['ispermalink']['msg'] = 'permalink';
1627 $toolbox['permalink']['id'] = 't-permalink';
1630 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1631 $toolbox['info'] = $this->data
['nav_urls']['info'];
1632 $toolbox['info']['id'] = 't-info';
1635 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1636 wfProfileOut( __METHOD__
);
1641 * Create an array of personal tools items from the data in the quicktemplate
1642 * stored by SkinTemplate.
1643 * The resulting array is built according to a format intended to be passed
1644 * through makeListItem to generate the html.
1645 * This is in reality the same list as already stored in personal_urls
1646 * however it is reformatted so that you can just pass the individual items
1647 * to makeListItem instead of hardcoding the element creation boilerplate.
1650 function getPersonalTools() {
1651 $personal_tools = array();
1652 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1653 # The class on a personal_urls item is meant to go on the <a> instead
1654 # of the <li> so we have to use a single item "links" array instead
1655 # of using most of the personal_url's keys directly.
1658 array( 'single-id' => "pt-$key" ),
1662 if ( isset( $plink['active'] ) ) {
1663 $ptool['active'] = $plink['active'];
1665 foreach ( array( 'href', 'class', 'text', 'dir' ) as $k ) {
1666 if ( isset( $plink[$k] ) ) {
1667 $ptool['links'][0][$k] = $plink[$k];
1670 $personal_tools[$key] = $ptool;
1672 return $personal_tools;
1675 function getSidebar( $options = array() ) {
1676 // Force the rendering of the following portals
1677 $sidebar = $this->data
['sidebar'];
1678 if ( !isset( $sidebar['SEARCH'] ) ) {
1679 $sidebar['SEARCH'] = true;
1681 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1682 $sidebar['TOOLBOX'] = true;
1684 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1685 $sidebar['LANGUAGES'] = true;
1688 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1689 unset( $sidebar['SEARCH'] );
1691 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1692 unset( $sidebar['TOOLBOX'] );
1694 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1695 unset( $sidebar['LANGUAGES'] );
1699 foreach ( $sidebar as $boxName => $content ) {
1700 if ( $content === false ) {
1703 switch ( $boxName ) {
1705 // Search is a special case, skins should custom implement this
1706 $boxes[$boxName] = array(
1708 'header' => $this->getMsg( 'search' )->text(),
1709 'generated' => false,
1714 $msgObj = $this->getMsg( 'toolbox' );
1715 $boxes[$boxName] = array(
1717 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1718 'generated' => false,
1719 'content' => $this->getToolbox(),
1723 if ( $this->data
['language_urls'] ) {
1724 $msgObj = $this->getMsg( 'otherlanguages' );
1725 $boxes[$boxName] = array(
1727 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1728 'generated' => false,
1729 'content' => $this->data
['language_urls'],
1734 $msgObj = $this->getMsg( $boxName );
1735 $boxes[$boxName] = array(
1736 'id' => "p-$boxName",
1737 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1738 'generated' => true,
1739 'content' => $content,
1745 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1746 $hookContents = null;
1747 if ( isset( $boxes['TOOLBOX'] ) ) {
1749 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1750 // can abort and avoid outputting double toolbox links
1751 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1752 $hookContents = ob_get_contents();
1754 if ( !trim( $hookContents ) ) {
1755 $hookContents = null;
1760 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1761 foreach ( $boxes as $boxName => $box ) {
1762 if ( is_array( $box['content'] ) ) {
1764 foreach ( $box['content'] as $key => $val ) {
1765 $content .= "\n " . $this->makeListItem( $key, $val );
1767 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1768 if ( $hookContents ) {
1769 $content .= "\n $hookContents";
1772 $content .= "\n</ul>\n";
1773 $boxes[$boxName]['content'] = $content;
1777 if ( $hookContents ) {
1778 $boxes['TOOLBOXEND'] = array(
1779 'id' => 'p-toolboxend',
1780 'header' => $boxes['TOOLBOX']['header'],
1781 'generated' => false,
1782 'content' => "<ul>{$hookContents}</ul>",
1784 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1786 foreach ( $boxes as $key => $box ) {
1787 if ( $key === 'TOOLBOXEND' ) {
1790 $boxes2[$key] = $box;
1791 if ( $key === 'TOOLBOX' ) {
1792 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1804 * @param string $name
1806 protected function renderAfterPortlet( $name ) {
1808 wfRunHooks( 'BaseTemplateAfterPortlet', array( $this, $name, &$content ) );
1810 if ( $content !== '' ) {
1811 echo "<div class='after-portlet after-portlet-$name'>$content</div>";
1817 * Makes a link, usually used by makeListItem to generate a link for an item
1818 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1820 * @param string $key usually a key from the list you are generating this
1822 * @param array $item contains some of a specific set of keys.
1824 * The text of the link will be generated either from the contents of the
1825 * "text" key in the $item array, if a "msg" key is present a message by
1826 * that name will be used, and if neither of those are set the $key will be
1827 * used as a message name.
1829 * If a "href" key is not present makeLink will just output htmlescaped text.
1830 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1831 * for the link if present.
1833 * If an "id" or "single-id" (if you don't want the actual id to be output
1834 * on the link) is present it will be used to generate a tooltip and
1835 * accesskey for the link.
1837 * The keys "context" and "primary" are ignored; these keys are used
1838 * internally by skins and are not supposed to be included in the HTML
1841 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1843 * @param array $options can be used to affect the output of a link.
1844 * Possible options are:
1845 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1846 * a link in. This should be an array of arrays containing a 'tag' and
1847 * optionally an 'attributes' key. If you only have one element you don't
1848 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1849 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1851 * - 'link-class' key can be used to specify additional classes to apply
1853 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1854 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1855 * any non-link will output a "<span>" instead of just text.
1859 function makeLink( $key, $item, $options = array() ) {
1860 if ( isset( $item['text'] ) ) {
1861 $text = $item['text'];
1863 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1866 $html = htmlspecialchars( $text );
1868 if ( isset( $options['text-wrapper'] ) ) {
1869 $wrapper = $options['text-wrapper'];
1870 if ( isset( $wrapper['tag'] ) ) {
1871 $wrapper = array( $wrapper );
1873 while ( count( $wrapper ) > 0 ) {
1874 $element = array_pop( $wrapper );
1875 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] )
1876 ?
$element['attributes']
1881 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1883 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1884 unset( $attrs[$k] );
1887 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1888 $item['single-id'] = $item['id'];
1890 if ( isset( $item['single-id'] ) ) {
1891 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1892 $title = Linker
::titleAttrib( $item['single-id'] );
1893 if ( $title !== false ) {
1894 $attrs['title'] = $title;
1897 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1898 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1899 $attrs['title'] = $tip['title'];
1901 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1902 $attrs['accesskey'] = $tip['accesskey'];
1906 if ( isset( $options['link-class'] ) ) {
1907 if ( isset( $attrs['class'] ) ) {
1908 $attrs['class'] .= " {$options['link-class']}";
1910 $attrs['class'] = $options['link-class'];
1913 $html = Html
::rawElement( isset( $attrs['href'] )
1915 : $options['link-fallback'], $attrs, $html );
1922 * Generates a list item for a navigation, portlet, portal, sidebar... list
1924 * @param string $key Usually a key from the list you are generating this link from.
1925 * @param array $item Array of list item data containing some of a specific set of keys.
1926 * The "id", "class" and "itemtitle" keys will be used as attributes for the list item,
1927 * if "active" contains a value of true a "active" class will also be appended to class.
1929 * @param array $options
1931 * If you want something other than a "<li>" you can pass a tag name such as
1932 * "tag" => "span" in the $options array to change the tag used.
1933 * link/content data for the list item may come in one of two forms
1934 * A "links" key may be used, in which case it should contain an array with
1935 * a list of links to include inside the list item, see makeLink for the
1936 * format of individual links array items.
1938 * Otherwise the relevant keys from the list item $item array will be passed
1939 * to makeLink instead. Note however that "id" and "class" are used by the
1940 * list item directly so they will not be passed to makeLink
1941 * (however the link will still support a tooltip and accesskey from it)
1942 * If you need an id or class on a single link you should include a "links"
1943 * array with just one link item inside of it. If you want to add a title
1944 * to the list item itself, you can set "itemtitle" to the value.
1945 * $options is also passed on to makeLink calls
1949 function makeListItem( $key, $item, $options = array() ) {
1950 if ( isset( $item['links'] ) ) {
1952 foreach ( $item['links'] as $linkKey => $link ) {
1953 $links[] = $this->makeLink( $linkKey, $link, $options );
1955 $html = implode( ' ', $links );
1958 // These keys are used by makeListItem and shouldn't be passed on to the link
1959 foreach ( array( 'id', 'class', 'active', 'tag', 'itemtitle' ) as $k ) {
1962 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1963 // The id goes on the <li> not on the <a> for single links
1964 // but makeSidebarLink still needs to know what id to use when
1965 // generating tooltips and accesskeys.
1966 $link['single-id'] = $item['id'];
1968 $html = $this->makeLink( $key, $link, $options );
1972 foreach ( array( 'id', 'class' ) as $attr ) {
1973 if ( isset( $item[$attr] ) ) {
1974 $attrs[$attr] = $item[$attr];
1977 if ( isset( $item['active'] ) && $item['active'] ) {
1978 if ( !isset( $attrs['class'] ) ) {
1979 $attrs['class'] = '';
1981 $attrs['class'] .= ' active';
1982 $attrs['class'] = trim( $attrs['class'] );
1984 if ( isset( $item['itemtitle'] ) ) {
1985 $attrs['title'] = $item['itemtitle'];
1987 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1990 function makeSearchInput( $attrs = array() ) {
1994 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1995 'value' => $this->get( 'search', '' ),
1997 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1998 return Html
::element( 'input', $realAttrs );
2001 function makeSearchButton( $mode, $attrs = array() ) {
2008 'value' => $this->translator
->translate(
2009 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
2011 $realAttrs = array_merge(
2013 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
2016 return Html
::element( 'input', $realAttrs );
2018 $buttonAttrs = array(
2022 $buttonAttrs = array_merge(
2024 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
2027 unset( $buttonAttrs['src'] );
2028 unset( $buttonAttrs['alt'] );
2029 unset( $buttonAttrs['width'] );
2030 unset( $buttonAttrs['height'] );
2032 'src' => $attrs['src'],
2033 'alt' => isset( $attrs['alt'] )
2035 : $this->translator
->translate( 'searchbutton' ),
2036 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
2037 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
2039 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
2041 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
2046 * Returns an array of footerlinks trimmed down to only those footer links that
2048 * If you pass "flat" as an option then the returned array will be a flat array
2049 * of footer icons instead of a key/value array of footerlinks arrays broken
2050 * up into categories.
2051 * @return array|mixed
2053 function getFooterLinks( $option = null ) {
2054 $footerlinks = $this->get( 'footerlinks' );
2056 // Reduce footer links down to only those which are being used
2057 $validFooterLinks = array();
2058 foreach ( $footerlinks as $category => $links ) {
2059 $validFooterLinks[$category] = array();
2060 foreach ( $links as $link ) {
2061 if ( isset( $this->data
[$link] ) && $this->data
[$link] ) {
2062 $validFooterLinks[$category][] = $link;
2065 if ( count( $validFooterLinks[$category] ) <= 0 ) {
2066 unset( $validFooterLinks[$category] );
2070 if ( $option == 'flat' ) {
2071 // fold footerlinks into a single array using a bit of trickery
2072 $validFooterLinks = call_user_func_array(
2074 array_values( $validFooterLinks )
2078 return $validFooterLinks;
2082 * Returns an array of footer icons filtered down by options relevant to how
2083 * the skin wishes to display them.
2084 * If you pass "icononly" as the option all footer icons which do not have an
2085 * image icon set will be filtered out.
2086 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
2087 * in the list of footer icons. This is mostly useful for skins which only
2088 * display the text from footericons instead of the images and don't want a
2089 * duplicate copyright statement because footerlinks already rendered one.
2092 function getFooterIcons( $option = null ) {
2093 // Generate additional footer icons
2094 $footericons = $this->get( 'footericons' );
2096 if ( $option == 'icononly' ) {
2097 // Unset any icons which don't have an image
2098 foreach ( $footericons as &$footerIconsBlock ) {
2099 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
2100 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
2101 unset( $footerIconsBlock[$footerIconKey] );
2105 // Redo removal of any empty blocks
2106 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
2107 if ( count( $footerIconsBlock ) <= 0 ) {
2108 unset( $footericons[$footerIconsKey] );
2111 } elseif ( $option == 'nocopyright' ) {
2112 unset( $footericons['copyright']['copyright'] );
2113 if ( count( $footericons['copyright'] ) <= 0 ) {
2114 unset( $footericons['copyright'] );
2118 return $footericons;
2122 * Output the basic end-page trail including bottomscripts, reporttime, and
2123 * debug stuff. This should be called right before outputting the closing
2124 * body and html tags.
2126 function printTrail() { ?
>
2127 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() ); ?
>
2128 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
2129 <?php
$this->html( 'reporttime' ) ?
>