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.
30 class MediaWiki_I18N
{
31 var $_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
{
76 * Name of our skin, it probably needs to be all lower case. Child classes
77 * should override the default.
79 var $skinname = 'monobook';
82 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
83 * are located. Child classes should override the default.
85 var $stylename = 'monobook';
88 * For QuickTemplate, the name of the subclass which will actually fill the
89 * template. Child classes should override the default.
91 var $template = 'QuickTemplate';
94 * Whether this skin use OutputPage::headElement() to generate the "<head>"
97 var $useHeadElement = false;
102 * Add specific styles for this skin
104 * @param $out OutputPage
106 function setupSkinUserCss( OutputPage
$out ) {
107 $out->addModuleStyles( array( 'mediawiki.legacy.shared', 'mediawiki.legacy.commonPrint' ) );
111 * Create the template engine object; we feed it a bunch of data
112 * and eventually it spits out some HTML. Should have interface
113 * roughly equivalent to PHPTAL 0.7.
115 * @param $classname String
116 * @param string $repository subdirectory where we keep template files
117 * @param $cache_dir string
118 * @return QuickTemplate
121 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
122 return new $classname();
126 * Generates array of language links for the current page
131 public function getLanguages() {
132 global $wgHideInterlanguageLinks;
133 if ( $wgHideInterlanguageLinks ) {
137 $out = $this->getOutput();
138 $userLang = $this->getLanguage();
140 $languageLinks = array();
142 foreach ( $out->getLanguageLinks() as $languageLinkText ) {
143 $languageLinkParts = explode( ':', $languageLinkText, 2 );
144 $class = 'interlanguage-link interwiki-' . $languageLinkParts[0];
145 unset( $languageLinkParts );
146 $languageLinkTitle = Title
::newFromText( $languageLinkText );
147 if ( $languageLinkTitle ) {
148 $ilInterwikiCode = $languageLinkTitle->getInterwiki();
149 $ilLangName = Language
::fetchLanguageName( $ilInterwikiCode );
151 if ( strval( $ilLangName ) === '' ) {
152 $ilLangName = $languageLinkText;
154 $ilLangName = $this->formatLanguageName( $ilLangName );
157 // CLDR extension or similar is required to localize the language name;
158 // otherwise we'll end up with the autonym again.
159 $ilLangLocalName = Language
::fetchLanguageName( $ilInterwikiCode, $userLang->getCode() );
161 if ( $languageLinkTitle->getText() === '' ) {
162 $ilTitle = wfMessage( 'interlanguage-link-title-langonly', $ilLangLocalName )->text();
164 $ilTitle = wfMessage( 'interlanguage-link-title', $languageLinkTitle->getText(),
165 $ilLangLocalName )->text();
168 $languageLinks[] = array(
169 'href' => $languageLinkTitle->getFullURL(),
170 'text' => $ilLangName,
173 'lang' => wfBCP47( $ilInterwikiCode ),
174 'hreflang' => wfBCP47( $ilInterwikiCode ),
179 return $languageLinks;
182 protected function setupTemplateForOutput() {
183 wfProfileIn( __METHOD__
);
185 $request = $this->getRequest();
186 $user = $this->getUser();
187 $title = $this->getTitle();
189 wfProfileIn( __METHOD__
. '-init' );
190 $tpl = $this->setupTemplate( $this->template
, 'skins' );
191 wfProfileOut( __METHOD__
. '-init' );
193 wfProfileIn( __METHOD__
. '-stuff' );
194 $this->thispage
= $title->getPrefixedDBkey();
195 $this->titletxt
= $title->getPrefixedText();
196 $this->userpage
= $user->getUserPage()->getPrefixedText();
198 if ( !$request->wasPosted() ) {
199 $query = $request->getValues();
200 unset( $query['title'] );
201 unset( $query['returnto'] );
202 unset( $query['returntoquery'] );
204 $this->thisquery
= wfArrayToCgi( $query );
205 $this->loggedin
= $user->isLoggedIn();
206 $this->username
= $user->getName();
208 if ( $this->loggedin ||
$this->showIPinHeader() ) {
209 $this->userpageUrlDetails
= self
::makeUrlDetails( $this->userpage
);
211 # This won't be used in the standard skins, but we define it to preserve the interface
212 # To save time, we check for existence
213 $this->userpageUrlDetails
= self
::makeKnownUrlDetails( $this->userpage
);
216 wfProfileOut( __METHOD__
. '-stuff' );
218 wfProfileOut( __METHOD__
);
224 * initialize various variables and generate the template
226 * @param $out OutputPage
228 function outputPage( OutputPage
$out = null ) {
229 wfProfileIn( __METHOD__
);
230 Profiler
::instance()->setTemplated( true );
233 if ( $out !== null ) {
234 // @todo Add wfDeprecated in 1.20
235 $oldContext = $this->getContext();
236 $this->setContext( $out->getContext() );
239 $out = $this->getOutput();
240 $user = $this->getUser();
242 wfProfileIn( __METHOD__
. '-init' );
243 $this->initPage( $out );
244 wfProfileOut( __METHOD__
. '-init' );
245 $tpl = $this->prepareQuickTemplate( $out );
247 wfProfileIn( __METHOD__
. '-execute' );
248 $res = $tpl->execute();
249 wfProfileOut( __METHOD__
. '-execute' );
251 // result may be an error
252 $this->printOrError( $res );
255 $this->setContext( $oldContext );
258 wfProfileOut( __METHOD__
);
262 * initialize various variables and generate the template
265 * @param $out OutputPage
266 * @return QuickTemplate the template to be executed by outputPage
268 protected function prepareQuickTemplate( OutputPage
$out = null ) {
269 global $wgContLang, $wgScript, $wgStylePath,
270 $wgMimeType, $wgJsMimeType, $wgXhtmlNamespaces, $wgHtml5Version,
271 $wgDisableCounters, $wgSitename, $wgLogo, $wgMaxCredits,
272 $wgShowCreditsIfMax, $wgPageShowWatchingUsers, $wgArticlePath,
273 $wgScriptPath, $wgServer;
275 wfProfileIn( __METHOD__
);
277 $title = $this->getTitle();
278 $request = $this->getRequest();
279 $tpl = $this->setupTemplateForOutput();
281 wfProfileIn( __METHOD__
. '-stuff-head' );
282 if ( !$this->useHeadElement
) {
283 $tpl->set( 'pagecss', false );
284 $tpl->set( 'usercss', false );
286 $tpl->set( 'userjs', false );
287 $tpl->set( 'userjsprev', false );
289 $tpl->set( 'jsvarurl', false );
291 $tpl->set( 'xhtmldefaultnamespace', 'http://www.w3.org/1999/xhtml' );
292 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
293 $tpl->set( 'html5version', $wgHtml5Version );
294 $tpl->set( 'headlinks', $out->getHeadLinks() );
295 $tpl->set( 'csslinks', $out->buildCssLinks() );
296 $tpl->set( 'pageclass', $this->getPageClasses( $title ) );
297 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer
::escapeClass( $this->getSkinName() ) ) );
299 wfProfileOut( __METHOD__
. '-stuff-head' );
301 wfProfileIn( __METHOD__
. '-stuff2' );
302 $tpl->set( 'title', $out->getPageTitle() );
303 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
304 $tpl->set( 'displaytitle', $out->mPageLinkTitle
);
306 $tpl->setRef( 'thispage', $this->thispage
);
307 $tpl->setRef( 'titleprefixeddbkey', $this->thispage
);
308 $tpl->set( 'titletext', $title->getText() );
309 $tpl->set( 'articleid', $title->getArticleID() );
311 $tpl->set( 'isarticle', $out->isArticle() );
313 $subpagestr = $this->subPageSubtitle();
314 if ( $subpagestr !== '' ) {
315 $subpagestr = '<span class="subpages">' . $subpagestr . '</span>';
317 $tpl->set( 'subtitle', $subpagestr . $out->getSubtitle() );
319 $undelete = $this->getUndeleteLink();
320 if ( $undelete === '' ) {
321 $tpl->set( 'undelete', '' );
323 $tpl->set( 'undelete', '<span class="subpages">' . $undelete . '</span>' );
326 $tpl->set( 'catlinks', $this->getCategories() );
327 if ( $out->isSyndicated() ) {
329 foreach ( $out->getSyndicationLinks() as $format => $link ) {
330 $feeds[$format] = array(
331 // Messages: feed-atom, feed-rss
332 'text' => $this->msg( "feed-$format" )->text(),
336 $tpl->setRef( 'feeds', $feeds );
338 $tpl->set( 'feeds', false );
341 $tpl->setRef( 'mimetype', $wgMimeType );
342 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
343 $tpl->set( 'charset', 'UTF-8' );
344 $tpl->setRef( 'wgScript', $wgScript );
345 $tpl->setRef( 'skinname', $this->skinname
);
346 $tpl->set( 'skinclass', get_class( $this ) );
347 $tpl->setRef( 'skin', $this );
348 $tpl->setRef( 'stylename', $this->stylename
);
349 $tpl->set( 'printable', $out->isPrintable() );
350 $tpl->set( 'handheld', $request->getBool( 'handheld' ) );
351 $tpl->setRef( 'loggedin', $this->loggedin
);
352 $tpl->set( 'notspecialpage', !$title->isSpecialPage() );
353 /* XXX currently unused, might get useful later
354 $tpl->set( 'editable', ( !$title->isSpecialPage() ) );
355 $tpl->set( 'exists', $title->getArticleID() != 0 );
356 $tpl->set( 'watch', $user->isWatched( $title ) ? 'unwatch' : 'watch' );
357 $tpl->set( 'protect', count( $title->isProtected() ) ? 'unprotect' : 'protect' );
358 $tpl->set( 'helppage', $this->msg( 'helppage' )->text() );
360 $tpl->set( 'searchaction', $this->escapeSearchLink() );
361 $tpl->set( 'searchtitle', SpecialPage
::getTitleFor( 'Search' )->getPrefixedDBkey() );
362 $tpl->set( 'search', trim( $request->getVal( 'search' ) ) );
363 $tpl->setRef( 'stylepath', $wgStylePath );
364 $tpl->setRef( 'articlepath', $wgArticlePath );
365 $tpl->setRef( 'scriptpath', $wgScriptPath );
366 $tpl->setRef( 'serverurl', $wgServer );
367 $tpl->setRef( 'logopath', $wgLogo );
368 $tpl->setRef( 'sitename', $wgSitename );
370 $userLang = $this->getLanguage();
371 $userLangCode = $userLang->getHtmlCode();
372 $userLangDir = $userLang->getDir();
374 $tpl->set( 'lang', $userLangCode );
375 $tpl->set( 'dir', $userLangDir );
376 $tpl->set( 'rtl', $userLang->isRTL() );
378 $tpl->set( 'capitalizeallnouns', $userLang->capitalizeAllNouns() ?
' capitalize-all-nouns' : '' );
379 $tpl->set( 'showjumplinks', true ); // showjumplinks preference has been removed
380 $tpl->set( 'username', $this->loggedin ?
$this->username
: null );
381 $tpl->setRef( 'userpage', $this->userpage
);
382 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails
['href'] );
383 $tpl->set( 'userlang', $userLangCode );
385 // Users can have their language set differently than the
386 // content of the wiki. For these users, tell the web browser
387 // that interface elements are in a different language.
388 $tpl->set( 'userlangattributes', '' );
389 $tpl->set( 'specialpageattributes', '' ); # obsolete
391 if ( $userLangCode !== $wgContLang->getHtmlCode() ||
$userLangDir !== $wgContLang->getDir() ) {
392 $escUserlang = htmlspecialchars( $userLangCode );
393 $escUserdir = htmlspecialchars( $userLangDir );
394 // Attributes must be in double quotes because htmlspecialchars() doesn't
395 // escape single quotes
396 $attrs = " lang=\"$escUserlang\" dir=\"$escUserdir\"";
397 $tpl->set( 'userlangattributes', $attrs );
400 wfProfileOut( __METHOD__
. '-stuff2' );
402 wfProfileIn( __METHOD__
. '-stuff3' );
403 $tpl->set( 'newtalk', $this->getNewtalks() );
404 $tpl->set( 'logo', $this->logoText() );
406 $tpl->set( 'copyright', false );
407 $tpl->set( 'viewcount', false );
408 $tpl->set( 'lastmod', false );
409 $tpl->set( 'credits', false );
410 $tpl->set( 'numberofwatchingusers', false );
411 if ( $out->isArticle() && $title->exists() ) {
412 if ( $this->isRevisionCurrent() ) {
413 if ( !$wgDisableCounters ) {
414 $viewcount = $this->getWikiPage()->getCount();
416 $tpl->set( 'viewcount', $this->msg( 'viewcount' )->numParams( $viewcount )->parse() );
420 if ( $wgPageShowWatchingUsers ) {
421 $dbr = wfGetDB( DB_SLAVE
);
422 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
423 array( 'wl_title' => $title->getDBkey(), 'wl_namespace' => $title->getNamespace() ),
427 $tpl->set( 'numberofwatchingusers',
428 $this->msg( 'number_of_watching_users_pageview' )->numParams( $num )->parse()
433 if ( $wgMaxCredits != 0 ) {
434 $tpl->set( 'credits', Action
::factory( 'credits', $this->getWikiPage(),
435 $this->getContext() )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
437 $tpl->set( 'lastmod', $this->lastModified() );
440 $tpl->set( 'copyright', $this->getCopyright() );
442 wfProfileOut( __METHOD__
. '-stuff3' );
444 wfProfileIn( __METHOD__
. '-stuff4' );
445 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
446 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
447 $tpl->set( 'disclaimer', $this->disclaimerLink() );
448 $tpl->set( 'privacy', $this->privacyLink() );
449 $tpl->set( 'about', $this->aboutLink() );
451 $tpl->set( 'footerlinks', array(
455 'numberofwatchingusers',
466 global $wgFooterIcons;
467 $tpl->set( 'footericons', $wgFooterIcons );
468 foreach ( $tpl->data
['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
469 if ( count( $footerIconsBlock ) > 0 ) {
470 foreach ( $footerIconsBlock as &$footerIcon ) {
471 if ( isset( $footerIcon['src'] ) ) {
472 if ( !isset( $footerIcon['width'] ) ) {
473 $footerIcon['width'] = 88;
475 if ( !isset( $footerIcon['height'] ) ) {
476 $footerIcon['height'] = 31;
481 unset( $tpl->data
['footericons'][$footerIconsKey] );
485 $tpl->set( 'sitenotice', $this->getSiteNotice() );
486 $tpl->set( 'bottomscripts', $this->bottomScripts() );
487 $tpl->set( 'printfooter', $this->printSource() );
489 # An ID that includes the actual body text; without categories, contentSub, ...
490 $realBodyAttribs = array( 'id' => 'mw-content-text' );
492 # Add a mw-content-ltr/rtl class to be able to style based on text direction
493 # when the content is different from the UI language, i.e.:
494 # not for special pages or file pages AND only when viewing AND if the page exists
495 # (or is in MW namespace, because that has default content)
496 if ( !in_array( $title->getNamespace(), array( NS_SPECIAL
, NS_FILE
) ) &&
497 Action
::getActionName( $this ) === 'view' &&
498 ( $title->exists() ||
$title->getNamespace() == NS_MEDIAWIKI
) ) {
499 $pageLang = $title->getPageViewLanguage();
500 $realBodyAttribs['lang'] = $pageLang->getHtmlCode();
501 $realBodyAttribs['dir'] = $pageLang->getDir();
502 $realBodyAttribs['class'] = 'mw-content-' . $pageLang->getDir();
505 $out->mBodytext
= Html
::rawElement( 'div', $realBodyAttribs, $out->mBodytext
);
506 $tpl->setRef( 'bodytext', $out->mBodytext
);
508 $language_urls = $this->getLanguages();
509 if ( count( $language_urls ) ) {
510 $tpl->setRef( 'language_urls', $language_urls );
512 $tpl->set( 'language_urls', false );
514 wfProfileOut( __METHOD__
. '-stuff4' );
516 wfProfileIn( __METHOD__
. '-stuff5' );
518 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
519 $content_navigation = $this->buildContentNavigationUrls();
520 $content_actions = $this->buildContentActionUrls( $content_navigation );
521 $tpl->setRef( 'content_navigation', $content_navigation );
522 $tpl->setRef( 'content_actions', $content_actions );
524 $tpl->set( 'sidebar', $this->buildSidebar() );
525 $tpl->set( 'nav_urls', $this->buildNavUrls() );
527 // Set the head scripts near the end, in case the above actions resulted in added scripts
528 if ( $this->useHeadElement
) {
529 $tpl->set( 'headelement', $out->headElement( $this ) );
531 $tpl->set( 'headscripts', $out->getHeadScripts() . $out->getHeadItems() );
534 $tpl->set( 'debug', '' );
535 $tpl->set( 'debughtml', $this->generateDebugHTML() );
536 $tpl->set( 'reporttime', wfReportTime() );
538 // original version by hansm
539 if ( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
540 wfDebug( __METHOD__
. ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
543 // Set the bodytext to another key so that skins can just output it on it's own
544 // and output printfooter and debughtml separately
545 $tpl->set( 'bodycontent', $tpl->data
['bodytext'] );
547 // Append printfooter and debughtml onto bodytext so that skins that were already
548 // using bodytext before they were split out don't suddenly start not outputting information
549 $tpl->data
['bodytext'] .= Html
::rawElement( 'div', array( 'class' => 'printfooter' ), "\n{$tpl->data['printfooter']}" ) . "\n";
550 $tpl->data
['bodytext'] .= $tpl->data
['debughtml'];
552 // allow extensions adding stuff after the page content.
553 // See Skin::afterContentHook() for further documentation.
554 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
555 wfProfileOut( __METHOD__
. '-stuff5' );
557 wfProfileOut( __METHOD__
);
562 * Get the HTML for the p-personal list
565 public function getPersonalToolsList() {
566 $tpl = $this->setupTemplateForOutput();
567 $tpl->set( 'personal_urls', $this->buildPersonalUrls() );
569 foreach ( $tpl->getPersonalTools() as $key => $item ) {
570 $html .= $tpl->makeListItem( $key, $item );
576 * Format language name for use in sidebar interlanguage links list.
577 * By default it is capitalized.
579 * @param string $name Language name, e.g. "English" or "español"
583 function formatLanguageName( $name ) {
584 return $this->getLanguage()->ucfirst( $name );
588 * Output the string, or print error message if it's
589 * an error object of the appropriate type.
590 * For the base class, assume strings all around.
595 function printOrError( $str ) {
600 * Output a boolean indicating if buildPersonalUrls should output separate
601 * login and create account links or output a combined link
602 * By default we simply return a global config setting that affects most skins
603 * This is setup as a method so that like with $wgLogo and getLogo() a skin
604 * can override this setting and always output one or the other if it has
605 * a reason it can't output one of the two modes.
608 function useCombinedLoginLink() {
609 global $wgUseCombinedLoginLink;
610 return $wgUseCombinedLoginLink;
614 * build array of urls for personal toolbar
617 protected function buildPersonalUrls() {
618 $title = $this->getTitle();
619 $request = $this->getRequest();
620 $pageurl = $title->getLocalURL();
621 wfProfileIn( __METHOD__
);
623 /* set up the default links for the personal toolbar */
624 $personal_urls = array();
626 # Due to bug 32276, if a user does not have read permissions,
627 # $this->getTitle() will just give Special:Badtitle, which is
628 # not especially useful as a returnto parameter. Use the title
629 # from the request instead, if there was one.
630 if ( $this->getUser()->isAllowed( 'read' ) ) {
631 $page = $this->getTitle();
633 $page = Title
::newFromText( $request->getVal( 'title', '' ) );
635 $page = $request->getVal( 'returnto', $page );
637 if ( strval( $page ) !== '' ) {
638 $a['returnto'] = $page;
639 $query = $request->getVal( 'returntoquery', $this->thisquery
);
640 if ( $query != '' ) {
641 $a['returntoquery'] = $query;
645 $returnto = wfArrayToCgi( $a );
646 if ( $this->loggedin
) {
647 $personal_urls['userpage'] = array(
648 'text' => $this->username
,
649 'href' => &$this->userpageUrlDetails
['href'],
650 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
651 'active' => ( $this->userpageUrlDetails
['href'] == $pageurl ),
654 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
655 $personal_urls['mytalk'] = array(
656 'text' => $this->msg( 'mytalk' )->text(),
657 'href' => &$usertalkUrlDetails['href'],
658 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
659 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
661 $href = self
::makeSpecialUrl( 'Preferences' );
662 $personal_urls['preferences'] = array(
663 'text' => $this->msg( 'mypreferences' )->text(),
665 'active' => ( $href == $pageurl )
668 if ( $this->getUser()->isAllowed( 'viewmywatchlist' ) ) {
669 $href = self
::makeSpecialUrl( 'Watchlist' );
670 $personal_urls['watchlist'] = array(
671 'text' => $this->msg( 'mywatchlist' )->text(),
673 'active' => ( $href == $pageurl )
677 # We need to do an explicit check for Special:Contributions, as we
678 # have to match both the title, and the target, which could come
679 # from request values (Special:Contributions?target=Jimbo_Wales)
680 # or be specified in "sub page" form
681 # (Special:Contributions/Jimbo_Wales). The plot
682 # thickens, because the Title object is altered for special pages,
683 # so it doesn't contain the original alias-with-subpage.
684 $origTitle = Title
::newFromText( $request->getText( 'title' ) );
685 if ( $origTitle instanceof Title
&& $origTitle->isSpecialPage() ) {
686 list( $spName, $spPar ) = SpecialPageFactory
::resolveAlias( $origTitle->getText() );
687 $active = $spName == 'Contributions'
688 && ( ( $spPar && $spPar == $this->username
)
689 ||
$request->getText( 'target' ) == $this->username
);
694 $href = self
::makeSpecialUrlSubpage( 'Contributions', $this->username
);
695 $personal_urls['mycontris'] = array(
696 'text' => $this->msg( 'mycontris' )->text(),
700 $personal_urls['logout'] = array(
701 'text' => $this->msg( 'userlogout' )->text(),
702 'href' => self
::makeSpecialUrl( 'Userlogout',
703 // userlogout link must always contain an & character, otherwise we might not be able
704 // to detect a buggy precaching proxy (bug 17790)
705 $title->isSpecial( 'Preferences' ) ?
'noreturnto' : $returnto
710 $useCombinedLoginLink = $this->useCombinedLoginLink();
711 $loginlink = $this->getUser()->isAllowed( 'createaccount' ) && $useCombinedLoginLink
712 ?
'nav-login-createaccount'
714 $is_signup = $request->getText( 'type' ) == 'signup';
716 $login_id = $this->showIPinHeader() ?
'anonlogin' : 'login';
718 'text' => $this->msg( $loginlink )->text(),
719 'href' => self
::makeSpecialUrl( 'Userlogin', $returnto ),
720 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == 'nav-login-createaccount' ||
!$is_signup ),
722 $createaccount_url = array(
723 'text' => $this->msg( 'createaccount' )->text(),
724 'href' => self
::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
725 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup,
728 if ( $this->showIPinHeader() ) {
729 $href = &$this->userpageUrlDetails
['href'];
730 $personal_urls['anonuserpage'] = array(
731 'text' => $this->username
,
733 'class' => $this->userpageUrlDetails
['exists'] ?
false : 'new',
734 'active' => ( $pageurl == $href )
736 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage
);
737 $href = &$usertalkUrlDetails['href'];
738 $personal_urls['anontalk'] = array(
739 'text' => $this->msg( 'anontalk' )->text(),
741 'class' => $usertalkUrlDetails['exists'] ?
false : 'new',
742 'active' => ( $pageurl == $href )
746 if ( $this->getUser()->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
747 $personal_urls['createaccount'] = $createaccount_url;
750 $personal_urls[$login_id] = $login_url;
753 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title, $this ) );
754 wfProfileOut( __METHOD__
);
755 return $personal_urls;
759 * Builds an array with tab definition
761 * @param Title $title page where the tab links to
762 * @param string|array $message message key or an array of message keys (will fall back)
763 * @param boolean $selected display the tab as selected
764 * @param string $query query string attached to tab URL
765 * @param boolean $checkEdit check if $title exists and mark with .new if one doesn't
769 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
772 $classes[] = 'selected';
774 if ( $checkEdit && !$title->isKnown() ) {
776 if ( $query !== '' ) {
777 $query = 'action=edit&redlink=1&' . $query;
779 $query = 'action=edit&redlink=1';
783 // wfMessageFallback will nicely accept $message as an array of fallbacks
784 // or just a single key
785 $msg = wfMessageFallback( $message )->setContext( $this->getContext() );
786 if ( is_array( $message ) ) {
787 // for hook compatibility just keep the last message name
788 $message = end( $message );
790 if ( $msg->exists() ) {
791 $text = $msg->text();
794 $text = $wgContLang->getFormattedNsText(
795 MWNamespace
::getSubject( $title->getNamespace() ) );
799 if ( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
800 $title, $message, $selected, $checkEdit,
801 &$classes, &$query, &$text, &$result ) ) ) {
806 'class' => implode( ' ', $classes ),
808 'href' => $title->getLocalURL( $query ),
812 function makeTalkUrlDetails( $name, $urlaction = '' ) {
813 $title = Title
::newFromText( $name );
814 if ( !is_object( $title ) ) {
815 throw new MWException( __METHOD__
. " given invalid pagename $name" );
817 $title = $title->getTalkPage();
818 self
::checkTitle( $title, $name );
820 'href' => $title->getLocalURL( $urlaction ),
821 'exists' => $title->getArticleID() != 0,
825 function makeArticleUrlDetails( $name, $urlaction = '' ) {
826 $title = Title
::newFromText( $name );
827 $title = $title->getSubjectPage();
828 self
::checkTitle( $title, $name );
830 'href' => $title->getLocalURL( $urlaction ),
831 'exists' => $title->getArticleID() != 0,
836 * a structured array of links usually used for the tabs in a skin
838 * There are 4 standard sections
839 * namespaces: Used for namespace tabs like special, page, and talk namespaces
840 * views: Used for primary page views like read, edit, history
841 * actions: Used for most extra page actions like deletion, protection, etc...
842 * variants: Used to list the language variants for the page
844 * Each section's value is a key/value array of links for that section.
845 * The links themselves have these common keys:
846 * - class: The css classes to apply to the tab
847 * - text: The text to display on the tab
848 * - href: The href for the tab to point to
849 * - rel: An optional rel= for the tab's link
850 * - redundant: If true the tab will be dropped in skins using content_actions
851 * this is useful for tabs like "Read" which only have meaning in skins that
852 * take special meaning from the grouped structure of content_navigation
854 * Views also have an extra key which can be used:
855 * - primary: If this is not true skins like vector may try to hide the tab
856 * when the user has limited space in their browser window
858 * content_navigation using code also expects these ids to be present on the
859 * links, however these are usually automatically generated by SkinTemplate
860 * itself and are not necessary when using a hook. The only things these may
861 * matter to are people modifying content_navigation after it's initial creation:
862 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
863 * - tooltiponly: This is set to true for some tabs in cases where the system
864 * believes that the accesskey should not be added to the tab.
868 protected function buildContentNavigationUrls() {
869 global $wgDisableLangConversion;
871 wfProfileIn( __METHOD__
);
873 // Display tabs for the relevant title rather than always the title itself
874 $title = $this->getRelevantTitle();
875 $onPage = $title->equals( $this->getTitle() );
877 $out = $this->getOutput();
878 $request = $this->getRequest();
879 $user = $this->getUser();
881 $content_navigation = array(
882 'namespaces' => array(),
884 'actions' => array(),
885 'variants' => array()
889 $action = $request->getVal( 'action', 'view' );
891 $userCanRead = $title->quickUserCan( 'read', $user );
893 $preventActiveTabs = false;
894 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
896 // Checks if page is some kind of content
897 if ( $title->canExist() ) {
898 // Gets page objects for the related namespaces
899 $subjectPage = $title->getSubjectPage();
900 $talkPage = $title->getTalkPage();
902 // Determines if this is a talk page
903 $isTalk = $title->isTalkPage();
905 // Generates XML IDs from namespace names
906 $subjectId = $title->getNamespaceKey( '' );
908 if ( $subjectId == 'main' ) {
911 $talkId = "{$subjectId}_talk";
914 $skname = $this->skinname
;
916 // Adds namespace links
917 $subjectMsg = array( "nstab-$subjectId" );
918 if ( $subjectPage->isMainPage() ) {
919 array_unshift( $subjectMsg, 'mainpage-nstab' );
921 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
922 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
924 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
925 $content_navigation['namespaces'][$talkId] = $this->tabAction(
926 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
928 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
930 if ( $userCanRead ) {
931 // Adds view view link
932 if ( $title->exists() ) {
933 $content_navigation['views']['view'] = $this->tabAction(
934 $isTalk ?
$talkPage : $subjectPage,
935 array( "$skname-view-view", 'view' ),
936 ( $onPage && ( $action == 'view' ||
$action == 'purge' ) ), '', true
938 // signal to hide this from simple content_actions
939 $content_navigation['views']['view']['redundant'] = true;
942 wfProfileIn( __METHOD__
. '-edit' );
944 // Checks if user can edit the current page if it exists or create it otherwise
945 if ( $title->quickUserCan( 'edit', $user ) && ( $title->exists() ||
$title->quickUserCan( 'create', $user ) ) ) {
946 // Builds CSS class for talk page links
947 $isTalkClass = $isTalk ?
' istalk' : '';
948 // Whether the user is editing the page
949 $isEditing = $onPage && ( $action == 'edit' ||
$action == 'submit' );
950 // Whether to show the "Add a new section" tab
951 // Checks if this is a current rev of talk page and is not forced to be hidden
952 $showNewSection = !$out->forceHideNewSectionLink()
953 && ( ( $isTalk && $this->isRevisionCurrent() ) ||
$out->showNewSectionLink() );
954 $section = $request->getVal( 'section' );
956 $msgKey = $title->exists() ||
( $title->getNamespace() == NS_MEDIAWIKI
&& $title->getDefaultMessageText() !== false ) ?
958 $content_navigation['views']['edit'] = array(
959 'class' => ( $isEditing && ( $section !== 'new' ||
!$showNewSection ) ?
'selected' : '' ) . $isTalkClass,
960 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->setContext( $this->getContext() )->text(),
961 'href' => $title->getLocalURL( $this->editUrlOptions() ),
962 'primary' => true, // don't collapse this in vector
966 if ( $showNewSection ) {
967 // Adds new section link
968 //$content_navigation['actions']['addsection']
969 $content_navigation['views']['addsection'] = array(
970 'class' => ( $isEditing && $section == 'new' ) ?
'selected' : false,
971 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->setContext( $this->getContext() )->text(),
972 'href' => $title->getLocalURL( 'action=edit§ion=new' )
975 // Checks if the page has some kind of viewable content
976 } elseif ( $title->hasSourceText() ) {
977 // Adds view source view link
978 $content_navigation['views']['viewsource'] = array(
979 'class' => ( $onPage && $action == 'edit' ) ?
'selected' : false,
980 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->setContext( $this->getContext() )->text(),
981 'href' => $title->getLocalURL( $this->editUrlOptions() ),
982 'primary' => true, // don't collapse this in vector
985 wfProfileOut( __METHOD__
. '-edit' );
987 wfProfileIn( __METHOD__
. '-live' );
988 // Checks if the page exists
989 if ( $title->exists() ) {
990 // Adds history view link
991 $content_navigation['views']['history'] = array(
992 'class' => ( $onPage && $action == 'history' ) ?
'selected' : false,
993 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->setContext( $this->getContext() )->text(),
994 'href' => $title->getLocalURL( 'action=history' ),
998 if ( $title->quickUserCan( 'delete', $user ) ) {
999 $content_navigation['actions']['delete'] = array(
1000 'class' => ( $onPage && $action == 'delete' ) ?
'selected' : false,
1001 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->setContext( $this->getContext() )->text(),
1002 'href' => $title->getLocalURL( 'action=delete' )
1006 if ( $title->quickUserCan( 'move', $user ) ) {
1007 $moveTitle = SpecialPage
::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
1008 $content_navigation['actions']['move'] = array(
1009 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ?
'selected' : false,
1010 'text' => wfMessageFallback( "$skname-action-move", 'move' )->setContext( $this->getContext() )->text(),
1011 'href' => $moveTitle->getLocalURL()
1015 // article doesn't exist or is deleted
1016 if ( $user->isAllowed( 'deletedhistory' ) ) {
1017 $n = $title->isDeleted();
1019 $undelTitle = SpecialPage
::getTitleFor( 'Undelete' );
1020 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
1021 $msgKey = $user->isAllowed( 'undelete' ) ?
'undelete' : 'viewdeleted';
1022 $content_navigation['actions']['undelete'] = array(
1023 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ?
'selected' : false,
1024 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
1025 ->setContext( $this->getContext() )->numParams( $n )->text(),
1026 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
1032 if ( $title->getNamespace() !== NS_MEDIAWIKI
&& $title->quickUserCan( 'protect', $user ) && $title->getRestrictionTypes() ) {
1033 $mode = $title->isProtected() ?
'unprotect' : 'protect';
1034 $content_navigation['actions'][$mode] = array(
1035 'class' => ( $onPage && $action == $mode ) ?
'selected' : false,
1036 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->setContext( $this->getContext() )->text(),
1037 'href' => $title->getLocalURL( "action=$mode" )
1041 wfProfileOut( __METHOD__
. '-live' );
1043 // Checks if the user is logged in
1044 if ( $this->loggedin
&& $user->isAllowedAll( 'viewmywatchlist', 'editmywatchlist' ) ) {
1046 * The following actions use messages which, if made particular to
1047 * the any specific skins, would break the Ajax code which makes this
1048 * action happen entirely inline. Skin::makeGlobalVariablesScript
1049 * defines a set of messages in a javascript object - and these
1050 * messages are assumed to be global for all skins. Without making
1051 * a change to that procedure these messages will have to remain as
1052 * the global versions.
1054 $mode = $user->isWatched( $title ) ?
'unwatch' : 'watch';
1055 $token = WatchAction
::getWatchToken( $title, $user, $mode );
1056 $content_navigation['actions'][$mode] = array(
1057 'class' => $onPage && ( $action == 'watch' ||
$action == 'unwatch' ) ?
'selected' : false,
1058 // uses 'watch' or 'unwatch' message
1059 'text' => $this->msg( $mode )->text(),
1060 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
1065 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
1067 if ( $userCanRead && !$wgDisableLangConversion ) {
1068 $pageLang = $title->getPageLanguage();
1069 // Gets list of language variants
1070 $variants = $pageLang->getVariants();
1071 // Checks that language conversion is enabled and variants exist
1072 // And if it is not in the special namespace
1073 if ( count( $variants ) > 1 ) {
1074 // Gets preferred variant (note that user preference is
1075 // only possible for wiki content language variant)
1076 $preferred = $pageLang->getPreferredVariant();
1077 if ( Action
::getActionName( $this ) === 'view' ) {
1078 $params = $request->getQueryValues();
1079 unset( $params['title'] );
1083 // Loops over each variant
1084 foreach ( $variants as $code ) {
1085 // Gets variant name from language code
1086 $varname = $pageLang->getVariantname( $code );
1087 // Appends variant link
1088 $content_navigation['variants'][] = array(
1089 'class' => ( $code == $preferred ) ?
'selected' : false,
1091 'href' => $title->getLocalURL( array( 'variant' => $code ) +
$params ),
1092 'lang' => wfBCP47( $code ),
1093 'hreflang' => wfBCP47( $code ),
1099 // If it's not content, it's got to be a special page
1100 $content_navigation['namespaces']['special'] = array(
1101 'class' => 'selected',
1102 'text' => $this->msg( 'nstab-special' )->text(),
1103 'href' => $request->getRequestURL(), // @see: bug 2457, bug 2510
1104 'context' => 'subject'
1107 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
1108 array( &$this, &$content_navigation ) );
1111 // Equiv to SkinTemplateContentActions
1112 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1114 // Setup xml ids and tooltip info
1115 foreach ( $content_navigation as $section => &$links ) {
1116 foreach ( $links as $key => &$link ) {
1118 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1119 $xmlID = 'ca-nstab-' . $xmlID;
1120 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1122 } elseif ( $section == 'variants' ) {
1123 $xmlID = 'ca-varlang-' . $xmlID;
1125 $xmlID = 'ca-' . $xmlID;
1127 $link['id'] = $xmlID;
1131 # We don't want to give the watch tab an accesskey if the
1132 # page is being edited, because that conflicts with the
1133 # accesskey on the watch checkbox. We also don't want to
1134 # give the edit tab an accesskey, because that's fairly
1135 # superfluous and conflicts with an accesskey (Ctrl-E) often
1136 # used for editing in Safari.
1137 if ( in_array( $action, array( 'edit', 'submit' ) ) ) {
1138 if ( isset( $content_navigation['views']['edit'] ) ) {
1139 $content_navigation['views']['edit']['tooltiponly'] = true;
1141 if ( isset( $content_navigation['actions']['watch'] ) ) {
1142 $content_navigation['actions']['watch']['tooltiponly'] = true;
1144 if ( isset( $content_navigation['actions']['unwatch'] ) ) {
1145 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1149 wfProfileOut( __METHOD__
);
1151 return $content_navigation;
1155 * an array of edit links by default used for the tabs
1159 function buildContentActionUrls( $content_navigation ) {
1161 wfProfileIn( __METHOD__
);
1163 // content_actions has been replaced with content_navigation for backwards
1164 // compatibility and also for skins that just want simple tabs content_actions
1165 // is now built by flattening the content_navigation arrays into one
1167 $content_actions = array();
1169 foreach ( $content_navigation as $links ) {
1171 foreach ( $links as $key => $value ) {
1173 if ( isset( $value['redundant'] ) && $value['redundant'] ) {
1174 // Redundant tabs are dropped from content_actions
1178 // content_actions used to have ids built using the "ca-$key" pattern
1179 // so the xmlID based id is much closer to the actual $key that we want
1180 // for that reason we'll just strip out the ca- if present and use
1181 // the latter potion of the "id" as the $key
1182 if ( isset( $value['id'] ) && substr( $value['id'], 0, 3 ) == 'ca-' ) {
1183 $key = substr( $value['id'], 3 );
1186 if ( isset( $content_actions[$key] ) ) {
1187 wfDebug( __METHOD__
. ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1191 $content_actions[$key] = $value;
1197 wfProfileOut( __METHOD__
);
1199 return $content_actions;
1203 * build array of common navigation links
1207 protected function buildNavUrls() {
1208 global $wgUploadNavigationUrl;
1210 wfProfileIn( __METHOD__
);
1212 $out = $this->getOutput();
1213 $request = $this->getRequest();
1215 $nav_urls = array();
1216 $nav_urls['mainpage'] = array( 'href' => self
::makeMainPageUrl() );
1217 if ( $wgUploadNavigationUrl ) {
1218 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1219 } elseif ( UploadBase
::isEnabled() && UploadBase
::isAllowed( $this->getUser() ) === true ) {
1220 $nav_urls['upload'] = array( 'href' => self
::makeSpecialUrl( 'Upload' ) );
1222 $nav_urls['upload'] = false;
1224 $nav_urls['specialpages'] = array( 'href' => self
::makeSpecialUrl( 'Specialpages' ) );
1226 $nav_urls['print'] = false;
1227 $nav_urls['permalink'] = false;
1228 $nav_urls['info'] = false;
1229 $nav_urls['whatlinkshere'] = false;
1230 $nav_urls['recentchangeslinked'] = false;
1231 $nav_urls['contributions'] = false;
1232 $nav_urls['log'] = false;
1233 $nav_urls['blockip'] = false;
1234 $nav_urls['emailuser'] = false;
1235 $nav_urls['userrights'] = false;
1237 // A print stylesheet is attached to all pages, but nobody ever
1238 // figures that out. :) Add a link...
1239 if ( !$out->isPrintable() && ( $out->isArticle() ||
$this->getTitle()->isSpecialPage() ) ) {
1240 $nav_urls['print'] = array(
1241 'text' => $this->msg( 'printableversion' )->text(),
1242 'href' => $this->getTitle()->getLocalURL(
1243 $request->appendQueryValue( 'printable', 'yes', true ) )
1247 if ( $out->isArticle() ) {
1248 // Also add a "permalink" while we're at it
1249 $revid = $this->getRevisionId();
1251 $nav_urls['permalink'] = array(
1252 'text' => $this->msg( 'permalink' )->text(),
1253 'href' => $this->getTitle()->getLocalURL( "oldid=$revid" )
1257 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1258 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1259 array( &$this, &$nav_urls, &$revid, &$revid ) );
1262 if ( $out->isArticleRelated() ) {
1263 $nav_urls['whatlinkshere'] = array(
1264 'href' => SpecialPage
::getTitleFor( 'Whatlinkshere', $this->thispage
)->getLocalURL()
1267 $nav_urls['info'] = array(
1268 'text' => $this->msg( 'pageinfo-toolboxlink' )->text(),
1269 'href' => $this->getTitle()->getLocalURL( "action=info" )
1272 if ( $this->getTitle()->getArticleID() ) {
1273 $nav_urls['recentchangeslinked'] = array(
1274 'href' => SpecialPage
::getTitleFor( 'Recentchangeslinked', $this->thispage
)->getLocalURL()
1279 $user = $this->getRelevantUser();
1281 $rootUser = $user->getName();
1283 $nav_urls['contributions'] = array(
1284 'text' => $this->msg( 'contributions', $rootUser )->text(),
1285 'href' => self
::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1288 $nav_urls['log'] = array(
1289 'href' => self
::makeSpecialUrlSubpage( 'Log', $rootUser )
1292 if ( $this->getUser()->isAllowed( 'block' ) ) {
1293 $nav_urls['blockip'] = array(
1294 'href' => self
::makeSpecialUrlSubpage( 'Block', $rootUser )
1298 if ( $this->showEmailUser( $user ) ) {
1299 $nav_urls['emailuser'] = array(
1300 'href' => self
::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1304 if ( !$user->isAnon() ) {
1305 $sur = new UserrightsPage
;
1306 $sur->setContext( $this->getContext() );
1307 if ( $sur->userCanExecute( $this->getUser() ) ) {
1308 $nav_urls['userrights'] = array(
1309 'href' => self
::makeSpecialUrlSubpage( 'Userrights', $rootUser )
1315 wfProfileOut( __METHOD__
);
1320 * Generate strings used for xml 'id' names
1324 function getNameSpaceKey() {
1325 return $this->getTitle()->getNamespaceKey();
1330 * Generic wrapper for template functions, with interface
1331 * compatible with what we use of PHPTAL 0.7.
1334 abstract class QuickTemplate
{
1338 function __construct() {
1339 $this->data
= array();
1340 $this->translator
= new MediaWiki_I18N();
1344 * Sets the value $value to $name
1348 public function set( $name, $value ) {
1349 $this->data
[$name] = $value;
1353 * Gets the template data requested
1355 * @param string $name Key for the data
1356 * @param mixed $default Optional default (or null)
1357 * @return mixed The value of the data requested or the deafult
1359 public function get( $name, $default = null ) {
1360 if ( isset( $this->data
[$name] ) ) {
1361 return $this->data
[$name];
1371 public function setRef( $name, &$value ) {
1372 $this->data
[$name] =& $value;
1378 public function setTranslator( &$t ) {
1379 $this->translator
= &$t;
1383 * Main function, used by classes that subclass QuickTemplate
1384 * to show the actual HTML output
1386 abstract public function execute();
1391 function text( $str ) {
1392 echo htmlspecialchars( $this->data
[$str] );
1397 * @deprecated since 1.21; use Xml::encodeJsVar() or Xml::encodeJsCall() instead
1399 function jstext( $str ) {
1400 wfDeprecated( __METHOD__
, '1.21' );
1401 echo Xml
::escapeJsString( $this->data
[$str] );
1407 function html( $str ) {
1408 echo $this->data
[$str];
1414 function msg( $str ) {
1415 echo htmlspecialchars( $this->translator
->translate( $str ) );
1421 function msgHtml( $str ) {
1422 echo $this->translator
->translate( $str );
1426 * An ugly, ugly hack.
1429 function msgWiki( $str ) {
1432 $text = $this->translator
->translate( $str );
1433 echo $wgOut->parse( $text );
1440 function haveData( $str ) {
1441 return isset( $this->data
[$str] );
1449 function haveMsg( $str ) {
1450 $msg = $this->translator
->translate( $str );
1451 return ( $msg != '-' ) && ( $msg != '' ); # ????
1455 * Get the Skin object related to this object
1457 * @return Skin object
1459 public function getSkin() {
1460 return $this->data
['skin'];
1464 * Fetch the output of a QuickTemplate and return it
1469 public function getHTML() {
1472 $html = ob_get_contents();
1479 * New base template for a skin's template extended from QuickTemplate
1480 * this class features helper methods that provide common ways of interacting
1481 * with the data stored in the QuickTemplate
1483 abstract class BaseTemplate
extends QuickTemplate
{
1486 * Get a Message object with its context set
1488 * @param string $name message name
1491 public function getMsg( $name ) {
1492 return $this->getSkin()->msg( $name );
1495 function msg( $str ) {
1496 echo $this->getMsg( $str )->escaped();
1499 function msgHtml( $str ) {
1500 echo $this->getMsg( $str )->text();
1503 function msgWiki( $str ) {
1504 echo $this->getMsg( $str )->parseAsBlock();
1508 * Create an array of common toolbox items from the data in the quicktemplate
1509 * stored by SkinTemplate.
1510 * The resulting array is built according to a format intended to be passed
1511 * through makeListItem to generate the html.
1514 function getToolbox() {
1515 wfProfileIn( __METHOD__
);
1518 if ( isset( $this->data
['nav_urls']['whatlinkshere'] ) && $this->data
['nav_urls']['whatlinkshere'] ) {
1519 $toolbox['whatlinkshere'] = $this->data
['nav_urls']['whatlinkshere'];
1520 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1522 if ( isset( $this->data
['nav_urls']['recentchangeslinked'] ) && $this->data
['nav_urls']['recentchangeslinked'] ) {
1523 $toolbox['recentchangeslinked'] = $this->data
['nav_urls']['recentchangeslinked'];
1524 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1525 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1527 if ( isset( $this->data
['feeds'] ) && $this->data
['feeds'] ) {
1528 $toolbox['feeds']['id'] = 'feedlinks';
1529 $toolbox['feeds']['links'] = array();
1530 foreach ( $this->data
['feeds'] as $key => $feed ) {
1531 $toolbox['feeds']['links'][$key] = $feed;
1532 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1533 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1534 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1535 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1538 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'userrights', 'upload', 'specialpages' ) as $special ) {
1539 if ( isset( $this->data
['nav_urls'][$special] ) && $this->data
['nav_urls'][$special] ) {
1540 $toolbox[$special] = $this->data
['nav_urls'][$special];
1541 $toolbox[$special]['id'] = "t-$special";
1544 if ( isset( $this->data
['nav_urls']['print'] ) && $this->data
['nav_urls']['print'] ) {
1545 $toolbox['print'] = $this->data
['nav_urls']['print'];
1546 $toolbox['print']['id'] = 't-print';
1547 $toolbox['print']['rel'] = 'alternate';
1548 $toolbox['print']['msg'] = 'printableversion';
1550 if ( isset( $this->data
['nav_urls']['permalink'] ) && $this->data
['nav_urls']['permalink'] ) {
1551 $toolbox['permalink'] = $this->data
['nav_urls']['permalink'];
1552 if ( $toolbox['permalink']['href'] === '' ) {
1553 unset( $toolbox['permalink']['href'] );
1554 $toolbox['ispermalink']['tooltiponly'] = true;
1555 $toolbox['ispermalink']['id'] = 't-ispermalink';
1556 $toolbox['ispermalink']['msg'] = 'permalink';
1558 $toolbox['permalink']['id'] = 't-permalink';
1561 if ( isset( $this->data
['nav_urls']['info'] ) && $this->data
['nav_urls']['info'] ) {
1562 $toolbox['info'] = $this->data
['nav_urls']['info'];
1563 $toolbox['info']['id'] = 't-info';
1566 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1567 wfProfileOut( __METHOD__
);
1572 * Create an array of personal tools items from the data in the quicktemplate
1573 * stored by SkinTemplate.
1574 * The resulting array is built according to a format intended to be passed
1575 * through makeListItem to generate the html.
1576 * This is in reality the same list as already stored in personal_urls
1577 * however it is reformatted so that you can just pass the individual items
1578 * to makeListItem instead of hardcoding the element creation boilerplate.
1581 function getPersonalTools() {
1582 $personal_tools = array();
1583 foreach ( $this->get( 'personal_urls' ) as $key => $plink ) {
1584 # The class on a personal_urls item is meant to go on the <a> instead
1585 # of the <li> so we have to use a single item "links" array instead
1586 # of using most of the personal_url's keys directly.
1589 array( 'single-id' => "pt-$key" ),
1593 if ( isset( $plink['active'] ) ) {
1594 $ptool['active'] = $plink['active'];
1596 foreach ( array( 'href', 'class', 'text' ) as $k ) {
1597 if ( isset( $plink[$k] ) ) {
1598 $ptool['links'][0][$k] = $plink[$k];
1601 $personal_tools[$key] = $ptool;
1603 return $personal_tools;
1606 function getSidebar( $options = array() ) {
1607 // Force the rendering of the following portals
1608 $sidebar = $this->data
['sidebar'];
1609 if ( !isset( $sidebar['SEARCH'] ) ) {
1610 $sidebar['SEARCH'] = true;
1612 if ( !isset( $sidebar['TOOLBOX'] ) ) {
1613 $sidebar['TOOLBOX'] = true;
1615 if ( !isset( $sidebar['LANGUAGES'] ) ) {
1616 $sidebar['LANGUAGES'] = true;
1619 if ( !isset( $options['search'] ) ||
$options['search'] !== true ) {
1620 unset( $sidebar['SEARCH'] );
1622 if ( isset( $options['toolbox'] ) && $options['toolbox'] === false ) {
1623 unset( $sidebar['TOOLBOX'] );
1625 if ( isset( $options['languages'] ) && $options['languages'] === false ) {
1626 unset( $sidebar['LANGUAGES'] );
1630 foreach ( $sidebar as $boxName => $content ) {
1631 if ( $content === false ) {
1634 switch ( $boxName ) {
1636 // Search is a special case, skins should custom implement this
1637 $boxes[$boxName] = array(
1639 'header' => $this->getMsg( 'search' )->text(),
1640 'generated' => false,
1645 $msgObj = $this->getMsg( 'toolbox' );
1646 $boxes[$boxName] = array(
1648 'header' => $msgObj->exists() ?
$msgObj->text() : 'toolbox',
1649 'generated' => false,
1650 'content' => $this->getToolbox(),
1654 if ( $this->data
['language_urls'] ) {
1655 $msgObj = $this->getMsg( 'otherlanguages' );
1656 $boxes[$boxName] = array(
1658 'header' => $msgObj->exists() ?
$msgObj->text() : 'otherlanguages',
1659 'generated' => false,
1660 'content' => $this->data
['language_urls'],
1665 $msgObj = $this->getMsg( $boxName );
1666 $boxes[$boxName] = array(
1667 'id' => "p-$boxName",
1668 'header' => $msgObj->exists() ?
$msgObj->text() : $boxName,
1669 'generated' => true,
1670 'content' => $content,
1676 // HACK: Compatibility with extensions still using SkinTemplateToolboxEnd
1677 $hookContents = null;
1678 if ( isset( $boxes['TOOLBOX'] ) ) {
1680 // We pass an extra 'true' at the end so extensions using BaseTemplateToolbox
1681 // can abort and avoid outputting double toolbox links
1682 wfRunHooks( 'SkinTemplateToolboxEnd', array( &$this, true ) );
1683 $hookContents = ob_get_contents();
1685 if ( !trim( $hookContents ) ) {
1686 $hookContents = null;
1691 if ( isset( $options['htmlOnly'] ) && $options['htmlOnly'] === true ) {
1692 foreach ( $boxes as $boxName => $box ) {
1693 if ( is_array( $box['content'] ) ) {
1695 foreach ( $box['content'] as $key => $val ) {
1696 $content .= "\n " . $this->makeListItem( $key, $val );
1698 // HACK, shove the toolbox end onto the toolbox if we're rendering itself
1699 if ( $hookContents ) {
1700 $content .= "\n $hookContents";
1703 $content .= "\n</ul>\n";
1704 $boxes[$boxName]['content'] = $content;
1708 if ( $hookContents ) {
1709 $boxes['TOOLBOXEND'] = array(
1710 'id' => 'p-toolboxend',
1711 'header' => $boxes['TOOLBOX']['header'],
1712 'generated' => false,
1713 'content' => "<ul>{$hookContents}</ul>",
1715 // HACK: Make sure that TOOLBOXEND is sorted next to TOOLBOX
1717 foreach ( $boxes as $key => $box ) {
1718 if ( $key === 'TOOLBOXEND' ) {
1721 $boxes2[$key] = $box;
1722 if ( $key === 'TOOLBOX' ) {
1723 $boxes2['TOOLBOXEND'] = $boxes['TOOLBOXEND'];
1735 * Makes a link, usually used by makeListItem to generate a link for an item
1736 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1738 * @param string $key usually a key from the list you are generating this
1740 * @param array $item contains some of a specific set of keys.
1742 * The text of the link will be generated either from the contents of the
1743 * "text" key in the $item array, if a "msg" key is present a message by
1744 * that name will be used, and if neither of those are set the $key will be
1745 * used as a message name.
1747 * If a "href" key is not present makeLink will just output htmlescaped text.
1748 * The "href", "id", "class", "rel", and "type" keys are used as attributes
1749 * for the link if present.
1751 * If an "id" or "single-id" (if you don't want the actual id to be output
1752 * on the link) is present it will be used to generate a tooltip and
1753 * accesskey for the link.
1755 * The keys "context" and "primary" are ignored; these keys are used
1756 * internally by skins and are not supposed to be included in the HTML
1759 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1761 * @param array $options can be used to affect the output of a link.
1762 * Possible options are:
1763 * - 'text-wrapper' key to specify a list of elements to wrap the text of
1764 * a link in. This should be an array of arrays containing a 'tag' and
1765 * optionally an 'attributes' key. If you only have one element you don't
1766 * need to wrap it in another array. eg: To use <a><span>...</span></a>
1767 * in all links use array( 'text-wrapper' => array( 'tag' => 'span' ) )
1769 * - 'link-class' key can be used to specify additional classes to apply
1771 * - 'link-fallback' can be used to specify a tag to use instead of "<a>"
1772 * if there is no link. eg: If you specify 'link-fallback' => 'span' than
1773 * any non-link will output a "<span>" instead of just text.
1777 function makeLink( $key, $item, $options = array() ) {
1778 if ( isset( $item['text'] ) ) {
1779 $text = $item['text'];
1781 $text = $this->translator
->translate( isset( $item['msg'] ) ?
$item['msg'] : $key );
1784 $html = htmlspecialchars( $text );
1786 if ( isset( $options['text-wrapper'] ) ) {
1787 $wrapper = $options['text-wrapper'];
1788 if ( isset( $wrapper['tag'] ) ) {
1789 $wrapper = array( $wrapper );
1791 while ( count( $wrapper ) > 0 ) {
1792 $element = array_pop( $wrapper );
1793 $html = Html
::rawElement( $element['tag'], isset( $element['attributes'] ) ?
$element['attributes'] : null, $html );
1797 if ( isset( $item['href'] ) ||
isset( $options['link-fallback'] ) ) {
1799 foreach ( array( 'single-id', 'text', 'msg', 'tooltiponly', 'context', 'primary' ) as $k ) {
1800 unset( $attrs[$k] );
1803 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1804 $item['single-id'] = $item['id'];
1806 if ( isset( $item['single-id'] ) ) {
1807 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1808 $title = Linker
::titleAttrib( $item['single-id'] );
1809 if ( $title !== false ) {
1810 $attrs['title'] = $title;
1813 $tip = Linker
::tooltipAndAccesskeyAttribs( $item['single-id'] );
1814 if ( isset( $tip['title'] ) && $tip['title'] !== false ) {
1815 $attrs['title'] = $tip['title'];
1817 if ( isset( $tip['accesskey'] ) && $tip['accesskey'] !== false ) {
1818 $attrs['accesskey'] = $tip['accesskey'];
1822 if ( isset( $options['link-class'] ) ) {
1823 if ( isset( $attrs['class'] ) ) {
1824 $attrs['class'] .= " {$options['link-class']}";
1826 $attrs['class'] = $options['link-class'];
1829 $html = Html
::rawElement( isset( $attrs['href'] ) ?
'a' : $options['link-fallback'], $attrs, $html );
1836 * Generates a list item for a navigation, portlet, portal, sidebar... list
1838 * @param $key string, usually a key from the list you are generating this link from.
1839 * @param $item array, of list item data containing some of a specific set of keys.
1840 * The "id" and "class" keys will be used as attributes for the list item,
1841 * if "active" contains a value of true a "active" class will also be appended to class.
1843 * @param $options array
1845 * If you want something other than a "<li>" you can pass a tag name such as
1846 * "tag" => "span" in the $options array to change the tag used.
1847 * link/content data for the list item may come in one of two forms
1848 * A "links" key may be used, in which case it should contain an array with
1849 * a list of links to include inside the list item, see makeLink for the
1850 * format of individual links array items.
1852 * Otherwise the relevant keys from the list item $item array will be passed
1853 * to makeLink instead. Note however that "id" and "class" are used by the
1854 * list item directly so they will not be passed to makeLink
1855 * (however the link will still support a tooltip and accesskey from it)
1856 * If you need an id or class on a single link you should include a "links"
1857 * array with just one link item inside of it.
1858 * $options is also passed on to makeLink calls
1862 function makeListItem( $key, $item, $options = array() ) {
1863 if ( isset( $item['links'] ) ) {
1865 foreach ( $item['links'] as $linkKey => $link ) {
1866 $html .= $this->makeLink( $linkKey, $link, $options );
1870 // These keys are used by makeListItem and shouldn't be passed on to the link
1871 foreach ( array( 'id', 'class', 'active', 'tag' ) as $k ) {
1874 if ( isset( $item['id'] ) && !isset( $item['single-id'] ) ) {
1875 // The id goes on the <li> not on the <a> for single links
1876 // but makeSidebarLink still needs to know what id to use when
1877 // generating tooltips and accesskeys.
1878 $link['single-id'] = $item['id'];
1880 $html = $this->makeLink( $key, $link, $options );
1884 foreach ( array( 'id', 'class' ) as $attr ) {
1885 if ( isset( $item[$attr] ) ) {
1886 $attrs[$attr] = $item[$attr];
1889 if ( isset( $item['active'] ) && $item['active'] ) {
1890 if ( !isset( $attrs['class'] ) ) {
1891 $attrs['class'] = '';
1893 $attrs['class'] .= ' active';
1894 $attrs['class'] = trim( $attrs['class'] );
1896 return Html
::rawElement( isset( $options['tag'] ) ?
$options['tag'] : 'li', $attrs, $html );
1899 function makeSearchInput( $attrs = array() ) {
1903 'placeholder' => wfMessage( 'searchsuggest-search' )->text(),
1904 'value' => $this->get( 'search', '' ),
1906 $realAttrs = array_merge( $realAttrs, Linker
::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1907 return Html
::element( 'input', $realAttrs );
1910 function makeSearchButton( $mode, $attrs = array() ) {
1917 'value' => $this->translator
->translate(
1918 $mode == 'go' ?
'searcharticle' : 'searchbutton' ),
1920 $realAttrs = array_merge(
1922 Linker
::tooltipAndAccesskeyAttribs( "search-$mode" ),
1925 return Html
::element( 'input', $realAttrs );
1927 $buttonAttrs = array(
1931 $buttonAttrs = array_merge(
1933 Linker
::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1936 unset( $buttonAttrs['src'] );
1937 unset( $buttonAttrs['alt'] );
1938 unset( $buttonAttrs['width'] );
1939 unset( $buttonAttrs['height'] );
1941 'src' => $attrs['src'],
1942 'alt' => isset( $attrs['alt'] )
1944 : $this->translator
->translate( 'searchbutton' ),
1945 'width' => isset( $attrs['width'] ) ?
$attrs['width'] : null,
1946 'height' => isset( $attrs['height'] ) ?
$attrs['height'] : null,
1948 return Html
::rawElement( 'button', $buttonAttrs, Html
::element( 'img', $imgAttrs ) );
1950 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1955 * Returns an array of footerlinks trimmed down to only those footer links that
1957 * If you pass "flat" as an option then the returned array will be a flat array
1958 * of footer icons instead of a key/value array of footerlinks arrays broken
1959 * up into categories.
1960 * @return array|mixed
1962 function getFooterLinks( $option = null ) {
1963 $footerlinks = $this->get( 'footerlinks' );
1965 // Reduce footer links down to only those which are being used
1966 $validFooterLinks = array();
1967 foreach ( $footerlinks as $category => $links ) {
1968 $validFooterLinks[$category] = array();
1969 foreach ( $links as $link ) {
1970 if ( isset( $this->data
[$link] ) && $this->data
[$link] ) {
1971 $validFooterLinks[$category][] = $link;
1974 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1975 unset( $validFooterLinks[$category] );
1979 if ( $option == 'flat' ) {
1980 // fold footerlinks into a single array using a bit of trickery
1981 $validFooterLinks = call_user_func_array(
1983 array_values( $validFooterLinks )
1987 return $validFooterLinks;
1991 * Returns an array of footer icons filtered down by options relevant to how
1992 * the skin wishes to display them.
1993 * If you pass "icononly" as the option all footer icons which do not have an
1994 * image icon set will be filtered out.
1995 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1996 * in the list of footer icons. This is mostly useful for skins which only
1997 * display the text from footericons instead of the images and don't want a
1998 * duplicate copyright statement because footerlinks already rendered one.
2001 function getFooterIcons( $option = null ) {
2002 // Generate additional footer icons
2003 $footericons = $this->get( 'footericons' );
2005 if ( $option == 'icononly' ) {
2006 // Unset any icons which don't have an image
2007 foreach ( $footericons as &$footerIconsBlock ) {
2008 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
2009 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
2010 unset( $footerIconsBlock[$footerIconKey] );
2014 // Redo removal of any empty blocks
2015 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
2016 if ( count( $footerIconsBlock ) <= 0 ) {
2017 unset( $footericons[$footerIconsKey] );
2020 } elseif ( $option == 'nocopyright' ) {
2021 unset( $footericons['copyright']['copyright'] );
2022 if ( count( $footericons['copyright'] ) <= 0 ) {
2023 unset( $footericons['copyright'] );
2027 return $footericons;
2031 * Output the basic end-page trail including bottomscripts, reporttime, and
2032 * debug stuff. This should be called right before outputting the closing
2033 * body and html tags.
2035 function printTrail() { ?
>
2036 <?php
echo MWDebug
::getDebugHTML( $this->getSkin()->getContext() ); ?
>
2037 <?php
$this->html( 'bottomscripts' ); /* JS call to runBodyOnloadHook */ ?
>
2038 <?php
$this->html( 'reporttime' ) ?
>