dc0a998416be988683ace3fd8a0f70c3e8ae0126
2 if ( ! defined( 'MEDIAWIKI' ) )
11 # Get a list of available skins
12 # Build using the regular expression '^(.*).php$'
13 # Array keys are all lower case, array value keep the case used by filename
17 * The main skin class that provide methods and properties for all other skins.
18 * This base class is also the "Standard" skin.
21 class Skin
extends Linker
{
25 var $lastdate, $lastline;
26 var $rc_cache ; # Cache for Enhanced Recent Changes
27 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
31 /** Constructor, call parent constructor */
32 function Skin() { parent
::Linker(); }
35 * Fetch the set of available skins.
36 * @return array of strings
39 function getSkinNames() {
40 global $wgValidSkinNames;
41 if (!is_array($wgValidSkinNames)) {
42 Skin
::initializeSkinNames();
44 return $wgValidSkinNames;
48 * Initializes set of available skins.
49 * @return array of strings - skin names
53 function initializeSkinNames() {
54 global $wgStyleDirectory, $wgValidSkinNames;
55 $skinDir = dir( $wgStyleDirectory );
57 # while code from www.php.net
58 while (false !== ($file = $skinDir->read())) {
59 // Skip non-PHP files, hidden files, and '.dep' includes
60 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
62 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
71 * Normalize a skin preference value to a form that can be loaded.
72 * If a skin can't be found, it will fall back to the configured
73 * default (or the old 'Classic' skin if that's broken).
78 function normalizeKey( $key ) {
79 global $wgDefaultSkin;
80 $skinNames = Skin
::getSkinNames();
83 // Don't return the default immediately;
84 // in a misconfiguration we need to fall back.
85 $key = $wgDefaultSkin;
88 if( isset( $skinNames[$key] ) ) {
92 // Older versions of the software used a numeric setting
93 // in the user preferences.
99 if( isset( $fallback[$key] ) ){
100 $key = $fallback[$key];
103 if( isset( $skinNames[$key] ) ) {
106 // The old built-in skin
112 * Factory method for loading a skin of a given type
113 * @param string $key 'monobook', 'standard', etc
117 function &newFromKey( $key ) {
118 $key = Skin
::normalizeKey( $key );
120 $skinNames = Skin
::getSkinNames();
121 $skinName = $skinNames[$key];
125 # Grab the skin class and initialise it.
126 wfSuppressWarnings();
127 // Preload base classes to work around APC/PHP5 bug
128 include_once( $IP.'/skins/'.$skinName.'.deps.php' );
130 require_once( $IP.'/skins/'.$skinName.'.php' );
132 # Check if we got if not failback to default skin
133 $className = 'Skin'.$skinName;
134 if( !class_exists( $className ) ) {
135 # DO NOT die if the class isn't found. This breaks maintenance
136 # scripts and can cause a user account to be unrecoverable
137 # except by SQL manipulation if a previously valid skin name
138 # is no longer valid.
139 wfDebug( "Skin class does not exist: $className\n" );
140 $className = 'SkinStandard';
141 require_once( $IP.'/skins/Standard.php' );
143 $skin =& new $className;
147 /** @return string path to the skin stylesheet */
148 function getStylesheet() {
149 return 'common/wikistandard.css?1';
152 /** @return string skin name */
153 function getSkinName() {
157 function qbSetting() {
158 global $wgOut, $wgUser;
160 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
161 $q = $wgUser->getOption( 'quickbar' );
162 if ( '' == $q ) { $q = 0; }
166 function initPage( &$out ) {
169 $fname = 'Skin::initPage';
170 wfProfileIn( $fname );
172 if( false !== $wgFavicon ) {
173 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
176 $this->addMetadataLinks($out);
178 $this->mRevisionId
= $out->mRevisionId
;
180 $this->preloadExistence();
182 wfProfileOut( $fname );
186 * Preload the existence of three commonly-requested pages in a single query
188 function preloadExistence() {
189 global $wgUser, $wgTitle;
191 if ( $wgTitle->isTalkPage() ) {
192 $otherTab = $wgTitle->getSubjectPage();
194 $otherTab = $wgTitle->getTalkPage();
196 $lb = new LinkBatch( array(
197 $wgUser->getUserPage(),
198 $wgUser->getTalkPage(),
204 function addMetadataLinks( &$out ) {
205 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
206 global $wgRightsPage, $wgRightsUrl;
208 if( $out->isArticleRelated() ) {
209 # note: buggy CC software only reads first "meta" link
210 if( $wgEnableCreativeCommonsRdf ) {
211 $out->addMetadataLink( array(
212 'title' => 'Creative Commons',
213 'type' => 'application/rdf+xml',
214 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
216 if( $wgEnableDublinCoreRdf ) {
217 $out->addMetadataLink( array(
218 'title' => 'Dublin Core',
219 'type' => 'application/rdf+xml',
220 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
224 if( $wgRightsPage ) {
225 $copy = Title
::newFromText( $wgRightsPage );
227 $copyright = $copy->getLocalURL();
230 if( !$copyright && $wgRightsUrl ) {
231 $copyright = $wgRightsUrl;
234 $out->addLink( array(
235 'rel' => 'copyright',
236 'href' => $copyright ) );
240 function outputPage( &$out ) {
241 global $wgDebugComments;
243 wfProfileIn( 'Skin::outputPage' );
244 $this->initPage( $out );
246 $out->out( $out->headElement() );
248 $out->out( "\n<body" );
249 $ops = $this->getBodyOptions();
250 foreach ( $ops as $name => $val ) {
251 $out->out( " $name='$val'" );
254 if ( $wgDebugComments ) {
255 $out->out( "<!-- Wiki debugging output:\n" .
256 $out->mDebugtext
. "-->\n" );
259 $out->out( $this->beforeContent() );
261 $out->out( $out->mBodytext
. "\n" );
263 $out->out( $this->afterContent() );
265 $out->out( $out->reportTime() );
267 $out->out( "\n</body></html>" );
270 function getHeadScripts() {
271 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
272 $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
273 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
274 $userpage = $wgUser->getUserPage();
275 $userjs = htmlspecialchars( $this->makeUrl(
276 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
277 'action=raw&ctype='.$wgJsMimeType));
278 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
284 * To make it harder for someone to slip a user a fake
285 * user-JavaScript or user-CSS preview, a random token
286 * is associated with the login session. If it's not
287 * passed back with the preview request, we won't render
290 * @param string $action
294 function userCanPreview( $action ) {
295 global $wgTitle, $wgRequest, $wgUser;
297 if( $action != 'submit' )
299 if( !$wgRequest->wasPosted() )
301 if( !$wgTitle->userCanEditCssJsSubpage() )
303 return $wgUser->matchEditToken(
304 $wgRequest->getVal( 'wpEditToken' ) );
307 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
308 function getUserStylesheet() {
309 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
310 $sheet = $this->getStylesheet();
311 $action = $wgRequest->getText('action');
312 $s = "@import \"$wgStylePath/$sheet\";\n";
313 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
315 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
316 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
317 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
319 $s .= $this->doGetUserStyles();
324 * placeholder, returns generated js in monobook
326 function getUserJs() { return; }
329 * Return html code that include User stylesheets
331 function getUserStyles() {
332 $s = "<style type='text/css'>\n";
333 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
334 $s .= $this->getUserStylesheet();
335 $s .= "/*]]>*/ /* */\n";
341 * Some styles that are set by user through the user settings interface.
343 function doGetUserStyles() {
344 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
348 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
349 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
350 $s .= $wgRequest->getText('wpTextbox1');
352 $userpage = $wgUser->getUserPage();
353 $s.= '@import "'.$this->makeUrl(
354 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
355 'action=raw&ctype=text/css').'";'."\n";
359 return $s . $this->reallyDoGetUserStyles();
362 function reallyDoGetUserStyles() {
365 if (($undopt = $wgUser->getOption("underline")) != 2) {
366 $underline = $undopt ?
'underline' : 'none';
367 $s .= "a { text-decoration: $underline; }\n";
369 if( $wgUser->getOption( 'highlightbroken' ) ) {
370 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
373 a.new, #quickbar a.new,
374 a.stub, #quickbar a.stub {
376 text-decoration: inherit;
378 a.new:after, #quickbar a.new:after {
381 text-decoration: $underline;
383 a.stub:after, #quickbar a.stub:after {
386 text-decoration: $underline;
390 if( $wgUser->getOption( 'justify' ) ) {
391 $s .= "#article, #bodyContent { text-align: justify; }\n";
393 if( !$wgUser->getOption( 'showtoc' ) ) {
394 $s .= "#toc { display: none; }\n";
396 if( !$wgUser->getOption( 'editsection' ) ) {
397 $s .= ".editsection { display: none; }\n";
402 function getBodyOptions() {
403 global $wgUser, $wgTitle, $wgOut, $wgRequest;
405 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
407 if ( 0 != $wgTitle->getNamespace() ) {
408 $a = array( 'bgcolor' => '#ffffec' );
410 else $a = array( 'bgcolor' => '#FFFFFF' );
411 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
412 $wgTitle->userCanEdit() ) {
413 $t = wfMsg( 'editthispage' );
414 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
415 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
416 $a +
= array ('ondblclick' => $s);
419 $a['onload'] = $wgOut->getOnloadHandler();
420 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
421 if( $a['onload'] != '' ) {
424 $a['onload'] .= 'setupRightClickEdit()';
438 * This will be called immediately after the <body> tag. Split into
439 * two functions to make it easier to subclass.
441 function beforeContent() {
442 return $this->doBeforeContent();
445 function doBeforeContent() {
447 $fname = 'Skin::doBeforeContent';
448 wfProfileIn( $fname );
451 $qb = $this->qbSetting();
453 if( $langlinks = $this->otherLanguages() ) {
459 $borderhack = 'class="top"';
462 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
463 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
466 $left = ($qb == 1 ||
$qb == 3);
467 if($wgContLang->isRTL()) $left = !$left;
470 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
471 $this->logoText() . '</td>';
473 $s .= $this->getQuickbarCompensator( $rows );
475 $l = $wgContLang->isRTL() ?
'right' : 'left';
476 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
478 $s .= $this->topLinks() ;
479 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
481 $r = $wgContLang->isRTL() ?
"left" : "right";
482 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
483 $s .= $this->nameAndLogin();
484 $s .= "\n<br />" . $this->searchForm() . "</td>";
487 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
490 if ( $shove && !$left ) { # Right
491 $s .= $this->getQuickbarCompensator( $rows );
493 $s .= "</tr>\n</table>\n</div>\n";
494 $s .= "\n<div id='article'>\n";
496 $notice = wfGetSiteNotice();
498 $s .= "\n<div id='siteNotice'>$notice</div>\n";
500 $s .= $this->pageTitle();
501 $s .= $this->pageSubtitle() ;
502 $s .= $this->getCategories();
503 wfProfileOut( $fname );
508 function getCategoryLinks () {
509 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
512 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
515 $sep = wfMsgHtml( 'catseparator' );
517 // Use Unicode bidi embedding override characters,
518 // to make sure links don't smash each other up in ugly ways.
519 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
520 $embed = "<span dir='$dir'>";
522 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
524 $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks
));
525 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
526 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
529 # optional 'dmoz-like' category browser. Will be shown under the list
530 # of categories an article belong to
531 if($wgUseCategoryBrowser) {
532 $s .= '<br /><hr />';
534 # get a big array of the parents tree
535 $parenttree = $wgTitle->getParentCategoryTree();
536 # Skin object passed by reference cause it can not be
537 # accessed under the method subfunction drawCategoryBrowser
538 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
539 # Clean out bogus first entry and sort them
542 # Output one per line
543 $s .= implode("<br />\n", $tempout);
549 /** Render the array as a serie of links.
550 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
551 * @param &skin Object: skin passed by reference
552 * @return String separated by >, terminate with "\n"
554 function drawCategoryBrowser($tree, &$skin) {
556 foreach ($tree as $element => $parent) {
557 if (empty($parent)) {
558 # element start a new list
561 # grab the others elements
562 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
564 # add our current element to the list
565 $eltitle = Title
::NewFromText($element);
566 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
571 function getCategories() {
572 $catlinks=$this->getCategoryLinks();
573 if(!empty($catlinks)) {
574 return "<p class='catlinks'>{$catlinks}</p>";
578 function getQuickbarCompensator( $rows = 1 ) {
579 return "<td width='152' rowspan='{$rows}'> </td>";
583 * This gets called immediately before the \</body\> tag.
584 * @return String HTML to be put after \</body\> ???
586 function afterContent() {
587 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
588 return $printfooter . $this->doAfterContent();
591 /** @return string Retrievied from HTML text */
592 function printSource() {
594 $url = htmlspecialchars( $wgTitle->getFullURL() );
595 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
598 function printFooter() {
599 return "<p>" . $this->printSource() .
600 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
603 /** overloaded by derived classes */
604 function doAfterContent() { }
606 function pageTitleLinks() {
607 global $wgOut, $wgTitle, $wgUser, $wgRequest;
609 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
610 $action = $wgRequest->getText( 'action' );
612 $s = $this->printableLink();
613 $disclaimer = $this->disclaimerLink(); # may be empty
615 $s .= ' | ' . $disclaimer;
617 $privacy = $this->privacyLink(); # may be empty too
619 $s .= ' | ' . $privacy;
622 if ( $wgOut->isArticleRelated() ) {
623 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
624 $name = $wgTitle->getDBkey();
625 $image = new Image( $wgTitle );
626 if( $image->exists() ) {
627 $link = htmlspecialchars( $image->getURL() );
628 $style = $this->getInternalLinkAttributes( $link, $name );
629 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
633 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
634 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
635 wfMsg( 'currentrev' ) );
638 if ( $wgUser->getNewtalk() ) {
639 # do not show "You have new messages" text when we are viewing our
641 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
642 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
643 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
644 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
646 $wgOut->setSquidMaxage(0);
647 $wgOut->enableClientCache(false);
651 $undelete = $this->getUndeleteLink();
652 if( !empty( $undelete ) ) {
653 $s .= ' | '.$undelete;
658 function getUndeleteLink() {
659 global $wgUser, $wgTitle, $wgContLang, $action;
660 if( $wgUser->isAllowed( 'deletedhistory' ) &&
661 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
662 ($n = $wgTitle->isDeleted() ) )
664 if ( $wgUser->isAllowed( 'delete' ) ) {
665 $msg = 'thisisdeleted';
667 $msg = 'viewdeleted';
670 $this->makeKnownLink(
671 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
672 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
677 function printableLink() {
678 global $wgOut, $wgFeedClasses, $wgRequest;
680 $baseurl = $_SERVER['REQUEST_URI'];
681 if( strpos( '?', $baseurl ) == false ) {
686 $baseurl = htmlspecialchars( $baseurl );
687 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
689 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
690 if( $wgOut->isSyndicated() ) {
691 foreach( $wgFeedClasses as $format => $class ) {
692 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
693 $s .= " | <a href=\"$feedurl\">{$format}</a>";
699 function pageTitle() {
701 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
705 function pageSubtitle() {
708 $sub = $wgOut->getSubtitle();
710 global $wgExtraSubtitle;
711 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
713 $subpages = $this->subPageSubtitle();
714 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
715 $s = "<p class='subtitle'>{$sub}</p>\n";
719 function subPageSubtitle() {
720 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
722 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
723 $ptext=$wgTitle->getPrefixedText();
724 if(preg_match('/\//',$ptext)) {
725 $links = explode('/',$ptext);
728 foreach($links as $link) {
730 if ($c<count($links)) {
731 $growinglink .= $link;
732 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
733 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
737 $subpages .= '< ';
739 $subpages .= $getlink;
748 function nameAndLogin() {
749 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
751 $li = $wgContLang->specialPage( 'Userlogin' );
752 $lo = $wgContLang->specialPage( 'Userlogout' );
755 if ( $wgUser->isAnon() ) {
756 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
757 $n = ProxyTools
::getIP();
759 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
760 $wgLang->getNsText( NS_TALK
) );
762 $s .= $n . ' ('.$tl.')';
764 $s .= wfMsg('notloggedin');
767 $rt = $wgTitle->getPrefixedURL();
768 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
770 } else { $q = "returnto={$rt}"; }
772 $s .= "\n<br />" . $this->makeKnownLinkObj(
773 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
774 wfMsg( 'login' ), $q );
776 $n = $wgUser->getName();
777 $rt = $wgTitle->getPrefixedURL();
778 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
779 $wgLang->getNsText( NS_TALK
) );
783 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
784 $n ) . "{$tl}<br />" .
785 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
786 "returnto={$rt}" ) . ' | ' .
787 $this->specialLink( 'preferences' );
789 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
795 function getSearchLink() {
796 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
797 return $searchPage->getLocalURL();
800 function escapeSearchLink() {
801 return htmlspecialchars( $this->getSearchLink() );
804 function searchForm() {
806 $search = $wgRequest->getText( 'search' );
808 $s = '<form name="search" class="inline" method="post" action="'
809 . $this->escapeSearchLink() . "\">\n"
810 . '<input type="text" name="search" size="19" value="'
811 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
812 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" /> '
813 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
818 function topLinks() {
822 $s = $this->mainPageLink() . $sep
823 . $this->specialLink( 'recentchanges' );
825 if ( $wgOut->isArticleRelated() ) {
826 $s .= $sep . $this->editThisPage()
827 . $sep . $this->historyLink();
829 # Many people don't like this dropdown box
830 #$s .= $sep . $this->specialPagesList();
832 /* show links to different language variants */
833 global $wgDisableLangConversion, $wgContLang, $wgTitle;
834 $variants = $wgContLang->getVariants();
835 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
836 foreach( $variants as $code ) {
837 $varname = $wgContLang->getVariantname( $code );
838 if( $varname == 'disable' )
840 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
847 function bottomLinks() {
848 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
852 if ( $wgOut->isArticleRelated() ) {
853 $s .= '<strong>' . $this->editThisPage() . '</strong>';
854 if ( $wgUser->isLoggedIn() ) {
855 $s .= $sep . $this->watchThisPage();
857 $s .= $sep . $this->talkLink()
858 . $sep . $this->historyLink()
859 . $sep . $this->whatLinksHere()
860 . $sep . $this->watchPageLinksLink();
862 if ($wgUseTrackbacks)
863 $s .= $sep . $this->trackbackLink();
865 if ( $wgTitle->getNamespace() == NS_USER
866 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
869 $id=User
::idFromName($wgTitle->getText());
870 $ip=User
::isIP($wgTitle->getText());
872 if($id ||
$ip) { # both anons and non-anons have contri list
873 $s .= $sep . $this->userContribsLink();
875 if( $this->showEmailUser( $id ) ) {
876 $s .= $sep . $this->emailUserLink();
879 if ( $wgTitle->getArticleId() ) {
881 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
882 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
883 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
885 $s .= "<br />\n" . $this->otherLanguages();
890 function pageStats() {
891 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
892 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
894 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
895 if ( ! $wgOut->isArticle() ) { return ''; }
896 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
897 if ( 0 == $wgArticle->getID() ) { return ''; }
900 if ( !$wgDisableCounters ) {
901 $count = $wgLang->formatNum( $wgArticle->getCount() );
903 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
907 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
908 $s .= ' ' . Credits
::getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
910 $s .= $this->lastModified();
913 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
914 $dbr =& wfGetDB( DB_SLAVE
);
915 extract( $dbr->tableNames( 'watchlist' ) );
916 $sql = "SELECT COUNT(*) AS n FROM $watchlist
917 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
918 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
919 $res = $dbr->query( $sql, 'Skin::pageStats');
920 $x = $dbr->fetchObject( $res );
921 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
924 return $s . ' ' . $this->getCopyright();
927 function getCopyright( $type = 'detect' ) {
928 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
930 if ( $type == 'detect' ) {
931 $oldid = $wgRequest->getVal( 'oldid' );
932 $diff = $wgRequest->getVal( 'diff' );
934 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
941 if ( $type == 'history' ) {
942 $msg = 'history_copyright';
948 if( $wgRightsPage ) {
949 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
950 } elseif( $wgRightsUrl ) {
951 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
956 $out .= wfMsgForContent( $msg, $link );
960 function getCopyrightIcon() {
961 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
963 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
964 $out = $wgCopyrightIcon;
965 } else if ( $wgRightsIcon ) {
966 $icon = htmlspecialchars( $wgRightsIcon );
967 if ( $wgRightsUrl ) {
968 $url = htmlspecialchars( $wgRightsUrl );
969 $out .= '<a href="'.$url.'">';
971 $text = htmlspecialchars( $wgRightsText );
972 $out .= "<img src=\"$icon\" alt='$text' />";
973 if ( $wgRightsUrl ) {
980 function getPoweredBy() {
982 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
983 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
987 function lastModified() {
988 global $wgLang, $wgArticle, $wgLoadBalancer;
990 $timestamp = $wgArticle->getTimestamp();
992 $d = $wgLang->timeanddate( $timestamp, true );
993 $s = ' ' . wfMsg( 'lastmodified', $d );
997 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
998 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1003 function logoText( $align = '' ) {
1004 if ( '' != $align ) { $a = " align='{$align}'"; }
1007 $mp = wfMsg( 'mainpage' );
1008 $titleObj = Title
::newFromText( $mp );
1009 if ( is_object( $titleObj ) ) {
1010 $url = $titleObj->escapeLocalURL();
1015 $logourl = $this->getLogo();
1016 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1021 * show a drop-down box of special pages
1022 * @TODO crash bug913. Need to be rewrote completly.
1024 function specialPagesList() {
1025 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
1027 $pages = SpecialPage
::getPages();
1029 // special pages without access restriction
1030 foreach ( $pages[''] as $name => $page ) {
1031 $a[$name] = $page->getDescription();
1034 // Other special pages that are restricted.
1035 // Copied from SpecialSpecialpages.php
1036 foreach($wgAvailableRights as $right) {
1037 if( $wgUser->isAllowed($right) ) {
1038 /** Add all pages for this right */
1039 if(isset($pages[$right])) {
1040 foreach($pages[$right] as $name => $page) {
1041 $a[$name] = $page->getDescription();
1047 $go = wfMsg( 'go' );
1048 $sp = wfMsg( 'specialpages' );
1049 $spp = $wgContLang->specialPage( 'Specialpages' );
1051 $s = '<form id="specialpages" method="get" class="inline" ' .
1052 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1053 $s .= "<select name=\"wpDropdown\">\n";
1054 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1057 foreach ( $a as $name => $desc ) {
1058 $p = $wgContLang->specialPage( $name );
1059 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1061 $s .= "</select>\n";
1062 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1067 function mainPageLink() {
1068 $mp = wfMsgForContent( 'mainpage' );
1069 $mptxt = wfMsg( 'mainpage');
1070 $s = $this->makeKnownLink( $mp, $mptxt );
1074 function copyrightLink() {
1075 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1076 wfMsg( 'copyrightpagename' ) );
1080 function privacyLink() {
1081 $privacy = wfMsg( 'privacy' );
1082 if ($privacy == '-') {
1085 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1089 function aboutLink() {
1090 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1091 wfMsg( 'aboutsite' ) );
1095 function disclaimerLink() {
1096 $disclaimers = wfMsg( 'disclaimers' );
1097 if ($disclaimers == '-') {
1100 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1105 function editThisPage() {
1106 global $wgOut, $wgTitle;
1108 if ( ! $wgOut->isArticleRelated() ) {
1109 $s = wfMsg( 'protectedpage' );
1111 if ( $wgTitle->userCanEdit() ) {
1112 $t = wfMsg( 'editthispage' );
1114 $t = wfMsg( 'viewsource' );
1117 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1123 * Return URL options for the 'edit page' link.
1124 * This may include an 'oldid' specifier, if the current page view is such.
1129 function editUrlOptions() {
1132 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1133 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1135 return "action=edit";
1139 function deleteThisPage() {
1140 global $wgUser, $wgTitle, $wgRequest;
1142 $diff = $wgRequest->getVal( 'diff' );
1143 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1144 $t = wfMsg( 'deletethispage' );
1146 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1153 function protectThisPage() {
1154 global $wgUser, $wgTitle, $wgRequest;
1156 $diff = $wgRequest->getVal( 'diff' );
1157 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1158 if ( $wgTitle->isProtected() ) {
1159 $t = wfMsg( 'unprotectthispage' );
1160 $q = 'action=unprotect';
1162 $t = wfMsg( 'protectthispage' );
1163 $q = 'action=protect';
1165 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1172 function watchThisPage() {
1173 global $wgOut, $wgTitle;
1175 if ( $wgOut->isArticleRelated() ) {
1176 if ( $wgTitle->userIsWatching() ) {
1177 $t = wfMsg( 'unwatchthispage' );
1178 $q = 'action=unwatch';
1180 $t = wfMsg( 'watchthispage' );
1181 $q = 'action=watch';
1183 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1185 $s = wfMsg( 'notanarticle' );
1190 function moveThisPage() {
1193 if ( $wgTitle->userCanMove() ) {
1194 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1195 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1197 // no message if page is protected - would be redundant
1202 function historyLink() {
1205 return $this->makeKnownLinkObj( $wgTitle,
1206 wfMsg( 'history' ), 'action=history' );
1209 function whatLinksHere() {
1212 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1213 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1216 function userContribsLink() {
1219 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1220 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1223 function showEmailUser( $id ) {
1224 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1225 return $wgEnableEmail &&
1226 $wgEnableUserEmail &&
1227 $wgUser->isLoggedIn() && # show only to signed in users
1228 0 != $id; # we can only email to non-anons ..
1229 # '' != $id->getEmail() && # who must have an email address stored ..
1230 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1231 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1234 function emailUserLink() {
1237 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1238 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1241 function watchPageLinksLink() {
1242 global $wgOut, $wgTitle;
1244 if ( ! $wgOut->isArticleRelated() ) {
1245 return '(' . wfMsg( 'notanarticle' ) . ')';
1247 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1248 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1249 'target=' . $wgTitle->getPrefixedURL() );
1253 function trackbackLink() {
1256 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1257 . wfMsg('trackbacklink') . "</a>";
1260 function otherLanguages() {
1261 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1263 if ( $wgHideInterlanguageLinks ) {
1267 $a = $wgOut->getLanguageLinks();
1268 if ( 0 == count( $a ) ) {
1272 $s = wfMsg( 'otherlanguages' ) . ': ';
1274 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1275 foreach( $a as $l ) {
1276 if ( ! $first ) { $s .= ' | '; }
1279 $nt = Title
::newFromText( $l );
1280 $url = $nt->escapeFullURL();
1281 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1283 if ( '' == $text ) { $text = $l; }
1284 $style = $this->getExternalLinkAttributes( $l, $text );
1285 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1287 if($wgContLang->isRTL()) $s .= '</span>';
1291 function bugReportsLink() {
1292 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1293 wfMsg( 'bugreports' ) );
1297 function dateLink() {
1298 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1299 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1301 $id = $t1->getArticleID();
1304 $s = $this->makeBrokenLink( $t1->getText() );
1306 $s = $this->makeKnownLink( $t1->getText() );
1310 $id = $t2->getArticleID();
1313 $s .= $this->makeBrokenLink( $t2->getText() );
1315 $s .= $this->makeKnownLink( $t2->getText() );
1320 function talkLink() {
1323 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1324 # No discussion links for special pages
1328 if( $wgTitle->isTalkPage() ) {
1329 $link = $wgTitle->getSubjectPage();
1330 switch( $link->getNamespace() ) {
1332 $text = wfMsg('articlepage');
1335 $text = wfMsg('userpage');
1338 $text = wfMsg('projectpage');
1341 $text = wfMsg('imagepage');
1344 $text= wfMsg('articlepage');
1347 $link = $wgTitle->getTalkPage();
1348 $text = wfMsg( 'talkpage' );
1351 $s = $this->makeLinkObj( $link, $text );
1356 function commentLink() {
1357 global $wgTitle, $wgOut;
1359 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1363 # __NEWSECTIONLINK___ changes behaviour here
1364 # If it's present, the link points to this page, otherwise
1365 # it points to the talk page
1366 if( $wgTitle->isTalkPage() ) {
1368 } elseif( $wgOut->showNewSectionLink() ) {
1371 $title =& $wgTitle->getTalkPage();
1374 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1377 /* these are used extensively in SkinTemplate, but also some other places */
1378 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1379 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1380 return $title->getLocalURL( $urlaction );
1383 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1384 $title = Title
::newFromText( wfMsgForContent($name) );
1385 $this->checkTitle($title, $name);
1386 return $title->getLocalURL( $urlaction );
1389 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1390 $title = Title
::newFromText( $name );
1391 $this->checkTitle($title, $name);
1392 return $title->getLocalURL( $urlaction );
1395 # If url string starts with http, consider as external URL, else
1397 /*static*/ function makeInternalOrExternalUrl( $name ) {
1398 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1401 return $this->makeUrl( $name );
1405 # this can be passed the NS number as defined in Language.php
1406 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN
) {
1407 $title = Title
::makeTitleSafe( $namespace, $name );
1408 $this->checkTitle($title, $name);
1409 return $title->getLocalURL( $urlaction );
1412 /* these return an array with the 'href' and boolean 'exists' */
1413 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1414 $title = Title
::newFromText( $name );
1415 $this->checkTitle($title, $name);
1417 'href' => $title->getLocalURL( $urlaction ),
1418 'exists' => $title->getArticleID() != 0?
true:false
1423 * Make URL details where the article exists (or at least it's convenient to think so)
1425 function makeKnownUrlDetails( $name, $urlaction='' ) {
1426 $title = Title
::newFromText( $name );
1427 $this->checkTitle($title, $name);
1429 'href' => $title->getLocalURL( $urlaction ),
1434 # make sure we have some title to operate on
1435 /*static*/ function checkTitle ( &$title, &$name ) {
1436 if(!is_object($title)) {
1437 $title = Title
::newFromText( $name );
1438 if(!is_object($title)) {
1439 $title = Title
::newFromText( '--error: link target missing--' );
1445 * Build an array that represents the sidebar(s), the navigation bar among them
1450 function buildSidebar() {
1451 global $wgDBname, $parserMemc, $wgEnableSidebarCache;
1452 global $wgLanguageCode, $wgContLanguageCode;
1454 $fname = 'SkinTemplate::buildSidebar';
1456 wfProfileIn( $fname );
1458 $key = "{$wgDBname}:sidebar";
1459 $cacheSidebar = $wgEnableSidebarCache &&
1460 ($wgLanguageCode == $wgContLanguageCode);
1462 if ($cacheSidebar) {
1463 $cachedsidebar = $parserMemc->get( $key );
1464 if ($cachedsidebar!="") {
1465 wfProfileOut($fname);
1466 return $cachedsidebar;
1471 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1472 foreach ($lines as $line) {
1473 if (strpos($line, '*') !== 0)
1475 if (strpos($line, '**') !== 0) {
1476 $line = trim($line, '* ');
1479 if (strpos($line, '|') !== false) { // sanity check
1480 $line = explode( '|' , trim($line, '* '), 2 );
1481 $link = wfMsgForContent( $line[0] );
1484 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1486 if (wfEmptyMsg($line[0], $link))
1488 $href = $this->makeInternalOrExternalUrl( $link );
1489 $bar[$heading][] = array(
1492 'id' => 'n-' . strtr($line[1], ' ', '-'),
1495 } else { continue; }
1499 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1500 wfProfileOut( $fname );