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 $s = "@import \"$wgStylePath/common/common.css?$wgStyleVersion\";\n";
367 $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
368 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
370 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
371 $s .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
372 '@import "' . self
::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
374 $s .= $this->doGetUserStyles();
379 * placeholder, returns generated js in monobook
381 function getUserJs() { return; }
384 * Return html code that include User stylesheets
386 function getUserStyles() {
387 $s = "<style type='text/css'>\n";
388 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
389 $s .= $this->getUserStylesheet();
390 $s .= "/*]]>*/ /* */\n";
396 * Some styles that are set by user through the user settings interface.
398 function doGetUserStyles() {
399 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
403 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
404 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
405 $s .= $wgRequest->getText('wpTextbox1');
407 $userpage = $wgUser->getUserPage();
408 $s.= '@import "'.self
::makeUrl(
409 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
410 'action=raw&ctype=text/css').'";'."\n";
414 return $s . $this->reallyDoGetUserStyles();
417 function reallyDoGetUserStyles() {
420 if (($undopt = $wgUser->getOption("underline")) != 2) {
421 $underline = $undopt ?
'underline' : 'none';
422 $s .= "a { text-decoration: $underline; }\n";
424 if( $wgUser->getOption( 'highlightbroken' ) ) {
425 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
428 a.new, #quickbar a.new,
429 a.stub, #quickbar a.stub {
431 text-decoration: inherit;
433 a.new:after, #quickbar a.new:after {
436 text-decoration: $underline;
438 a.stub:after, #quickbar a.stub:after {
441 text-decoration: $underline;
445 if( $wgUser->getOption( 'justify' ) ) {
446 $s .= "#article, #bodyContent { text-align: justify; }\n";
448 if( !$wgUser->getOption( 'showtoc' ) ) {
449 $s .= "#toc { display: none; }\n";
451 if( !$wgUser->getOption( 'editsection' ) ) {
452 $s .= ".editsection { display: none; }\n";
457 function getBodyOptions() {
458 global $wgUser, $wgTitle, $wgOut, $wgRequest, $wgContLang;
460 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
462 if ( 0 != $wgTitle->getNamespace() ) {
463 $a = array( 'bgcolor' => '#ffffec' );
465 else $a = array( 'bgcolor' => '#FFFFFF' );
466 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
467 $wgTitle->userCanEdit() ) {
468 $t = wfMsg( 'editthispage' );
469 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
470 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
471 $a +
= array ('ondblclick' => $s);
474 $a['onload'] = $wgOut->getOnloadHandler();
475 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
476 if( $a['onload'] != '' ) {
479 $a['onload'] .= 'setupRightClickEdit()';
481 $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ?
"rtl" : "ltr").
482 ' '.Sanitizer
::escapeId( 'page-'.$wgTitle->getPrefixedText() );
495 * This will be called immediately after the <body> tag. Split into
496 * two functions to make it easier to subclass.
498 function beforeContent() {
499 return $this->doBeforeContent();
502 function doBeforeContent() {
504 $fname = 'Skin::doBeforeContent';
505 wfProfileIn( $fname );
508 $qb = $this->qbSetting();
510 if( $langlinks = $this->otherLanguages() ) {
516 $borderhack = 'class="top"';
519 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
520 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
523 $left = ($qb == 1 ||
$qb == 3);
524 if($wgContLang->isRTL()) $left = !$left;
527 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
528 $this->logoText() . '</td>';
530 $s .= $this->getQuickbarCompensator( $rows );
532 $l = $wgContLang->isRTL() ?
'right' : 'left';
533 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
535 $s .= $this->topLinks() ;
536 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
538 $r = $wgContLang->isRTL() ?
"left" : "right";
539 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
540 $s .= $this->nameAndLogin();
541 $s .= "\n<br />" . $this->searchForm() . "</td>";
544 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
547 if ( $shove && !$left ) { # Right
548 $s .= $this->getQuickbarCompensator( $rows );
550 $s .= "</tr>\n</table>\n</div>\n";
551 $s .= "\n<div id='article'>\n";
553 $notice = wfGetSiteNotice();
555 $s .= "\n<div id='siteNotice'>$notice</div>\n";
557 $s .= $this->pageTitle();
558 $s .= $this->pageSubtitle() ;
559 $s .= $this->getCategories();
560 wfProfileOut( $fname );
565 function getCategoryLinks () {
566 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
569 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
572 $sep = wfMsgHtml( 'catseparator' );
574 // Use Unicode bidi embedding override characters,
575 // to make sure links don't smash each other up in ugly ways.
576 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
577 $embed = "<span dir='$dir'>";
579 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
581 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks
) );
582 $s = $this->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Categories' ),
583 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
586 # optional 'dmoz-like' category browser. Will be shown under the list
587 # of categories an article belong to
588 if($wgUseCategoryBrowser) {
589 $s .= '<br /><hr />';
591 # get a big array of the parents tree
592 $parenttree = $wgTitle->getParentCategoryTree();
593 # Skin object passed by reference cause it can not be
594 # accessed under the method subfunction drawCategoryBrowser
595 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
596 # Clean out bogus first entry and sort them
599 # Output one per line
600 $s .= implode("<br />\n", $tempout);
606 /** Render the array as a serie of links.
607 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
608 * @param &skin Object: skin passed by reference
609 * @return String separated by >, terminate with "\n"
611 function drawCategoryBrowser($tree, &$skin) {
613 foreach ($tree as $element => $parent) {
614 if (empty($parent)) {
615 # element start a new list
618 # grab the others elements
619 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
621 # add our current element to the list
622 $eltitle = Title
::NewFromText($element);
623 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
628 function getCategories() {
629 $catlinks=$this->getCategoryLinks();
630 if(!empty($catlinks)) {
631 return "<p class='catlinks'>{$catlinks}</p>";
635 function getQuickbarCompensator( $rows = 1 ) {
636 return "<td width='152' rowspan='{$rows}'> </td>";
640 * This gets called shortly before the \</body\> tag.
641 * @return String HTML to be put before \</body\>
643 function afterContent() {
644 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
645 return $printfooter . $this->doAfterContent();
649 * This gets called shortly before the \</body\> tag.
650 * @return String HTML-wrapped JS code to be put before \</body\>
652 function bottomScripts() {
653 global $wgJsMimeType;
654 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
657 /** @return string Retrievied from HTML text */
658 function printSource() {
660 $url = htmlspecialchars( $wgTitle->getFullURL() );
661 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
664 function printFooter() {
665 return "<p>" . $this->printSource() .
666 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
669 /** overloaded by derived classes */
670 function doAfterContent() { }
672 function pageTitleLinks() {
673 global $wgOut, $wgTitle, $wgUser, $wgRequest;
675 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
676 $action = $wgRequest->getText( 'action' );
678 $s = $this->printableLink();
679 $disclaimer = $this->disclaimerLink(); # may be empty
681 $s .= ' | ' . $disclaimer;
683 $privacy = $this->privacyLink(); # may be empty too
685 $s .= ' | ' . $privacy;
688 if ( $wgOut->isArticleRelated() ) {
689 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
690 $name = $wgTitle->getDBkey();
691 $image = new Image( $wgTitle );
692 if( $image->exists() ) {
693 $link = htmlspecialchars( $image->getURL() );
694 $style = $this->getInternalLinkAttributes( $link, $name );
695 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
699 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
700 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
701 wfMsg( 'currentrev' ) );
704 if ( $wgUser->getNewtalk() ) {
705 # do not show "You have new messages" text when we are viewing our
707 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
708 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
709 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
710 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
712 $wgOut->setSquidMaxage(0);
713 $wgOut->enableClientCache(false);
717 $undelete = $this->getUndeleteLink();
718 if( !empty( $undelete ) ) {
719 $s .= ' | '.$undelete;
724 function getUndeleteLink() {
725 global $wgUser, $wgTitle, $wgContLang, $action;
726 if( $wgUser->isAllowed( 'deletedhistory' ) &&
727 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
728 ($n = $wgTitle->isDeleted() ) )
730 if ( $wgUser->isAllowed( 'delete' ) ) {
731 $msg = 'thisisdeleted';
733 $msg = 'viewdeleted';
736 $this->makeKnownLink(
737 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
738 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
743 function printableLink() {
744 global $wgOut, $wgFeedClasses, $wgRequest;
746 $baseurl = $_SERVER['REQUEST_URI'];
747 if( strpos( '?', $baseurl ) == false ) {
752 $baseurl = htmlspecialchars( $baseurl );
753 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
755 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
756 if( $wgOut->isSyndicated() ) {
757 foreach( $wgFeedClasses as $format => $class ) {
758 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
759 $s .= " | <a href=\"$feedurl\">{$format}</a>";
765 function pageTitle() {
767 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
771 function pageSubtitle() {
774 $sub = $wgOut->getSubtitle();
776 global $wgExtraSubtitle;
777 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
779 $subpages = $this->subPageSubtitle();
780 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
781 $s = "<p class='subtitle'>{$sub}</p>\n";
785 function subPageSubtitle() {
786 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
788 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
789 $ptext=$wgTitle->getPrefixedText();
790 if(preg_match('/\//',$ptext)) {
791 $links = explode('/',$ptext);
794 foreach($links as $link) {
796 if ($c<count($links)) {
797 $growinglink .= $link;
798 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
799 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
803 $subpages .= '< ';
805 $subpages .= $getlink;
814 function nameAndLogin() {
815 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
817 $li = $wgContLang->specialPage( 'Userlogin' );
818 $lo = $wgContLang->specialPage( 'Userlogout' );
821 if ( $wgUser->isAnon() ) {
822 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
825 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
826 $wgLang->getNsText( NS_TALK
) );
828 $s .= $n . ' ('.$tl.')';
830 $s .= wfMsg('notloggedin');
833 $rt = $wgTitle->getPrefixedURL();
834 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
836 } else { $q = "returnto={$rt}"; }
838 $s .= "\n<br />" . $this->makeKnownLinkObj(
839 SpecialPage
::getTitleFor( 'Userlogin' ),
840 wfMsg( 'login' ), $q );
842 $n = $wgUser->getName();
843 $rt = $wgTitle->getPrefixedURL();
844 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
845 $wgLang->getNsText( NS_TALK
) );
849 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
850 $n ) . "{$tl}<br />" .
851 $this->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
852 "returnto={$rt}" ) . ' | ' .
853 $this->specialLink( 'preferences' );
855 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
861 function getSearchLink() {
862 $searchPage =& SpecialPage
::getTitleFor( 'Search' );
863 return $searchPage->getLocalURL();
866 function escapeSearchLink() {
867 return htmlspecialchars( $this->getSearchLink() );
870 function searchForm() {
872 $search = $wgRequest->getText( 'search' );
874 $s = '<form name="search" class="inline" method="post" action="'
875 . $this->escapeSearchLink() . "\">\n"
876 . '<input type="text" name="search" size="19" value="'
877 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
878 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" /> '
879 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
884 function topLinks() {
888 $s = $this->mainPageLink() . $sep
889 . $this->specialLink( 'recentchanges' );
891 if ( $wgOut->isArticleRelated() ) {
892 $s .= $sep . $this->editThisPage()
893 . $sep . $this->historyLink();
895 # Many people don't like this dropdown box
896 #$s .= $sep . $this->specialPagesList();
898 $s .= $this->variantLinks();
904 * Language/charset variant links for classic-style skins
907 function variantLinks() {
909 /* show links to different language variants */
910 global $wgDisableLangConversion, $wgContLang, $wgTitle;
911 $variants = $wgContLang->getVariants();
912 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
913 foreach( $variants as $code ) {
914 $varname = $wgContLang->getVariantname( $code );
915 if( $varname == 'disable' )
917 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
923 function bottomLinks() {
924 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
928 if ( $wgOut->isArticleRelated() ) {
929 $s .= '<strong>' . $this->editThisPage() . '</strong>';
930 if ( $wgUser->isLoggedIn() ) {
931 $s .= $sep . $this->watchThisPage();
933 $s .= $sep . $this->talkLink()
934 . $sep . $this->historyLink()
935 . $sep . $this->whatLinksHere()
936 . $sep . $this->watchPageLinksLink();
938 if ($wgUseTrackbacks)
939 $s .= $sep . $this->trackbackLink();
941 if ( $wgTitle->getNamespace() == NS_USER
942 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
945 $id=User
::idFromName($wgTitle->getText());
946 $ip=User
::isIP($wgTitle->getText());
948 if($id ||
$ip) { # both anons and non-anons have contri list
949 $s .= $sep . $this->userContribsLink();
951 if( $this->showEmailUser( $id ) ) {
952 $s .= $sep . $this->emailUserLink();
955 if ( $wgTitle->getArticleId() ) {
957 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
958 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
959 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
961 $s .= "<br />\n" . $this->otherLanguages();
966 function pageStats() {
967 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
968 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
970 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
971 if ( ! $wgOut->isArticle() ) { return ''; }
972 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
973 if ( 0 == $wgArticle->getID() ) { return ''; }
976 if ( !$wgDisableCounters ) {
977 $count = $wgLang->formatNum( $wgArticle->getCount() );
979 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
983 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
984 require_once('Credits.php');
985 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
987 $s .= $this->lastModified();
990 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
991 $dbr =& wfGetDB( DB_SLAVE
);
992 extract( $dbr->tableNames( 'watchlist' ) );
993 $sql = "SELECT COUNT(*) AS n FROM $watchlist
994 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
995 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
996 $res = $dbr->query( $sql, 'Skin::pageStats');
997 $x = $dbr->fetchObject( $res );
998 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
1001 return $s . ' ' . $this->getCopyright();
1004 function getCopyright( $type = 'detect' ) {
1005 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1007 if ( $type == 'detect' ) {
1008 $oldid = $wgRequest->getVal( 'oldid' );
1009 $diff = $wgRequest->getVal( 'diff' );
1011 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1018 if ( $type == 'history' ) {
1019 $msg = 'history_copyright';
1025 if( $wgRightsPage ) {
1026 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1027 } elseif( $wgRightsUrl ) {
1028 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1033 $out .= wfMsgForContent( $msg, $link );
1037 function getCopyrightIcon() {
1038 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1040 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1041 $out = $wgCopyrightIcon;
1042 } else if ( $wgRightsIcon ) {
1043 $icon = htmlspecialchars( $wgRightsIcon );
1044 if ( $wgRightsUrl ) {
1045 $url = htmlspecialchars( $wgRightsUrl );
1046 $out .= '<a href="'.$url.'">';
1048 $text = htmlspecialchars( $wgRightsText );
1049 $out .= "<img src=\"$icon\" alt='$text' />";
1050 if ( $wgRightsUrl ) {
1057 function getPoweredBy() {
1058 global $wgStylePath;
1059 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1060 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1064 function lastModified() {
1065 global $wgLang, $wgArticle, $wgLoadBalancer;
1067 $timestamp = $wgArticle->getTimestamp();
1069 $d = $wgLang->date( $timestamp, true );
1070 $t = $wgLang->time( $timestamp, true );
1071 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1075 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1076 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1081 function logoText( $align = '' ) {
1082 if ( '' != $align ) { $a = " align='{$align}'"; }
1085 $mp = wfMsg( 'mainpage' );
1086 $titleObj = Title
::newFromText( $mp );
1087 if ( is_object( $titleObj ) ) {
1088 $url = $titleObj->escapeLocalURL();
1093 $logourl = $this->getLogo();
1094 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1099 * show a drop-down box of special pages
1101 function specialPagesList() {
1102 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1104 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1105 foreach ( $pages as $name => $page ) {
1106 $pages[$name] = $page->getDescription();
1109 $go = wfMsg( 'go' );
1110 $sp = wfMsg( 'specialpages' );
1111 $spp = $wgContLang->specialPage( 'Specialpages' );
1113 $s = '<form id="specialpages" method="get" class="inline" ' .
1114 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1115 $s .= "<select name=\"wpDropdown\">\n";
1116 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1119 foreach ( $pages as $name => $desc ) {
1120 $p = $wgContLang->specialPage( $name );
1121 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1123 $s .= "</select>\n";
1124 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1129 function mainPageLink() {
1130 $mp = wfMsgForContent( 'mainpage' );
1131 $mptxt = wfMsg( 'mainpage');
1132 $s = $this->makeKnownLink( $mp, $mptxt );
1136 function copyrightLink() {
1137 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1138 wfMsg( 'copyrightpagename' ) );
1142 function privacyLink() {
1143 $privacy = wfMsg( 'privacy' );
1144 if ($privacy == '-') {
1147 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1151 function aboutLink() {
1152 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1153 wfMsg( 'aboutsite' ) );
1157 function disclaimerLink() {
1158 $disclaimers = wfMsg( 'disclaimers' );
1159 if ($disclaimers == '-') {
1162 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1167 function editThisPage() {
1168 global $wgOut, $wgTitle;
1170 if ( ! $wgOut->isArticleRelated() ) {
1171 $s = wfMsg( 'protectedpage' );
1173 if ( $wgTitle->userCanEdit() ) {
1174 $t = wfMsg( 'editthispage' );
1176 $t = wfMsg( 'viewsource' );
1179 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1185 * Return URL options for the 'edit page' link.
1186 * This may include an 'oldid' specifier, if the current page view is such.
1191 function editUrlOptions() {
1194 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1195 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1197 return "action=edit";
1201 function deleteThisPage() {
1202 global $wgUser, $wgTitle, $wgRequest;
1204 $diff = $wgRequest->getVal( 'diff' );
1205 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1206 $t = wfMsg( 'deletethispage' );
1208 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1215 function protectThisPage() {
1216 global $wgUser, $wgTitle, $wgRequest;
1218 $diff = $wgRequest->getVal( 'diff' );
1219 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1220 if ( $wgTitle->isProtected() ) {
1221 $t = wfMsg( 'unprotectthispage' );
1222 $q = 'action=unprotect';
1224 $t = wfMsg( 'protectthispage' );
1225 $q = 'action=protect';
1227 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1234 function watchThisPage() {
1235 global $wgOut, $wgTitle;
1237 if ( $wgOut->isArticleRelated() ) {
1238 if ( $wgTitle->userIsWatching() ) {
1239 $t = wfMsg( 'unwatchthispage' );
1240 $q = 'action=unwatch';
1242 $t = wfMsg( 'watchthispage' );
1243 $q = 'action=watch';
1245 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1247 $s = wfMsg( 'notanarticle' );
1252 function moveThisPage() {
1255 if ( $wgTitle->userCanMove() ) {
1256 return $this->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Movepage' ),
1257 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1259 // no message if page is protected - would be redundant
1264 function historyLink() {
1267 return $this->makeKnownLinkObj( $wgTitle,
1268 wfMsg( 'history' ), 'action=history' );
1271 function whatLinksHere() {
1274 return $this->makeKnownLinkObj(
1275 SpecialPage
::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1276 wfMsg( 'whatlinkshere' ) );
1279 function userContribsLink() {
1282 return $this->makeKnownLinkObj(
1283 SpecialPage
::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1284 wfMsg( 'contributions' ) );
1287 function showEmailUser( $id ) {
1288 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1289 return $wgEnableEmail &&
1290 $wgEnableUserEmail &&
1291 $wgUser->isLoggedIn() && # show only to signed in users
1292 0 != $id; # we can only email to non-anons ..
1293 # '' != $id->getEmail() && # who must have an email address stored ..
1294 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1295 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1298 function emailUserLink() {
1301 return $this->makeKnownLinkObj(
1302 SpecialPage
::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1303 wfMsg( 'emailuser' ) );
1306 function watchPageLinksLink() {
1307 global $wgOut, $wgTitle;
1309 if ( ! $wgOut->isArticleRelated() ) {
1310 return '(' . wfMsg( 'notanarticle' ) . ')';
1312 return $this->makeKnownLinkObj(
1313 SpecialPage
::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1314 wfMsg( 'recentchangeslinked' ) );
1318 function trackbackLink() {
1321 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1322 . wfMsg('trackbacklink') . "</a>";
1325 function otherLanguages() {
1326 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1328 if ( $wgHideInterlanguageLinks ) {
1332 $a = $wgOut->getLanguageLinks();
1333 if ( 0 == count( $a ) ) {
1337 $s = wfMsg( 'otherlanguages' ) . ': ';
1339 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1340 foreach( $a as $l ) {
1341 if ( ! $first ) { $s .= ' | '; }
1344 $nt = Title
::newFromText( $l );
1345 $url = $nt->escapeFullURL();
1346 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1348 if ( '' == $text ) { $text = $l; }
1349 $style = $this->getExternalLinkAttributes( $l, $text );
1350 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1352 if($wgContLang->isRTL()) $s .= '</span>';
1356 function bugReportsLink() {
1357 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1358 wfMsg( 'bugreports' ) );
1362 function dateLink() {
1363 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1364 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1366 $id = $t1->getArticleID();
1369 $s = $this->makeBrokenLink( $t1->getText() );
1371 $s = $this->makeKnownLink( $t1->getText() );
1375 $id = $t2->getArticleID();
1378 $s .= $this->makeBrokenLink( $t2->getText() );
1380 $s .= $this->makeKnownLink( $t2->getText() );
1385 function talkLink() {
1388 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1389 # No discussion links for special pages
1393 if( $wgTitle->isTalkPage() ) {
1394 $link = $wgTitle->getSubjectPage();
1395 switch( $link->getNamespace() ) {
1397 $text = wfMsg( 'articlepage' );
1400 $text = wfMsg( 'userpage' );
1403 $text = wfMsg( 'projectpage' );
1406 $text = wfMsg( 'imagepage' );
1409 $text = wfMsg( 'mediawikipage' );
1412 $text = wfMsg( 'templatepage' );
1415 $text = wfMsg( 'viewhelppage' );
1418 $text = wfMsg( 'categorypage' );
1421 $text = wfMsg( 'articlepage' );
1424 $link = $wgTitle->getTalkPage();
1425 $text = wfMsg( 'talkpage' );
1428 $s = $this->makeLinkObj( $link, $text );
1433 function commentLink() {
1434 global $wgTitle, $wgOut;
1436 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1440 # __NEWSECTIONLINK___ changes behaviour here
1441 # If it's present, the link points to this page, otherwise
1442 # it points to the talk page
1443 if( $wgTitle->isTalkPage() ) {
1445 } elseif( $wgOut->showNewSectionLink() ) {
1448 $title =& $wgTitle->getTalkPage();
1451 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1454 /* these are used extensively in SkinTemplate, but also some other places */
1455 static function makeSpecialUrl( $name, $urlaction = '' ) {
1456 $title = SpecialPage
::getTitleFor( $name );
1457 return $title->getLocalURL( $urlaction );
1460 static function makeI18nUrl( $name, $urlaction = '' ) {
1461 $title = Title
::newFromText( wfMsgForContent( $name ) );
1462 self
::checkTitle( $title, $name );
1463 return $title->getLocalURL( $urlaction );
1466 static function makeUrl( $name, $urlaction = '' ) {
1467 $title = Title
::newFromText( $name );
1468 self
::checkTitle( $title, $name );
1469 return $title->getLocalURL( $urlaction );
1472 # If url string starts with http, consider as external URL, else
1474 static function makeInternalOrExternalUrl( $name ) {
1475 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1478 return self
::makeUrl( $name );
1482 # this can be passed the NS number as defined in Language.php
1483 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1484 $title = Title
::makeTitleSafe( $namespace, $name );
1485 self
::checkTitle( $title, $name );
1486 return $title->getLocalURL( $urlaction );
1489 /* these return an array with the 'href' and boolean 'exists' */
1490 static function makeUrlDetails( $name, $urlaction = '' ) {
1491 $title = Title
::newFromText( $name );
1492 self
::checkTitle( $title, $name );
1494 'href' => $title->getLocalURL( $urlaction ),
1495 'exists' => $title->getArticleID() != 0 ?
true : false
1500 * Make URL details where the article exists (or at least it's convenient to think so)
1502 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1503 $title = Title
::newFromText( $name );
1504 self
::checkTitle( $title, $name );
1506 'href' => $title->getLocalURL( $urlaction ),
1511 # make sure we have some title to operate on
1512 static function checkTitle( &$title, &$name ) {
1513 if( !is_object( $title ) ) {
1514 $title = Title
::newFromText( $name );
1515 if( !is_object( $title ) ) {
1516 $title = Title
::newFromText( '--error: link target missing--' );
1522 * Build an array that represents the sidebar(s), the navigation bar among them
1527 function buildSidebar() {
1528 global $parserMemc, $wgEnableSidebarCache;
1529 global $wgLang, $wgContLang;
1531 $fname = 'SkinTemplate::buildSidebar';
1533 wfProfileIn( $fname );
1535 $key = wfMemcKey( 'sidebar' );
1536 $cacheSidebar = $wgEnableSidebarCache &&
1537 ($wgLang->getCode() == $wgContLang->getCode());
1539 if ($cacheSidebar) {
1540 $cachedsidebar = $parserMemc->get( $key );
1541 if ($cachedsidebar!="") {
1542 wfProfileOut($fname);
1543 return $cachedsidebar;
1548 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1549 foreach ($lines as $line) {
1550 if (strpos($line, '*') !== 0)
1552 if (strpos($line, '**') !== 0) {
1553 $line = trim($line, '* ');
1556 if (strpos($line, '|') !== false) { // sanity check
1557 $line = explode( '|' , trim($line, '* '), 2 );
1558 $link = wfMsgForContent( $line[0] );
1561 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1563 if (wfEmptyMsg($line[0], $link))
1566 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1569 $title = Title
::newFromText( $link );
1570 $title = $title->fixSpecialName();
1571 $href = $title->getLocalURL();
1574 $bar[$heading][] = array(
1577 'id' => 'n-' . strtr($line[1], ' ', '-'),
1580 } else { continue; }
1584 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1585 wfProfileOut( $fname );