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?1';
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 ) {
162 $fname = 'Skin::initPage';
163 wfProfileIn( $fname );
165 if( false !== $wgFavicon ) {
166 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
169 $this->addMetadataLinks($out);
171 $this->mRevisionId
= $out->mRevisionId
;
173 $this->preloadExistence();
175 wfProfileOut( $fname );
179 * Preload the existence of three commonly-requested pages in a single query
181 function preloadExistence() {
182 global $wgUser, $wgTitle;
184 if ( $wgTitle->isTalkPage() ) {
185 $otherTab = $wgTitle->getSubjectPage();
187 $otherTab = $wgTitle->getTalkPage();
189 $lb = new LinkBatch( array(
190 $wgUser->getUserPage(),
191 $wgUser->getTalkPage(),
197 function addMetadataLinks( &$out ) {
198 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
199 global $wgRightsPage, $wgRightsUrl;
201 if( $out->isArticleRelated() ) {
202 # note: buggy CC software only reads first "meta" link
203 if( $wgEnableCreativeCommonsRdf ) {
204 $out->addMetadataLink( array(
205 'title' => 'Creative Commons',
206 'type' => 'application/rdf+xml',
207 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
209 if( $wgEnableDublinCoreRdf ) {
210 $out->addMetadataLink( array(
211 'title' => 'Dublin Core',
212 'type' => 'application/rdf+xml',
213 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
217 if( $wgRightsPage ) {
218 $copy = Title
::newFromText( $wgRightsPage );
220 $copyright = $copy->getLocalURL();
223 if( !$copyright && $wgRightsUrl ) {
224 $copyright = $wgRightsUrl;
227 $out->addLink( array(
228 'rel' => 'copyright',
229 'href' => $copyright ) );
233 function outputPage( &$out ) {
234 global $wgDebugComments;
236 wfProfileIn( 'Skin::outputPage' );
237 $this->initPage( $out );
239 $out->out( $out->headElement() );
241 $out->out( "\n<body" );
242 $ops = $this->getBodyOptions();
243 foreach ( $ops as $name => $val ) {
244 $out->out( " $name='$val'" );
247 if ( $wgDebugComments ) {
248 $out->out( "<!-- Wiki debugging output:\n" .
249 $out->mDebugtext
. "-->\n" );
252 $out->out( $this->beforeContent() );
254 $out->out( $out->mBodytext
. "\n" );
256 $out->out( $this->afterContent() );
258 $out->out( $this->bottomScripts() );
260 $out->out( $out->reportTime() );
262 $out->out( "\n</body></html>" );
265 /*static*/ function makeGlobalVariablesScript( $data ) {
266 $r = '<script type= "' . $data['jsmimetype'] . '">
267 var skin = "' . Xml
::escapeJsString( $data['skinname'] ) . '";
268 var stylepath = "' . Xml
::escapeJsString( $data['stylepath'] ) . '";
270 var wgArticlePath = "' . Xml
::escapeJsString( $data['articlepath'] ) . '";
271 var wgScriptPath = "' . Xml
::escapeJsString( $data['scriptpath'] ) . '";
272 var wgServer = "' . Xml
::escapeJsString( $data['serverurl'] ) . '";
274 var wgCanonicalNamespace = "' . Xml
::escapeJsString( $data['nscanonical'] ) . '";
275 var wgPageName = "' . Xml
::escapeJsString( $data['titleprefixeddbkey'] ) . '";
276 var wgTitle = "' . Xml
::escapeJsString( $data['titletext'] ) . '";
277 var wgArticleId = ' . (int)$data['articleid'] . ';
279 var wgUserName = ' . ( $data['username'] == NULL ?
'null' : ( '"' . Xml
::escapeJsString( $data['username'] ) . '"' ) ) . ';
280 var wgUserLanguage = "' . Xml
::escapeJsString( $data['userlang'] ) . '";
281 var wgContentLanguage = "' . Xml
::escapeJsString( $data['lang'] ) . '";
288 function getHeadScripts() {
289 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
290 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
291 global $wgTitle, $wgCanonicalNamespaceNames;
293 $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
294 if ( $nsname === NULL ) $nsname = $wgTitle->getNsText();
297 'jsmimetype' => $wgJsMimeType,
298 'skinname' => $this->getSkinName(),
299 'stylepath' => $wgStylePath,
300 'articlepath' => $wgArticlePath,
301 'scriptpath' => $wgScriptPath,
302 'serverurl' => $wgServer,
303 'nscanonical' => $nsname,
304 'titleprefixeddbkey' => $wgTitle->getPrefixedDBKey(),
305 'titletext' => $wgTitle->getText(),
306 'articleid' => $wgTitle->getArticleId(),
307 'username' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
308 'userlang' => $wgLang->getCode(),
309 'lang' => $wgContLang->getCode(),
312 $r = Skin
::makeGlobalVariablesScript( $vars );
314 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
315 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
316 $userpage = $wgUser->getUserPage();
317 $userjs = htmlspecialchars( $this->makeUrl(
318 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
319 'action=raw&ctype='.$wgJsMimeType));
320 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
326 * To make it harder for someone to slip a user a fake
327 * user-JavaScript or user-CSS preview, a random token
328 * is associated with the login session. If it's not
329 * passed back with the preview request, we won't render
332 * @param string $action
336 function userCanPreview( $action ) {
337 global $wgTitle, $wgRequest, $wgUser;
339 if( $action != 'submit' )
341 if( !$wgRequest->wasPosted() )
343 if( !$wgTitle->userCanEditCssJsSubpage() )
345 return $wgUser->matchEditToken(
346 $wgRequest->getVal( 'wpEditToken' ) );
349 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
350 function getUserStylesheet() {
351 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
352 $sheet = $this->getStylesheet();
353 $action = $wgRequest->getText('action');
354 $s = "@import \"$wgStylePath/$sheet\";\n";
355 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
357 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
358 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
359 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
361 $s .= $this->doGetUserStyles();
366 * placeholder, returns generated js in monobook
368 function getUserJs() { return; }
371 * Return html code that include User stylesheets
373 function getUserStyles() {
374 $s = "<style type='text/css'>\n";
375 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
376 $s .= $this->getUserStylesheet();
377 $s .= "/*]]>*/ /* */\n";
383 * Some styles that are set by user through the user settings interface.
385 function doGetUserStyles() {
386 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
390 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
391 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
392 $s .= $wgRequest->getText('wpTextbox1');
394 $userpage = $wgUser->getUserPage();
395 $s.= '@import "'.$this->makeUrl(
396 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
397 'action=raw&ctype=text/css').'";'."\n";
401 return $s . $this->reallyDoGetUserStyles();
404 function reallyDoGetUserStyles() {
407 if (($undopt = $wgUser->getOption("underline")) != 2) {
408 $underline = $undopt ?
'underline' : 'none';
409 $s .= "a { text-decoration: $underline; }\n";
411 if( $wgUser->getOption( 'highlightbroken' ) ) {
412 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
415 a.new, #quickbar a.new,
416 a.stub, #quickbar a.stub {
418 text-decoration: inherit;
420 a.new:after, #quickbar a.new:after {
423 text-decoration: $underline;
425 a.stub:after, #quickbar a.stub:after {
428 text-decoration: $underline;
432 if( $wgUser->getOption( 'justify' ) ) {
433 $s .= "#article, #bodyContent { text-align: justify; }\n";
435 if( !$wgUser->getOption( 'showtoc' ) ) {
436 $s .= "#toc { display: none; }\n";
438 if( !$wgUser->getOption( 'editsection' ) ) {
439 $s .= ".editsection { display: none; }\n";
444 function getBodyOptions() {
445 global $wgUser, $wgTitle, $wgOut, $wgRequest;
447 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
449 if ( 0 != $wgTitle->getNamespace() ) {
450 $a = array( 'bgcolor' => '#ffffec' );
452 else $a = array( 'bgcolor' => '#FFFFFF' );
453 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
454 $wgTitle->userCanEdit() ) {
455 $t = wfMsg( 'editthispage' );
456 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
457 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
458 $a +
= array ('ondblclick' => $s);
461 $a['onload'] = $wgOut->getOnloadHandler();
462 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
463 if( $a['onload'] != '' ) {
466 $a['onload'] .= 'setupRightClickEdit()';
480 * This will be called immediately after the <body> tag. Split into
481 * two functions to make it easier to subclass.
483 function beforeContent() {
484 return $this->doBeforeContent();
487 function doBeforeContent() {
489 $fname = 'Skin::doBeforeContent';
490 wfProfileIn( $fname );
493 $qb = $this->qbSetting();
495 if( $langlinks = $this->otherLanguages() ) {
501 $borderhack = 'class="top"';
504 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
505 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
508 $left = ($qb == 1 ||
$qb == 3);
509 if($wgContLang->isRTL()) $left = !$left;
512 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
513 $this->logoText() . '</td>';
515 $s .= $this->getQuickbarCompensator( $rows );
517 $l = $wgContLang->isRTL() ?
'right' : 'left';
518 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
520 $s .= $this->topLinks() ;
521 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
523 $r = $wgContLang->isRTL() ?
"left" : "right";
524 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
525 $s .= $this->nameAndLogin();
526 $s .= "\n<br />" . $this->searchForm() . "</td>";
529 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
532 if ( $shove && !$left ) { # Right
533 $s .= $this->getQuickbarCompensator( $rows );
535 $s .= "</tr>\n</table>\n</div>\n";
536 $s .= "\n<div id='article'>\n";
538 $notice = wfGetSiteNotice();
540 $s .= "\n<div id='siteNotice'>$notice</div>\n";
542 $s .= $this->pageTitle();
543 $s .= $this->pageSubtitle() ;
544 $s .= $this->getCategories();
545 wfProfileOut( $fname );
550 function getCategoryLinks () {
551 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
554 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
557 $sep = wfMsgHtml( 'catseparator' );
559 // Use Unicode bidi embedding override characters,
560 // to make sure links don't smash each other up in ugly ways.
561 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
562 $embed = "<span dir='$dir'>";
564 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
566 $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks
));
567 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
568 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
571 # optional 'dmoz-like' category browser. Will be shown under the list
572 # of categories an article belong to
573 if($wgUseCategoryBrowser) {
574 $s .= '<br /><hr />';
576 # get a big array of the parents tree
577 $parenttree = $wgTitle->getParentCategoryTree();
578 # Skin object passed by reference cause it can not be
579 # accessed under the method subfunction drawCategoryBrowser
580 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
581 # Clean out bogus first entry and sort them
584 # Output one per line
585 $s .= implode("<br />\n", $tempout);
591 /** Render the array as a serie of links.
592 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
593 * @param &skin Object: skin passed by reference
594 * @return String separated by >, terminate with "\n"
596 function drawCategoryBrowser($tree, &$skin) {
598 foreach ($tree as $element => $parent) {
599 if (empty($parent)) {
600 # element start a new list
603 # grab the others elements
604 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
606 # add our current element to the list
607 $eltitle = Title
::NewFromText($element);
608 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
613 function getCategories() {
614 $catlinks=$this->getCategoryLinks();
615 if(!empty($catlinks)) {
616 return "<p class='catlinks'>{$catlinks}</p>";
620 function getQuickbarCompensator( $rows = 1 ) {
621 return "<td width='152' rowspan='{$rows}'> </td>";
625 * This gets called shortly before the \</body\> tag.
626 * @return String HTML to be put before \</body\>
628 function afterContent() {
629 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
630 return $printfooter . $this->doAfterContent();
634 * This gets called shortly before the \</body\> tag.
635 * @return String HTML-wrapped JS code to be put before \</body\>
637 function bottomScripts() {
638 global $wgJsMimeType;
639 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
642 /** @return string Retrievied from HTML text */
643 function printSource() {
645 $url = htmlspecialchars( $wgTitle->getFullURL() );
646 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
649 function printFooter() {
650 return "<p>" . $this->printSource() .
651 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
654 /** overloaded by derived classes */
655 function doAfterContent() { }
657 function pageTitleLinks() {
658 global $wgOut, $wgTitle, $wgUser, $wgRequest;
660 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
661 $action = $wgRequest->getText( 'action' );
663 $s = $this->printableLink();
664 $disclaimer = $this->disclaimerLink(); # may be empty
666 $s .= ' | ' . $disclaimer;
668 $privacy = $this->privacyLink(); # may be empty too
670 $s .= ' | ' . $privacy;
673 if ( $wgOut->isArticleRelated() ) {
674 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
675 $name = $wgTitle->getDBkey();
676 $image = new Image( $wgTitle );
677 if( $image->exists() ) {
678 $link = htmlspecialchars( $image->getURL() );
679 $style = $this->getInternalLinkAttributes( $link, $name );
680 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
684 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
685 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
686 wfMsg( 'currentrev' ) );
689 if ( $wgUser->getNewtalk() ) {
690 # do not show "You have new messages" text when we are viewing our
692 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
693 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
694 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
695 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
697 $wgOut->setSquidMaxage(0);
698 $wgOut->enableClientCache(false);
702 $undelete = $this->getUndeleteLink();
703 if( !empty( $undelete ) ) {
704 $s .= ' | '.$undelete;
709 function getUndeleteLink() {
710 global $wgUser, $wgTitle, $wgContLang, $action;
711 if( $wgUser->isAllowed( 'deletedhistory' ) &&
712 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
713 ($n = $wgTitle->isDeleted() ) )
715 if ( $wgUser->isAllowed( 'delete' ) ) {
716 $msg = 'thisisdeleted';
718 $msg = 'viewdeleted';
721 $this->makeKnownLink(
722 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
723 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
728 function printableLink() {
729 global $wgOut, $wgFeedClasses, $wgRequest;
731 $baseurl = $_SERVER['REQUEST_URI'];
732 if( strpos( '?', $baseurl ) == false ) {
737 $baseurl = htmlspecialchars( $baseurl );
738 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
740 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
741 if( $wgOut->isSyndicated() ) {
742 foreach( $wgFeedClasses as $format => $class ) {
743 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
744 $s .= " | <a href=\"$feedurl\">{$format}</a>";
750 function pageTitle() {
752 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
756 function pageSubtitle() {
759 $sub = $wgOut->getSubtitle();
761 global $wgExtraSubtitle;
762 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
764 $subpages = $this->subPageSubtitle();
765 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
766 $s = "<p class='subtitle'>{$sub}</p>\n";
770 function subPageSubtitle() {
771 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
773 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
774 $ptext=$wgTitle->getPrefixedText();
775 if(preg_match('/\//',$ptext)) {
776 $links = explode('/',$ptext);
779 foreach($links as $link) {
781 if ($c<count($links)) {
782 $growinglink .= $link;
783 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
784 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
788 $subpages .= '< ';
790 $subpages .= $getlink;
799 function nameAndLogin() {
800 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
802 $li = $wgContLang->specialPage( 'Userlogin' );
803 $lo = $wgContLang->specialPage( 'Userlogout' );
806 if ( $wgUser->isAnon() ) {
807 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
810 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
811 $wgLang->getNsText( NS_TALK
) );
813 $s .= $n . ' ('.$tl.')';
815 $s .= wfMsg('notloggedin');
818 $rt = $wgTitle->getPrefixedURL();
819 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
821 } else { $q = "returnto={$rt}"; }
823 $s .= "\n<br />" . $this->makeKnownLinkObj(
824 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
825 wfMsg( 'login' ), $q );
827 $n = $wgUser->getName();
828 $rt = $wgTitle->getPrefixedURL();
829 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
830 $wgLang->getNsText( NS_TALK
) );
834 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
835 $n ) . "{$tl}<br />" .
836 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
837 "returnto={$rt}" ) . ' | ' .
838 $this->specialLink( 'preferences' );
840 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
846 function getSearchLink() {
847 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
848 return $searchPage->getLocalURL();
851 function escapeSearchLink() {
852 return htmlspecialchars( $this->getSearchLink() );
855 function searchForm() {
857 $search = $wgRequest->getText( 'search' );
859 $s = '<form name="search" class="inline" method="post" action="'
860 . $this->escapeSearchLink() . "\">\n"
861 . '<input type="text" name="search" size="19" value="'
862 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
863 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" /> '
864 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
869 function topLinks() {
873 $s = $this->mainPageLink() . $sep
874 . $this->specialLink( 'recentchanges' );
876 if ( $wgOut->isArticleRelated() ) {
877 $s .= $sep . $this->editThisPage()
878 . $sep . $this->historyLink();
880 # Many people don't like this dropdown box
881 #$s .= $sep . $this->specialPagesList();
883 /* show links to different language variants */
884 global $wgDisableLangConversion, $wgContLang, $wgTitle;
885 $variants = $wgContLang->getVariants();
886 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
887 foreach( $variants as $code ) {
888 $varname = $wgContLang->getVariantname( $code );
889 if( $varname == 'disable' )
891 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
898 function bottomLinks() {
899 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
903 if ( $wgOut->isArticleRelated() ) {
904 $s .= '<strong>' . $this->editThisPage() . '</strong>';
905 if ( $wgUser->isLoggedIn() ) {
906 $s .= $sep . $this->watchThisPage();
908 $s .= $sep . $this->talkLink()
909 . $sep . $this->historyLink()
910 . $sep . $this->whatLinksHere()
911 . $sep . $this->watchPageLinksLink();
913 if ($wgUseTrackbacks)
914 $s .= $sep . $this->trackbackLink();
916 if ( $wgTitle->getNamespace() == NS_USER
917 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
920 $id=User
::idFromName($wgTitle->getText());
921 $ip=User
::isIP($wgTitle->getText());
923 if($id ||
$ip) { # both anons and non-anons have contri list
924 $s .= $sep . $this->userContribsLink();
926 if( $this->showEmailUser( $id ) ) {
927 $s .= $sep . $this->emailUserLink();
930 if ( $wgTitle->getArticleId() ) {
932 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
933 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
934 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
936 $s .= "<br />\n" . $this->otherLanguages();
941 function pageStats() {
942 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
943 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
945 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
946 if ( ! $wgOut->isArticle() ) { return ''; }
947 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
948 if ( 0 == $wgArticle->getID() ) { return ''; }
951 if ( !$wgDisableCounters ) {
952 $count = $wgLang->formatNum( $wgArticle->getCount() );
954 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
958 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
959 require_once('Credits.php');
960 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
962 $s .= $this->lastModified();
965 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
966 $dbr =& wfGetDB( DB_SLAVE
);
967 extract( $dbr->tableNames( 'watchlist' ) );
968 $sql = "SELECT COUNT(*) AS n FROM $watchlist
969 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
970 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
971 $res = $dbr->query( $sql, 'Skin::pageStats');
972 $x = $dbr->fetchObject( $res );
973 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
976 return $s . ' ' . $this->getCopyright();
979 function getCopyright( $type = 'detect' ) {
980 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
982 if ( $type == 'detect' ) {
983 $oldid = $wgRequest->getVal( 'oldid' );
984 $diff = $wgRequest->getVal( 'diff' );
986 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
993 if ( $type == 'history' ) {
994 $msg = 'history_copyright';
1000 if( $wgRightsPage ) {
1001 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1002 } elseif( $wgRightsUrl ) {
1003 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1008 $out .= wfMsgForContent( $msg, $link );
1012 function getCopyrightIcon() {
1013 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1015 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1016 $out = $wgCopyrightIcon;
1017 } else if ( $wgRightsIcon ) {
1018 $icon = htmlspecialchars( $wgRightsIcon );
1019 if ( $wgRightsUrl ) {
1020 $url = htmlspecialchars( $wgRightsUrl );
1021 $out .= '<a href="'.$url.'">';
1023 $text = htmlspecialchars( $wgRightsText );
1024 $out .= "<img src=\"$icon\" alt='$text' />";
1025 if ( $wgRightsUrl ) {
1032 function getPoweredBy() {
1033 global $wgStylePath;
1034 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1035 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1039 function lastModified() {
1040 global $wgLang, $wgArticle, $wgLoadBalancer;
1042 $timestamp = $wgArticle->getTimestamp();
1044 $d = $wgLang->timeanddate( $timestamp, true );
1045 $s = ' ' . wfMsg( 'lastmodified', $d );
1049 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1050 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1055 function logoText( $align = '' ) {
1056 if ( '' != $align ) { $a = " align='{$align}'"; }
1059 $mp = wfMsg( 'mainpage' );
1060 $titleObj = Title
::newFromText( $mp );
1061 if ( is_object( $titleObj ) ) {
1062 $url = $titleObj->escapeLocalURL();
1067 $logourl = $this->getLogo();
1068 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1073 * show a drop-down box of special pages
1074 * @TODO crash bug913. Need to be rewrote completly.
1076 function specialPagesList() {
1077 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1078 require_once('SpecialPage.php');
1080 $pages = SpecialPage
::getPages();
1082 // special pages without access restriction
1083 foreach ( $pages[''] as $name => $page ) {
1084 $a[$name] = $page->getDescription();
1087 // Other special pages that are restricted.
1088 foreach ( $pages['restricted'] as $name => $page ) {
1089 if( $wgUser->isAllowed( $page->getRestriction() ) ) {
1090 $a[$name] = $page->getDescription();
1094 $go = wfMsg( 'go' );
1095 $sp = wfMsg( 'specialpages' );
1096 $spp = $wgContLang->specialPage( 'Specialpages' );
1098 $s = '<form id="specialpages" method="get" class="inline" ' .
1099 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1100 $s .= "<select name=\"wpDropdown\">\n";
1101 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1104 foreach ( $a as $name => $desc ) {
1105 $p = $wgContLang->specialPage( $name );
1106 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1108 $s .= "</select>\n";
1109 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1114 function mainPageLink() {
1115 $mp = wfMsgForContent( 'mainpage' );
1116 $mptxt = wfMsg( 'mainpage');
1117 $s = $this->makeKnownLink( $mp, $mptxt );
1121 function copyrightLink() {
1122 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1123 wfMsg( 'copyrightpagename' ) );
1127 function privacyLink() {
1128 $privacy = wfMsg( 'privacy' );
1129 if ($privacy == '-') {
1132 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1136 function aboutLink() {
1137 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1138 wfMsg( 'aboutsite' ) );
1142 function disclaimerLink() {
1143 $disclaimers = wfMsg( 'disclaimers' );
1144 if ($disclaimers == '-') {
1147 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1152 function editThisPage() {
1153 global $wgOut, $wgTitle;
1155 if ( ! $wgOut->isArticleRelated() ) {
1156 $s = wfMsg( 'protectedpage' );
1158 if ( $wgTitle->userCanEdit() ) {
1159 $t = wfMsg( 'editthispage' );
1161 $t = wfMsg( 'viewsource' );
1164 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1170 * Return URL options for the 'edit page' link.
1171 * This may include an 'oldid' specifier, if the current page view is such.
1176 function editUrlOptions() {
1179 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1180 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1182 return "action=edit";
1186 function deleteThisPage() {
1187 global $wgUser, $wgTitle, $wgRequest;
1189 $diff = $wgRequest->getVal( 'diff' );
1190 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1191 $t = wfMsg( 'deletethispage' );
1193 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1200 function protectThisPage() {
1201 global $wgUser, $wgTitle, $wgRequest;
1203 $diff = $wgRequest->getVal( 'diff' );
1204 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1205 if ( $wgTitle->isProtected() ) {
1206 $t = wfMsg( 'unprotectthispage' );
1207 $q = 'action=unprotect';
1209 $t = wfMsg( 'protectthispage' );
1210 $q = 'action=protect';
1212 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1219 function watchThisPage() {
1220 global $wgOut, $wgTitle;
1222 if ( $wgOut->isArticleRelated() ) {
1223 if ( $wgTitle->userIsWatching() ) {
1224 $t = wfMsg( 'unwatchthispage' );
1225 $q = 'action=unwatch';
1227 $t = wfMsg( 'watchthispage' );
1228 $q = 'action=watch';
1230 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1232 $s = wfMsg( 'notanarticle' );
1237 function moveThisPage() {
1240 if ( $wgTitle->userCanMove() ) {
1241 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1242 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1244 // no message if page is protected - would be redundant
1249 function historyLink() {
1252 return $this->makeKnownLinkObj( $wgTitle,
1253 wfMsg( 'history' ), 'action=history' );
1256 function whatLinksHere() {
1259 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1260 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1263 function userContribsLink() {
1266 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1267 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1270 function showEmailUser( $id ) {
1271 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1272 return $wgEnableEmail &&
1273 $wgEnableUserEmail &&
1274 $wgUser->isLoggedIn() && # show only to signed in users
1275 0 != $id; # we can only email to non-anons ..
1276 # '' != $id->getEmail() && # who must have an email address stored ..
1277 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1278 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1281 function emailUserLink() {
1284 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1285 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1288 function watchPageLinksLink() {
1289 global $wgOut, $wgTitle;
1291 if ( ! $wgOut->isArticleRelated() ) {
1292 return '(' . wfMsg( 'notanarticle' ) . ')';
1294 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1295 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1296 'target=' . $wgTitle->getPrefixedURL() );
1300 function trackbackLink() {
1303 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1304 . wfMsg('trackbacklink') . "</a>";
1307 function otherLanguages() {
1308 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1310 if ( $wgHideInterlanguageLinks ) {
1314 $a = $wgOut->getLanguageLinks();
1315 if ( 0 == count( $a ) ) {
1319 $s = wfMsg( 'otherlanguages' ) . ': ';
1321 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1322 foreach( $a as $l ) {
1323 if ( ! $first ) { $s .= ' | '; }
1326 $nt = Title
::newFromText( $l );
1327 $url = $nt->escapeFullURL();
1328 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1330 if ( '' == $text ) { $text = $l; }
1331 $style = $this->getExternalLinkAttributes( $l, $text );
1332 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1334 if($wgContLang->isRTL()) $s .= '</span>';
1338 function bugReportsLink() {
1339 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1340 wfMsg( 'bugreports' ) );
1344 function dateLink() {
1345 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1346 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1348 $id = $t1->getArticleID();
1351 $s = $this->makeBrokenLink( $t1->getText() );
1353 $s = $this->makeKnownLink( $t1->getText() );
1357 $id = $t2->getArticleID();
1360 $s .= $this->makeBrokenLink( $t2->getText() );
1362 $s .= $this->makeKnownLink( $t2->getText() );
1367 function talkLink() {
1370 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1371 # No discussion links for special pages
1375 if( $wgTitle->isTalkPage() ) {
1376 $link = $wgTitle->getSubjectPage();
1377 switch( $link->getNamespace() ) {
1379 $text = wfMsg('articlepage');
1382 $text = wfMsg('userpage');
1385 $text = wfMsg('projectpage');
1388 $text = wfMsg('imagepage');
1391 $text= wfMsg('articlepage');
1394 $link = $wgTitle->getTalkPage();
1395 $text = wfMsg( 'talkpage' );
1398 $s = $this->makeLinkObj( $link, $text );
1403 function commentLink() {
1404 global $wgTitle, $wgOut;
1406 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1410 # __NEWSECTIONLINK___ changes behaviour here
1411 # If it's present, the link points to this page, otherwise
1412 # it points to the talk page
1413 if( $wgTitle->isTalkPage() ) {
1415 } elseif( $wgOut->showNewSectionLink() ) {
1418 $title =& $wgTitle->getTalkPage();
1421 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1424 /* these are used extensively in SkinTemplate, but also some other places */
1425 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1426 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1427 return $title->getLocalURL( $urlaction );
1430 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1431 $title = Title
::newFromText( wfMsgForContent($name) );
1432 $this->checkTitle($title, $name);
1433 return $title->getLocalURL( $urlaction );
1436 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1437 $title = Title
::newFromText( $name );
1438 $this->checkTitle($title, $name);
1439 return $title->getLocalURL( $urlaction );
1442 # If url string starts with http, consider as external URL, else
1444 /*static*/ function makeInternalOrExternalUrl( $name ) {
1445 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1448 return $this->makeUrl( $name );
1452 # this can be passed the NS number as defined in Language.php
1453 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN
) {
1454 $title = Title
::makeTitleSafe( $namespace, $name );
1455 $this->checkTitle($title, $name);
1456 return $title->getLocalURL( $urlaction );
1459 /* these return an array with the 'href' and boolean 'exists' */
1460 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1461 $title = Title
::newFromText( $name );
1462 $this->checkTitle($title, $name);
1464 'href' => $title->getLocalURL( $urlaction ),
1465 'exists' => $title->getArticleID() != 0?
true:false
1470 * Make URL details where the article exists (or at least it's convenient to think so)
1472 function makeKnownUrlDetails( $name, $urlaction='' ) {
1473 $title = Title
::newFromText( $name );
1474 $this->checkTitle($title, $name);
1476 'href' => $title->getLocalURL( $urlaction ),
1481 # make sure we have some title to operate on
1482 /*static*/ function checkTitle ( &$title, &$name ) {
1483 if(!is_object($title)) {
1484 $title = Title
::newFromText( $name );
1485 if(!is_object($title)) {
1486 $title = Title
::newFromText( '--error: link target missing--' );
1492 * Build an array that represents the sidebar(s), the navigation bar among them
1497 function buildSidebar() {
1498 global $wgDBname, $parserMemc, $wgEnableSidebarCache;
1499 global $wgLang, $wgContLang;
1501 $fname = 'SkinTemplate::buildSidebar';
1503 wfProfileIn( $fname );
1505 $key = "{$wgDBname}:sidebar";
1506 $cacheSidebar = $wgEnableSidebarCache &&
1507 ($wgLang->getCode() == $wgContLang->getCode());
1509 if ($cacheSidebar) {
1510 $cachedsidebar = $parserMemc->get( $key );
1511 if ($cachedsidebar!="") {
1512 wfProfileOut($fname);
1513 return $cachedsidebar;
1518 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1519 foreach ($lines as $line) {
1520 if (strpos($line, '*') !== 0)
1522 if (strpos($line, '**') !== 0) {
1523 $line = trim($line, '* ');
1526 if (strpos($line, '|') !== false) { // sanity check
1527 $line = explode( '|' , trim($line, '* '), 2 );
1528 $link = wfMsgForContent( $line[0] );
1531 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1533 if (wfEmptyMsg($line[0], $link))
1535 $href = $this->makeInternalOrExternalUrl( $link );
1536 $bar[$heading][] = array(
1539 'id' => 'n-' . strtr($line[1], ' ', '-'),
1542 } else { continue; }
1546 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1547 wfProfileOut( $fname );