More cleanup from r22859
[mediawiki.git] / includes / Skin.php
blobb46bcfd9a8ffff21461df346703607acb4784153
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 $lastdate, $lastline;
20 var $rc_cache ; # Cache for Enhanced Recent Changes
21 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
22 var $rcMoveIndex;
23 var $mWatchLinkNum = 0; // Appended to end of watch link id's
24 /**#@-*/
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(); }
31 /**
32 * Fetch the set of available skins.
33 * @return array of strings
34 * @static
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
51 $matches = array();
52 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
53 $aSkin = $matches[1];
54 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
57 $skinDir->close();
58 $skinsInitialised = true;
59 wfProfileOut( __METHOD__ . '-init' );
61 return $wgValidSkinNames;
64 /**
65 * Normalize a skin preference value to a form that can be loaded.
66 * If a skin can't be found, it will fall back to the configured
67 * default (or the old 'Classic' skin if that's broken).
68 * @param string $key
69 * @return string
70 * @static
72 static function normalizeKey( $key ) {
73 global $wgDefaultSkin;
74 $skinNames = Skin::getSkinNames();
76 if( $key == '' ) {
77 // Don't return the default immediately;
78 // in a misconfiguration we need to fall back.
79 $key = $wgDefaultSkin;
82 if( isset( $skinNames[$key] ) ) {
83 return $key;
86 // Older versions of the software used a numeric setting
87 // in the user preferences.
88 $fallback = array(
89 0 => $wgDefaultSkin,
90 1 => 'nostalgia',
91 2 => 'cologneblue' );
93 if( isset( $fallback[$key] ) ){
94 $key = $fallback[$key];
97 if( isset( $skinNames[$key] ) ) {
98 return $key;
99 } else {
100 // The old built-in skin
101 return 'standard';
106 * Factory method for loading a skin of a given type
107 * @param string $key 'monobook', 'standard', etc
108 * @return Skin
109 * @static
111 static function &newFromKey( $key ) {
112 global $wgStyleDirectory;
114 $key = Skin::normalizeKey( $key );
116 $skinNames = Skin::getSkinNames();
117 $skinName = $skinNames[$key];
119 # Grab the skin class and initialise it.
120 // Preload base classes to work around APC/PHP5 bug
121 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
122 if( file_exists( $deps ) ) include_once( $deps );
123 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
125 # Check if we got if not failback to default skin
126 $className = 'Skin'.$skinName;
127 if( !class_exists( $className ) ) {
128 # DO NOT die if the class isn't found. This breaks maintenance
129 # scripts and can cause a user account to be unrecoverable
130 # except by SQL manipulation if a previously valid skin name
131 # is no longer valid.
132 wfDebug( "Skin class does not exist: $className\n" );
133 $className = 'SkinStandard';
134 require_once( "{$wgStyleDirectory}/Standard.php" );
136 $skin = new $className;
137 return $skin;
140 /** @return string path to the skin stylesheet */
141 function getStylesheet() {
142 return 'common/wikistandard.css';
145 /** @return string skin name */
146 public function getSkinName() {
147 return $this->skinname;
150 function qbSetting() {
151 global $wgOut, $wgUser;
153 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
154 $q = $wgUser->getOption( 'quickbar', 0 );
155 return $q;
158 function initPage( &$out ) {
159 global $wgFavicon, $wgScriptPath, $wgSitename, $wgLanguageCode, $wgLanguageNames;
161 $fname = 'Skin::initPage';
162 wfProfileIn( $fname );
164 if( false !== $wgFavicon ) {
165 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
168 # OpenSearch description link
169 $out->addLink( array(
170 'rel' => 'search',
171 'type' => 'application/opensearchdescription+xml',
172 'href' => "$wgScriptPath/opensearch_desc.php",
173 'title' => "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})",
176 $this->addMetadataLinks($out);
178 $this->mRevisionId = $out->mRevisionId;
180 $this->preloadExistence();
182 wfProfileOut( $fname );
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 $wgStylePath, $wgUser;
297 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
298 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
299 global $wgBreakFrames, $wgRequest;
301 $ns = $wgTitle->getNamespace();
302 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
304 $vars = array(
305 'skin' => $data['skinname'],
306 'stylepath' => $wgStylePath,
307 'wgArticlePath' => $wgArticlePath,
308 'wgScriptPath' => $wgScriptPath,
309 'wgServer' => $wgServer,
310 'wgCanonicalNamespace' => $nsname,
311 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBKey() ),
312 'wgNamespaceNumber' => $wgTitle->getNamespace(),
313 'wgPageName' => $wgTitle->getPrefixedDBKey(),
314 'wgTitle' => $wgTitle->getText(),
315 'wgAction' => $wgRequest->getText( 'action', 'view' ),
316 'wgRestrictionEdit' => $wgTitle->getRestrictions( 'edit' ),
317 'wgRestrictionMove' => $wgTitle->getRestrictions( 'move' ),
318 'wgArticleId' => $wgTitle->getArticleId(),
319 'wgIsArticle' => $wgOut->isArticle(),
320 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
321 'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
322 'wgUserLanguage' => $wgLang->getCode(),
323 'wgContentLanguage' => $wgContLang->getCode(),
324 'wgBreakFrames' => $wgBreakFrames,
325 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
328 global $wgLivePreview;
329 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
330 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
331 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
332 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
333 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
336 return self::makeVariablesScript( $vars );
339 function getHeadScripts( $allowUserJs ) {
340 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
342 $r = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
344 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
345 global $wgUseSiteJs;
346 if ($wgUseSiteJs) {
347 if ($wgUser->isLoggedIn()) {
348 $r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self::makeUrl('-','action=raw&smaxage=0&gen=js'))."\"><!-- site js --></script>\n";
349 } else {
350 $r .= "<script type=\"$wgJsMimeType\" src=\"".htmlspecialchars(self::makeUrl('-','action=raw&gen=js'))."\"><!-- site js --></script>\n";
353 if( $allowUserJs && $wgUser->isLoggedIn() ) {
354 $userpage = $wgUser->getUserPage();
355 $userjs = htmlspecialchars( self::makeUrl(
356 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
357 'action=raw&ctype='.$wgJsMimeType));
358 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
360 return $r;
364 * To make it harder for someone to slip a user a fake
365 * user-JavaScript or user-CSS preview, a random token
366 * is associated with the login session. If it's not
367 * passed back with the preview request, we won't render
368 * the code.
370 * @param string $action
371 * @return bool
372 * @private
374 function userCanPreview( $action ) {
375 global $wgTitle, $wgRequest, $wgUser;
377 if( $action != 'submit' )
378 return false;
379 if( !$wgRequest->wasPosted() )
380 return false;
381 if( !$wgTitle->userCanEditCssJsSubpage() )
382 return false;
383 return $wgUser->matchEditToken(
384 $wgRequest->getVal( 'wpEditToken' ) );
387 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
388 function getUserStylesheet() {
389 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
390 $sheet = $this->getStylesheet();
391 $s = "@import \"$wgStylePath/common/common.css?$wgStyleVersion\";\n";
392 $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
393 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
395 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
396 $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
397 '@import "' . self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
399 $s .= $this->doGetUserStyles();
400 return $s."\n";
404 * This returns MediaWiki:Common.js. For some bizarre reason, it does
405 * *not* return any custom user JS from user subpages. Huh?
407 * @return string
409 function getUserJs() {
410 wfProfileIn( __METHOD__ );
412 global $wgStylePath;
413 $s = "/* generated javascript */\n";
414 $s .= "var skin = '{$this->skinname}';\nvar stylepath = '{$wgStylePath}';";
415 $s .= "\n\n/* MediaWiki:Common.js */\n";
416 $commonJs = wfMsgForContent('common.js');
417 if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
418 $s .= $commonJs;
421 global $wgUseAjax, $wgAjaxWatch;
422 if($wgUseAjax && $wgAjaxWatch) {
423 $s .= "
425 /* AJAX (un)watch (see /skins/common/ajaxwatch.js) */
426 var wgAjaxWatch = {
427 watchMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watch', array() ) )."',
428 unwatchMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatch', array() ) )."',
429 watchingMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'watching', array() ) )."',
430 unwatchingMsg: '". str_replace( array("'", "\n"), array("\\'", ' '), wfMsgExt( 'unwatching', array() ) )."'
431 };";
434 wfProfileOut( __METHOD__ );
435 return $s;
439 * Return html code that include User stylesheets
441 function getUserStyles() {
442 $s = "<style type='text/css'>\n";
443 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
444 $s .= $this->getUserStylesheet();
445 $s .= "/*]]>*/ /* */\n";
446 $s .= "</style>\n";
447 return $s;
451 * Some styles that are set by user through the user settings interface.
453 function doGetUserStyles() {
454 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
456 $s = '';
458 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
459 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
460 $s .= $wgRequest->getText('wpTextbox1');
461 } else {
462 $userpage = $wgUser->getUserPage();
463 $s.= '@import "'.self::makeUrl(
464 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
465 'action=raw&ctype=text/css').'";'."\n";
469 return $s . $this->reallyDoGetUserStyles();
472 function reallyDoGetUserStyles() {
473 global $wgUser;
474 $s = '';
475 if (($undopt = $wgUser->getOption("underline")) != 2) {
476 $underline = $undopt ? 'underline' : 'none';
477 $s .= "a { text-decoration: $underline; }\n";
479 if( $wgUser->getOption( 'highlightbroken' ) ) {
480 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
481 } else {
482 $s .= <<<END
483 a.new, #quickbar a.new,
484 a.stub, #quickbar a.stub {
485 color: inherit;
486 text-decoration: inherit;
488 a.new:after, #quickbar a.new:after {
489 content: "?";
490 color: #CC2200;
491 text-decoration: $underline;
493 a.stub:after, #quickbar a.stub:after {
494 content: "!";
495 color: #772233;
496 text-decoration: $underline;
498 END;
500 if( $wgUser->getOption( 'justify' ) ) {
501 $s .= "#article, #bodyContent { text-align: justify; }\n";
503 if( !$wgUser->getOption( 'showtoc' ) ) {
504 $s .= "#toc { display: none; }\n";
506 if( !$wgUser->getOption( 'editsection' ) ) {
507 $s .= ".editsection { display: none; }\n";
509 return $s;
512 function getBodyOptions() {
513 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
515 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
517 if ( 0 != $wgTitle->getNamespace() ) {
518 $a = array( 'bgcolor' => '#ffffec' );
520 else $a = array( 'bgcolor' => '#FFFFFF' );
521 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
522 $wgTitle->userCan( 'edit' ) ) {
523 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
524 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
525 $a += array ('ondblclick' => $s);
528 $a['onload'] = $wgOut->getOnloadHandler();
529 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
530 if( $a['onload'] != '' ) {
531 $a['onload'] .= ';';
533 $a['onload'] .= 'setupRightClickEdit()';
535 $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
536 ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() );
537 return $a;
541 * URL to the logo
543 function getLogo() {
544 global $wgLogo;
545 return $wgLogo;
549 * This will be called immediately after the <body> tag. Split into
550 * two functions to make it easier to subclass.
552 function beforeContent() {
553 return $this->doBeforeContent();
556 function doBeforeContent() {
557 global $wgContLang;
558 $fname = 'Skin::doBeforeContent';
559 wfProfileIn( $fname );
561 $s = '';
562 $qb = $this->qbSetting();
564 if( $langlinks = $this->otherLanguages() ) {
565 $rows = 2;
566 $borderhack = '';
567 } else {
568 $rows = 1;
569 $langlinks = false;
570 $borderhack = 'class="top"';
573 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
574 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
576 $shove = ($qb != 0);
577 $left = ($qb == 1 || $qb == 3);
578 if($wgContLang->isRTL()) $left = !$left;
580 if ( !$shove ) {
581 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
582 $this->logoText() . '</td>';
583 } elseif( $left ) {
584 $s .= $this->getQuickbarCompensator( $rows );
586 $l = $wgContLang->isRTL() ? 'right' : 'left';
587 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
589 $s .= $this->topLinks() ;
590 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
592 $r = $wgContLang->isRTL() ? "left" : "right";
593 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
594 $s .= $this->nameAndLogin();
595 $s .= "\n<br />" . $this->searchForm() . "</td>";
597 if ( $langlinks ) {
598 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
601 if ( $shove && !$left ) { # Right
602 $s .= $this->getQuickbarCompensator( $rows );
604 $s .= "</tr>\n</table>\n</div>\n";
605 $s .= "\n<div id='article'>\n";
607 $notice = wfGetSiteNotice();
608 if( $notice ) {
609 $s .= "\n<div id='siteNotice'>$notice</div>\n";
611 $s .= $this->pageTitle();
612 $s .= $this->pageSubtitle() ;
613 $s .= $this->getCategories();
614 wfProfileOut( $fname );
615 return $s;
619 function getCategoryLinks () {
620 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
621 global $wgContLang;
623 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
625 # Separator
626 $sep = wfMsgHtml( 'catseparator' );
628 // Use Unicode bidi embedding override characters,
629 // to make sure links don't smash each other up in ugly ways.
630 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
631 $embed = "<span dir='$dir'>";
632 $pop = '</span>';
633 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop;
635 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) );
636 $s = $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
637 . ': ' . $t;
639 # optional 'dmoz-like' category browser. Will be shown under the list
640 # of categories an article belong to
641 if($wgUseCategoryBrowser) {
642 $s .= '<br /><hr />';
644 # get a big array of the parents tree
645 $parenttree = $wgTitle->getParentCategoryTree();
646 # Skin object passed by reference cause it can not be
647 # accessed under the method subfunction drawCategoryBrowser
648 $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
649 # Clean out bogus first entry and sort them
650 unset($tempout[0]);
651 asort($tempout);
652 # Output one per line
653 $s .= implode("<br />\n", $tempout);
656 return $s;
659 /** Render the array as a serie of links.
660 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
661 * @param &skin Object: skin passed by reference
662 * @return String separated by &gt;, terminate with "\n"
664 function drawCategoryBrowser($tree, &$skin) {
665 $return = '';
666 foreach ($tree as $element => $parent) {
667 if (empty($parent)) {
668 # element start a new list
669 $return .= "\n";
670 } else {
671 # grab the others elements
672 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
674 # add our current element to the list
675 $eltitle = Title::NewFromText($element);
676 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
678 return $return;
681 function getCategories() {
682 $catlinks=$this->getCategoryLinks();
683 if(!empty($catlinks)) {
684 return "<p class='catlinks'>{$catlinks}</p>";
688 function getQuickbarCompensator( $rows = 1 ) {
689 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
693 * This gets called shortly before the \</body\> tag.
694 * @return String HTML to be put before \</body\>
696 function afterContent() {
697 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
698 return $printfooter . $this->doAfterContent();
702 * This gets called shortly before the \</body\> tag.
703 * @return String HTML-wrapped JS code to be put before \</body\>
705 function bottomScripts() {
706 global $wgJsMimeType;
707 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
710 /** @return string Retrievied from HTML text */
711 function printSource() {
712 global $wgTitle;
713 $url = htmlspecialchars( $wgTitle->getFullURL() );
714 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
717 function printFooter() {
718 return "<p>" . $this->printSource() .
719 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
722 /** overloaded by derived classes */
723 function doAfterContent() { }
725 function pageTitleLinks() {
726 global $wgOut, $wgTitle, $wgUser, $wgRequest;
728 $oldid = $wgRequest->getVal( 'oldid' );
729 $diff = $wgRequest->getVal( 'diff' );
730 $action = $wgRequest->getText( 'action' );
732 $s = $this->printableLink();
733 $disclaimer = $this->disclaimerLink(); # may be empty
734 if( $disclaimer ) {
735 $s .= ' | ' . $disclaimer;
737 $privacy = $this->privacyLink(); # may be empty too
738 if( $privacy ) {
739 $s .= ' | ' . $privacy;
742 if ( $wgOut->isArticleRelated() ) {
743 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
744 $name = $wgTitle->getDBkey();
745 $image = wfFindFile( $wgTitle );
746 if( $image ) {
747 $link = htmlspecialchars( $image->getURL() );
748 $style = $this->getInternalLinkAttributes( $link, $name );
749 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
753 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
754 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
755 wfMsg( 'currentrev' ) );
758 if ( $wgUser->getNewtalk() ) {
759 # do not show "You have new messages" text when we are viewing our
760 # own talk page
761 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
762 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
763 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
764 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
765 # disable caching
766 $wgOut->setSquidMaxage(0);
767 $wgOut->enableClientCache(false);
771 $undelete = $this->getUndeleteLink();
772 if( !empty( $undelete ) ) {
773 $s .= ' | '.$undelete;
775 return $s;
778 function getUndeleteLink() {
779 global $wgUser, $wgTitle, $wgContLang, $action;
780 if( $wgUser->isAllowed( 'deletedhistory' ) &&
781 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
782 ($n = $wgTitle->isDeleted() ) )
784 if ( $wgUser->isAllowed( 'delete' ) ) {
785 $msg = 'thisisdeleted';
786 } else {
787 $msg = 'viewdeleted';
789 return wfMsg( $msg,
790 $this->makeKnownLinkObj(
791 SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
792 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
794 return '';
797 function printableLink() {
798 global $wgOut, $wgFeedClasses, $wgRequest;
800 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
802 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
803 if( $wgOut->isSyndicated() ) {
804 foreach( $wgFeedClasses as $format => $class ) {
805 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
806 $s .= " | <a href=\"$feedurl\">{$format}</a>";
809 return $s;
812 function pageTitle() {
813 global $wgOut;
814 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
815 return $s;
818 function pageSubtitle() {
819 global $wgOut;
821 $sub = $wgOut->getSubtitle();
822 if ( '' == $sub ) {
823 global $wgExtraSubtitle;
824 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
826 $subpages = $this->subPageSubtitle();
827 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
828 $s = "<p class='subtitle'>{$sub}</p>\n";
829 return $s;
832 function subPageSubtitle() {
833 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
834 $subpages = '';
835 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
836 $ptext=$wgTitle->getPrefixedText();
837 if(preg_match('/\//',$ptext)) {
838 $links = explode('/',$ptext);
839 $c = 0;
840 $growinglink = '';
841 foreach($links as $link) {
842 $c++;
843 if ($c<count($links)) {
844 $growinglink .= $link;
845 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
846 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
847 if ($c>1) {
848 $subpages .= ' | ';
849 } else {
850 $subpages .= '&lt; ';
852 $subpages .= $getlink;
853 $growinglink .= '/';
858 return $subpages;
862 * Returns true if the IP should be shown in the header
864 function showIPinHeader() {
865 global $wgShowIPinHeader;
866 return $wgShowIPinHeader && session_id() != '';
869 function nameAndLogin() {
870 global $wgUser, $wgTitle, $wgLang, $wgContLang;
872 $lo = $wgContLang->specialPage( 'Userlogout' );
874 $s = '';
875 if ( $wgUser->isAnon() ) {
876 if( $this->showIPinHeader() ) {
877 $n = wfGetIP();
879 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
880 $wgLang->getNsText( NS_TALK ) );
882 $s .= $n . ' ('.$tl.')';
883 } else {
884 $s .= wfMsg('notloggedin');
887 $rt = $wgTitle->getPrefixedURL();
888 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
889 $q = '';
890 } else { $q = "returnto={$rt}"; }
892 $s .= "\n<br />" . $this->makeKnownLinkObj(
893 SpecialPage::getTitleFor( 'Userlogin' ),
894 wfMsg( 'login' ), $q );
895 } else {
896 $n = $wgUser->getName();
897 $rt = $wgTitle->getPrefixedURL();
898 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
899 $wgLang->getNsText( NS_TALK ) );
901 $tl = " ({$tl})";
903 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
904 $n ) . "{$tl}<br />" .
905 $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
906 "returnto={$rt}" ) . ' | ' .
907 $this->specialLink( 'preferences' );
909 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
910 wfMsg( 'help' ) );
912 return $s;
915 function getSearchLink() {
916 $searchPage = SpecialPage::getTitleFor( 'Search' );
917 return $searchPage->getLocalURL();
920 function escapeSearchLink() {
921 return htmlspecialchars( $this->getSearchLink() );
924 function searchForm() {
925 global $wgRequest;
926 $search = $wgRequest->getText( 'search' );
928 $s = '<form name="search" class="inline" method="post" action="'
929 . $this->escapeSearchLink() . "\">\n"
930 . '<input type="text" name="search" size="19" value="'
931 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
932 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
933 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
935 return $s;
938 function topLinks() {
939 global $wgOut;
940 $sep = " |\n";
942 $s = $this->mainPageLink() . $sep
943 . $this->specialLink( 'recentchanges' );
945 if ( $wgOut->isArticleRelated() ) {
946 $s .= $sep . $this->editThisPage()
947 . $sep . $this->historyLink();
949 # Many people don't like this dropdown box
950 #$s .= $sep . $this->specialPagesList();
952 $s .= $this->variantLinks();
954 $s .= $this->extensionTabLinks();
956 return $s;
960 * Compatibility for extensions adding functionality through tabs.
961 * Eventually these old skins should be replaced with SkinTemplate-based
962 * versions, sigh...
963 * @return string
965 function extensionTabLinks() {
966 $tabs = array();
967 $s = '';
968 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
969 foreach( $tabs as $tab ) {
970 $s .= ' | ' . Xml::element( 'a',
971 array( 'href' => $tab['href'] ),
972 $tab['text'] );
974 return $s;
978 * Language/charset variant links for classic-style skins
979 * @return string
981 function variantLinks() {
982 $s = '';
983 /* show links to different language variants */
984 global $wgDisableLangConversion, $wgContLang, $wgTitle;
985 $variants = $wgContLang->getVariants();
986 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
987 foreach( $variants as $code ) {
988 $varname = $wgContLang->getVariantname( $code );
989 if( $varname == 'disable' )
990 continue;
991 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
994 return $s;
997 function bottomLinks() {
998 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
999 $sep = " |\n";
1001 $s = '';
1002 if ( $wgOut->isArticleRelated() ) {
1003 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1004 if ( $wgUser->isLoggedIn() ) {
1005 $s .= $sep . $this->watchThisPage();
1007 $s .= $sep . $this->talkLink()
1008 . $sep . $this->historyLink()
1009 . $sep . $this->whatLinksHere()
1010 . $sep . $this->watchPageLinksLink();
1012 if ($wgUseTrackbacks)
1013 $s .= $sep . $this->trackbackLink();
1015 if ( $wgTitle->getNamespace() == NS_USER
1016 || $wgTitle->getNamespace() == NS_USER_TALK )
1019 $id=User::idFromName($wgTitle->getText());
1020 $ip=User::isIP($wgTitle->getText());
1022 if($id || $ip) { # both anons and non-anons have contri list
1023 $s .= $sep . $this->userContribsLink();
1025 if( $this->showEmailUser( $id ) ) {
1026 $s .= $sep . $this->emailUserLink();
1029 if ( $wgTitle->getArticleId() ) {
1030 $s .= "\n<br />";
1031 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1032 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1033 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1035 $s .= "<br />\n" . $this->otherLanguages();
1037 return $s;
1040 function pageStats() {
1041 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1042 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1044 $oldid = $wgRequest->getVal( 'oldid' );
1045 $diff = $wgRequest->getVal( 'diff' );
1046 if ( ! $wgOut->isArticle() ) { return ''; }
1047 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1048 if ( 0 == $wgArticle->getID() ) { return ''; }
1050 $s = '';
1051 if ( !$wgDisableCounters ) {
1052 $count = $wgLang->formatNum( $wgArticle->getCount() );
1053 if ( $count ) {
1054 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1058 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
1059 require_once('Credits.php');
1060 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1061 } else {
1062 $s .= $this->lastModified();
1065 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
1066 $dbr = wfGetDB( DB_SLAVE );
1067 $watchlist = $dbr->tableName( 'watchlist' );
1068 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1069 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
1070 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1071 $res = $dbr->query( $sql, 'Skin::pageStats');
1072 $x = $dbr->fetchObject( $res );
1073 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
1076 return $s . ' ' . $this->getCopyright();
1079 function getCopyright( $type = 'detect' ) {
1080 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1082 if ( $type == 'detect' ) {
1083 $oldid = $wgRequest->getVal( 'oldid' );
1084 $diff = $wgRequest->getVal( 'diff' );
1086 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1087 $type = 'history';
1088 } else {
1089 $type = 'normal';
1093 if ( $type == 'history' ) {
1094 $msg = 'history_copyright';
1095 } else {
1096 $msg = 'copyright';
1099 $out = '';
1100 if( $wgRightsPage ) {
1101 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1102 } elseif( $wgRightsUrl ) {
1103 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1104 } else {
1105 # Give up now
1106 return $out;
1108 $out .= wfMsgForContent( $msg, $link );
1109 return $out;
1112 function getCopyrightIcon() {
1113 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1114 $out = '';
1115 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1116 $out = $wgCopyrightIcon;
1117 } else if ( $wgRightsIcon ) {
1118 $icon = htmlspecialchars( $wgRightsIcon );
1119 if ( $wgRightsUrl ) {
1120 $url = htmlspecialchars( $wgRightsUrl );
1121 $out .= '<a href="'.$url.'">';
1123 $text = htmlspecialchars( $wgRightsText );
1124 $out .= "<img src=\"$icon\" alt='$text' />";
1125 if ( $wgRightsUrl ) {
1126 $out .= '</a>';
1129 return $out;
1132 function getPoweredBy() {
1133 global $wgStylePath;
1134 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1135 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1136 return $img;
1139 function lastModified() {
1140 global $wgLang, $wgArticle, $wgLoadBalancer;
1142 $timestamp = $wgArticle->getTimestamp();
1143 if ( $timestamp ) {
1144 $d = $wgLang->date( $timestamp, true );
1145 $t = $wgLang->time( $timestamp, true );
1146 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1147 } else {
1148 $s = '';
1150 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1151 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1153 return $s;
1156 function logoText( $align = '' ) {
1157 if ( '' != $align ) { $a = " align='{$align}'"; }
1158 else { $a = ''; }
1160 $mp = wfMsg( 'mainpage' );
1161 $mptitle = Title::newMainPage();
1162 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1164 $logourl = $this->getLogo();
1165 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1166 return $s;
1170 * show a drop-down box of special pages
1172 function specialPagesList() {
1173 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1174 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1175 foreach ( $pages as $name => $page ) {
1176 $pages[$name] = $page->getDescription();
1179 $go = wfMsg( 'go' );
1180 $sp = wfMsg( 'specialpages' );
1181 $spp = $wgContLang->specialPage( 'Specialpages' );
1183 $s = '<form id="specialpages" method="get" class="inline" ' .
1184 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1185 $s .= "<select name=\"wpDropdown\">\n";
1186 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1189 foreach ( $pages as $name => $desc ) {
1190 $p = $wgContLang->specialPage( $name );
1191 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1193 $s .= "</select>\n";
1194 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1195 $s .= "</form>\n";
1196 return $s;
1199 function mainPageLink() {
1200 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1201 return $s;
1204 function copyrightLink() {
1205 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1206 wfMsg( 'copyrightpagename' ) );
1207 return $s;
1210 private function footerLink ( $desc, $page ) {
1211 // if the link description has been set to "-" in the default language,
1212 if ( wfMsgForContent( $desc ) == '-') {
1213 // then it is disabled, for all languages.
1214 return '';
1215 } else {
1216 // Otherwise, we display the link for the user, described in their
1217 // language (which may or may not be the same as the default language),
1218 // but we make the link target be the one site-wide page.
1219 return $this->makeKnownLink( wfMsgForContent( $page ), wfMsg( $desc ) );
1223 function privacyLink() {
1224 return $this->footerLink( 'privacy', 'privacypage' );
1227 function aboutLink() {
1228 return $this->footerLink( 'aboutsite', 'aboutpage' );
1231 function disclaimerLink() {
1232 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1235 function editThisPage() {
1236 global $wgOut, $wgTitle;
1238 if ( ! $wgOut->isArticleRelated() ) {
1239 $s = wfMsg( 'protectedpage' );
1240 } else {
1241 if ( $wgTitle->userCan( 'edit' ) ) {
1242 $t = wfMsg( 'editthispage' );
1243 } else {
1244 $t = wfMsg( 'viewsource' );
1247 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1249 return $s;
1253 * Return URL options for the 'edit page' link.
1254 * This may include an 'oldid' specifier, if the current page view is such.
1256 * @return string
1257 * @private
1259 function editUrlOptions() {
1260 global $wgArticle;
1262 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1263 return "action=edit&oldid=" . intval( $this->mRevisionId );
1264 } else {
1265 return "action=edit";
1269 function deleteThisPage() {
1270 global $wgUser, $wgTitle, $wgRequest;
1272 $diff = $wgRequest->getVal( 'diff' );
1273 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1274 $t = wfMsg( 'deletethispage' );
1276 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1277 } else {
1278 $s = '';
1280 return $s;
1283 function protectThisPage() {
1284 global $wgUser, $wgTitle, $wgRequest;
1286 $diff = $wgRequest->getVal( 'diff' );
1287 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1288 if ( $wgTitle->isProtected() ) {
1289 $t = wfMsg( 'unprotectthispage' );
1290 $q = 'action=unprotect';
1291 } else {
1292 $t = wfMsg( 'protectthispage' );
1293 $q = 'action=protect';
1295 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1296 } else {
1297 $s = '';
1299 return $s;
1302 function watchThisPage() {
1303 global $wgOut, $wgTitle;
1304 ++$this->mWatchLinkNum;
1306 if ( $wgOut->isArticleRelated() ) {
1307 if ( $wgTitle->userIsWatching() ) {
1308 $t = wfMsg( 'unwatchthispage' );
1309 $q = 'action=unwatch';
1310 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1311 } else {
1312 $t = wfMsg( 'watchthispage' );
1313 $q = 'action=watch';
1314 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1316 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1317 } else {
1318 $s = wfMsg( 'notanarticle' );
1320 return $s;
1323 function moveThisPage() {
1324 global $wgTitle;
1326 if ( $wgTitle->userCan( 'move' ) ) {
1327 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1328 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1329 } else {
1330 // no message if page is protected - would be redundant
1331 return '';
1335 function historyLink() {
1336 global $wgTitle;
1338 return $this->makeKnownLinkObj( $wgTitle,
1339 wfMsg( 'history' ), 'action=history' );
1342 function whatLinksHere() {
1343 global $wgTitle;
1345 return $this->makeKnownLinkObj(
1346 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1347 wfMsg( 'whatlinkshere' ) );
1350 function userContribsLink() {
1351 global $wgTitle;
1353 return $this->makeKnownLinkObj(
1354 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1355 wfMsg( 'contributions' ) );
1358 function showEmailUser( $id ) {
1359 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1360 return $wgEnableEmail &&
1361 $wgEnableUserEmail &&
1362 $wgUser->isLoggedIn() && # show only to signed in users
1363 0 != $id; # we can only email to non-anons ..
1364 # '' != $id->getEmail() && # who must have an email address stored ..
1365 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1366 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1369 function emailUserLink() {
1370 global $wgTitle;
1372 return $this->makeKnownLinkObj(
1373 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1374 wfMsg( 'emailuser' ) );
1377 function watchPageLinksLink() {
1378 global $wgOut, $wgTitle;
1380 if ( ! $wgOut->isArticleRelated() ) {
1381 return '(' . wfMsg( 'notanarticle' ) . ')';
1382 } else {
1383 return $this->makeKnownLinkObj(
1384 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1385 wfMsg( 'recentchangeslinked' ) );
1389 function trackbackLink() {
1390 global $wgTitle;
1392 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1393 . wfMsg('trackbacklink') . "</a>";
1396 function otherLanguages() {
1397 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1399 if ( $wgHideInterlanguageLinks ) {
1400 return '';
1403 $a = $wgOut->getLanguageLinks();
1404 if ( 0 == count( $a ) ) {
1405 return '';
1408 $s = wfMsg( 'otherlanguages' ) . ': ';
1409 $first = true;
1410 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1411 foreach( $a as $l ) {
1412 if ( ! $first ) { $s .= ' | '; }
1413 $first = false;
1415 $nt = Title::newFromText( $l );
1416 $url = $nt->escapeFullURL();
1417 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1419 if ( '' == $text ) { $text = $l; }
1420 $style = $this->getExternalLinkAttributes( $l, $text );
1421 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1423 if($wgContLang->isRTL()) $s .= '</span>';
1424 return $s;
1427 function bugReportsLink() {
1428 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1429 wfMsg( 'bugreports' ) );
1430 return $s;
1433 function talkLink() {
1434 global $wgTitle;
1436 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1437 # No discussion links for special pages
1438 return '';
1441 if( $wgTitle->isTalkPage() ) {
1442 $link = $wgTitle->getSubjectPage();
1443 switch( $link->getNamespace() ) {
1444 case NS_MAIN:
1445 $text = wfMsg( 'articlepage' );
1446 break;
1447 case NS_USER:
1448 $text = wfMsg( 'userpage' );
1449 break;
1450 case NS_PROJECT:
1451 $text = wfMsg( 'projectpage' );
1452 break;
1453 case NS_IMAGE:
1454 $text = wfMsg( 'imagepage' );
1455 break;
1456 case NS_MEDIAWIKI:
1457 $text = wfMsg( 'mediawikipage' );
1458 break;
1459 case NS_TEMPLATE:
1460 $text = wfMsg( 'templatepage' );
1461 break;
1462 case NS_HELP:
1463 $text = wfMsg( 'viewhelppage' );
1464 break;
1465 case NS_CATEGORY:
1466 $text = wfMsg( 'categorypage' );
1467 break;
1468 default:
1469 $text = wfMsg( 'articlepage' );
1471 } else {
1472 $link = $wgTitle->getTalkPage();
1473 $text = wfMsg( 'talkpage' );
1476 $s = $this->makeLinkObj( $link, $text );
1478 return $s;
1481 function commentLink() {
1482 global $wgTitle, $wgOut;
1484 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1485 return '';
1488 # __NEWSECTIONLINK___ changes behaviour here
1489 # If it's present, the link points to this page, otherwise
1490 # it points to the talk page
1491 if( $wgTitle->isTalkPage() ) {
1492 $title =& $wgTitle;
1493 } elseif( $wgOut->showNewSectionLink() ) {
1494 $title =& $wgTitle;
1495 } else {
1496 $title =& $wgTitle->getTalkPage();
1499 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1502 /* these are used extensively in SkinTemplate, but also some other places */
1503 static function makeMainPageUrl( $urlaction = '' ) {
1504 $title = Title::newMainPage();
1505 self::checkTitle( $title, '' );
1506 return $title->getLocalURL( $urlaction );
1509 static function makeSpecialUrl( $name, $urlaction = '' ) {
1510 $title = SpecialPage::getTitleFor( $name );
1511 return $title->getLocalURL( $urlaction );
1514 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1515 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1516 return $title->getLocalURL( $urlaction );
1519 static function makeI18nUrl( $name, $urlaction = '' ) {
1520 $title = Title::newFromText( wfMsgForContent( $name ) );
1521 self::checkTitle( $title, $name );
1522 return $title->getLocalURL( $urlaction );
1525 static function makeUrl( $name, $urlaction = '' ) {
1526 $title = Title::newFromText( $name );
1527 self::checkTitle( $title, $name );
1528 return $title->getLocalURL( $urlaction );
1531 # If url string starts with http, consider as external URL, else
1532 # internal
1533 static function makeInternalOrExternalUrl( $name ) {
1534 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1535 return $name;
1536 } else {
1537 return self::makeUrl( $name );
1541 # this can be passed the NS number as defined in Language.php
1542 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1543 $title = Title::makeTitleSafe( $namespace, $name );
1544 self::checkTitle( $title, $name );
1545 return $title->getLocalURL( $urlaction );
1548 /* these return an array with the 'href' and boolean 'exists' */
1549 static function makeUrlDetails( $name, $urlaction = '' ) {
1550 $title = Title::newFromText( $name );
1551 self::checkTitle( $title, $name );
1552 return array(
1553 'href' => $title->getLocalURL( $urlaction ),
1554 'exists' => $title->getArticleID() != 0 ? true : false
1559 * Make URL details where the article exists (or at least it's convenient to think so)
1561 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1562 $title = Title::newFromText( $name );
1563 self::checkTitle( $title, $name );
1564 return array(
1565 'href' => $title->getLocalURL( $urlaction ),
1566 'exists' => true
1570 # make sure we have some title to operate on
1571 static function checkTitle( &$title, $name ) {
1572 if( !is_object( $title ) ) {
1573 $title = Title::newFromText( $name );
1574 if( !is_object( $title ) ) {
1575 $title = Title::newFromText( '--error: link target missing--' );
1581 * Build an array that represents the sidebar(s), the navigation bar among them
1583 * @return array
1584 * @private
1586 function buildSidebar() {
1587 global $parserMemc, $wgEnableSidebarCache;
1588 global $wgLang, $wgContLang;
1590 $fname = 'SkinTemplate::buildSidebar';
1592 wfProfileIn( $fname );
1594 $key = wfMemcKey( 'sidebar' );
1595 $cacheSidebar = $wgEnableSidebarCache &&
1596 ($wgLang->getCode() == $wgContLang->getCode());
1598 if ($cacheSidebar) {
1599 $cachedsidebar = $parserMemc->get( $key );
1600 if ($cachedsidebar!="") {
1601 wfProfileOut($fname);
1602 return $cachedsidebar;
1606 $bar = array();
1607 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1608 foreach ($lines as $line) {
1609 if (strpos($line, '*') !== 0)
1610 continue;
1611 if (strpos($line, '**') !== 0) {
1612 $line = trim($line, '* ');
1613 $heading = $line;
1614 } else {
1615 if (strpos($line, '|') !== false) { // sanity check
1616 $line = explode( '|' , trim($line, '* '), 2 );
1617 $link = wfMsgForContent( $line[0] );
1618 if ($link == '-')
1619 continue;
1620 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1621 $text = $line[1];
1622 if (wfEmptyMsg($line[0], $link))
1623 $link = $line[0];
1625 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1626 $href = $link;
1627 } else {
1628 $title = Title::newFromText( $link );
1629 if ( $title ) {
1630 $title = $title->fixSpecialName();
1631 $href = $title->getLocalURL();
1632 } else {
1633 $href = 'INVALID-TITLE';
1637 $bar[$heading][] = array(
1638 'text' => $text,
1639 'href' => $href,
1640 'id' => 'n-' . strtr($line[1], ' ', '-'),
1641 'active' => false
1643 } else { continue; }
1646 if ($cacheSidebar)
1647 $parserMemc->set( $key, $bar, 86400 );
1648 wfProfileOut( $fname );
1649 return $bar;