Ajax suggestions:
[mediawiki.git] / includes / Skin.php
blob5e324bba4e8a8bf28d22b61d5f97961f9e1f7a04
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
5 # See skin.txt
7 /**
8 * The main skin class that provide methods and properties for all other skins.
9 * This base class is also the "Standard" skin.
11 * See docs/skin.txt for more information.
13 * @addtogroup Skins
15 class Skin extends Linker {
16 /**#@+
17 * @private
19 var $mWatchLinkNum = 0; // Appended to end of watch link id's
20 /**#@-*/
21 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
22 protected $skinname = 'standard' ;
24 /** Constructor, call parent constructor */
25 function Skin() { parent::__construct(); }
27 /**
28 * Fetch the set of available skins.
29 * @return array of strings
30 * @static
32 static function getSkinNames() {
33 global $wgValidSkinNames;
34 static $skinsInitialised = false;
35 if ( !$skinsInitialised ) {
36 # Get a list of available skins
37 # Build using the regular expression '^(.*).php$'
38 # Array keys are all lower case, array value keep the case used by filename
40 wfProfileIn( __METHOD__ . '-init' );
41 global $wgStyleDirectory;
42 $skinDir = dir( $wgStyleDirectory );
44 # while code from www.php.net
45 while (false !== ($file = $skinDir->read())) {
46 // Skip non-PHP files, hidden files, and '.dep' includes
47 $matches = array();
48 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
49 $aSkin = $matches[1];
50 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
53 $skinDir->close();
54 $skinsInitialised = true;
55 wfProfileOut( __METHOD__ . '-init' );
57 return $wgValidSkinNames;
60 /**
61 * Normalize a skin preference value to a form that can be loaded.
62 * If a skin can't be found, it will fall back to the configured
63 * default (or the old 'Classic' skin if that's broken).
64 * @param string $key
65 * @return string
66 * @static
68 static function normalizeKey( $key ) {
69 global $wgDefaultSkin;
70 $skinNames = Skin::getSkinNames();
72 if( $key == '' ) {
73 // Don't return the default immediately;
74 // in a misconfiguration we need to fall back.
75 $key = $wgDefaultSkin;
78 if( isset( $skinNames[$key] ) ) {
79 return $key;
82 // Older versions of the software used a numeric setting
83 // in the user preferences.
84 $fallback = array(
85 0 => $wgDefaultSkin,
86 1 => 'nostalgia',
87 2 => 'cologneblue' );
89 if( isset( $fallback[$key] ) ){
90 $key = $fallback[$key];
93 if( isset( $skinNames[$key] ) ) {
94 return $key;
95 } else {
96 return 'monobook';
101 * Factory method for loading a skin of a given type
102 * @param string $key 'monobook', 'standard', etc
103 * @return Skin
104 * @static
106 static function &newFromKey( $key ) {
107 global $wgStyleDirectory;
109 $key = Skin::normalizeKey( $key );
111 $skinNames = Skin::getSkinNames();
112 $skinName = $skinNames[$key];
113 $className = 'Skin'.ucfirst($key);
115 # Grab the skin class and initialise it.
116 if ( !class_exists( $className ) ) {
117 // Preload base classes to work around APC/PHP5 bug
118 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
119 if( file_exists( $deps ) ) include_once( $deps );
120 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
122 # Check if we got if not failback to default skin
123 if( !class_exists( $className ) ) {
124 # DO NOT die if the class isn't found. This breaks maintenance
125 # scripts and can cause a user account to be unrecoverable
126 # except by SQL manipulation if a previously valid skin name
127 # is no longer valid.
128 wfDebug( "Skin class does not exist: $className\n" );
129 $className = 'SkinMonobook';
130 require_once( "{$wgStyleDirectory}/MonoBook.php" );
133 $skin = new $className;
134 return $skin;
137 /** @return string path to the skin stylesheet */
138 function getStylesheet() {
139 return 'common/wikistandard.css';
142 /** @return string skin name */
143 public function getSkinName() {
144 return $this->skinname;
147 function qbSetting() {
148 global $wgOut, $wgUser;
150 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
151 $q = $wgUser->getOption( 'quickbar', 0 );
152 return $q;
155 function initPage( &$out ) {
156 global $wgFavicon, $wgAppleTouchIcon, $wgScriptPath, $wgScriptExtension;
158 wfProfileIn( __METHOD__ );
160 if( false !== $wgFavicon ) {
161 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
164 if( false !== $wgAppleTouchIcon ) {
165 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
168 # OpenSearch description link
169 $out->addLink( array(
170 'rel' => 'search',
171 'type' => 'application/opensearchdescription+xml',
172 'href' => "$wgScriptPath/opensearch_desc{$wgScriptExtension}",
173 'title' => wfMsgForContent( 'opensearch-desc' ),
176 $this->addMetadataLinks($out);
178 $this->mRevisionId = $out->mRevisionId;
180 $this->preloadExistence();
182 wfProfileOut( __METHOD__ );
186 * Preload the existence of three commonly-requested pages in a single query
188 function preloadExistence() {
189 global $wgUser, $wgTitle;
191 // User/talk link
192 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
194 // Other tab link
195 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
196 // nothing
197 } elseif ( $wgTitle->isTalkPage() ) {
198 $titles[] = $wgTitle->getSubjectPage();
199 } else {
200 $titles[] = $wgTitle->getTalkPage();
203 $lb = new LinkBatch( $titles );
204 $lb->execute();
207 function addMetadataLinks( &$out ) {
208 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
209 global $wgRightsPage, $wgRightsUrl;
211 if( $out->isArticleRelated() ) {
212 # note: buggy CC software only reads first "meta" link
213 if( $wgEnableCreativeCommonsRdf ) {
214 $out->addMetadataLink( array(
215 'title' => 'Creative Commons',
216 'type' => 'application/rdf+xml',
217 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
219 if( $wgEnableDublinCoreRdf ) {
220 $out->addMetadataLink( array(
221 'title' => 'Dublin Core',
222 'type' => 'application/rdf+xml',
223 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
226 $copyright = '';
227 if( $wgRightsPage ) {
228 $copy = Title::newFromText( $wgRightsPage );
229 if( $copy ) {
230 $copyright = $copy->getLocalURL();
233 if( !$copyright && $wgRightsUrl ) {
234 $copyright = $wgRightsUrl;
236 if( $copyright ) {
237 $out->addLink( array(
238 'rel' => 'copyright',
239 'href' => $copyright ) );
243 function outputPage( &$out ) {
244 global $wgDebugComments;
246 wfProfileIn( __METHOD__ );
247 $this->initPage( $out );
249 $out->out( $out->headElement() );
251 $out->out( "\n<body" );
252 $ops = $this->getBodyOptions();
253 foreach ( $ops as $name => $val ) {
254 $out->out( " $name='$val'" );
256 $out->out( ">\n" );
257 if ( $wgDebugComments ) {
258 $out->out( "<!-- Wiki debugging output:\n" .
259 $out->mDebugtext . "-->\n" );
262 $out->out( $this->beforeContent() );
264 $out->out( $out->mBodytext . "\n" );
266 $out->out( $this->afterContent() );
268 $out->out( $this->bottomScripts() );
270 $out->out( $out->reportTime() );
272 $out->out( "\n</body></html>" );
273 wfProfileOut( __METHOD__ );
276 static function makeVariablesScript( $data ) {
277 global $wgJsMimeType;
279 $r = "<script type= \"$wgJsMimeType\">/*<![CDATA[*/\n";
280 foreach ( $data as $name => $value ) {
281 $encValue = Xml::encodeJsVar( $value );
282 $r .= "var $name = $encValue;\n";
284 $r .= "/*]]>*/</script>\n";
286 return $r;
290 * Make a <script> tag containing global variables
291 * @param array $data Associative array containing one element:
292 * skinname => the skin name
293 * The odd calling convention is for backwards compatibility
295 static function makeGlobalVariablesScript( $data ) {
296 global $wgScript, $wgStylePath, $wgUser;
297 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
298 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
299 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
300 global $wgUseAjax, $wgAjaxWatch;
301 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
302 global $wgRestrictionTypes, $wgLivePreview;
303 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
305 $ns = $wgTitle->getNamespace();
306 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
308 $vars = array(
309 'skin' => $data['skinname'],
310 'stylepath' => $wgStylePath,
311 'wgArticlePath' => $wgArticlePath,
312 'wgScriptPath' => $wgScriptPath,
313 'wgScript' => $wgScript,
314 'wgVariantArticlePath' => $wgVariantArticlePath,
315 'wgActionPaths' => $wgActionPaths,
316 'wgServer' => $wgServer,
317 'wgCanonicalNamespace' => $nsname,
318 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBkey() ),
319 'wgNamespaceNumber' => $wgTitle->getNamespace(),
320 'wgPageName' => $wgTitle->getPrefixedDBKey(),
321 'wgTitle' => $wgTitle->getText(),
322 'wgAction' => $wgRequest->getText( 'action', 'view' ),
323 'wgArticleId' => $wgTitle->getArticleId(),
324 'wgIsArticle' => $wgOut->isArticle(),
325 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
326 'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
327 'wgUserLanguage' => $wgLang->getCode(),
328 'wgContentLanguage' => $wgContLang->getCode(),
329 'wgBreakFrames' => $wgBreakFrames,
330 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
331 'wgVersion' => $wgVersion,
332 'wgEnableAPI' => $wgEnableAPI,
333 'wgEnableWriteAPI' => $wgEnableWriteAPI,
336 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false )){
337 $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
338 $vars['wgDBname'] = $wgDBname;
339 $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
340 $vars['wgMWSuggestMessages'] = array( wfMsg('search-mwsuggest-enabled'), wfMsg('search-mwsuggest-disabled'));
343 foreach( $wgRestrictionTypes as $type )
344 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
346 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
347 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
348 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
349 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
350 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
353 if($wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
354 $msgs = (object)array();
355 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
356 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
358 $vars['wgAjaxWatch'] = $msgs;
361 return self::makeVariablesScript( $vars );
364 function getHeadScripts( $allowUserJs ) {
365 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
367 $r = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
369 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
370 global $wgUseSiteJs;
371 if ($wgUseSiteJs) {
372 $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
373 $r .= "<script type=\"$wgJsMimeType\" src=\"".
374 htmlspecialchars(self::makeUrl('-',
375 "action=raw$jsCache&gen=js&useskin=" .
376 urlencode( $this->getSkinName() ) ) ) .
377 "\"><!-- site js --></script>\n";
379 if( $allowUserJs && $wgUser->isLoggedIn() ) {
380 $userpage = $wgUser->getUserPage();
381 $userjs = htmlspecialchars( self::makeUrl(
382 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
383 'action=raw&ctype='.$wgJsMimeType));
384 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
386 return $r;
390 * To make it harder for someone to slip a user a fake
391 * user-JavaScript or user-CSS preview, a random token
392 * is associated with the login session. If it's not
393 * passed back with the preview request, we won't render
394 * the code.
396 * @param string $action
397 * @return bool
398 * @private
400 function userCanPreview( $action ) {
401 global $wgTitle, $wgRequest, $wgUser;
403 if( $action != 'submit' )
404 return false;
405 if( !$wgRequest->wasPosted() )
406 return false;
407 if( !$wgTitle->userCanEditCssJsSubpage() )
408 return false;
409 return $wgUser->matchEditToken(
410 $wgRequest->getVal( 'wpEditToken' ) );
413 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
414 function getUserStylesheet() {
415 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
416 $sheet = $this->getStylesheet();
417 $s = "@import \"$wgStylePath/common/shared.css?$wgStyleVersion\";\n";
418 $s .= "@import \"$wgStylePath/common/oldshared.css?$wgStyleVersion\";\n";
419 $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
420 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
422 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
423 $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
424 '@import "' . self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
426 $s .= $this->doGetUserStyles();
427 return $s."\n";
431 * This returns MediaWiki:Common.js, and derived classes may add other JS.
432 * Despite its name, it does *not* return any custom user JS from user
433 * subpages. The returned script is sitewide and publicly cacheable and
434 * therefore must not include anything that varies according to user,
435 * interface language, etc. (although it may vary by skin). See
436 * makeGlobalVariablesScript for things that can vary per page view and are
437 * not cacheable.
439 * @return string Raw JavaScript to be returned
441 public function getUserJs() {
442 wfProfileIn( __METHOD__ );
444 global $wgStylePath;
445 $s = "/* generated javascript */\n";
446 $s .= "var skin = '" . Xml::escapeJsString( $this->getSkinName() ) . "';\n";
447 $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
448 $s .= "\n\n/* MediaWiki:Common.js */\n";
449 $commonJs = wfMsgForContent('common.js');
450 if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
451 $s .= $commonJs;
453 wfProfileOut( __METHOD__ );
454 return $s;
458 * Return html code that include User stylesheets
460 function getUserStyles() {
461 $s = "<style type='text/css'>\n";
462 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
463 $s .= $this->getUserStylesheet();
464 $s .= "/*]]>*/ /* */\n";
465 $s .= "</style>\n";
466 return $s;
470 * Some styles that are set by user through the user settings interface.
472 function doGetUserStyles() {
473 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
475 $s = '';
477 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
478 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
479 $s .= $wgRequest->getText('wpTextbox1');
480 } else {
481 $userpage = $wgUser->getUserPage();
482 $s.= '@import "'.self::makeUrl(
483 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
484 'action=raw&ctype=text/css').'";'."\n";
488 return $s . $this->reallyDoGetUserStyles();
491 function reallyDoGetUserStyles() {
492 global $wgUser;
493 $s = '';
494 if (($undopt = $wgUser->getOption("underline")) < 2) {
495 $underline = $undopt ? 'underline' : 'none';
496 $s .= "a { text-decoration: $underline; }\n";
498 if( $wgUser->getOption( 'highlightbroken' ) ) {
499 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
500 } else {
501 $s .= <<<END
502 a.new, #quickbar a.new,
503 a.stub, #quickbar a.stub {
504 color: inherit;
506 a.new:after, #quickbar a.new:after {
507 content: "?";
508 color: #CC2200;
510 a.stub:after, #quickbar a.stub:after {
511 content: "!";
512 color: #772233;
514 END;
516 if( $wgUser->getOption( 'justify' ) ) {
517 $s .= "#article, #bodyContent { text-align: justify; }\n";
519 if( !$wgUser->getOption( 'showtoc' ) ) {
520 $s .= "#toc { display: none; }\n";
522 if( !$wgUser->getOption( 'editsection' ) ) {
523 $s .= ".editsection { display: none; }\n";
525 return $s;
528 function getBodyOptions() {
529 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
531 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
533 if ( 0 != $wgTitle->getNamespace() ) {
534 $a = array( 'bgcolor' => '#ffffec' );
536 else $a = array( 'bgcolor' => '#FFFFFF' );
537 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
538 $wgTitle->userCan( 'edit' ) ) {
539 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
540 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
541 $a += array ('ondblclick' => $s);
544 $a['onload'] = $wgOut->getOnloadHandler();
545 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
546 if( $a['onload'] != '' ) {
547 $a['onload'] .= ';';
549 $a['onload'] .= 'setupRightClickEdit()';
551 $a['class'] =
552 'mediawiki ns-'.$wgTitle->getNamespace().
553 ' '.($wgContLang->isRTL() ? "rtl" : "ltr").
554 ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() );
555 return $a;
559 * URL to the logo
561 function getLogo() {
562 global $wgLogo;
563 return $wgLogo;
567 * This will be called immediately after the <body> tag. Split into
568 * two functions to make it easier to subclass.
570 function beforeContent() {
571 return $this->doBeforeContent();
574 function doBeforeContent() {
575 global $wgContLang;
576 $fname = 'Skin::doBeforeContent';
577 wfProfileIn( $fname );
579 $s = '';
580 $qb = $this->qbSetting();
582 if( $langlinks = $this->otherLanguages() ) {
583 $rows = 2;
584 $borderhack = '';
585 } else {
586 $rows = 1;
587 $langlinks = false;
588 $borderhack = 'class="top"';
591 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
592 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
594 $shove = ($qb != 0);
595 $left = ($qb == 1 || $qb == 3);
596 if($wgContLang->isRTL()) $left = !$left;
598 if ( !$shove ) {
599 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
600 $this->logoText() . '</td>';
601 } elseif( $left ) {
602 $s .= $this->getQuickbarCompensator( $rows );
604 $l = $wgContLang->isRTL() ? 'right' : 'left';
605 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
607 $s .= $this->topLinks() ;
608 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
610 $r = $wgContLang->isRTL() ? "left" : "right";
611 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
612 $s .= $this->nameAndLogin();
613 $s .= "\n<br />" . $this->searchForm() . "</td>";
615 if ( $langlinks ) {
616 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
619 if ( $shove && !$left ) { # Right
620 $s .= $this->getQuickbarCompensator( $rows );
622 $s .= "</tr>\n</table>\n</div>\n";
623 $s .= "\n<div id='article'>\n";
625 $notice = wfGetSiteNotice();
626 if( $notice ) {
627 $s .= "\n<div id='siteNotice'>$notice</div>\n";
629 $s .= $this->pageTitle();
630 $s .= $this->pageSubtitle() ;
631 $s .= $this->getCategories();
632 wfProfileOut( $fname );
633 return $s;
637 function getCategoryLinks() {
638 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
639 global $wgContLang, $wgUser;
641 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
643 # Separator
644 $sep = wfMsgHtml( 'catseparator' );
646 // Use Unicode bidi embedding override characters,
647 // to make sure links don't smash each other up in ugly ways.
648 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
649 $embed = "<span dir='$dir'>";
650 $pop = '</span>';
652 $allCats = $wgOut->getCategoryLinks();
653 $s = '';
654 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
655 if ( !empty( $allCats['normal'] ) ) {
656 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
658 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
659 $s .= '<div id="mw-normal-catlinks">' .
660 $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
661 . $colon . $t . '</div>';
664 # Hidden categories
665 if ( isset( $allCats['hidden'] ) ) {
666 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
667 $class ='mw-hidden-cats-user-shown';
668 } elseif ( $wgTitle->getNamespace() == NS_CATEGORY ) {
669 $class = 'mw-hidden-cats-ns-shown';
670 } else {
671 $class = 'mw-hidden-cats-hidden';
673 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
674 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
675 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
676 "</div>";
679 # optional 'dmoz-like' category browser. Will be shown under the list
680 # of categories an article belong to
681 if($wgUseCategoryBrowser) {
682 $s .= '<br /><hr />';
684 # get a big array of the parents tree
685 $parenttree = $wgTitle->getParentCategoryTree();
686 # Skin object passed by reference cause it can not be
687 # accessed under the method subfunction drawCategoryBrowser
688 $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
689 # Clean out bogus first entry and sort them
690 unset($tempout[0]);
691 asort($tempout);
692 # Output one per line
693 $s .= implode("<br />\n", $tempout);
696 return $s;
699 /** Render the array as a serie of links.
700 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
701 * @param &skin Object: skin passed by reference
702 * @return String separated by &gt;, terminate with "\n"
704 function drawCategoryBrowser($tree, &$skin) {
705 $return = '';
706 foreach ($tree as $element => $parent) {
707 if (empty($parent)) {
708 # element start a new list
709 $return .= "\n";
710 } else {
711 # grab the others elements
712 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
714 # add our current element to the list
715 $eltitle = Title::NewFromText($element);
716 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
718 return $return;
721 function getCategories() {
722 $catlinks=$this->getCategoryLinks();
724 $classes = 'catlinks';
726 if(FALSE === strpos($catlinks,'<div id="mw-normal-catlinks">')) {
727 $classes .= ' catlinks-allhidden';
730 if(!empty($catlinks)) {
731 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
735 function getQuickbarCompensator( $rows = 1 ) {
736 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
740 * This gets called shortly before the \</body\> tag.
741 * @return String HTML to be put before \</body\>
743 function afterContent() {
744 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
745 return $printfooter . $this->doAfterContent();
749 * This gets called shortly before the \</body\> tag.
750 * @return String HTML-wrapped JS code to be put before \</body\>
752 function bottomScripts() {
753 global $wgJsMimeType;
754 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
755 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
756 return $bottomScriptText;
759 /** @return string Retrievied from HTML text */
760 function printSource() {
761 global $wgTitle;
762 $url = htmlspecialchars( $wgTitle->getFullURL() );
763 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
766 function printFooter() {
767 return "<p>" . $this->printSource() .
768 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
771 /** overloaded by derived classes */
772 function doAfterContent() { }
774 function pageTitleLinks() {
775 global $wgOut, $wgTitle, $wgUser, $wgRequest;
777 $oldid = $wgRequest->getVal( 'oldid' );
778 $diff = $wgRequest->getVal( 'diff' );
779 $action = $wgRequest->getText( 'action' );
781 $s = $this->printableLink();
782 $disclaimer = $this->disclaimerLink(); # may be empty
783 if( $disclaimer ) {
784 $s .= ' | ' . $disclaimer;
786 $privacy = $this->privacyLink(); # may be empty too
787 if( $privacy ) {
788 $s .= ' | ' . $privacy;
791 if ( $wgOut->isArticleRelated() ) {
792 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
793 $name = $wgTitle->getDBkey();
794 $image = wfFindFile( $wgTitle );
795 if( $image ) {
796 $link = htmlspecialchars( $image->getURL() );
797 $style = $this->getInternalLinkAttributes( $link, $name );
798 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
802 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
803 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
804 wfMsg( 'currentrev' ) );
807 if ( $wgUser->getNewtalk() ) {
808 # do not show "You have new messages" text when we are viewing our
809 # own talk page
810 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
811 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
812 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
813 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
814 # disable caching
815 $wgOut->setSquidMaxage(0);
816 $wgOut->enableClientCache(false);
820 $undelete = $this->getUndeleteLink();
821 if( !empty( $undelete ) ) {
822 $s .= ' | '.$undelete;
824 return $s;
827 function getUndeleteLink() {
828 global $wgUser, $wgTitle, $wgContLang, $wgLang, $action;
829 if( $wgUser->isAllowed( 'deletedhistory' ) &&
830 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
831 ($n = $wgTitle->isDeleted() ) )
833 if ( $wgUser->isAllowed( 'undelete' ) ) {
834 $msg = 'thisisdeleted';
835 } else {
836 $msg = 'viewdeleted';
838 return wfMsg( $msg,
839 $this->makeKnownLinkObj(
840 SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
841 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
843 return '';
846 function printableLink() {
847 global $wgOut, $wgFeedClasses, $wgRequest;
849 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
851 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
852 if( $wgOut->isSyndicated() ) {
853 foreach( $wgFeedClasses as $format => $class ) {
854 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
855 $s .= " | <a href=\"$feedurl\">{$format}</a>";
858 return $s;
861 function pageTitle() {
862 global $wgOut;
863 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
864 return $s;
867 function pageSubtitle() {
868 global $wgOut;
870 $sub = $wgOut->getSubtitle();
871 if ( '' == $sub ) {
872 global $wgExtraSubtitle;
873 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
875 $subpages = $this->subPageSubtitle();
876 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
877 $s = "<p class='subtitle'>{$sub}</p>\n";
878 return $s;
881 function subPageSubtitle() {
882 $subpages = '';
883 if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages)))
884 return $retval;
886 global $wgOut, $wgTitle, $wgNamespacesWithSubpages;
887 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
888 $ptext=$wgTitle->getPrefixedText();
889 if(preg_match('/\//',$ptext)) {
890 $links = explode('/',$ptext);
891 $c = 0;
892 $growinglink = '';
893 foreach($links as $link) {
894 $c++;
895 if ($c<count($links)) {
896 $growinglink .= $link;
897 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
898 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
899 if ($c>1) {
900 $subpages .= ' | ';
901 } else {
902 $subpages .= '&lt; ';
904 $subpages .= $getlink;
905 $growinglink .= '/';
910 return $subpages;
914 * Returns true if the IP should be shown in the header
916 function showIPinHeader() {
917 global $wgShowIPinHeader;
918 return $wgShowIPinHeader && session_id() != '';
921 function nameAndLogin() {
922 global $wgUser, $wgTitle, $wgLang, $wgContLang;
924 $lo = $wgContLang->specialPage( 'Userlogout' );
926 $s = '';
927 if ( $wgUser->isAnon() ) {
928 if( $this->showIPinHeader() ) {
929 $n = wfGetIP();
931 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
932 $wgLang->getNsText( NS_TALK ) );
934 $s .= $n . ' ('.$tl.')';
935 } else {
936 $s .= wfMsg('notloggedin');
939 $rt = $wgTitle->getPrefixedURL();
940 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
941 $q = '';
942 } else { $q = "returnto={$rt}"; }
944 $s .= "\n<br />" . $this->makeKnownLinkObj(
945 SpecialPage::getTitleFor( 'Userlogin' ),
946 wfMsg( 'login' ), $q );
947 } else {
948 $n = $wgUser->getName();
949 $rt = $wgTitle->getPrefixedURL();
950 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
951 $wgLang->getNsText( NS_TALK ) );
953 $tl = " ({$tl})";
955 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
956 $n ) . "{$tl}<br />" .
957 $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
958 "returnto={$rt}" ) . ' | ' .
959 $this->specialLink( 'preferences' );
961 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
962 wfMsg( 'help' ) );
964 return $s;
967 function getSearchLink() {
968 $searchPage = SpecialPage::getTitleFor( 'Search' );
969 return $searchPage->getLocalURL();
972 function escapeSearchLink() {
973 return htmlspecialchars( $this->getSearchLink() );
976 function searchForm() {
977 global $wgRequest;
978 $search = $wgRequest->getText( 'search' );
980 $s = '<form name="search" class="inline" method="post" action="'
981 . $this->escapeSearchLink() . "\">\n"
982 . '<input type="text" name="search" size="19" value="'
983 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
984 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
985 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
987 return $s;
990 function topLinks() {
991 global $wgOut;
992 $sep = " |\n";
994 $s = $this->mainPageLink() . $sep
995 . $this->specialLink( 'recentchanges' );
997 if ( $wgOut->isArticleRelated() ) {
998 $s .= $sep . $this->editThisPage()
999 . $sep . $this->historyLink();
1001 # Many people don't like this dropdown box
1002 #$s .= $sep . $this->specialPagesList();
1004 $s .= $this->variantLinks();
1006 $s .= $this->extensionTabLinks();
1008 return $s;
1012 * Compatibility for extensions adding functionality through tabs.
1013 * Eventually these old skins should be replaced with SkinTemplate-based
1014 * versions, sigh...
1015 * @return string
1017 function extensionTabLinks() {
1018 $tabs = array();
1019 $s = '';
1020 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1021 foreach( $tabs as $tab ) {
1022 $s .= ' | ' . Xml::element( 'a',
1023 array( 'href' => $tab['href'] ),
1024 $tab['text'] );
1026 return $s;
1030 * Language/charset variant links for classic-style skins
1031 * @return string
1033 function variantLinks() {
1034 $s = '';
1035 /* show links to different language variants */
1036 global $wgDisableLangConversion, $wgContLang, $wgTitle;
1037 $variants = $wgContLang->getVariants();
1038 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1039 foreach( $variants as $code ) {
1040 $varname = $wgContLang->getVariantname( $code );
1041 if( $varname == 'disable' )
1042 continue;
1043 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
1046 return $s;
1049 function bottomLinks() {
1050 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1051 $sep = " |\n";
1053 $s = '';
1054 if ( $wgOut->isArticleRelated() ) {
1055 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1056 if ( $wgUser->isLoggedIn() ) {
1057 $s .= $sep . $this->watchThisPage();
1059 $s .= $sep . $this->talkLink()
1060 . $sep . $this->historyLink()
1061 . $sep . $this->whatLinksHere()
1062 . $sep . $this->watchPageLinksLink();
1064 if ($wgUseTrackbacks)
1065 $s .= $sep . $this->trackbackLink();
1067 if ( $wgTitle->getNamespace() == NS_USER
1068 || $wgTitle->getNamespace() == NS_USER_TALK )
1071 $id=User::idFromName($wgTitle->getText());
1072 $ip=User::isIP($wgTitle->getText());
1074 if($id || $ip) { # both anons and non-anons have contri list
1075 $s .= $sep . $this->userContribsLink();
1077 if( $this->showEmailUser( $id ) ) {
1078 $s .= $sep . $this->emailUserLink();
1081 if ( $wgTitle->getArticleId() ) {
1082 $s .= "\n<br />";
1083 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1084 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1085 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1087 $s .= "<br />\n" . $this->otherLanguages();
1089 return $s;
1092 function pageStats() {
1093 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1094 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1096 $oldid = $wgRequest->getVal( 'oldid' );
1097 $diff = $wgRequest->getVal( 'diff' );
1098 if ( ! $wgOut->isArticle() ) { return ''; }
1099 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1100 if ( 0 == $wgArticle->getID() ) { return ''; }
1102 $s = '';
1103 if ( !$wgDisableCounters ) {
1104 $count = $wgLang->formatNum( $wgArticle->getCount() );
1105 if ( $count ) {
1106 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1110 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
1111 require_once('Credits.php');
1112 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1113 } else {
1114 $s .= $this->lastModified();
1117 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
1118 $dbr = wfGetDB( DB_SLAVE );
1119 $watchlist = $dbr->tableName( 'watchlist' );
1120 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1121 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) .
1122 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1123 $res = $dbr->query( $sql, 'Skin::pageStats');
1124 $x = $dbr->fetchObject( $res );
1126 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1127 array( 'parseinline' ), $wgLang->formatNum($x->n)
1131 return $s . ' ' . $this->getCopyright();
1134 function getCopyright( $type = 'detect' ) {
1135 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1137 if ( $type == 'detect' ) {
1138 $oldid = $wgRequest->getVal( 'oldid' );
1139 $diff = $wgRequest->getVal( 'diff' );
1141 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1142 $type = 'history';
1143 } else {
1144 $type = 'normal';
1148 if ( $type == 'history' ) {
1149 $msg = 'history_copyright';
1150 } else {
1151 $msg = 'copyright';
1154 $out = '';
1155 if( $wgRightsPage ) {
1156 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1157 } elseif( $wgRightsUrl ) {
1158 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1159 } else {
1160 # Give up now
1161 return $out;
1163 $out .= wfMsgForContent( $msg, $link );
1164 return $out;
1167 function getCopyrightIcon() {
1168 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1169 $out = '';
1170 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1171 $out = $wgCopyrightIcon;
1172 } else if ( $wgRightsIcon ) {
1173 $icon = htmlspecialchars( $wgRightsIcon );
1174 if ( $wgRightsUrl ) {
1175 $url = htmlspecialchars( $wgRightsUrl );
1176 $out .= '<a href="'.$url.'">';
1178 $text = htmlspecialchars( $wgRightsText );
1179 $out .= "<img src=\"$icon\" alt='$text' />";
1180 if ( $wgRightsUrl ) {
1181 $out .= '</a>';
1184 return $out;
1187 function getPoweredBy() {
1188 global $wgStylePath;
1189 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1190 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1191 return $img;
1194 function lastModified() {
1195 global $wgLang, $wgArticle;
1197 $timestamp = $wgArticle->getTimestamp();
1198 if ( $timestamp ) {
1199 $d = $wgLang->date( $timestamp, true );
1200 $t = $wgLang->time( $timestamp, true );
1201 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1202 } else {
1203 $s = '';
1205 if ( wfGetLB()->getLaggedSlaveMode() ) {
1206 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1208 return $s;
1211 function logoText( $align = '' ) {
1212 if ( '' != $align ) { $a = " align='{$align}'"; }
1213 else { $a = ''; }
1215 $mp = wfMsg( 'mainpage' );
1216 $mptitle = Title::newMainPage();
1217 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1219 $logourl = $this->getLogo();
1220 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1221 return $s;
1225 * show a drop-down box of special pages
1227 function specialPagesList() {
1228 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1229 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1230 foreach ( $pages as $name => $page ) {
1231 $pages[$name] = $page->getDescription();
1234 $go = wfMsg( 'go' );
1235 $sp = wfMsg( 'specialpages' );
1236 $spp = $wgContLang->specialPage( 'Specialpages' );
1238 $s = '<form id="specialpages" method="get" class="inline" ' .
1239 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1240 $s .= "<select name=\"wpDropdown\">\n";
1241 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1244 foreach ( $pages as $name => $desc ) {
1245 $p = $wgContLang->specialPage( $name );
1246 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1248 $s .= "</select>\n";
1249 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1250 $s .= "</form>\n";
1251 return $s;
1254 function mainPageLink() {
1255 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1256 return $s;
1259 function copyrightLink() {
1260 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1261 wfMsg( 'copyrightpagename' ) );
1262 return $s;
1265 private function footerLink ( $desc, $page ) {
1266 // if the link description has been set to "-" in the default language,
1267 if ( wfMsgForContent( $desc ) == '-') {
1268 // then it is disabled, for all languages.
1269 return '';
1270 } else {
1271 // Otherwise, we display the link for the user, described in their
1272 // language (which may or may not be the same as the default language),
1273 // but we make the link target be the one site-wide page.
1274 return $this->makeKnownLink( wfMsgForContent( $page ),
1275 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1279 function privacyLink() {
1280 return $this->footerLink( 'privacy', 'privacypage' );
1283 function aboutLink() {
1284 return $this->footerLink( 'aboutsite', 'aboutpage' );
1287 function disclaimerLink() {
1288 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1291 function editThisPage() {
1292 global $wgOut, $wgTitle;
1294 if ( !$wgOut->isArticleRelated() ) {
1295 $s = wfMsg( 'protectedpage' );
1296 } else {
1297 if( $wgTitle->userCan( 'edit' ) && $wgTitle->exists() ) {
1298 $t = wfMsg( 'editthispage' );
1299 } elseif( $wgTitle->userCan( 'create' ) && !$wgTitle->exists() ) {
1300 $t = wfMsg( 'create-this-page' );
1301 } else {
1302 $t = wfMsg( 'viewsource' );
1305 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1307 return $s;
1311 * Return URL options for the 'edit page' link.
1312 * This may include an 'oldid' specifier, if the current page view is such.
1314 * @return string
1315 * @private
1317 function editUrlOptions() {
1318 global $wgArticle;
1320 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1321 return "action=edit&oldid=" . intval( $this->mRevisionId );
1322 } else {
1323 return "action=edit";
1327 function deleteThisPage() {
1328 global $wgUser, $wgTitle, $wgRequest;
1330 $diff = $wgRequest->getVal( 'diff' );
1331 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1332 $t = wfMsg( 'deletethispage' );
1334 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1335 } else {
1336 $s = '';
1338 return $s;
1341 function protectThisPage() {
1342 global $wgUser, $wgTitle, $wgRequest;
1344 $diff = $wgRequest->getVal( 'diff' );
1345 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1346 if ( $wgTitle->isProtected() ) {
1347 $t = wfMsg( 'unprotectthispage' );
1348 $q = 'action=unprotect';
1349 } else {
1350 $t = wfMsg( 'protectthispage' );
1351 $q = 'action=protect';
1353 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1354 } else {
1355 $s = '';
1357 return $s;
1360 function watchThisPage() {
1361 global $wgOut, $wgTitle;
1362 ++$this->mWatchLinkNum;
1364 if ( $wgOut->isArticleRelated() ) {
1365 if ( $wgTitle->userIsWatching() ) {
1366 $t = wfMsg( 'unwatchthispage' );
1367 $q = 'action=unwatch';
1368 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1369 } else {
1370 $t = wfMsg( 'watchthispage' );
1371 $q = 'action=watch';
1372 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1374 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1375 } else {
1376 $s = wfMsg( 'notanarticle' );
1378 return $s;
1381 function moveThisPage() {
1382 global $wgTitle;
1384 if ( $wgTitle->userCan( 'move' ) ) {
1385 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1386 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1387 } else {
1388 // no message if page is protected - would be redundant
1389 return '';
1393 function historyLink() {
1394 global $wgTitle;
1396 return $this->makeKnownLinkObj( $wgTitle,
1397 wfMsg( 'history' ), 'action=history' );
1400 function whatLinksHere() {
1401 global $wgTitle;
1403 return $this->makeKnownLinkObj(
1404 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1405 wfMsg( 'whatlinkshere' ) );
1408 function userContribsLink() {
1409 global $wgTitle;
1411 return $this->makeKnownLinkObj(
1412 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1413 wfMsg( 'contributions' ) );
1416 function showEmailUser( $id ) {
1417 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1418 return $wgEnableEmail &&
1419 $wgEnableUserEmail &&
1420 $wgUser->isLoggedIn() && # show only to signed in users
1421 0 != $id; # we can only email to non-anons ..
1422 # '' != $id->getEmail() && # who must have an email address stored ..
1423 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1424 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1427 function emailUserLink() {
1428 global $wgTitle;
1430 return $this->makeKnownLinkObj(
1431 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1432 wfMsg( 'emailuser' ) );
1435 function watchPageLinksLink() {
1436 global $wgOut, $wgTitle;
1438 if ( ! $wgOut->isArticleRelated() ) {
1439 return '(' . wfMsg( 'notanarticle' ) . ')';
1440 } else {
1441 return $this->makeKnownLinkObj(
1442 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1443 wfMsg( 'recentchangeslinked' ) );
1447 function trackbackLink() {
1448 global $wgTitle;
1450 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1451 . wfMsg('trackbacklink') . "</a>";
1454 function otherLanguages() {
1455 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1457 if ( $wgHideInterlanguageLinks ) {
1458 return '';
1461 $a = $wgOut->getLanguageLinks();
1462 if ( 0 == count( $a ) ) {
1463 return '';
1466 $s = wfMsg( 'otherlanguages' ) . ': ';
1467 $first = true;
1468 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1469 foreach( $a as $l ) {
1470 if ( ! $first ) { $s .= ' | '; }
1471 $first = false;
1473 $nt = Title::newFromText( $l );
1474 $url = $nt->escapeFullURL();
1475 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1477 if ( '' == $text ) { $text = $l; }
1478 $style = $this->getExternalLinkAttributes( $l, $text );
1479 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1481 if($wgContLang->isRTL()) $s .= '</span>';
1482 return $s;
1485 function bugReportsLink() {
1486 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1487 wfMsg( 'bugreports' ) );
1488 return $s;
1491 function talkLink() {
1492 global $wgTitle;
1494 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1495 # No discussion links for special pages
1496 return '';
1499 if( $wgTitle->isTalkPage() ) {
1500 $link = $wgTitle->getSubjectPage();
1501 switch( $link->getNamespace() ) {
1502 case NS_MAIN:
1503 $text = wfMsg( 'articlepage' );
1504 break;
1505 case NS_USER:
1506 $text = wfMsg( 'userpage' );
1507 break;
1508 case NS_PROJECT:
1509 $text = wfMsg( 'projectpage' );
1510 break;
1511 case NS_IMAGE:
1512 $text = wfMsg( 'imagepage' );
1513 break;
1514 case NS_MEDIAWIKI:
1515 $text = wfMsg( 'mediawikipage' );
1516 break;
1517 case NS_TEMPLATE:
1518 $text = wfMsg( 'templatepage' );
1519 break;
1520 case NS_HELP:
1521 $text = wfMsg( 'viewhelppage' );
1522 break;
1523 case NS_CATEGORY:
1524 $text = wfMsg( 'categorypage' );
1525 break;
1526 default:
1527 $text = wfMsg( 'articlepage' );
1529 } else {
1530 $link = $wgTitle->getTalkPage();
1531 $text = wfMsg( 'talkpage' );
1534 $s = $this->makeLinkObj( $link, $text );
1536 return $s;
1539 function commentLink() {
1540 global $wgTitle, $wgOut;
1542 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1543 return '';
1546 # __NEWSECTIONLINK___ changes behaviour here
1547 # If it's present, the link points to this page, otherwise
1548 # it points to the talk page
1549 if( $wgTitle->isTalkPage() ) {
1550 $title = $wgTitle;
1551 } elseif( $wgOut->showNewSectionLink() ) {
1552 $title = $wgTitle;
1553 } else {
1554 $title = $wgTitle->getTalkPage();
1557 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1560 /* these are used extensively in SkinTemplate, but also some other places */
1561 static function makeMainPageUrl( $urlaction = '' ) {
1562 $title = Title::newMainPage();
1563 self::checkTitle( $title, '' );
1564 return $title->getLocalURL( $urlaction );
1567 static function makeSpecialUrl( $name, $urlaction = '' ) {
1568 $title = SpecialPage::getTitleFor( $name );
1569 return $title->getLocalURL( $urlaction );
1572 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1573 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1574 return $title->getLocalURL( $urlaction );
1577 static function makeI18nUrl( $name, $urlaction = '' ) {
1578 $title = Title::newFromText( wfMsgForContent( $name ) );
1579 self::checkTitle( $title, $name );
1580 return $title->getLocalURL( $urlaction );
1583 static function makeUrl( $name, $urlaction = '' ) {
1584 $title = Title::newFromText( $name );
1585 self::checkTitle( $title, $name );
1586 return $title->getLocalURL( $urlaction );
1589 # If url string starts with http, consider as external URL, else
1590 # internal
1591 static function makeInternalOrExternalUrl( $name ) {
1592 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1593 return $name;
1594 } else {
1595 return self::makeUrl( $name );
1599 # this can be passed the NS number as defined in Language.php
1600 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1601 $title = Title::makeTitleSafe( $namespace, $name );
1602 self::checkTitle( $title, $name );
1603 return $title->getLocalURL( $urlaction );
1606 /* these return an array with the 'href' and boolean 'exists' */
1607 static function makeUrlDetails( $name, $urlaction = '' ) {
1608 $title = Title::newFromText( $name );
1609 self::checkTitle( $title, $name );
1610 return array(
1611 'href' => $title->getLocalURL( $urlaction ),
1612 'exists' => $title->getArticleID() != 0 ? true : false
1617 * Make URL details where the article exists (or at least it's convenient to think so)
1619 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1620 $title = Title::newFromText( $name );
1621 self::checkTitle( $title, $name );
1622 return array(
1623 'href' => $title->getLocalURL( $urlaction ),
1624 'exists' => true
1628 # make sure we have some title to operate on
1629 static function checkTitle( &$title, $name ) {
1630 if( !is_object( $title ) ) {
1631 $title = Title::newFromText( $name );
1632 if( !is_object( $title ) ) {
1633 $title = Title::newFromText( '--error: link target missing--' );
1639 * Build an array that represents the sidebar(s), the navigation bar among them
1641 * @return array
1642 * @private
1644 function buildSidebar() {
1645 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1646 global $wgLang, $wgContLang;
1648 $fname = 'SkinTemplate::buildSidebar';
1650 wfProfileIn( $fname );
1652 $key = wfMemcKey( 'sidebar' );
1653 $cacheSidebar = $wgEnableSidebarCache &&
1654 ($wgLang->getCode() == $wgContLang->getCode());
1656 if ($cacheSidebar) {
1657 $cachedsidebar = $parserMemc->get( $key );
1658 if ($cachedsidebar!="") {
1659 wfProfileOut($fname);
1660 return $cachedsidebar;
1664 $bar = array();
1665 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1666 $heading = '';
1667 foreach ($lines as $line) {
1668 if (strpos($line, '*') !== 0)
1669 continue;
1670 if (strpos($line, '**') !== 0) {
1671 $line = trim($line, '* ');
1672 $heading = $line;
1673 } else {
1674 if (strpos($line, '|') !== false) { // sanity check
1675 $line = explode( '|' , trim($line, '* '), 2 );
1676 $link = wfMsgForContent( $line[0] );
1677 if ($link == '-')
1678 continue;
1679 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1680 $text = $line[1];
1681 if (wfEmptyMsg($line[0], $link))
1682 $link = $line[0];
1684 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1685 $href = $link;
1686 } else {
1687 $title = Title::newFromText( $link );
1688 if ( $title ) {
1689 $title = $title->fixSpecialName();
1690 $href = $title->getLocalURL();
1691 } else {
1692 $href = 'INVALID-TITLE';
1696 $bar[$heading][] = array(
1697 'text' => $text,
1698 'href' => $href,
1699 'id' => 'n-' . strtr($line[1], ' ', '-'),
1700 'active' => false
1702 } else { continue; }
1705 if ($cacheSidebar)
1706 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1707 wfProfileOut( $fname );
1708 return $bar;