2 if ( ! defined( 'MEDIAWIKI' ) )
12 require_once( 'Linker.php' );
13 require_once( 'Image.php' );
15 # Get a list of all skins available in /skins/
16 # Build using the regular expression '^(.*).php$'
17 # Array keys are all lower case, array value keep the case used by filename
20 $skinDir = dir($IP.'/skins');
22 # while code from www.php.net
23 while (false !== ($file = $skinDir->read())) {
24 // Skip non-PHP files, hidden files, and '.dep' includes
25 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
27 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
34 * The main skin class that provide methods and properties for all other skins.
35 * This base class is also the "Standard" skin.
38 class Skin
extends Linker
{
45 $rc_cache, # Cache for Enhanced Recent Changes
46 $rcCacheIndex, # Recent Changes Cache Counter for visibility toggle
50 /** Constructor, call parent constructor */
51 function Skin() { parent
::Linker(); }
54 * Fetch the set of available skins.
55 * @return array of strings
58 function getSkinNames() {
59 global $wgValidSkinNames;
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 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 function &newFromKey( $key ) {
111 $key = Skin
::normalizeKey( $key );
113 $skinNames = Skin
::getSkinNames();
114 $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( $IP.'/skins/'.$skinName.'.deps.php' );
123 require_once( $IP.'/skins/'.$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( $IP.'/skins/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( $out->reportTime() );
260 $out->out( "\n</body></html>" );
263 function getHeadScripts() {
264 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
265 $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
266 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
267 $userpage = $wgUser->getUserPage();
268 $userjs = htmlspecialchars( $this->makeUrl(
269 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
270 'action=raw&ctype='.$wgJsMimeType));
271 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
277 * To make it harder for someone to slip a user a fake
278 * user-JavaScript or user-CSS preview, a random token
279 * is associated with the login session. If it's not
280 * passed back with the preview request, we won't render
283 * @param string $action
287 function userCanPreview( $action ) {
288 global $wgTitle, $wgRequest, $wgUser;
290 if( $action != 'submit' )
292 if( !$wgRequest->wasPosted() )
294 if( !$wgTitle->userCanEditCssJsSubpage() )
296 return $wgUser->matchEditToken(
297 $wgRequest->getVal( 'wpEditToken' ) );
300 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
301 function getUserStylesheet() {
302 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
303 $sheet = $this->getStylesheet();
304 $action = $wgRequest->getText('action');
305 $s = "@import \"$wgStylePath/$sheet\";\n";
306 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
308 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
309 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
310 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
312 $s .= $this->doGetUserStyles();
317 * placeholder, returns generated js in monobook
319 function getUserJs() { return; }
322 * Return html code that include User stylesheets
324 function getUserStyles() {
325 $s = "<style type='text/css'>\n";
326 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
327 $s .= $this->getUserStylesheet();
328 $s .= "/*]]>*/ /* */\n";
334 * Some styles that are set by user through the user settings interface.
335 * @todo undefined variables (bug #4940)
337 function doGetUserStyles() {
338 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
342 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
343 # FIXME: $action undefined, bug #4940
344 if($wgTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
345 $s .= $wgRequest->getText('wpTextbox1');
347 $userpage = $wgUser->getUserPage();
348 $s.= '@import "'.$this->makeUrl(
349 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
350 'action=raw&ctype=text/css').'";'."\n";
354 return $s . $this->reallyDoGetUserStyles();
357 function reallyDoGetUserStyles() {
360 if (($undopt = $wgUser->getOption("underline")) != 2) {
361 $underline = $undopt ?
'underline' : 'none';
362 $s .= "a { text-decoration: $underline; }\n";
364 if( $wgUser->getOption( 'highlightbroken' ) ) {
365 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
368 a.new, #quickbar a.new,
369 a.stub, #quickbar a.stub {
371 text-decoration: inherit;
373 a.new:after, #quickbar a.new:after {
376 text-decoration: $underline;
378 a.stub:after, #quickbar a.stub:after {
381 text-decoration: $underline;
385 if( $wgUser->getOption( 'justify' ) ) {
386 $s .= "#article, #bodyContent { text-align: justify; }\n";
388 if( !$wgUser->getOption( 'showtoc' ) ) {
389 $s .= "#toc { display: none; }\n";
391 if( !$wgUser->getOption( 'editsection' ) ) {
392 $s .= ".editsection { display: none; }\n";
397 function getBodyOptions() {
398 global $wgUser, $wgTitle, $wgOut, $wgRequest;
400 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
402 if ( 0 != $wgTitle->getNamespace() ) {
403 $a = array( 'bgcolor' => '#ffffec' );
405 else $a = array( 'bgcolor' => '#FFFFFF' );
406 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
407 $wgTitle->userCanEdit() ) {
408 $t = wfMsg( 'editthispage' );
409 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
410 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
411 $a +
= array ('ondblclick' => $s);
414 $a['onload'] = $wgOut->getOnloadHandler();
415 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
416 if( $a['onload'] != '' ) {
419 $a['onload'] .= 'setupRightClickEdit()';
433 * This will be called immediately after the <body> tag. Split into
434 * two functions to make it easier to subclass.
436 function beforeContent() {
437 return $this->doBeforeContent();
440 function doBeforeContent() {
442 $fname = 'Skin::doBeforeContent';
443 wfProfileIn( $fname );
446 $qb = $this->qbSetting();
448 if( $langlinks = $this->otherLanguages() ) {
454 $borderhack = 'class="top"';
457 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
458 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
461 $left = ($qb == 1 ||
$qb == 3);
462 if($wgContLang->isRTL()) $left = !$left;
465 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
466 $this->logoText() . '</td>';
468 $s .= $this->getQuickbarCompensator( $rows );
470 $l = $wgContLang->isRTL() ?
'right' : 'left';
471 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
473 $s .= $this->topLinks() ;
474 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
476 $r = $wgContLang->isRTL() ?
"left" : "right";
477 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
478 $s .= $this->nameAndLogin();
479 $s .= "\n<br />" . $this->searchForm() . "</td>";
482 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
485 if ( $shove && !$left ) { # Right
486 $s .= $this->getQuickbarCompensator( $rows );
488 $s .= "</tr>\n</table>\n</div>\n";
489 $s .= "\n<div id='article'>\n";
491 $notice = wfGetSiteNotice();
493 $s .= "\n<div id='siteNotice'>$notice</div>\n";
495 $s .= $this->pageTitle();
496 $s .= $this->pageSubtitle() ;
497 $s .= $this->getCategories();
498 wfProfileOut( $fname );
503 function getCategoryLinks () {
504 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
507 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
510 $sep = wfMsgHtml( 'catseparator' );
512 // Use Unicode bidi embedding override characters,
513 // to make sure links don't smash each other up in ugly ways.
514 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
515 $embed = "<span dir='$dir'>";
517 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
519 $msg = count( $wgOut->mCategoryLinks
) === 1 ?
'categories1' : 'categories';
520 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
521 wfMsg( $msg ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
524 # optional 'dmoz-like' category browser. Will be shown under the list
525 # of categories an article belong to
526 if($wgUseCategoryBrowser) {
527 $s .= '<br /><hr />';
529 # get a big array of the parents tree
530 $parenttree = $wgTitle->getParentCategoryTree();
531 # Skin object passed by reference cause it can not be
532 # accessed under the method subfunction drawCategoryBrowser
533 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
534 # Clean out bogus first entry and sort them
537 # Output one per line
538 $s .= implode("<br />\n", $tempout);
544 /** Render the array as a serie of links.
545 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
546 * @param &skin Object: skin passed by reference
547 * @return String separated by >, terminate with "\n"
549 function drawCategoryBrowser($tree, &$skin) {
551 foreach ($tree as $element => $parent) {
552 if (empty($parent)) {
553 # element start a new list
556 # grab the others elements
557 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
559 # add our current element to the list
560 $eltitle = Title
::NewFromText($element);
561 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
566 function getCategories() {
567 $catlinks=$this->getCategoryLinks();
568 if(!empty($catlinks)) {
569 return "<p class='catlinks'>{$catlinks}</p>";
573 function getQuickbarCompensator( $rows = 1 ) {
574 return "<td width='152' rowspan='{$rows}'> </td>";
578 * This gets called immediately before the \</body\> tag.
579 * @return String HTML to be put after \</body\> ???
581 function afterContent() {
582 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
583 return $printfooter . $this->doAfterContent();
586 /** @return string Retrievied from HTML text */
587 function printSource() {
589 $url = htmlspecialchars( $wgTitle->getFullURL() );
590 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
593 function printFooter() {
594 return "<p>" . $this->printSource() .
595 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
598 /** overloaded by derived classes */
599 function doAfterContent() { }
601 function pageTitleLinks() {
602 global $wgOut, $wgTitle, $wgUser, $wgRequest;
604 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
605 $action = $wgRequest->getText( 'action' );
607 $s = $this->printableLink();
608 $disclaimer = $this->disclaimerLink(); # may be empty
610 $s .= ' | ' . $disclaimer;
612 $privacy = $this->privacyLink(); # may be empty too
614 $s .= ' | ' . $privacy;
617 if ( $wgOut->isArticleRelated() ) {
618 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
619 $name = $wgTitle->getDBkey();
620 $image = new Image( $wgTitle );
621 if( $image->exists() ) {
622 $link = htmlspecialchars( $image->getURL() );
623 $style = $this->getInternalLinkAttributes( $link, $name );
624 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
628 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
629 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
630 wfMsg( 'currentrev' ) );
633 if ( $wgUser->getNewtalk() ) {
634 # do not show "You have new messages" text when we are viewing our
636 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
637 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
638 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
639 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
641 $wgOut->setSquidMaxage(0);
642 $wgOut->enableClientCache(false);
646 $undelete = $this->getUndeleteLink();
647 if( !empty( $undelete ) ) {
648 $s .= ' | '.$undelete;
653 function getUndeleteLink() {
654 global $wgUser, $wgTitle, $wgContLang, $action;
655 if( $wgUser->isAllowed( 'deletedhistory' ) &&
656 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
657 ($n = $wgTitle->isDeleted() ) )
659 if ( $wgUser->isAllowed( 'delete' ) ) {
660 $msg = 'thisisdeleted';
662 $msg = 'viewdeleted';
665 $this->makeKnownLink(
666 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
667 wfMsg( 'restorelink' . ($n == 1 ?
'1' : ''), $n ) ) );
672 function printableLink() {
673 global $wgOut, $wgFeedClasses, $wgRequest;
675 $baseurl = $_SERVER['REQUEST_URI'];
676 if( strpos( '?', $baseurl ) == false ) {
681 $baseurl = htmlspecialchars( $baseurl );
682 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
684 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
685 if( $wgOut->isSyndicated() ) {
686 foreach( $wgFeedClasses as $format => $class ) {
687 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
688 $s .= " | <a href=\"$feedurl\">{$format}</a>";
694 function pageTitle() {
696 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
700 function pageSubtitle() {
703 $sub = $wgOut->getSubtitle();
705 global $wgExtraSubtitle;
706 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
708 $subpages = $this->subPageSubtitle();
709 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
710 $s = "<p class='subtitle'>{$sub}</p>\n";
714 function subPageSubtitle() {
715 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
717 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
718 $ptext=$wgTitle->getPrefixedText();
719 if(preg_match('/\//',$ptext)) {
720 $links = explode('/',$ptext);
723 foreach($links as $link) {
725 if ($c<count($links)) {
726 $growinglink .= $link;
727 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
728 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
732 $subpages .= '< ';
734 $subpages .= $getlink;
743 function nameAndLogin() {
744 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
746 $li = $wgContLang->specialPage( 'Userlogin' );
747 $lo = $wgContLang->specialPage( 'Userlogout' );
750 if ( $wgUser->isAnon() ) {
751 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
754 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
755 $wgLang->getNsText( NS_TALK
) );
757 $s .= $n . ' ('.$tl.')';
759 $s .= wfMsg('notloggedin');
762 $rt = $wgTitle->getPrefixedURL();
763 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
765 } else { $q = "returnto={$rt}"; }
767 $s .= "\n<br />" . $this->makeKnownLinkObj(
768 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
769 wfMsg( 'login' ), $q );
771 $n = $wgUser->getName();
772 $rt = $wgTitle->getPrefixedURL();
773 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
774 $wgLang->getNsText( NS_TALK
) );
778 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
779 $n ) . "{$tl}<br />" .
780 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
781 "returnto={$rt}" ) . ' | ' .
782 $this->specialLink( 'preferences' );
784 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
790 function getSearchLink() {
791 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
792 return $searchPage->getLocalURL();
795 function escapeSearchLink() {
796 return htmlspecialchars( $this->getSearchLink() );
799 function searchForm() {
801 $search = $wgRequest->getText( 'search' );
803 $s = '<form name="search" class="inline" method="post" action="'
804 . $this->escapeSearchLink() . "\">\n"
805 . '<input type="text" name="search" size="19" value="'
806 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
807 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" /> '
808 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
813 function topLinks() {
817 $s = $this->mainPageLink() . $sep
818 . $this->specialLink( 'recentchanges' );
820 if ( $wgOut->isArticleRelated() ) {
821 $s .= $sep . $this->editThisPage()
822 . $sep . $this->historyLink();
824 # Many people don't like this dropdown box
825 #$s .= $sep . $this->specialPagesList();
827 /* show links to different language variants */
828 global $wgDisableLangConversion, $wgContLang, $wgTitle;
829 $variants = $wgContLang->getVariants();
830 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
831 foreach( $variants as $code ) {
832 $varname = $wgContLang->getVariantname( $code );
833 if( $varname == 'disable' )
835 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
842 function bottomLinks() {
843 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
847 if ( $wgOut->isArticleRelated() ) {
848 $s .= '<strong>' . $this->editThisPage() . '</strong>';
849 if ( $wgUser->isLoggedIn() ) {
850 $s .= $sep . $this->watchThisPage();
852 $s .= $sep . $this->talkLink()
853 . $sep . $this->historyLink()
854 . $sep . $this->whatLinksHere()
855 . $sep . $this->watchPageLinksLink();
857 if ($wgUseTrackbacks)
858 $s .= $sep . $this->trackbackLink();
860 if ( $wgTitle->getNamespace() == NS_USER
861 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
864 $id=User
::idFromName($wgTitle->getText());
865 $ip=User
::isIP($wgTitle->getText());
867 if($id ||
$ip) { # both anons and non-anons have contri list
868 $s .= $sep . $this->userContribsLink();
870 if( $this->showEmailUser( $id ) ) {
871 $s .= $sep . $this->emailUserLink();
874 if ( $wgTitle->getArticleId() ) {
876 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
877 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
878 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
880 $s .= "<br />\n" . $this->otherLanguages();
885 function pageStats() {
886 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
887 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
889 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
890 if ( ! $wgOut->isArticle() ) { return ''; }
891 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
892 if ( 0 == $wgArticle->getID() ) { return ''; }
895 if ( !$wgDisableCounters ) {
896 $count = $wgLang->formatNum( $wgArticle->getCount() );
898 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
902 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
903 require_once('Credits.php');
904 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
906 $s .= $this->lastModified();
909 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
910 $dbr =& wfGetDB( DB_SLAVE
);
911 extract( $dbr->tableNames( 'watchlist' ) );
912 $sql = "SELECT COUNT(*) AS n FROM $watchlist
913 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
914 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
915 $res = $dbr->query( $sql, 'Skin::pageStats');
916 $x = $dbr->fetchObject( $res );
917 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
920 return $s . ' ' . $this->getCopyright();
923 function getCopyright( $type = 'detect' ) {
924 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
926 if ( $type == 'detect' ) {
927 $oldid = $wgRequest->getVal( 'oldid' );
928 $diff = $wgRequest->getVal( 'diff' );
930 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
937 if ( $type == 'history' ) {
938 $msg = 'history_copyright';
944 if( $wgRightsPage ) {
945 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
946 } elseif( $wgRightsUrl ) {
947 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
952 $out .= wfMsgForContent( $msg, $link );
956 function getCopyrightIcon() {
957 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
959 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
960 $out = $wgCopyrightIcon;
961 } else if ( $wgRightsIcon ) {
962 $icon = htmlspecialchars( $wgRightsIcon );
963 if ( $wgRightsUrl ) {
964 $url = htmlspecialchars( $wgRightsUrl );
965 $out .= '<a href="'.$url.'">';
967 $text = htmlspecialchars( $wgRightsText );
968 $out .= "<img src=\"$icon\" alt='$text' />";
969 if ( $wgRightsUrl ) {
976 function getPoweredBy() {
978 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
979 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
983 function lastModified() {
984 global $wgLang, $wgArticle, $wgLoadBalancer;
986 $timestamp = $wgArticle->getTimestamp();
988 $d = $wgLang->timeanddate( $timestamp, true );
989 $s = ' ' . wfMsg( 'lastmodified', $d );
993 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
994 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
999 function logoText( $align = '' ) {
1000 if ( '' != $align ) { $a = " align='{$align}'"; }
1003 $mp = wfMsg( 'mainpage' );
1004 $titleObj = Title
::newFromText( $mp );
1005 if ( is_object( $titleObj ) ) {
1006 $url = $titleObj->escapeLocalURL();
1011 $logourl = $this->getLogo();
1012 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1017 * show a drop-down box of special pages
1018 * @TODO crash bug913. Need to be rewrote completly.
1020 function specialPagesList() {
1021 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
1022 require_once('SpecialPage.php');
1024 $pages = SpecialPage
::getPages();
1026 // special pages without access restriction
1027 foreach ( $pages[''] as $name => $page ) {
1028 $a[$name] = $page->getDescription();
1031 // Other special pages that are restricted.
1032 // Copied from SpecialSpecialpages.php
1033 foreach($wgAvailableRights as $right) {
1034 if( $wgUser->isAllowed($right) ) {
1035 /** Add all pages for this right */
1036 if(isset($pages[$right])) {
1037 foreach($pages[$right] as $name => $page) {
1038 $a[$name] = $page->getDescription();
1044 $go = wfMsg( 'go' );
1045 $sp = wfMsg( 'specialpages' );
1046 $spp = $wgContLang->specialPage( 'Specialpages' );
1048 $s = '<form id="specialpages" method="get" class="inline" ' .
1049 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1050 $s .= "<select name=\"wpDropdown\">\n";
1051 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1054 foreach ( $a as $name => $desc ) {
1055 $p = $wgContLang->specialPage( $name );
1056 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1058 $s .= "</select>\n";
1059 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1064 function mainPageLink() {
1065 $mp = wfMsgForContent( 'mainpage' );
1066 $mptxt = wfMsg( 'mainpage');
1067 $s = $this->makeKnownLink( $mp, $mptxt );
1071 function copyrightLink() {
1072 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1073 wfMsg( 'copyrightpagename' ) );
1077 function privacyLink() {
1078 $privacy = wfMsg( 'privacy' );
1079 if ($privacy == '-') {
1082 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1086 function aboutLink() {
1087 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1088 wfMsg( 'aboutsite' ) );
1092 function disclaimerLink() {
1093 $disclaimers = wfMsg( 'disclaimers' );
1094 if ($disclaimers == '-') {
1097 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1102 function editThisPage() {
1103 global $wgOut, $wgTitle;
1105 if ( ! $wgOut->isArticleRelated() ) {
1106 $s = wfMsg( 'protectedpage' );
1108 if ( $wgTitle->userCanEdit() ) {
1109 $t = wfMsg( 'editthispage' );
1111 $t = wfMsg( 'viewsource' );
1114 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1120 * Return URL options for the 'edit page' link.
1121 * This may include an 'oldid' specifier, if the current page view is such.
1126 function editUrlOptions() {
1129 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1130 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1132 return "action=edit";
1136 function deleteThisPage() {
1137 global $wgUser, $wgTitle, $wgRequest;
1139 $diff = $wgRequest->getVal( 'diff' );
1140 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1141 $t = wfMsg( 'deletethispage' );
1143 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1150 function protectThisPage() {
1151 global $wgUser, $wgTitle, $wgRequest;
1153 $diff = $wgRequest->getVal( 'diff' );
1154 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1155 if ( $wgTitle->isProtected() ) {
1156 $t = wfMsg( 'unprotectthispage' );
1157 $q = 'action=unprotect';
1159 $t = wfMsg( 'protectthispage' );
1160 $q = 'action=protect';
1162 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1169 function watchThisPage() {
1170 global $wgOut, $wgTitle;
1172 if ( $wgOut->isArticleRelated() ) {
1173 if ( $wgTitle->userIsWatching() ) {
1174 $t = wfMsg( 'unwatchthispage' );
1175 $q = 'action=unwatch';
1177 $t = wfMsg( 'watchthispage' );
1178 $q = 'action=watch';
1180 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1182 $s = wfMsg( 'notanarticle' );
1187 function moveThisPage() {
1190 if ( $wgTitle->userCanMove() ) {
1191 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1192 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1194 // no message if page is protected - would be redundant
1199 function historyLink() {
1202 return $this->makeKnownLinkObj( $wgTitle,
1203 wfMsg( 'history' ), 'action=history' );
1206 function whatLinksHere() {
1209 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1210 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1213 function userContribsLink() {
1216 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1217 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1220 function showEmailUser( $id ) {
1221 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1222 return $wgEnableEmail &&
1223 $wgEnableUserEmail &&
1224 $wgUser->isLoggedIn() && # show only to signed in users
1225 0 != $id; # we can only email to non-anons ..
1226 # '' != $id->getEmail() && # who must have an email address stored ..
1227 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1228 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1231 function emailUserLink() {
1234 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1235 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1238 function watchPageLinksLink() {
1239 global $wgOut, $wgTitle;
1241 if ( ! $wgOut->isArticleRelated() ) {
1242 return '(' . wfMsg( 'notanarticle' ) . ')';
1244 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1245 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1246 'target=' . $wgTitle->getPrefixedURL() );
1250 function trackbackLink() {
1253 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1254 . wfMsg('trackbacklink') . "</a>";
1257 function otherLanguages() {
1258 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1260 if ( $wgHideInterlanguageLinks ) {
1264 $a = $wgOut->getLanguageLinks();
1265 if ( 0 == count( $a ) ) {
1269 $s = wfMsg( 'otherlanguages' ) . ': ';
1271 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1272 foreach( $a as $l ) {
1273 if ( ! $first ) { $s .= ' | '; }
1276 $nt = Title
::newFromText( $l );
1277 $url = $nt->escapeFullURL();
1278 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1280 if ( '' == $text ) { $text = $l; }
1281 $style = $this->getExternalLinkAttributes( $l, $text );
1282 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1284 if($wgContLang->isRTL()) $s .= '</span>';
1288 function bugReportsLink() {
1289 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1290 wfMsg( 'bugreports' ) );
1294 function dateLink() {
1295 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1296 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1298 $id = $t1->getArticleID();
1301 $s = $this->makeBrokenLink( $t1->getText() );
1303 $s = $this->makeKnownLink( $t1->getText() );
1307 $id = $t2->getArticleID();
1310 $s .= $this->makeBrokenLink( $t2->getText() );
1312 $s .= $this->makeKnownLink( $t2->getText() );
1317 function talkLink() {
1320 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1321 # No discussion links for special pages
1325 if( $wgTitle->isTalkPage() ) {
1326 $link = $wgTitle->getSubjectPage();
1327 switch( $link->getNamespace() ) {
1329 $text = wfMsg('articlepage');
1332 $text = wfMsg('userpage');
1335 $text = wfMsg('wikipediapage');
1338 $text = wfMsg('imagepage');
1341 $text= wfMsg('articlepage');
1344 $link = $wgTitle->getTalkPage();
1345 $text = wfMsg( 'talkpage' );
1348 $s = $this->makeLinkObj( $link, $text );
1353 function commentLink() {
1354 global $wgTitle, $wgOut;
1356 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1360 # __NEWSECTIONLINK___ changes behaviour here
1361 # If it's present, the link points to this page, otherwise
1362 # it points to the talk page
1363 if( $wgTitle->isTalkPage() ) {
1365 } elseif( $wgOut->showNewSectionLink() ) {
1368 $title =& $wgTitle->getTalkPage();
1371 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1374 /* these are used extensively in SkinTemplate, but also some other places */
1375 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1376 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1377 return $title->getLocalURL( $urlaction );
1380 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1381 $title = Title
::newFromText( wfMsgForContent($name) );
1382 $this->checkTitle($title, $name);
1383 return $title->getLocalURL( $urlaction );
1386 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1387 $title = Title
::newFromText( $name );
1388 $this->checkTitle($title, $name);
1389 return $title->getLocalURL( $urlaction );
1392 # If url string starts with http, consider as external URL, else
1394 /*static*/ function makeInternalOrExternalUrl( $name ) {
1395 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1398 return $this->makeUrl( $name );
1402 # this can be passed the NS number as defined in Language.php
1403 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN
) {
1404 $title = Title
::makeTitleSafe( $namespace, $name );
1405 $this->checkTitle($title, $name);
1406 return $title->getLocalURL( $urlaction );
1409 /* these return an array with the 'href' and boolean 'exists' */
1410 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1411 $title = Title
::newFromText( $name );
1412 $this->checkTitle($title, $name);
1414 'href' => $title->getLocalURL( $urlaction ),
1415 'exists' => $title->getArticleID() != 0?
true:false
1420 * Make URL details where the article exists (or at least it's convenient to think so)
1422 function makeKnownUrlDetails( $name, $urlaction='' ) {
1423 $title = Title
::newFromText( $name );
1424 $this->checkTitle($title, $name);
1426 'href' => $title->getLocalURL( $urlaction ),
1431 # make sure we have some title to operate on
1432 /*static*/ function checkTitle ( &$title, &$name ) {
1433 if(!is_object($title)) {
1434 $title = Title
::newFromText( $name );
1435 if(!is_object($title)) {
1436 $title = Title
::newFromText( '--error: link target missing--' );
1442 * Build an array that represents the sidebar(s), the navigation bar among them
1447 function buildSidebar() {
1448 global $wgDBname, $parserMemc, $wgEnableSidebarCache;
1449 global $wgLanguageCode, $wgContLanguageCode;
1451 $fname = 'SkinTemplate::buildSidebar';
1453 wfProfileIn( $fname );
1455 $key = "{$wgDBname}:sidebar";
1456 $cacheSidebar = $wgEnableSidebarCache &&
1457 ($wgLanguageCode == $wgContLanguageCode);
1459 if ($cacheSidebar) {
1460 $cachedsidebar = $parserMemc->get( $key );
1461 if ($cachedsidebar!="") {
1462 wfProfileOut($fname);
1463 return $cachedsidebar;
1468 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1469 foreach ($lines as $line) {
1470 if (strpos($line, '*') !== 0)
1472 if (strpos($line, '**') !== 0) {
1473 $line = trim($line, '* ');
1476 if (strpos($line, '|') !== false) { // sanity check
1477 $line = explode( '|' , trim($line, '* '), 2 );
1478 $link = wfMsgForContent( $line[0] );
1481 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1483 if (wfEmptyMsg($line[0], $link))
1485 $href = $this->makeInternalOrExternalUrl( $link );
1486 $bar[$heading][] = array(
1489 'id' => 'n-' . strtr($line[1], ' ', '-'),
1492 } else { continue; }
1496 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1497 wfProfileOut( $fname );