835062bbfc284db1a916697f83a8faf2908e1f3b
3 * @defgroup Skins Skins
6 if ( ! defined( 'MEDIAWIKI' ) )
10 * The main skin class that provide methods and properties for all other skins.
11 * This base class is also the "Standard" skin.
13 * See docs/skin.txt for more information.
17 class Skin
extends Linker
{
21 var $mWatchLinkNum = 0; // Appended to end of watch link id's
22 // How many search boxes have we made? Avoid duplicate id's.
23 protected $searchboxes = '';
25 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
26 protected $skinname = 'standard' ;
28 /** Constructor, call parent constructor */
29 function Skin() { parent
::__construct(); }
32 * Fetch the set of available skins.
33 * @return array of strings
36 static function getSkinNames() {
37 global $wgValidSkinNames;
38 static $skinsInitialised = false;
39 if ( !$skinsInitialised ) {
40 # Get a list of available skins
41 # Build using the regular expression '^(.*).php$'
42 # Array keys are all lower case, array value keep the case used by filename
44 wfProfileIn( __METHOD__
. '-init' );
45 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
48 # while code from www.php.net
49 while (false !== ($file = $skinDir->read())) {
50 // Skip non-PHP files, hidden files, and '.dep' includes
52 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
54 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
58 $skinsInitialised = true;
59 wfProfileOut( __METHOD__
. '-init' );
61 return $wgValidSkinNames;
65 * Fetch the list of usable skins in regards to $wgSkipSkins.
66 * Useful for Special:Preferences and other places where you
67 * only want to show skins users _can_ use.
68 * @return array of strings
70 public static function getUsableSkins() {
72 $usableSkins = self
::getSkinNames();
73 foreach ( $wgSkipSkins as $skip ) {
74 unset( $usableSkins[$skip] );
80 * Normalize a skin preference value to a form that can be loaded.
81 * If a skin can't be found, it will fall back to the configured
82 * default (or the old 'Classic' skin if that's broken).
87 static function normalizeKey( $key ) {
88 global $wgDefaultSkin;
89 $skinNames = Skin
::getSkinNames();
92 // Don't return the default immediately;
93 // in a misconfiguration we need to fall back.
94 $key = $wgDefaultSkin;
97 if( isset( $skinNames[$key] ) ) {
101 // Older versions of the software used a numeric setting
102 // in the user preferences.
106 2 => 'cologneblue' );
108 if( isset( $fallback[$key] ) ){
109 $key = $fallback[$key];
112 if( isset( $skinNames[$key] ) ) {
120 * Factory method for loading a skin of a given type
121 * @param string $key 'monobook', 'standard', etc
125 static function &newFromKey( $key ) {
126 global $wgStyleDirectory;
128 $key = Skin
::normalizeKey( $key );
130 $skinNames = Skin
::getSkinNames();
131 $skinName = $skinNames[$key];
132 $className = 'Skin'.ucfirst($key);
134 # Grab the skin class and initialise it.
135 if ( !class_exists( $className ) ) {
136 // Preload base classes to work around APC/PHP5 bug
137 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
138 if( file_exists( $deps ) ) include_once( $deps );
139 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
141 # Check if we got if not failback to default skin
142 if( !class_exists( $className ) ) {
143 # DO NOT die if the class isn't found. This breaks maintenance
144 # scripts and can cause a user account to be unrecoverable
145 # except by SQL manipulation if a previously valid skin name
146 # is no longer valid.
147 wfDebug( "Skin class does not exist: $className\n" );
148 $className = 'SkinMonobook';
149 require_once( "{$wgStyleDirectory}/MonoBook.php" );
152 $skin = new $className;
156 /** @return string path to the skin stylesheet */
157 function getStylesheet() {
158 return 'common/wikistandard.css';
161 /** @return string skin name */
162 public function getSkinName() {
163 return $this->skinname
;
166 function qbSetting() {
167 global $wgOut, $wgUser;
169 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
170 $q = $wgUser->getOption( 'quickbar', 0 );
174 function initPage( &$out ) {
175 global $wgFavicon, $wgAppleTouchIcon;
177 wfProfileIn( __METHOD__
);
179 if( false !== $wgFavicon ) {
180 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
183 if( false !== $wgAppleTouchIcon ) {
184 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
187 # OpenSearch description link
188 $out->addLink( array(
190 'type' => 'application/opensearchdescription+xml',
191 'href' => wfScript( 'opensearch_desc' ),
192 'title' => wfMsgForContent( 'opensearch-desc' ),
195 $this->addMetadataLinks($out);
197 $this->mRevisionId
= $out->mRevisionId
;
199 $this->preloadExistence();
201 wfProfileOut( __METHOD__
);
205 * Preload the existence of three commonly-requested pages in a single query
207 function preloadExistence() {
208 global $wgUser, $wgTitle;
211 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
214 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
216 } elseif ( $wgTitle->isTalkPage() ) {
217 $titles[] = $wgTitle->getSubjectPage();
219 $titles[] = $wgTitle->getTalkPage();
222 $lb = new LinkBatch( $titles );
226 function addMetadataLinks( &$out ) {
227 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
228 global $wgRightsPage, $wgRightsUrl;
230 if( $out->isArticleRelated() ) {
231 # note: buggy CC software only reads first "meta" link
232 if( $wgEnableCreativeCommonsRdf ) {
233 $out->addMetadataLink( array(
234 'title' => 'Creative Commons',
235 'type' => 'application/rdf+xml',
236 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
238 if( $wgEnableDublinCoreRdf ) {
239 $out->addMetadataLink( array(
240 'title' => 'Dublin Core',
241 'type' => 'application/rdf+xml',
242 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
246 if( $wgRightsPage ) {
247 $copy = Title
::newFromText( $wgRightsPage );
249 $copyright = $copy->getLocalURL();
252 if( !$copyright && $wgRightsUrl ) {
253 $copyright = $wgRightsUrl;
256 $out->addLink( array(
257 'rel' => 'copyright',
258 'href' => $copyright ) );
262 function outputPage( &$out ) {
263 global $wgDebugComments;
265 wfProfileIn( __METHOD__
);
266 $this->initPage( $out );
268 // See self::afterContentHook() for documentation
269 $afterContent = $this->afterContentHook();
271 $out->out( $out->headElement() );
273 $out->out( "\n<body" );
274 $ops = $this->getBodyOptions();
275 foreach ( $ops as $name => $val ) {
276 $out->out( " $name='$val'" );
279 if ( $wgDebugComments ) {
280 $out->out( "<!-- Wiki debugging output:\n" .
281 $out->mDebugtext
. "-->\n" );
284 $out->out( $this->beforeContent() );
286 $out->out( $out->mBodytext
. "\n" );
288 $out->out( $this->afterContent() );
290 $out->out( $afterContent );
292 $out->out( $this->bottomScripts() );
294 $out->out( wfReportTime() );
296 $out->out( "\n</body></html>" );
297 wfProfileOut( __METHOD__
);
300 static function makeVariablesScript( $data ) {
301 global $wgJsMimeType;
303 $r = array( "<script type= \"$wgJsMimeType\">/*<![CDATA[*/" );
304 foreach ( $data as $name => $value ) {
305 $encValue = Xml
::encodeJsVar( $value );
306 $r[] = "var $name = $encValue;";
308 $r[] = "/*]]>*/</script>\n";
310 return implode( "\n\t\t", $r );
314 * Make a <script> tag containing global variables
315 * @param array $data Associative array containing one element:
316 * skinname => the skin name
317 * The odd calling convention is for backwards compatibility
319 static function makeGlobalVariablesScript( $data ) {
320 global $wgScript, $wgStylePath, $wgUser;
321 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
322 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
323 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
324 global $wgUseAjax, $wgAjaxWatch;
325 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
326 global $wgRestrictionTypes, $wgLivePreview;
327 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
329 $ns = $wgTitle->getNamespace();
330 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ?
$wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
333 'skin' => $data['skinname'],
334 'stylepath' => $wgStylePath,
335 'wgArticlePath' => $wgArticlePath,
336 'wgScriptPath' => $wgScriptPath,
337 'wgScript' => $wgScript,
338 'wgVariantArticlePath' => $wgVariantArticlePath,
339 'wgActionPaths' => $wgActionPaths,
340 'wgServer' => $wgServer,
341 'wgCanonicalNamespace' => $nsname,
342 'wgCanonicalSpecialPageName' => SpecialPage
::resolveAlias( $wgTitle->getDBkey() ),
343 'wgNamespaceNumber' => $wgTitle->getNamespace(),
344 'wgPageName' => $wgTitle->getPrefixedDBKey(),
345 'wgTitle' => $wgTitle->getText(),
346 'wgAction' => $wgRequest->getText( 'action', 'view' ),
347 'wgArticleId' => $wgTitle->getArticleId(),
348 'wgIsArticle' => $wgOut->isArticle(),
349 'wgUserName' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
350 'wgUserGroups' => $wgUser->isAnon() ?
NULL : $wgUser->getEffectiveGroups(),
351 'wgUserLanguage' => $wgLang->getCode(),
352 'wgContentLanguage' => $wgContLang->getCode(),
353 'wgBreakFrames' => $wgBreakFrames,
354 'wgCurRevisionId' => isset( $wgArticle ) ?
$wgArticle->getLatest() : 0,
355 'wgVersion' => $wgVersion,
356 'wgEnableAPI' => $wgEnableAPI,
357 'wgEnableWriteAPI' => $wgEnableWriteAPI,
360 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false )){
361 $vars['wgMWSuggestTemplate'] = SearchEngine
::getMWSuggestTemplate();
362 $vars['wgDBname'] = $wgDBname;
363 $vars['wgSearchNamespaces'] = SearchEngine
::userNamespaces( $wgUser );
364 $vars['wgMWSuggestMessages'] = array( wfMsg('search-mwsuggest-enabled'), wfMsg('search-mwsuggest-disabled'));
367 foreach( $wgRestrictionTypes as $type )
368 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
370 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
371 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
372 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
373 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
374 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
377 if($wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
378 $msgs = (object)array();
379 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
380 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
382 $vars['wgAjaxWatch'] = $msgs;
385 wfRunHooks('MakeGlobalVariablesScript', array(&$vars));
387 return self
::makeVariablesScript( $vars );
390 function getHeadScripts( $allowUserJs ) {
391 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
393 $r = self
::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
395 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
398 $jsCache = $wgUser->isLoggedIn() ?
'&smaxage=0' : '';
399 $r .= "<script type=\"$wgJsMimeType\" src=\"".
400 htmlspecialchars(self
::makeUrl('-',
401 "action=raw$jsCache&gen=js&useskin=" .
402 urlencode( $this->getSkinName() ) ) ) .
403 "\"><!-- site js --></script>\n";
405 if( $allowUserJs && $wgUser->isLoggedIn() ) {
406 $userpage = $wgUser->getUserPage();
407 $userjs = htmlspecialchars( self
::makeUrl(
408 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
409 'action=raw&ctype='.$wgJsMimeType));
410 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
416 * To make it harder for someone to slip a user a fake
417 * user-JavaScript or user-CSS preview, a random token
418 * is associated with the login session. If it's not
419 * passed back with the preview request, we won't render
422 * @param string $action
426 function userCanPreview( $action ) {
427 global $wgTitle, $wgRequest, $wgUser;
429 if( $action != 'submit' )
431 if( !$wgRequest->wasPosted() )
433 if( !$wgTitle->userCanEditCssJsSubpage() )
435 return $wgUser->matchEditToken(
436 $wgRequest->getVal( 'wpEditToken' ) );
440 * Get the site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
442 function getSiteStylesheet() {
443 global $wgStylePath, $wgContLang, $wgStyleVersion;
444 $sheet = $this->getStylesheet();
445 $s = "@import \"$wgStylePath/common/shared.css?$wgStyleVersion\";\n";
446 $s .= "@import \"$wgStylePath/common/oldshared.css?$wgStyleVersion\";\n";
447 $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
448 if( $wgContLang->isRTL() )
449 $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
454 * Get the user-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
456 function getUserStylesheet() {
457 global $wgContLang, $wgSquidMaxage, $wgStyleVersion;
458 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
459 $s = '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n";
460 $s .= '@import "' . self
::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
461 $s .= $this->doGetUserStyles();
466 * This returns MediaWiki:Common.js, and derived classes may add other JS.
467 * Despite its name, it does *not* return any custom user JS from user
468 * subpages. The returned script is sitewide and publicly cacheable and
469 * therefore must not include anything that varies according to user,
470 * interface language, etc. (although it may vary by skin). See
471 * makeGlobalVariablesScript for things that can vary per page view and are
474 * @return string Raw JavaScript to be returned
476 public function getUserJs() {
477 wfProfileIn( __METHOD__
);
480 $s = "/* generated javascript */\n";
481 $s .= "var skin = '" . Xml
::escapeJsString( $this->getSkinName() ) . "';\n";
482 $s .= "var stylepath = '" . Xml
::escapeJsString( $wgStylePath ) . "';";
483 $s .= "\n\n/* MediaWiki:Common.js */\n";
484 $commonJs = wfMsgForContent('common.js');
485 if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
488 wfProfileOut( __METHOD__
);
493 * Return html code that include site stylesheets
495 function getSiteStyles() {
496 $s = "<style type='text/css'>\n";
497 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
498 $s .= $this->getSiteStylesheet();
499 $s .= "/*]]>*/ /* */\n";
505 * Return html code that include User stylesheets
507 function getUserStyles() {
508 $s = "<style type='text/css'>\n";
509 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
510 $s .= $this->getUserStylesheet();
511 $s .= "/*]]>*/ /* */\n";
517 * Some styles that are set by user through the user settings interface.
519 function doGetUserStyles() {
520 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
524 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
525 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
526 $s .= $wgRequest->getText('wpTextbox1');
528 $userpage = $wgUser->getUserPage();
529 $s.= '@import "'.self
::makeUrl(
530 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
531 'action=raw&ctype=text/css').'";'."\n";
535 return $s . $this->reallyDoGetUserStyles();
538 function reallyDoGetUserStyles() {
541 if (($undopt = $wgUser->getOption("underline")) < 2) {
542 $underline = $undopt ?
'underline' : 'none';
543 $s .= "a { text-decoration: $underline; }\n";
545 if( $wgUser->getOption( 'highlightbroken' ) ) {
546 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
549 a.new, #quickbar a.new,
550 a.stub, #quickbar a.stub {
553 a.new:after, #quickbar a.new:after {
557 a.stub:after, #quickbar a.stub:after {
563 if( $wgUser->getOption( 'justify' ) ) {
564 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
566 if( !$wgUser->getOption( 'showtoc' ) ) {
567 $s .= "#toc { display: none; }\n";
569 if( !$wgUser->getOption( 'editsection' ) ) {
570 $s .= ".editsection { display: none; }\n";
575 function getBodyOptions() {
576 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
578 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
580 if ( 0 != $wgTitle->getNamespace() ) {
581 $a = array( 'bgcolor' => '#ffffec' );
583 else $a = array( 'bgcolor' => '#FFFFFF' );
584 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
585 $wgTitle->userCan( 'edit' ) ) {
586 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
587 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
588 $a +
= array ('ondblclick' => $s);
591 $a['onload'] = $wgOut->getOnloadHandler();
594 ' '.( $wgContLang->isRTL() ?
"rtl" : "ltr" ).
595 ' '.$this->getPageClasses( $wgTitle ) .
596 ' skin-'. Sanitizer
::escapeClass( $this->getSkinName( ) );
600 function getPageClasses( $title ) {
601 $numeric = 'ns-'.$title->getNamespace();
602 if( $title->getNamespace() == NS_SPECIAL
) {
603 $type = "ns-special";
604 } elseif( $title->isTalkPage() ) {
607 $type = "ns-subject";
609 $name = Sanitizer
::escapeClass( 'page-'.$title->getPrefixedText() );
610 return "$numeric $type $name";
622 * This will be called immediately after the <body> tag. Split into
623 * two functions to make it easier to subclass.
625 function beforeContent() {
626 return $this->doBeforeContent();
629 function doBeforeContent() {
631 $fname = 'Skin::doBeforeContent';
632 wfProfileIn( $fname );
635 $qb = $this->qbSetting();
637 if( $langlinks = $this->otherLanguages() ) {
643 $borderhack = 'class="top"';
646 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
647 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
650 $left = ($qb == 1 ||
$qb == 3);
651 if($wgContLang->isRTL()) $left = !$left;
654 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
655 $this->logoText() . '</td>';
657 $s .= $this->getQuickbarCompensator( $rows );
659 $l = $wgContLang->isRTL() ?
'right' : 'left';
660 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
662 $s .= $this->topLinks() ;
663 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
665 $r = $wgContLang->isRTL() ?
"left" : "right";
666 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
667 $s .= $this->nameAndLogin();
668 $s .= "\n<br />" . $this->searchForm() . "</td>";
671 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
674 if ( $shove && !$left ) { # Right
675 $s .= $this->getQuickbarCompensator( $rows );
677 $s .= "</tr>\n</table>\n</div>\n";
678 $s .= "\n<div id='article'>\n";
680 $notice = wfGetSiteNotice();
682 $s .= "\n<div id='siteNotice'>$notice</div>\n";
684 $s .= $this->pageTitle();
685 $s .= $this->pageSubtitle() ;
686 $s .= $this->getCategories();
687 wfProfileOut( $fname );
692 function getCategoryLinks() {
693 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
694 global $wgContLang, $wgUser;
696 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
699 $sep = wfMsgHtml( 'catseparator' );
701 // Use Unicode bidi embedding override characters,
702 // to make sure links don't smash each other up in ugly ways.
703 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
704 $embed = "<span dir='$dir'>";
707 $allCats = $wgOut->getCategoryLinks();
709 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
710 if ( !empty( $allCats['normal'] ) ) {
711 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
713 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
714 $s .= '<div id="mw-normal-catlinks">' .
715 $this->link( Title
::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
716 . $colon . $t . '</div>';
720 if ( isset( $allCats['hidden'] ) ) {
721 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
722 $class ='mw-hidden-cats-user-shown';
723 } elseif ( $wgTitle->getNamespace() == NS_CATEGORY
) {
724 $class = 'mw-hidden-cats-ns-shown';
726 $class = 'mw-hidden-cats-hidden';
728 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
729 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
730 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
734 # optional 'dmoz-like' category browser. Will be shown under the list
735 # of categories an article belong to
736 if($wgUseCategoryBrowser) {
737 $s .= '<br /><hr />';
739 # get a big array of the parents tree
740 $parenttree = $wgTitle->getParentCategoryTree();
741 # Skin object passed by reference cause it can not be
742 # accessed under the method subfunction drawCategoryBrowser
743 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
744 # Clean out bogus first entry and sort them
747 # Output one per line
748 $s .= implode("<br />\n", $tempout);
754 /** Render the array as a serie of links.
755 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
756 * @param &skin Object: skin passed by reference
757 * @return String separated by >, terminate with "\n"
759 function drawCategoryBrowser($tree, &$skin) {
761 foreach ($tree as $element => $parent) {
762 if (empty($parent)) {
763 # element start a new list
766 # grab the others elements
767 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
769 # add our current element to the list
770 $eltitle = Title
::newFromText($element);
771 $return .= $skin->link( $eltitle, $eltitle->getText() ) ;
776 function getCategories() {
777 $catlinks=$this->getCategoryLinks();
779 $classes = 'catlinks';
781 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
782 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
783 $classes .= ' catlinks-allhidden';
786 if( !empty( $catlinks ) ){
787 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
791 function getQuickbarCompensator( $rows = 1 ) {
792 return "<td width='152' rowspan='{$rows}'> </td>";
796 * This runs a hook to allow extensions placing their stuff after content
797 * and article metadata (e.g. categories).
798 * Note: This function has nothing to do with afterContent().
800 * This hook is placed here in order to allow using the same hook for all
801 * skins, both the SkinTemplate based ones and the older ones, which directly
802 * use this class to get their data.
804 * The output of this function gets processed in SkinTemplate::outputPage() for
805 * the SkinTemplate based skins, all other skins should directly echo it.
807 * Returns an empty string by default, if not changed by any hook function.
809 protected function afterContentHook () {
812 if (wfRunHooks ('SkinAfterContent', array (&$data))) {
813 // adding just some spaces shouldn't toggle the output
814 // of the whole <div/>, so we use trim() here
815 if (trim ($data) != "") {
816 // Doing this here instead of in the skins to
817 // ensure that the div has the same ID in all
819 $data = "<div id='mw-data-after-content'>\n" .
824 wfDebug ('Hook SkinAfterContent changed output processing.');
831 * This gets called shortly before the \</body\> tag.
832 * @return String HTML to be put before \</body\>
834 function afterContent() {
835 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
836 return $printfooter . $this->doAfterContent();
840 * This gets called shortly before the \</body\> tag.
841 * @return String HTML-wrapped JS code to be put before \</body\>
843 function bottomScripts() {
844 global $wgJsMimeType;
845 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
846 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
847 return $bottomScriptText;
850 /** @return string Retrievied from HTML text */
851 function printSource() {
853 $url = htmlspecialchars( $wgTitle->getFullURL() );
854 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
857 function printFooter() {
858 return "<p>" . $this->printSource() .
859 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
862 /** overloaded by derived classes */
863 function doAfterContent() { }
865 function pageTitleLinks() {
866 global $wgOut, $wgTitle, $wgUser, $wgRequest;
868 $oldid = $wgRequest->getVal( 'oldid' );
869 $diff = $wgRequest->getVal( 'diff' );
870 $action = $wgRequest->getText( 'action' );
872 $s = $this->printableLink();
873 $disclaimer = $this->disclaimerLink(); # may be empty
875 $s .= ' | ' . $disclaimer;
877 $privacy = $this->privacyLink(); # may be empty too
879 $s .= ' | ' . $privacy;
882 if ( $wgOut->isArticleRelated() ) {
883 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
884 $name = $wgTitle->getDBkey();
885 $image = wfFindFile( $wgTitle );
887 $link = htmlspecialchars( $image->getURL() );
888 $style = $this->getInternalLinkAttributes( $link, $name );
889 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
893 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
894 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
895 wfMsg( 'currentrev' ) );
898 if ( $wgUser->getNewtalk() ) {
899 # do not show "You have new messages" text when we are viewing our
901 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
902 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
903 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
904 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
906 $wgOut->setSquidMaxage(0);
907 $wgOut->enableClientCache(false);
911 $undelete = $this->getUndeleteLink();
912 if( !empty( $undelete ) ) {
913 $s .= ' | '.$undelete;
918 function getUndeleteLink() {
919 global $wgUser, $wgTitle, $wgContLang, $wgLang, $action;
920 if( $wgUser->isAllowed( 'deletedhistory' ) &&
921 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
922 ($n = $wgTitle->isDeleted() ) )
924 if ( $wgUser->isAllowed( 'undelete' ) ) {
925 $msg = 'thisisdeleted';
927 $msg = 'viewdeleted';
930 $this->makeKnownLinkObj(
931 SpecialPage
::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
932 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
937 function printableLink() {
938 global $wgOut, $wgFeedClasses, $wgRequest;
940 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
942 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
943 if( $wgOut->isSyndicated() ) {
944 foreach( $wgFeedClasses as $format => $class ) {
945 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
946 $s .= " | <a href=\"$feedurl\">{$format}</a>";
952 function pageTitle() {
954 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
958 function pageSubtitle() {
961 $sub = $wgOut->getSubtitle();
963 global $wgExtraSubtitle;
964 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
966 $subpages = $this->subPageSubtitle();
967 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
968 $s = "<p class='subtitle'>{$sub}</p>\n";
972 function subPageSubtitle() {
974 if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages)))
977 global $wgOut, $wgTitle;
978 if($wgOut->isArticle() && MWNamespace
::hasSubpages( $wgTitle->getNamespace() )) {
979 $ptext=$wgTitle->getPrefixedText();
980 if(preg_match('/\//',$ptext)) {
981 $links = explode('/',$ptext);
986 foreach($links as $link) {
987 $growinglink .= $link;
989 $linkObj = Title
::newFromText( $growinglink );
990 if( is_object( $linkObj ) && $linkObj->exists() ){
991 $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
996 $subpages .= '< ';
998 $subpages .= $getlink;
1003 $growinglink .= '/';
1011 * Returns true if the IP should be shown in the header
1013 function showIPinHeader() {
1014 global $wgShowIPinHeader;
1015 return $wgShowIPinHeader && session_id() != '';
1018 function nameAndLogin() {
1019 global $wgUser, $wgTitle, $wgLang, $wgContLang;
1021 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1024 if ( $wgUser->isAnon() ) {
1025 if( $this->showIPinHeader() ) {
1028 $talkLink = $this->link( $wgUser->getTalkPage(),
1029 $wgLang->getNsText( NS_TALK
) );
1031 $ret .= "$name ($talkLink)";
1033 $ret .= wfMsg( 'notloggedin' );
1036 $returnTo = $wgTitle->getPrefixedDBkey();
1038 if ( $logoutPage != $returnTo ) {
1039 $query['returnto'] = $returnTo;
1042 $loginlink = $wgUser->isAllowed( 'createaccount' )
1043 ?
'nav-login-createaccount'
1045 $ret .= "\n<br />" . $this->link(
1046 SpecialPage
::getTitleFor( 'Userlogin' ),
1047 wfMsg( $loginlink ), array(), $query
1050 $returnTo = $wgTitle->getPrefixedDBkey();
1051 $talkLink = $this->link( $wgUser->getTalkPage(),
1052 $wgLang->getNsText( NS_TALK
) );
1054 $ret .= $this->link( $wgUser->getUserPage(),
1055 htmlspecialchars( $wgUser->getName() ) );
1056 $ret .= " ($talkLink)<br />";
1057 $ret .= $this->link(
1058 SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1059 array(), array( 'returnto' => $returnTo )
1061 $ret .= ' | ' . $this->specialLink( 'preferences' );
1063 $ret .= ' | ' . $this->link(
1064 Title
::newFromText( wfMsgForContent( 'helppage' ) ),
1071 function getSearchLink() {
1072 $searchPage = SpecialPage
::getTitleFor( 'Search' );
1073 return $searchPage->getLocalURL();
1076 function escapeSearchLink() {
1077 return htmlspecialchars( $this->getSearchLink() );
1080 function searchForm() {
1082 $search = $wgRequest->getText( 'search' );
1084 $s = '<form id="searchform'.$this->searchboxes
.'" name="search" class="inline" method="post" action="'
1085 . $this->escapeSearchLink() . "\">\n"
1086 . '<input type="text" id="searchInput'.$this->searchboxes
.'" name="search" size="19" value="'
1087 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
1088 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" /> '
1089 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
1091 // Ensure unique id's for search boxes made after the first
1092 $this->searchboxes
= $this->searchboxes
== '' ?
2 : $this->searchboxes +
1;
1097 function topLinks() {
1101 $s = $this->mainPageLink() . $sep
1102 . $this->specialLink( 'recentchanges' );
1104 if ( $wgOut->isArticleRelated() ) {
1105 $s .= $sep . $this->editThisPage()
1106 . $sep . $this->historyLink();
1108 # Many people don't like this dropdown box
1109 #$s .= $sep . $this->specialPagesList();
1111 $s .= $this->variantLinks();
1113 $s .= $this->extensionTabLinks();
1119 * Compatibility for extensions adding functionality through tabs.
1120 * Eventually these old skins should be replaced with SkinTemplate-based
1124 function extensionTabLinks() {
1127 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1128 foreach( $tabs as $tab ) {
1129 $s .= ' | ' . Xml
::element( 'a',
1130 array( 'href' => $tab['href'] ),
1137 * Language/charset variant links for classic-style skins
1140 function variantLinks() {
1142 /* show links to different language variants */
1143 global $wgDisableLangConversion, $wgContLang, $wgTitle;
1144 $variants = $wgContLang->getVariants();
1145 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1146 foreach( $variants as $code ) {
1147 $varname = $wgContLang->getVariantname( $code );
1148 if( $varname == 'disable' )
1150 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
1156 function bottomLinks() {
1157 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1161 if ( $wgOut->isArticleRelated() ) {
1162 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1163 if ( $wgUser->isLoggedIn() ) {
1164 $s .= $sep . $this->watchThisPage();
1166 $s .= $sep . $this->talkLink()
1167 . $sep . $this->historyLink()
1168 . $sep . $this->whatLinksHere()
1169 . $sep . $this->watchPageLinksLink();
1171 if ($wgUseTrackbacks)
1172 $s .= $sep . $this->trackbackLink();
1174 if ( $wgTitle->getNamespace() == NS_USER
1175 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
1178 $id=User
::idFromName($wgTitle->getText());
1179 $ip=User
::isIP($wgTitle->getText());
1181 if($id ||
$ip) { # both anons and non-anons have contri list
1182 $s .= $sep . $this->userContribsLink();
1184 if( $this->showEmailUser( $id ) ) {
1185 $s .= $sep . $this->emailUserLink();
1188 if ( $wgTitle->getArticleId() ) {
1190 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1191 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1192 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1194 $s .= "<br />\n" . $this->otherLanguages();
1199 function pageStats() {
1200 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1201 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1203 $oldid = $wgRequest->getVal( 'oldid' );
1204 $diff = $wgRequest->getVal( 'diff' );
1205 if ( ! $wgOut->isArticle() ) { return ''; }
1206 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
1207 if ( 0 == $wgArticle->getID() ) { return ''; }
1210 if ( !$wgDisableCounters ) {
1211 $count = $wgLang->formatNum( $wgArticle->getCount() );
1213 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1217 if( $wgMaxCredits != 0 ){
1218 $s .= ' ' . Credits
::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1220 $s .= $this->lastModified();
1223 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1224 $dbr = wfGetDB( DB_SLAVE
);
1225 $watchlist = $dbr->tableName( 'watchlist' );
1226 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1227 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) .
1228 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1229 $res = $dbr->query( $sql, 'Skin::pageStats');
1230 $x = $dbr->fetchObject( $res );
1232 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1233 array( 'parseinline' ), $wgLang->formatNum($x->n
)
1237 return $s . ' ' . $this->getCopyright();
1240 function getCopyright( $type = 'detect' ) {
1241 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1243 if ( $type == 'detect' ) {
1244 $oldid = $wgRequest->getVal( 'oldid' );
1245 $diff = $wgRequest->getVal( 'diff' );
1247 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1254 if ( $type == 'history' ) {
1255 $msg = 'history_copyright';
1261 if( $wgRightsPage ) {
1262 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1263 } elseif( $wgRightsUrl ) {
1264 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1269 $out .= wfMsgForContent( $msg, $link );
1273 function getCopyrightIcon() {
1274 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1276 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1277 $out = $wgCopyrightIcon;
1278 } else if ( $wgRightsIcon ) {
1279 $icon = htmlspecialchars( $wgRightsIcon );
1280 if ( $wgRightsUrl ) {
1281 $url = htmlspecialchars( $wgRightsUrl );
1282 $out .= '<a href="'.$url.'">';
1284 $text = htmlspecialchars( $wgRightsText );
1285 $out .= "<img src=\"$icon\" alt='$text' />";
1286 if ( $wgRightsUrl ) {
1293 function getPoweredBy() {
1294 global $wgStylePath;
1295 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1296 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1300 function lastModified() {
1301 global $wgLang, $wgArticle;
1302 if( $this->mRevisionId
) {
1303 $timestamp = Revision
::getTimestampFromId( $this->mRevisionId
, $wgArticle->getId() );
1305 $timestamp = $wgArticle->getTimestamp();
1308 $d = $wgLang->date( $timestamp, true );
1309 $t = $wgLang->time( $timestamp, true );
1310 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1314 if ( wfGetLB()->getLaggedSlaveMode() ) {
1315 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1320 function logoText( $align = '' ) {
1321 if ( '' != $align ) { $a = " align='{$align}'"; }
1324 $mp = wfMsg( 'mainpage' );
1325 $mptitle = Title
::newMainPage();
1326 $url = ( is_object($mptitle) ?
$mptitle->escapeLocalURL() : '' );
1328 $logourl = $this->getLogo();
1329 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1334 * show a drop-down box of special pages
1336 function specialPagesList() {
1337 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1338 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1339 foreach ( $pages as $name => $page ) {
1340 $pages[$name] = $page->getDescription();
1343 $go = wfMsg( 'go' );
1344 $sp = wfMsg( 'specialpages' );
1345 $spp = $wgContLang->specialPage( 'Specialpages' );
1347 $s = '<form id="specialpages" method="get" class="inline" ' .
1348 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1349 $s .= "<select name=\"wpDropdown\">\n";
1350 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1353 foreach ( $pages as $name => $desc ) {
1354 $p = $wgContLang->specialPage( $name );
1355 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1357 $s .= "</select>\n";
1358 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1363 function mainPageLink() {
1364 $s = $this->makeKnownLinkObj( Title
::newMainPage(), wfMsg( 'mainpage' ) );
1368 function copyrightLink() {
1369 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1370 wfMsg( 'copyrightpagename' ) );
1374 private function footerLink ( $desc, $page ) {
1375 // if the link description has been set to "-" in the default language,
1376 if ( wfMsgForContent( $desc ) == '-') {
1377 // then it is disabled, for all languages.
1380 // Otherwise, we display the link for the user, described in their
1381 // language (which may or may not be the same as the default language),
1382 // but we make the link target be the one site-wide page.
1383 return $this->makeKnownLink( wfMsgForContent( $page ),
1384 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1388 function privacyLink() {
1389 return $this->footerLink( 'privacy', 'privacypage' );
1392 function aboutLink() {
1393 return $this->footerLink( 'aboutsite', 'aboutpage' );
1396 function disclaimerLink() {
1397 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1400 function editThisPage() {
1401 global $wgOut, $wgTitle;
1403 if ( !$wgOut->isArticleRelated() ) {
1404 $s = wfMsg( 'protectedpage' );
1406 if( $wgTitle->userCan( 'edit' ) && $wgTitle->exists() ) {
1407 $t = wfMsg( 'editthispage' );
1408 } elseif( $wgTitle->userCan( 'create' ) && !$wgTitle->exists() ) {
1409 $t = wfMsg( 'create-this-page' );
1411 $t = wfMsg( 'viewsource' );
1414 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1420 * Return URL options for the 'edit page' link.
1421 * This may include an 'oldid' specifier, if the current page view is such.
1426 function editUrlOptions() {
1429 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1430 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1432 return "action=edit";
1436 function deleteThisPage() {
1437 global $wgUser, $wgTitle, $wgRequest;
1439 $diff = $wgRequest->getVal( 'diff' );
1440 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1441 $t = wfMsg( 'deletethispage' );
1443 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1450 function protectThisPage() {
1451 global $wgUser, $wgTitle, $wgRequest;
1453 $diff = $wgRequest->getVal( 'diff' );
1454 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1455 if ( $wgTitle->isProtected() ) {
1456 $t = wfMsg( 'unprotectthispage' );
1457 $q = 'action=unprotect';
1459 $t = wfMsg( 'protectthispage' );
1460 $q = 'action=protect';
1462 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1469 function watchThisPage() {
1470 global $wgOut, $wgTitle;
1471 ++
$this->mWatchLinkNum
;
1473 if ( $wgOut->isArticleRelated() ) {
1474 if ( $wgTitle->userIsWatching() ) {
1475 $t = wfMsg( 'unwatchthispage' );
1476 $q = 'action=unwatch';
1477 $id = "mw-unwatch-link".$this->mWatchLinkNum
;
1479 $t = wfMsg( 'watchthispage' );
1480 $q = 'action=watch';
1481 $id = 'mw-watch-link'.$this->mWatchLinkNum
;
1483 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1485 $s = wfMsg( 'notanarticle' );
1490 function moveThisPage() {
1493 if ( $wgTitle->userCan( 'move' ) ) {
1494 return $this->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Movepage' ),
1495 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1497 // no message if page is protected - would be redundant
1502 function historyLink() {
1505 return $this->makeKnownLinkObj( $wgTitle,
1506 wfMsg( 'history' ), 'action=history' );
1509 function whatLinksHere() {
1512 return $this->makeKnownLinkObj(
1513 SpecialPage
::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1514 wfMsg( 'whatlinkshere' ) );
1517 function userContribsLink() {
1520 return $this->makeKnownLinkObj(
1521 SpecialPage
::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1522 wfMsg( 'contributions' ) );
1525 function showEmailUser( $id ) {
1526 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1527 return $wgEnableEmail &&
1528 $wgEnableUserEmail &&
1529 $wgUser->isLoggedIn() && # show only to signed in users
1530 0 != $id; # we can only email to non-anons ..
1531 # '' != $id->getEmail() && # who must have an email address stored ..
1532 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1533 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1536 function emailUserLink() {
1539 return $this->makeKnownLinkObj(
1540 SpecialPage
::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1541 wfMsg( 'emailuser' ) );
1544 function watchPageLinksLink() {
1545 global $wgOut, $wgTitle;
1547 if ( ! $wgOut->isArticleRelated() ) {
1548 return '(' . wfMsg( 'notanarticle' ) . ')';
1550 return $this->makeKnownLinkObj(
1551 SpecialPage
::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1552 wfMsg( 'recentchangeslinked' ) );
1556 function trackbackLink() {
1559 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1560 . wfMsg('trackbacklink') . "</a>";
1563 function otherLanguages() {
1564 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1566 if ( $wgHideInterlanguageLinks ) {
1570 $a = $wgOut->getLanguageLinks();
1571 if ( 0 == count( $a ) ) {
1575 $s = wfMsg( 'otherlanguages' ) . ': ';
1577 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1578 foreach( $a as $l ) {
1579 if ( ! $first ) { $s .= ' | '; }
1582 $nt = Title
::newFromText( $l );
1583 $url = $nt->escapeFullURL();
1584 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1586 if ( '' == $text ) { $text = $l; }
1587 $style = $this->getExternalLinkAttributes( $l, $text );
1588 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1590 if($wgContLang->isRTL()) $s .= '</span>';
1594 function bugReportsLink() {
1595 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1596 wfMsg( 'bugreports' ) );
1600 function talkLink() {
1603 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1604 # No discussion links for special pages
1608 if( $wgTitle->isTalkPage() ) {
1609 $link = $wgTitle->getSubjectPage();
1610 switch( $link->getNamespace() ) {
1612 $text = wfMsg( 'articlepage' );
1615 $text = wfMsg( 'userpage' );
1618 $text = wfMsg( 'projectpage' );
1621 $text = wfMsg( 'imagepage' );
1624 $text = wfMsg( 'mediawikipage' );
1627 $text = wfMsg( 'templatepage' );
1630 $text = wfMsg( 'viewhelppage' );
1633 $text = wfMsg( 'categorypage' );
1636 $text = wfMsg( 'articlepage' );
1639 $link = $wgTitle->getTalkPage();
1640 $text = wfMsg( 'talkpage' );
1643 $s = $this->makeLinkObj( $link, $text );
1648 function commentLink() {
1649 global $wgTitle, $wgOut;
1651 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1655 # __NEWSECTIONLINK___ changes behaviour here
1656 # If it's present, the link points to this page, otherwise
1657 # it points to the talk page
1658 if( $wgTitle->isTalkPage() ) {
1660 } elseif( $wgOut->showNewSectionLink() ) {
1663 $title = $wgTitle->getTalkPage();
1666 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1669 /* these are used extensively in SkinTemplate, but also some other places */
1670 static function makeMainPageUrl( $urlaction = '' ) {
1671 $title = Title
::newMainPage();
1672 self
::checkTitle( $title, '' );
1673 return $title->getLocalURL( $urlaction );
1676 static function makeSpecialUrl( $name, $urlaction = '' ) {
1677 $title = SpecialPage
::getTitleFor( $name );
1678 return $title->getLocalURL( $urlaction );
1681 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1682 $title = SpecialPage
::getSafeTitleFor( $name, $subpage );
1683 return $title->getLocalURL( $urlaction );
1686 static function makeI18nUrl( $name, $urlaction = '' ) {
1687 $title = Title
::newFromText( wfMsgForContent( $name ) );
1688 self
::checkTitle( $title, $name );
1689 return $title->getLocalURL( $urlaction );
1692 static function makeUrl( $name, $urlaction = '' ) {
1693 $title = Title
::newFromText( $name );
1694 self
::checkTitle( $title, $name );
1695 return $title->getLocalURL( $urlaction );
1698 # If url string starts with http, consider as external URL, else
1700 static function makeInternalOrExternalUrl( $name ) {
1701 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1704 return self
::makeUrl( $name );
1708 # this can be passed the NS number as defined in Language.php
1709 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1710 $title = Title
::makeTitleSafe( $namespace, $name );
1711 self
::checkTitle( $title, $name );
1712 return $title->getLocalURL( $urlaction );
1715 /* these return an array with the 'href' and boolean 'exists' */
1716 static function makeUrlDetails( $name, $urlaction = '' ) {
1717 $title = Title
::newFromText( $name );
1718 self
::checkTitle( $title, $name );
1720 'href' => $title->getLocalURL( $urlaction ),
1721 'exists' => $title->getArticleID() != 0 ?
true : false
1726 * Make URL details where the article exists (or at least it's convenient to think so)
1728 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1729 $title = Title
::newFromText( $name );
1730 self
::checkTitle( $title, $name );
1732 'href' => $title->getLocalURL( $urlaction ),
1737 # make sure we have some title to operate on
1738 static function checkTitle( &$title, $name ) {
1739 if( !is_object( $title ) ) {
1740 $title = Title
::newFromText( $name );
1741 if( !is_object( $title ) ) {
1742 $title = Title
::newFromText( '--error: link target missing--' );
1748 * Build an array that represents the sidebar(s), the navigation bar among them
1752 function buildSidebar() {
1753 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1755 wfProfileIn( __METHOD__
);
1757 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1759 if ( $wgEnableSidebarCache ) {
1760 $cachedsidebar = $parserMemc->get( $key );
1761 if ( $cachedsidebar ) {
1762 wfProfileOut( __METHOD__
);
1763 return $cachedsidebar;
1768 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1770 foreach ($lines as $line) {
1771 if (strpos($line, '*') !== 0)
1773 if (strpos($line, '**') !== 0) {
1774 $line = trim($line, '* ');
1776 if( !array_key_exists($heading, $bar) ) $bar[$heading] = array();
1778 if (strpos($line, '|') !== false) { // sanity check
1779 $line = array_map('trim', explode( '|' , trim($line, '* '), 2 ) );
1780 $link = wfMsgForContent( $line[0] );
1783 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1785 if (wfEmptyMsg($line[0], $link))
1788 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1791 $title = Title
::newFromText( $link );
1793 $title = $title->fixSpecialName();
1794 $href = $title->getLocalURL();
1796 $href = 'INVALID-TITLE';
1800 $bar[$heading][] = array(
1803 'id' => 'n-' . strtr($line[1], ' ', '-'),
1806 } else { continue; }
1809 wfRunHooks('SkinBuildSidebar', array($this, &$bar));
1810 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1811 wfProfileOut( __METHOD__
);