2 if ( ! defined( 'MEDIAWIKI' ) )
14 * The main skin class that provide methods and properties for all other skins.
15 * This base class is also the "Standard" skin.
18 class Skin
extends Linker
{
22 var $lastdate, $lastline;
23 var $rc_cache ; # Cache for Enhanced Recent Changes
24 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
28 /** Constructor, call parent constructor */
29 function Skin() { parent
::Linker(); }
32 * Fetch the set of available skins.
33 * @return array of strings
36 static function &getSkinNames() {
37 global $wgValidSkinNames;
38 static $skinsInitialised = false;
39 if ( !$skinsInitialised ) {
40 # Get a list of available skins
41 # Build using the regular expression '^(.*).php$'
42 # Array keys are all lower case, array value keep the case used by filename
44 wfProfileIn( __METHOD__
. '-init' );
45 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
48 # while code from www.php.net
49 while (false !== ($file = $skinDir->read())) {
50 // Skip non-PHP files, hidden files, and '.dep' includes
51 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
53 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
57 $skinsInitialised = true;
58 wfProfileOut( __METHOD__
. '-init' );
60 return $wgValidSkinNames;
64 * Normalize a skin preference value to a form that can be loaded.
65 * If a skin can't be found, it will fall back to the configured
66 * default (or the old 'Classic' skin if that's broken).
71 static function normalizeKey( $key ) {
72 global $wgDefaultSkin;
73 $skinNames = Skin
::getSkinNames();
76 // Don't return the default immediately;
77 // in a misconfiguration we need to fall back.
78 $key = $wgDefaultSkin;
81 if( isset( $skinNames[$key] ) ) {
85 // Older versions of the software used a numeric setting
86 // in the user preferences.
92 if( isset( $fallback[$key] ) ){
93 $key = $fallback[$key];
96 if( isset( $skinNames[$key] ) ) {
99 // The old built-in skin
105 * Factory method for loading a skin of a given type
106 * @param string $key 'monobook', 'standard', etc
110 static function &newFromKey( $key ) {
111 global $wgStyleDirectory;
113 $key = Skin
::normalizeKey( $key );
115 $skinNames = Skin
::getSkinNames();
116 $skinName = $skinNames[$key];
118 # Grab the skin class and initialise it.
119 wfSuppressWarnings();
120 // Preload base classes to work around APC/PHP5 bug
121 include_once( "{$wgStyleDirectory}/{$skinName}.deps.php" );
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;
140 /** @return string path to the skin stylesheet */
141 function getStylesheet() {
142 return 'common/wikistandard.css';
145 /** @return string skin name */
146 function getSkinName() {
150 function qbSetting() {
151 global $wgOut, $wgUser;
153 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
154 $q = $wgUser->getOption( 'quickbar' );
155 if ( '' == $q ) { $q = 0; }
159 function initPage( &$out ) {
160 global $wgFavicon, $wgScriptPath, $wgSitename, $wgLanguageCode, $wgLanguageNames;
162 $fname = 'Skin::initPage';
163 wfProfileIn( $fname );
165 if( false !== $wgFavicon ) {
166 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
169 # OpenSearch description link
170 $out->addLink( array(
172 'type' => 'application/opensearchdescription+xml',
173 'href' => "$wgScriptPath/opensearch_desc.php",
174 'title' => "$wgSitename ({$wgLanguageNames[$wgLanguageCode]})",
177 $this->addMetadataLinks($out);
179 $this->mRevisionId
= $out->mRevisionId
;
181 $this->preloadExistence();
183 wfProfileOut( $fname );
187 * Preload the existence of three commonly-requested pages in a single query
189 function preloadExistence() {
190 global $wgUser, $wgTitle;
192 if ( $wgTitle->isTalkPage() ) {
193 $otherTab = $wgTitle->getSubjectPage();
195 $otherTab = $wgTitle->getTalkPage();
197 $lb = new LinkBatch( array(
198 $wgUser->getUserPage(),
199 $wgUser->getTalkPage(),
205 function addMetadataLinks( &$out ) {
206 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
207 global $wgRightsPage, $wgRightsUrl;
209 if( $out->isArticleRelated() ) {
210 # note: buggy CC software only reads first "meta" link
211 if( $wgEnableCreativeCommonsRdf ) {
212 $out->addMetadataLink( array(
213 'title' => 'Creative Commons',
214 'type' => 'application/rdf+xml',
215 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
217 if( $wgEnableDublinCoreRdf ) {
218 $out->addMetadataLink( array(
219 'title' => 'Dublin Core',
220 'type' => 'application/rdf+xml',
221 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
225 if( $wgRightsPage ) {
226 $copy = Title
::newFromText( $wgRightsPage );
228 $copyright = $copy->getLocalURL();
231 if( !$copyright && $wgRightsUrl ) {
232 $copyright = $wgRightsUrl;
235 $out->addLink( array(
236 'rel' => 'copyright',
237 'href' => $copyright ) );
241 function outputPage( &$out ) {
242 global $wgDebugComments;
244 wfProfileIn( 'Skin::outputPage' );
245 $this->initPage( $out );
247 $out->out( $out->headElement() );
249 $out->out( "\n<body" );
250 $ops = $this->getBodyOptions();
251 foreach ( $ops as $name => $val ) {
252 $out->out( " $name='$val'" );
255 if ( $wgDebugComments ) {
256 $out->out( "<!-- Wiki debugging output:\n" .
257 $out->mDebugtext
. "-->\n" );
260 $out->out( $this->beforeContent() );
262 $out->out( $out->mBodytext
. "\n" );
264 $out->out( $this->afterContent() );
266 $out->out( $this->bottomScripts() );
268 $out->out( $out->reportTime() );
270 $out->out( "\n</body></html>" );
273 static function makeGlobalVariablesScript( $data ) {
274 $r = '<script type= "' . $data['jsmimetype'] . '">
275 var skin = "' . Xml
::escapeJsString( $data['skinname'] ) . '";
276 var stylepath = "' . Xml
::escapeJsString( $data['stylepath'] ) . '";
278 var wgArticlePath = "' . Xml
::escapeJsString( $data['articlepath'] ) . '";
279 var wgScriptPath = "' . Xml
::escapeJsString( $data['scriptpath'] ) . '";
280 var wgServer = "' . Xml
::escapeJsString( $data['serverurl'] ) . '";
282 var wgCanonicalNamespace = "' . Xml
::escapeJsString( $data['nscanonical'] ) . '";
283 var wgNamespaceNumber = ' . (int)$data['nsnumber'] . ';
284 var wgPageName = "' . Xml
::escapeJsString( $data['titleprefixeddbkey'] ) . '";
285 var wgTitle = "' . Xml
::escapeJsString( $data['titletext'] ) . '";
286 var wgArticleId = ' . (int)$data['articleid'] . ';
287 var wgIsArticle = ' . ( $data['isarticle'] ?
'true' : 'false' ) . ';
289 var wgUserName = ' . ( $data['username'] == NULL ?
'null' : ( '"' . Xml
::escapeJsString( $data['username'] ) . '"' ) ) . ';
290 var wgUserLanguage = "' . Xml
::escapeJsString( $data['userlang'] ) . '";
291 var wgContentLanguage = "' . Xml
::escapeJsString( $data['lang'] ) . '";
298 function getHeadScripts() {
299 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType, $wgStyleVersion;
300 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
301 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut;
303 $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
304 if ( $nsname === NULL ) $nsname = $wgTitle->getNsText();
307 'jsmimetype' => $wgJsMimeType,
308 'skinname' => $this->getSkinName(),
309 'stylepath' => $wgStylePath,
310 'articlepath' => $wgArticlePath,
311 'scriptpath' => $wgScriptPath,
312 'serverurl' => $wgServer,
313 'nscanonical' => $nsname,
314 'nsnumber' => $wgTitle->getNamespace(),
315 'titleprefixeddbkey' => $wgTitle->getPrefixedDBKey(),
316 'titletext' => $wgTitle->getText(),
317 'articleid' => $wgTitle->getArticleId(),
318 'isarticle' => $wgOut->isArticle(),
319 'username' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
320 'userlang' => $wgLang->getCode(),
321 'lang' => $wgContLang->getCode(),
324 $r = self
::makeGlobalVariablesScript( $vars );
326 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
327 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
328 $userpage = $wgUser->getUserPage();
329 $userjs = htmlspecialchars( self
::makeUrl(
330 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
331 'action=raw&ctype='.$wgJsMimeType));
332 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
338 * To make it harder for someone to slip a user a fake
339 * user-JavaScript or user-CSS preview, a random token
340 * is associated with the login session. If it's not
341 * passed back with the preview request, we won't render
344 * @param string $action
348 function userCanPreview( $action ) {
349 global $wgTitle, $wgRequest, $wgUser;
351 if( $action != 'submit' )
353 if( !$wgRequest->wasPosted() )
355 if( !$wgTitle->userCanEditCssJsSubpage() )
357 return $wgUser->matchEditToken(
358 $wgRequest->getVal( 'wpEditToken' ) );
361 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
362 function getUserStylesheet() {
363 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
364 $sheet = $this->getStylesheet();
365 $action = $wgRequest->getText('action');
366 // fixme: the common.css import might be doubled now...
367 $s = "@import \"$wgStylePath/common.css?$wgStyleVersion\";\n";
368 $s = "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
369 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
371 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
372 $s .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
373 '@import "' . self
::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
375 $s .= $this->doGetUserStyles();
380 * placeholder, returns generated js in monobook
382 function getUserJs() { return; }
385 * Return html code that include User stylesheets
387 function getUserStyles() {
388 $s = "<style type='text/css'>\n";
389 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
390 $s .= $this->getUserStylesheet();
391 $s .= "/*]]>*/ /* */\n";
397 * Some styles that are set by user through the user settings interface.
399 function doGetUserStyles() {
400 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
404 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
405 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
406 $s .= $wgRequest->getText('wpTextbox1');
408 $userpage = $wgUser->getUserPage();
409 $s.= '@import "'.self
::makeUrl(
410 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
411 'action=raw&ctype=text/css').'";'."\n";
415 return $s . $this->reallyDoGetUserStyles();
418 function reallyDoGetUserStyles() {
421 if (($undopt = $wgUser->getOption("underline")) != 2) {
422 $underline = $undopt ?
'underline' : 'none';
423 $s .= "a { text-decoration: $underline; }\n";
425 if( $wgUser->getOption( 'highlightbroken' ) ) {
426 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
429 a.new, #quickbar a.new,
430 a.stub, #quickbar a.stub {
432 text-decoration: inherit;
434 a.new:after, #quickbar a.new:after {
437 text-decoration: $underline;
439 a.stub:after, #quickbar a.stub:after {
442 text-decoration: $underline;
446 if( $wgUser->getOption( 'justify' ) ) {
447 $s .= "#article, #bodyContent { text-align: justify; }\n";
449 if( !$wgUser->getOption( 'showtoc' ) ) {
450 $s .= "#toc { display: none; }\n";
452 if( !$wgUser->getOption( 'editsection' ) ) {
453 $s .= ".editsection { display: none; }\n";
458 function getBodyOptions() {
459 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
461 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
463 if ( 0 != $wgTitle->getNamespace() ) {
464 $a = array( 'bgcolor' => '#ffffec' );
466 else $a = array( 'bgcolor' => '#FFFFFF' );
467 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
468 $wgTitle->userCanEdit() ) {
469 $t = wfMsg( 'editthispage' );
470 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
471 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
472 $a +
= array ('ondblclick' => $s);
475 $a['onload'] = $wgOut->getOnloadHandler();
476 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
477 if( $a['onload'] != '' ) {
480 $a['onload'] .= 'setupRightClickEdit()';
482 $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ?
"rtl" : "ltr").
483 ' '.Sanitizer
::escapeId( 'page-'.$wgTitle->getPrefixedText() );
496 * This will be called immediately after the <body> tag. Split into
497 * two functions to make it easier to subclass.
499 function beforeContent() {
500 return $this->doBeforeContent();
503 function doBeforeContent() {
505 $fname = 'Skin::doBeforeContent';
506 wfProfileIn( $fname );
509 $qb = $this->qbSetting();
511 if( $langlinks = $this->otherLanguages() ) {
517 $borderhack = 'class="top"';
520 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
521 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
524 $left = ($qb == 1 ||
$qb == 3);
525 if($wgContLang->isRTL()) $left = !$left;
528 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
529 $this->logoText() . '</td>';
531 $s .= $this->getQuickbarCompensator( $rows );
533 $l = $wgContLang->isRTL() ?
'right' : 'left';
534 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
536 $s .= $this->topLinks() ;
537 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
539 $r = $wgContLang->isRTL() ?
"left" : "right";
540 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
541 $s .= $this->nameAndLogin();
542 $s .= "\n<br />" . $this->searchForm() . "</td>";
545 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
548 if ( $shove && !$left ) { # Right
549 $s .= $this->getQuickbarCompensator( $rows );
551 $s .= "</tr>\n</table>\n</div>\n";
552 $s .= "\n<div id='article'>\n";
554 $notice = wfGetSiteNotice();
556 $s .= "\n<div id='siteNotice'>$notice</div>\n";
558 $s .= $this->pageTitle();
559 $s .= $this->pageSubtitle() ;
560 $s .= $this->getCategories();
561 wfProfileOut( $fname );
566 function getCategoryLinks () {
567 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
570 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
573 $sep = wfMsgHtml( 'catseparator' );
575 // Use Unicode bidi embedding override characters,
576 // to make sure links don't smash each other up in ugly ways.
577 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
578 $embed = "<span dir='$dir'>";
580 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
582 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks
) );
583 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
584 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
587 # optional 'dmoz-like' category browser. Will be shown under the list
588 # of categories an article belong to
589 if($wgUseCategoryBrowser) {
590 $s .= '<br /><hr />';
592 # get a big array of the parents tree
593 $parenttree = $wgTitle->getParentCategoryTree();
594 # Skin object passed by reference cause it can not be
595 # accessed under the method subfunction drawCategoryBrowser
596 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
597 # Clean out bogus first entry and sort them
600 # Output one per line
601 $s .= implode("<br />\n", $tempout);
607 /** Render the array as a serie of links.
608 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
609 * @param &skin Object: skin passed by reference
610 * @return String separated by >, terminate with "\n"
612 function drawCategoryBrowser($tree, &$skin) {
614 foreach ($tree as $element => $parent) {
615 if (empty($parent)) {
616 # element start a new list
619 # grab the others elements
620 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
622 # add our current element to the list
623 $eltitle = Title
::NewFromText($element);
624 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
629 function getCategories() {
630 $catlinks=$this->getCategoryLinks();
631 if(!empty($catlinks)) {
632 return "<p class='catlinks'>{$catlinks}</p>";
636 function getQuickbarCompensator( $rows = 1 ) {
637 return "<td width='152' rowspan='{$rows}'> </td>";
641 * This gets called shortly before the \</body\> tag.
642 * @return String HTML to be put before \</body\>
644 function afterContent() {
645 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
646 return $printfooter . $this->doAfterContent();
650 * This gets called shortly before the \</body\> tag.
651 * @return String HTML-wrapped JS code to be put before \</body\>
653 function bottomScripts() {
654 global $wgJsMimeType;
655 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
658 /** @return string Retrievied from HTML text */
659 function printSource() {
661 $url = htmlspecialchars( $wgTitle->getFullURL() );
662 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
665 function printFooter() {
666 return "<p>" . $this->printSource() .
667 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
670 /** overloaded by derived classes */
671 function doAfterContent() { }
673 function pageTitleLinks() {
674 global $wgOut, $wgTitle, $wgUser, $wgRequest;
676 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
677 $action = $wgRequest->getText( 'action' );
679 $s = $this->printableLink();
680 $disclaimer = $this->disclaimerLink(); # may be empty
682 $s .= ' | ' . $disclaimer;
684 $privacy = $this->privacyLink(); # may be empty too
686 $s .= ' | ' . $privacy;
689 if ( $wgOut->isArticleRelated() ) {
690 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
691 $name = $wgTitle->getDBkey();
692 $image = new Image( $wgTitle );
693 if( $image->exists() ) {
694 $link = htmlspecialchars( $image->getURL() );
695 $style = $this->getInternalLinkAttributes( $link, $name );
696 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
700 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
701 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
702 wfMsg( 'currentrev' ) );
705 if ( $wgUser->getNewtalk() ) {
706 # do not show "You have new messages" text when we are viewing our
708 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
709 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
710 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
711 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
713 $wgOut->setSquidMaxage(0);
714 $wgOut->enableClientCache(false);
718 $undelete = $this->getUndeleteLink();
719 if( !empty( $undelete ) ) {
720 $s .= ' | '.$undelete;
725 function getUndeleteLink() {
726 global $wgUser, $wgTitle, $wgContLang, $action;
727 if( $wgUser->isAllowed( 'deletedhistory' ) &&
728 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
729 ($n = $wgTitle->isDeleted() ) )
731 if ( $wgUser->isAllowed( 'delete' ) ) {
732 $msg = 'thisisdeleted';
734 $msg = 'viewdeleted';
737 $this->makeKnownLink(
738 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
739 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
744 function printableLink() {
745 global $wgOut, $wgFeedClasses, $wgRequest;
747 $baseurl = $_SERVER['REQUEST_URI'];
748 if( strpos( '?', $baseurl ) == false ) {
753 $baseurl = htmlspecialchars( $baseurl );
754 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
756 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
757 if( $wgOut->isSyndicated() ) {
758 foreach( $wgFeedClasses as $format => $class ) {
759 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
760 $s .= " | <a href=\"$feedurl\">{$format}</a>";
766 function pageTitle() {
768 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
772 function pageSubtitle() {
775 $sub = $wgOut->getSubtitle();
777 global $wgExtraSubtitle;
778 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
780 $subpages = $this->subPageSubtitle();
781 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
782 $s = "<p class='subtitle'>{$sub}</p>\n";
786 function subPageSubtitle() {
787 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
789 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
790 $ptext=$wgTitle->getPrefixedText();
791 if(preg_match('/\//',$ptext)) {
792 $links = explode('/',$ptext);
795 foreach($links as $link) {
797 if ($c<count($links)) {
798 $growinglink .= $link;
799 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
800 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
804 $subpages .= '< ';
806 $subpages .= $getlink;
815 function nameAndLogin() {
816 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
818 $li = $wgContLang->specialPage( 'Userlogin' );
819 $lo = $wgContLang->specialPage( 'Userlogout' );
822 if ( $wgUser->isAnon() ) {
823 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
826 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
827 $wgLang->getNsText( NS_TALK
) );
829 $s .= $n . ' ('.$tl.')';
831 $s .= wfMsg('notloggedin');
834 $rt = $wgTitle->getPrefixedURL();
835 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
837 } else { $q = "returnto={$rt}"; }
839 $s .= "\n<br />" . $this->makeKnownLinkObj(
840 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
841 wfMsg( 'login' ), $q );
843 $n = $wgUser->getName();
844 $rt = $wgTitle->getPrefixedURL();
845 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
846 $wgLang->getNsText( NS_TALK
) );
850 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
851 $n ) . "{$tl}<br />" .
852 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
853 "returnto={$rt}" ) . ' | ' .
854 $this->specialLink( 'preferences' );
856 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
862 function getSearchLink() {
863 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
864 return $searchPage->getLocalURL();
867 function escapeSearchLink() {
868 return htmlspecialchars( $this->getSearchLink() );
871 function searchForm() {
873 $search = $wgRequest->getText( 'search' );
875 $s = '<form name="search" class="inline" method="post" action="'
876 . $this->escapeSearchLink() . "\">\n"
877 . '<input type="text" name="search" size="19" value="'
878 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
879 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" /> '
880 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
885 function topLinks() {
889 $s = $this->mainPageLink() . $sep
890 . $this->specialLink( 'recentchanges' );
892 if ( $wgOut->isArticleRelated() ) {
893 $s .= $sep . $this->editThisPage()
894 . $sep . $this->historyLink();
896 # Many people don't like this dropdown box
897 #$s .= $sep . $this->specialPagesList();
899 /* show links to different language variants */
900 global $wgDisableLangConversion, $wgContLang, $wgTitle;
901 $variants = $wgContLang->getVariants();
902 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
903 foreach( $variants as $code ) {
904 $varname = $wgContLang->getVariantname( $code );
905 if( $varname == 'disable' )
907 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
914 function bottomLinks() {
915 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
919 if ( $wgOut->isArticleRelated() ) {
920 $s .= '<strong>' . $this->editThisPage() . '</strong>';
921 if ( $wgUser->isLoggedIn() ) {
922 $s .= $sep . $this->watchThisPage();
924 $s .= $sep . $this->talkLink()
925 . $sep . $this->historyLink()
926 . $sep . $this->whatLinksHere()
927 . $sep . $this->watchPageLinksLink();
929 if ($wgUseTrackbacks)
930 $s .= $sep . $this->trackbackLink();
932 if ( $wgTitle->getNamespace() == NS_USER
933 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
936 $id=User
::idFromName($wgTitle->getText());
937 $ip=User
::isIP($wgTitle->getText());
939 if($id ||
$ip) { # both anons and non-anons have contri list
940 $s .= $sep . $this->userContribsLink();
942 if( $this->showEmailUser( $id ) ) {
943 $s .= $sep . $this->emailUserLink();
946 if ( $wgTitle->getArticleId() ) {
948 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
949 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
950 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
952 $s .= "<br />\n" . $this->otherLanguages();
957 function pageStats() {
958 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
959 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
961 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
962 if ( ! $wgOut->isArticle() ) { return ''; }
963 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
964 if ( 0 == $wgArticle->getID() ) { return ''; }
967 if ( !$wgDisableCounters ) {
968 $count = $wgLang->formatNum( $wgArticle->getCount() );
970 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
974 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
975 require_once('Credits.php');
976 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
978 $s .= $this->lastModified();
981 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
982 $dbr =& wfGetDB( DB_SLAVE
);
983 extract( $dbr->tableNames( 'watchlist' ) );
984 $sql = "SELECT COUNT(*) AS n FROM $watchlist
985 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
986 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
987 $res = $dbr->query( $sql, 'Skin::pageStats');
988 $x = $dbr->fetchObject( $res );
989 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
992 return $s . ' ' . $this->getCopyright();
995 function getCopyright( $type = 'detect' ) {
996 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
998 if ( $type == 'detect' ) {
999 $oldid = $wgRequest->getVal( 'oldid' );
1000 $diff = $wgRequest->getVal( 'diff' );
1002 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1009 if ( $type == 'history' ) {
1010 $msg = 'history_copyright';
1016 if( $wgRightsPage ) {
1017 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1018 } elseif( $wgRightsUrl ) {
1019 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1024 $out .= wfMsgForContent( $msg, $link );
1028 function getCopyrightIcon() {
1029 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1031 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1032 $out = $wgCopyrightIcon;
1033 } else if ( $wgRightsIcon ) {
1034 $icon = htmlspecialchars( $wgRightsIcon );
1035 if ( $wgRightsUrl ) {
1036 $url = htmlspecialchars( $wgRightsUrl );
1037 $out .= '<a href="'.$url.'">';
1039 $text = htmlspecialchars( $wgRightsText );
1040 $out .= "<img src=\"$icon\" alt='$text' />";
1041 if ( $wgRightsUrl ) {
1048 function getPoweredBy() {
1049 global $wgStylePath;
1050 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1051 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1055 function lastModified() {
1056 global $wgLang, $wgArticle, $wgLoadBalancer;
1058 $timestamp = $wgArticle->getTimestamp();
1060 $d = $wgLang->date( $timestamp, true );
1061 $t = $wgLang->time( $timestamp, true );
1062 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1066 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1067 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1072 function logoText( $align = '' ) {
1073 if ( '' != $align ) { $a = " align='{$align}'"; }
1076 $mp = wfMsg( 'mainpage' );
1077 $titleObj = Title
::newFromText( $mp );
1078 if ( is_object( $titleObj ) ) {
1079 $url = $titleObj->escapeLocalURL();
1084 $logourl = $this->getLogo();
1085 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1090 * show a drop-down box of special pages
1092 function specialPagesList() {
1093 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1095 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1096 foreach ( $pages as $name => $page ) {
1097 $pages[$name] = $page->getDescription();
1100 $go = wfMsg( 'go' );
1101 $sp = wfMsg( 'specialpages' );
1102 $spp = $wgContLang->specialPage( 'Specialpages' );
1104 $s = '<form id="specialpages" method="get" class="inline" ' .
1105 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1106 $s .= "<select name=\"wpDropdown\">\n";
1107 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1110 foreach ( $pages as $name => $desc ) {
1111 $p = $wgContLang->specialPage( $name );
1112 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1114 $s .= "</select>\n";
1115 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1120 function mainPageLink() {
1121 $mp = wfMsgForContent( 'mainpage' );
1122 $mptxt = wfMsg( 'mainpage');
1123 $s = $this->makeKnownLink( $mp, $mptxt );
1127 function copyrightLink() {
1128 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1129 wfMsg( 'copyrightpagename' ) );
1133 function privacyLink() {
1134 $privacy = wfMsg( 'privacy' );
1135 if ($privacy == '-') {
1138 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1142 function aboutLink() {
1143 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1144 wfMsg( 'aboutsite' ) );
1148 function disclaimerLink() {
1149 $disclaimers = wfMsg( 'disclaimers' );
1150 if ($disclaimers == '-') {
1153 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1158 function editThisPage() {
1159 global $wgOut, $wgTitle;
1161 if ( ! $wgOut->isArticleRelated() ) {
1162 $s = wfMsg( 'protectedpage' );
1164 if ( $wgTitle->userCanEdit() ) {
1165 $t = wfMsg( 'editthispage' );
1167 $t = wfMsg( 'viewsource' );
1170 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1176 * Return URL options for the 'edit page' link.
1177 * This may include an 'oldid' specifier, if the current page view is such.
1182 function editUrlOptions() {
1185 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1186 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1188 return "action=edit";
1192 function deleteThisPage() {
1193 global $wgUser, $wgTitle, $wgRequest;
1195 $diff = $wgRequest->getVal( 'diff' );
1196 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1197 $t = wfMsg( 'deletethispage' );
1199 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1206 function protectThisPage() {
1207 global $wgUser, $wgTitle, $wgRequest;
1209 $diff = $wgRequest->getVal( 'diff' );
1210 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1211 if ( $wgTitle->isProtected() ) {
1212 $t = wfMsg( 'unprotectthispage' );
1213 $q = 'action=unprotect';
1215 $t = wfMsg( 'protectthispage' );
1216 $q = 'action=protect';
1218 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1225 function watchThisPage() {
1226 global $wgOut, $wgTitle;
1228 if ( $wgOut->isArticleRelated() ) {
1229 if ( $wgTitle->userIsWatching() ) {
1230 $t = wfMsg( 'unwatchthispage' );
1231 $q = 'action=unwatch';
1233 $t = wfMsg( 'watchthispage' );
1234 $q = 'action=watch';
1236 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1238 $s = wfMsg( 'notanarticle' );
1243 function moveThisPage() {
1246 if ( $wgTitle->userCanMove() ) {
1247 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1248 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1250 // no message if page is protected - would be redundant
1255 function historyLink() {
1258 return $this->makeKnownLinkObj( $wgTitle,
1259 wfMsg( 'history' ), 'action=history' );
1262 function whatLinksHere() {
1265 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1266 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1269 function userContribsLink() {
1272 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1273 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1276 function showEmailUser( $id ) {
1277 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1278 return $wgEnableEmail &&
1279 $wgEnableUserEmail &&
1280 $wgUser->isLoggedIn() && # show only to signed in users
1281 0 != $id; # we can only email to non-anons ..
1282 # '' != $id->getEmail() && # who must have an email address stored ..
1283 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1284 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1287 function emailUserLink() {
1290 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1291 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1294 function watchPageLinksLink() {
1295 global $wgOut, $wgTitle;
1297 if ( ! $wgOut->isArticleRelated() ) {
1298 return '(' . wfMsg( 'notanarticle' ) . ')';
1300 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1301 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1302 'target=' . $wgTitle->getPrefixedURL() );
1306 function trackbackLink() {
1309 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1310 . wfMsg('trackbacklink') . "</a>";
1313 function otherLanguages() {
1314 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1316 if ( $wgHideInterlanguageLinks ) {
1320 $a = $wgOut->getLanguageLinks();
1321 if ( 0 == count( $a ) ) {
1325 $s = wfMsg( 'otherlanguages' ) . ': ';
1327 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1328 foreach( $a as $l ) {
1329 if ( ! $first ) { $s .= ' | '; }
1332 $nt = Title
::newFromText( $l );
1333 $url = $nt->escapeFullURL();
1334 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1336 if ( '' == $text ) { $text = $l; }
1337 $style = $this->getExternalLinkAttributes( $l, $text );
1338 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1340 if($wgContLang->isRTL()) $s .= '</span>';
1344 function bugReportsLink() {
1345 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1346 wfMsg( 'bugreports' ) );
1350 function dateLink() {
1351 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1352 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1354 $id = $t1->getArticleID();
1357 $s = $this->makeBrokenLink( $t1->getText() );
1359 $s = $this->makeKnownLink( $t1->getText() );
1363 $id = $t2->getArticleID();
1366 $s .= $this->makeBrokenLink( $t2->getText() );
1368 $s .= $this->makeKnownLink( $t2->getText() );
1373 function talkLink() {
1376 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1377 # No discussion links for special pages
1381 if( $wgTitle->isTalkPage() ) {
1382 $link = $wgTitle->getSubjectPage();
1383 switch( $link->getNamespace() ) {
1385 $text = wfMsg( 'articlepage' );
1388 $text = wfMsg( 'userpage' );
1391 $text = wfMsg( 'projectpage' );
1394 $text = wfMsg( 'imagepage' );
1397 $text = wfMsg( 'mediawikipage' );
1400 $text = wfMsg( 'templatepage' );
1403 $text = wfMsg( 'viewhelppage' );
1406 $text = wfMsg( 'categorypage' );
1409 $text = wfMsg( 'articlepage' );
1412 $link = $wgTitle->getTalkPage();
1413 $text = wfMsg( 'talkpage' );
1416 $s = $this->makeLinkObj( $link, $text );
1421 function commentLink() {
1422 global $wgTitle, $wgOut;
1424 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1428 # __NEWSECTIONLINK___ changes behaviour here
1429 # If it's present, the link points to this page, otherwise
1430 # it points to the talk page
1431 if( $wgTitle->isTalkPage() ) {
1433 } elseif( $wgOut->showNewSectionLink() ) {
1436 $title =& $wgTitle->getTalkPage();
1439 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1442 /* these are used extensively in SkinTemplate, but also some other places */
1443 static function makeSpecialUrl( $name, $urlaction = '' ) {
1444 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1445 return $title->getLocalURL( $urlaction );
1448 static function makeI18nUrl( $name, $urlaction = '' ) {
1449 $title = Title
::newFromText( wfMsgForContent( $name ) );
1450 self
::checkTitle( $title, $name );
1451 return $title->getLocalURL( $urlaction );
1454 static function makeUrl( $name, $urlaction = '' ) {
1455 $title = Title
::newFromText( $name );
1456 self
::checkTitle( $title, $name );
1457 return $title->getLocalURL( $urlaction );
1460 # If url string starts with http, consider as external URL, else
1462 static function makeInternalOrExternalUrl( $name ) {
1463 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1466 return self
::makeUrl( $name );
1470 # this can be passed the NS number as defined in Language.php
1471 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1472 $title = Title
::makeTitleSafe( $namespace, $name );
1473 self
::checkTitle( $title, $name );
1474 return $title->getLocalURL( $urlaction );
1477 /* these return an array with the 'href' and boolean 'exists' */
1478 static function makeUrlDetails( $name, $urlaction = '' ) {
1479 $title = Title
::newFromText( $name );
1480 self
::checkTitle( $title, $name );
1482 'href' => $title->getLocalURL( $urlaction ),
1483 'exists' => $title->getArticleID() != 0 ?
true : false
1488 * Make URL details where the article exists (or at least it's convenient to think so)
1490 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1491 $title = Title
::newFromText( $name );
1492 self
::checkTitle( $title, $name );
1494 'href' => $title->getLocalURL( $urlaction ),
1499 # make sure we have some title to operate on
1500 static function checkTitle( &$title, &$name ) {
1501 if( !is_object( $title ) ) {
1502 $title = Title
::newFromText( $name );
1503 if( !is_object( $title ) ) {
1504 $title = Title
::newFromText( '--error: link target missing--' );
1510 * Build an array that represents the sidebar(s), the navigation bar among them
1515 function buildSidebar() {
1516 global $parserMemc, $wgEnableSidebarCache;
1517 global $wgLang, $wgContLang;
1519 $fname = 'SkinTemplate::buildSidebar';
1521 wfProfileIn( $fname );
1523 $key = wfMemcKey( 'sidebar' );
1524 $cacheSidebar = $wgEnableSidebarCache &&
1525 ($wgLang->getCode() == $wgContLang->getCode());
1527 if ($cacheSidebar) {
1528 $cachedsidebar = $parserMemc->get( $key );
1529 if ($cachedsidebar!="") {
1530 wfProfileOut($fname);
1531 return $cachedsidebar;
1536 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1537 foreach ($lines as $line) {
1538 if (strpos($line, '*') !== 0)
1540 if (strpos($line, '**') !== 0) {
1541 $line = trim($line, '* ');
1544 if (strpos($line, '|') !== false) { // sanity check
1545 $line = explode( '|' , trim($line, '* '), 2 );
1546 $link = wfMsgForContent( $line[0] );
1549 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1551 if (wfEmptyMsg($line[0], $link))
1553 $href = self
::makeInternalOrExternalUrl( $link );
1554 $bar[$heading][] = array(
1557 'id' => 'n-' . strtr($line[1], ' ', '-'),
1560 } else { continue; }
1564 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1565 wfProfileOut( $fname );