f349c39104e81b39a05190e2bfab34d1bdf29364
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( Title
::makeTitle( NS_SPECIAL
, '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 Title
::makeTitle( NS_SPECIAL
, '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( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
852 "returnto={$rt}" ) . ' | ' .
853 $this->specialLink( 'preferences' );
855 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
861 function getSearchLink() {
862 $searchPage =& Title
::makeTitle( NS_SPECIAL
, '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 /* show links to different language variants */
899 global $wgDisableLangConversion, $wgContLang, $wgTitle;
900 $variants = $wgContLang->getVariants();
901 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
902 foreach( $variants as $code ) {
903 $varname = $wgContLang->getVariantname( $code );
904 if( $varname == 'disable' )
906 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
913 function bottomLinks() {
914 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
918 if ( $wgOut->isArticleRelated() ) {
919 $s .= '<strong>' . $this->editThisPage() . '</strong>';
920 if ( $wgUser->isLoggedIn() ) {
921 $s .= $sep . $this->watchThisPage();
923 $s .= $sep . $this->talkLink()
924 . $sep . $this->historyLink()
925 . $sep . $this->whatLinksHere()
926 . $sep . $this->watchPageLinksLink();
928 if ($wgUseTrackbacks)
929 $s .= $sep . $this->trackbackLink();
931 if ( $wgTitle->getNamespace() == NS_USER
932 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
935 $id=User
::idFromName($wgTitle->getText());
936 $ip=User
::isIP($wgTitle->getText());
938 if($id ||
$ip) { # both anons and non-anons have contri list
939 $s .= $sep . $this->userContribsLink();
941 if( $this->showEmailUser( $id ) ) {
942 $s .= $sep . $this->emailUserLink();
945 if ( $wgTitle->getArticleId() ) {
947 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
948 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
949 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
951 $s .= "<br />\n" . $this->otherLanguages();
956 function pageStats() {
957 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
958 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
960 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
961 if ( ! $wgOut->isArticle() ) { return ''; }
962 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
963 if ( 0 == $wgArticle->getID() ) { return ''; }
966 if ( !$wgDisableCounters ) {
967 $count = $wgLang->formatNum( $wgArticle->getCount() );
969 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
973 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
974 require_once('Credits.php');
975 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
977 $s .= $this->lastModified();
980 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
981 $dbr =& wfGetDB( DB_SLAVE
);
982 extract( $dbr->tableNames( 'watchlist' ) );
983 $sql = "SELECT COUNT(*) AS n FROM $watchlist
984 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
985 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
986 $res = $dbr->query( $sql, 'Skin::pageStats');
987 $x = $dbr->fetchObject( $res );
988 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
991 return $s . ' ' . $this->getCopyright();
994 function getCopyright( $type = 'detect' ) {
995 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
997 if ( $type == 'detect' ) {
998 $oldid = $wgRequest->getVal( 'oldid' );
999 $diff = $wgRequest->getVal( 'diff' );
1001 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1008 if ( $type == 'history' ) {
1009 $msg = 'history_copyright';
1015 if( $wgRightsPage ) {
1016 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1017 } elseif( $wgRightsUrl ) {
1018 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1023 $out .= wfMsgForContent( $msg, $link );
1027 function getCopyrightIcon() {
1028 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1030 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1031 $out = $wgCopyrightIcon;
1032 } else if ( $wgRightsIcon ) {
1033 $icon = htmlspecialchars( $wgRightsIcon );
1034 if ( $wgRightsUrl ) {
1035 $url = htmlspecialchars( $wgRightsUrl );
1036 $out .= '<a href="'.$url.'">';
1038 $text = htmlspecialchars( $wgRightsText );
1039 $out .= "<img src=\"$icon\" alt='$text' />";
1040 if ( $wgRightsUrl ) {
1047 function getPoweredBy() {
1048 global $wgStylePath;
1049 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1050 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1054 function lastModified() {
1055 global $wgLang, $wgArticle, $wgLoadBalancer;
1057 $timestamp = $wgArticle->getTimestamp();
1059 $d = $wgLang->date( $timestamp, true );
1060 $t = $wgLang->time( $timestamp, true );
1061 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1065 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1066 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1071 function logoText( $align = '' ) {
1072 if ( '' != $align ) { $a = " align='{$align}'"; }
1075 $mp = wfMsg( 'mainpage' );
1076 $titleObj = Title
::newFromText( $mp );
1077 if ( is_object( $titleObj ) ) {
1078 $url = $titleObj->escapeLocalURL();
1083 $logourl = $this->getLogo();
1084 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1089 * show a drop-down box of special pages
1091 function specialPagesList() {
1092 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1094 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1095 foreach ( $pages as $name => $page ) {
1096 $pages[$name] = $page->getDescription();
1099 $go = wfMsg( 'go' );
1100 $sp = wfMsg( 'specialpages' );
1101 $spp = $wgContLang->specialPage( 'Specialpages' );
1103 $s = '<form id="specialpages" method="get" class="inline" ' .
1104 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1105 $s .= "<select name=\"wpDropdown\">\n";
1106 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1109 foreach ( $pages as $name => $desc ) {
1110 $p = $wgContLang->specialPage( $name );
1111 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1113 $s .= "</select>\n";
1114 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1119 function mainPageLink() {
1120 $mp = wfMsgForContent( 'mainpage' );
1121 $mptxt = wfMsg( 'mainpage');
1122 $s = $this->makeKnownLink( $mp, $mptxt );
1126 function copyrightLink() {
1127 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1128 wfMsg( 'copyrightpagename' ) );
1132 function privacyLink() {
1133 $privacy = wfMsg( 'privacy' );
1134 if ($privacy == '-') {
1137 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1141 function aboutLink() {
1142 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1143 wfMsg( 'aboutsite' ) );
1147 function disclaimerLink() {
1148 $disclaimers = wfMsg( 'disclaimers' );
1149 if ($disclaimers == '-') {
1152 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1157 function editThisPage() {
1158 global $wgOut, $wgTitle;
1160 if ( ! $wgOut->isArticleRelated() ) {
1161 $s = wfMsg( 'protectedpage' );
1163 if ( $wgTitle->userCanEdit() ) {
1164 $t = wfMsg( 'editthispage' );
1166 $t = wfMsg( 'viewsource' );
1169 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1175 * Return URL options for the 'edit page' link.
1176 * This may include an 'oldid' specifier, if the current page view is such.
1181 function editUrlOptions() {
1184 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1185 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1187 return "action=edit";
1191 function deleteThisPage() {
1192 global $wgUser, $wgTitle, $wgRequest;
1194 $diff = $wgRequest->getVal( 'diff' );
1195 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1196 $t = wfMsg( 'deletethispage' );
1198 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1205 function protectThisPage() {
1206 global $wgUser, $wgTitle, $wgRequest;
1208 $diff = $wgRequest->getVal( 'diff' );
1209 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1210 if ( $wgTitle->isProtected() ) {
1211 $t = wfMsg( 'unprotectthispage' );
1212 $q = 'action=unprotect';
1214 $t = wfMsg( 'protectthispage' );
1215 $q = 'action=protect';
1217 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1224 function watchThisPage() {
1225 global $wgOut, $wgTitle;
1227 if ( $wgOut->isArticleRelated() ) {
1228 if ( $wgTitle->userIsWatching() ) {
1229 $t = wfMsg( 'unwatchthispage' );
1230 $q = 'action=unwatch';
1232 $t = wfMsg( 'watchthispage' );
1233 $q = 'action=watch';
1235 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1237 $s = wfMsg( 'notanarticle' );
1242 function moveThisPage() {
1245 if ( $wgTitle->userCanMove() ) {
1246 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1247 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1249 // no message if page is protected - would be redundant
1254 function historyLink() {
1257 return $this->makeKnownLinkObj( $wgTitle,
1258 wfMsg( 'history' ), 'action=history' );
1261 function whatLinksHere() {
1264 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1265 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1268 function userContribsLink() {
1271 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1272 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1275 function showEmailUser( $id ) {
1276 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1277 return $wgEnableEmail &&
1278 $wgEnableUserEmail &&
1279 $wgUser->isLoggedIn() && # show only to signed in users
1280 0 != $id; # we can only email to non-anons ..
1281 # '' != $id->getEmail() && # who must have an email address stored ..
1282 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1283 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1286 function emailUserLink() {
1289 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1290 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1293 function watchPageLinksLink() {
1294 global $wgOut, $wgTitle;
1296 if ( ! $wgOut->isArticleRelated() ) {
1297 return '(' . wfMsg( 'notanarticle' ) . ')';
1299 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1300 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1301 'target=' . $wgTitle->getPrefixedURL() );
1305 function trackbackLink() {
1308 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1309 . wfMsg('trackbacklink') . "</a>";
1312 function otherLanguages() {
1313 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1315 if ( $wgHideInterlanguageLinks ) {
1319 $a = $wgOut->getLanguageLinks();
1320 if ( 0 == count( $a ) ) {
1324 $s = wfMsg( 'otherlanguages' ) . ': ';
1326 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1327 foreach( $a as $l ) {
1328 if ( ! $first ) { $s .= ' | '; }
1331 $nt = Title
::newFromText( $l );
1332 $url = $nt->escapeFullURL();
1333 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1335 if ( '' == $text ) { $text = $l; }
1336 $style = $this->getExternalLinkAttributes( $l, $text );
1337 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1339 if($wgContLang->isRTL()) $s .= '</span>';
1343 function bugReportsLink() {
1344 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1345 wfMsg( 'bugreports' ) );
1349 function dateLink() {
1350 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1351 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1353 $id = $t1->getArticleID();
1356 $s = $this->makeBrokenLink( $t1->getText() );
1358 $s = $this->makeKnownLink( $t1->getText() );
1362 $id = $t2->getArticleID();
1365 $s .= $this->makeBrokenLink( $t2->getText() );
1367 $s .= $this->makeKnownLink( $t2->getText() );
1372 function talkLink() {
1375 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1376 # No discussion links for special pages
1380 if( $wgTitle->isTalkPage() ) {
1381 $link = $wgTitle->getSubjectPage();
1382 switch( $link->getNamespace() ) {
1384 $text = wfMsg( 'articlepage' );
1387 $text = wfMsg( 'userpage' );
1390 $text = wfMsg( 'projectpage' );
1393 $text = wfMsg( 'imagepage' );
1396 $text = wfMsg( 'mediawikipage' );
1399 $text = wfMsg( 'templatepage' );
1402 $text = wfMsg( 'viewhelppage' );
1405 $text = wfMsg( 'categorypage' );
1408 $text = wfMsg( 'articlepage' );
1411 $link = $wgTitle->getTalkPage();
1412 $text = wfMsg( 'talkpage' );
1415 $s = $this->makeLinkObj( $link, $text );
1420 function commentLink() {
1421 global $wgTitle, $wgOut;
1423 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1427 # __NEWSECTIONLINK___ changes behaviour here
1428 # If it's present, the link points to this page, otherwise
1429 # it points to the talk page
1430 if( $wgTitle->isTalkPage() ) {
1432 } elseif( $wgOut->showNewSectionLink() ) {
1435 $title =& $wgTitle->getTalkPage();
1438 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1441 /* these are used extensively in SkinTemplate, but also some other places */
1442 static function makeSpecialUrl( $name, $urlaction = '' ) {
1443 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1444 return $title->getLocalURL( $urlaction );
1447 static function makeI18nUrl( $name, $urlaction = '' ) {
1448 $title = Title
::newFromText( wfMsgForContent( $name ) );
1449 self
::checkTitle( $title, $name );
1450 return $title->getLocalURL( $urlaction );
1453 static function makeUrl( $name, $urlaction = '' ) {
1454 $title = Title
::newFromText( $name );
1455 self
::checkTitle( $title, $name );
1456 return $title->getLocalURL( $urlaction );
1459 # If url string starts with http, consider as external URL, else
1461 static function makeInternalOrExternalUrl( $name ) {
1462 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1465 return self
::makeUrl( $name );
1469 # this can be passed the NS number as defined in Language.php
1470 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1471 $title = Title
::makeTitleSafe( $namespace, $name );
1472 self
::checkTitle( $title, $name );
1473 return $title->getLocalURL( $urlaction );
1476 /* these return an array with the 'href' and boolean 'exists' */
1477 static function makeUrlDetails( $name, $urlaction = '' ) {
1478 $title = Title
::newFromText( $name );
1479 self
::checkTitle( $title, $name );
1481 'href' => $title->getLocalURL( $urlaction ),
1482 'exists' => $title->getArticleID() != 0 ?
true : false
1487 * Make URL details where the article exists (or at least it's convenient to think so)
1489 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1490 $title = Title
::newFromText( $name );
1491 self
::checkTitle( $title, $name );
1493 'href' => $title->getLocalURL( $urlaction ),
1498 # make sure we have some title to operate on
1499 static function checkTitle( &$title, &$name ) {
1500 if( !is_object( $title ) ) {
1501 $title = Title
::newFromText( $name );
1502 if( !is_object( $title ) ) {
1503 $title = Title
::newFromText( '--error: link target missing--' );
1509 * Build an array that represents the sidebar(s), the navigation bar among them
1514 function buildSidebar() {
1515 global $parserMemc, $wgEnableSidebarCache;
1516 global $wgLang, $wgContLang;
1518 $fname = 'SkinTemplate::buildSidebar';
1520 wfProfileIn( $fname );
1522 $key = wfMemcKey( 'sidebar' );
1523 $cacheSidebar = $wgEnableSidebarCache &&
1524 ($wgLang->getCode() == $wgContLang->getCode());
1526 if ($cacheSidebar) {
1527 $cachedsidebar = $parserMemc->get( $key );
1528 if ($cachedsidebar!="") {
1529 wfProfileOut($fname);
1530 return $cachedsidebar;
1535 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1536 foreach ($lines as $line) {
1537 if (strpos($line, '*') !== 0)
1539 if (strpos($line, '**') !== 0) {
1540 $line = trim($line, '* ');
1543 if (strpos($line, '|') !== false) { // sanity check
1544 $line = explode( '|' , trim($line, '* '), 2 );
1545 $link = wfMsgForContent( $line[0] );
1548 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1550 if (wfEmptyMsg($line[0], $link))
1552 $href = self
::makeInternalOrExternalUrl( $link );
1553 $bar[$heading][] = array(
1556 'id' => 'n-' . strtr($line[1], ' ', '-'),
1559 } else { continue; }
1563 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1564 wfProfileOut( $fname );