2 if ( ! defined( 'MEDIAWIKI' ) )
12 require_once( 'Linker.php' );
13 require_once( 'Image.php' );
15 # Get a list of available 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( $wgStyleDirectory );
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
{
42 var $lastdate, $lastline;
43 var $rc_cache ; # Cache for Enhanced Recent Changes
44 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
48 /** Constructor, call parent constructor */
49 function Skin() { parent
::Linker(); }
52 * Fetch the set of available skins.
53 * @return array of strings
56 function getSkinNames() {
57 global $wgValidSkinNames;
58 return $wgValidSkinNames;
62 * Normalize a skin preference value to a form that can be loaded.
63 * If a skin can't be found, it will fall back to the configured
64 * default (or the old 'Classic' skin if that's broken).
69 function normalizeKey( $key ) {
70 global $wgDefaultSkin;
71 $skinNames = Skin
::getSkinNames();
74 // Don't return the default immediately;
75 // in a misconfiguration we need to fall back.
76 $key = $wgDefaultSkin;
79 if( isset( $skinNames[$key] ) ) {
83 // Older versions of the software used a numeric setting
84 // in the user preferences.
90 if( isset( $fallback[$key] ) ){
91 $key = $fallback[$key];
94 if( isset( $skinNames[$key] ) ) {
97 // The old built-in skin
103 * Factory method for loading a skin of a given type
104 * @param string $key 'monobook', 'standard', etc
108 function &newFromKey( $key ) {
109 $key = Skin
::normalizeKey( $key );
111 $skinNames = Skin
::getSkinNames();
112 $skinName = $skinNames[$key];
116 # Grab the skin class and initialise it.
117 wfSuppressWarnings();
118 // Preload base classes to work around APC/PHP5 bug
119 include_once( $IP.'/skins/'.$skinName.'.deps.php' );
121 require_once( $IP.'/skins/'.$skinName.'.php' );
123 # Check if we got if not failback to default skin
124 $className = 'Skin'.$skinName;
125 if( !class_exists( $className ) ) {
126 # DO NOT die if the class isn't found. This breaks maintenance
127 # scripts and can cause a user account to be unrecoverable
128 # except by SQL manipulation if a previously valid skin name
129 # is no longer valid.
130 wfDebug( "Skin class does not exist: $className\n" );
131 $className = 'SkinStandard';
132 require_once( $IP.'/skins/Standard.php' );
134 $skin =& new $className;
138 /** @return string path to the skin stylesheet */
139 function getStylesheet() {
140 return 'common/wikistandard.css?1';
143 /** @return string skin name */
144 function getSkinName() {
148 function qbSetting() {
149 global $wgOut, $wgUser;
151 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
152 $q = $wgUser->getOption( 'quickbar' );
153 if ( '' == $q ) { $q = 0; }
157 function initPage( &$out ) {
160 $fname = 'Skin::initPage';
161 wfProfileIn( $fname );
163 if( false !== $wgFavicon ) {
164 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
167 $this->addMetadataLinks($out);
169 $this->mRevisionId
= $out->mRevisionId
;
171 $this->preloadExistence();
173 wfProfileOut( $fname );
177 * Preload the existence of three commonly-requested pages in a single query
179 function preloadExistence() {
180 global $wgUser, $wgTitle;
182 if ( $wgTitle->isTalkPage() ) {
183 $otherTab = $wgTitle->getSubjectPage();
185 $otherTab = $wgTitle->getTalkPage();
187 $lb = new LinkBatch( array(
188 $wgUser->getUserPage(),
189 $wgUser->getTalkPage(),
195 function addMetadataLinks( &$out ) {
196 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
197 global $wgRightsPage, $wgRightsUrl;
199 if( $out->isArticleRelated() ) {
200 # note: buggy CC software only reads first "meta" link
201 if( $wgEnableCreativeCommonsRdf ) {
202 $out->addMetadataLink( array(
203 'title' => 'Creative Commons',
204 'type' => 'application/rdf+xml',
205 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
207 if( $wgEnableDublinCoreRdf ) {
208 $out->addMetadataLink( array(
209 'title' => 'Dublin Core',
210 'type' => 'application/rdf+xml',
211 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
215 if( $wgRightsPage ) {
216 $copy = Title
::newFromText( $wgRightsPage );
218 $copyright = $copy->getLocalURL();
221 if( !$copyright && $wgRightsUrl ) {
222 $copyright = $wgRightsUrl;
225 $out->addLink( array(
226 'rel' => 'copyright',
227 'href' => $copyright ) );
231 function outputPage( &$out ) {
232 global $wgDebugComments;
234 wfProfileIn( 'Skin::outputPage' );
235 $this->initPage( $out );
237 $out->out( $out->headElement() );
239 $out->out( "\n<body" );
240 $ops = $this->getBodyOptions();
241 foreach ( $ops as $name => $val ) {
242 $out->out( " $name='$val'" );
245 if ( $wgDebugComments ) {
246 $out->out( "<!-- Wiki debugging output:\n" .
247 $out->mDebugtext
. "-->\n" );
250 $out->out( $this->beforeContent() );
252 $out->out( $out->mBodytext
. "\n" );
254 $out->out( $this->afterContent() );
256 $out->out( $out->reportTime() );
258 $out->out( "\n</body></html>" );
261 function getHeadScripts() {
262 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
263 $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
264 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
265 $userpage = $wgUser->getUserPage();
266 $userjs = htmlspecialchars( $this->makeUrl(
267 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
268 'action=raw&ctype='.$wgJsMimeType));
269 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
275 * To make it harder for someone to slip a user a fake
276 * user-JavaScript or user-CSS preview, a random token
277 * is associated with the login session. If it's not
278 * passed back with the preview request, we won't render
281 * @param string $action
285 function userCanPreview( $action ) {
286 global $wgTitle, $wgRequest, $wgUser;
288 if( $action != 'submit' )
290 if( !$wgRequest->wasPosted() )
292 if( !$wgTitle->userCanEditCssJsSubpage() )
294 return $wgUser->matchEditToken(
295 $wgRequest->getVal( 'wpEditToken' ) );
298 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
299 function getUserStylesheet() {
300 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
301 $sheet = $this->getStylesheet();
302 $action = $wgRequest->getText('action');
303 $s = "@import \"$wgStylePath/$sheet\";\n";
304 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
306 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
307 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
308 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
310 $s .= $this->doGetUserStyles();
315 * placeholder, returns generated js in monobook
317 function getUserJs() { return; }
320 * Return html code that include User stylesheets
322 function getUserStyles() {
323 $s = "<style type='text/css'>\n";
324 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
325 $s .= $this->getUserStylesheet();
326 $s .= "/*]]>*/ /* */\n";
332 * Some styles that are set by user through the user settings interface.
334 function doGetUserStyles() {
335 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
339 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
340 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
341 $s .= $wgRequest->getText('wpTextbox1');
343 $userpage = $wgUser->getUserPage();
344 $s.= '@import "'.$this->makeUrl(
345 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
346 'action=raw&ctype=text/css').'";'."\n";
350 return $s . $this->reallyDoGetUserStyles();
353 function reallyDoGetUserStyles() {
356 if (($undopt = $wgUser->getOption("underline")) != 2) {
357 $underline = $undopt ?
'underline' : 'none';
358 $s .= "a { text-decoration: $underline; }\n";
360 if( $wgUser->getOption( 'highlightbroken' ) ) {
361 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
364 a.new, #quickbar a.new,
365 a.stub, #quickbar a.stub {
367 text-decoration: inherit;
369 a.new:after, #quickbar a.new:after {
372 text-decoration: $underline;
374 a.stub:after, #quickbar a.stub:after {
377 text-decoration: $underline;
381 if( $wgUser->getOption( 'justify' ) ) {
382 $s .= "#article, #bodyContent { text-align: justify; }\n";
384 if( !$wgUser->getOption( 'showtoc' ) ) {
385 $s .= "#toc { display: none; }\n";
387 if( !$wgUser->getOption( 'editsection' ) ) {
388 $s .= ".editsection { display: none; }\n";
393 function getBodyOptions() {
394 global $wgUser, $wgTitle, $wgOut, $wgRequest;
396 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
398 if ( 0 != $wgTitle->getNamespace() ) {
399 $a = array( 'bgcolor' => '#ffffec' );
401 else $a = array( 'bgcolor' => '#FFFFFF' );
402 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
403 $wgTitle->userCanEdit() ) {
404 $t = wfMsg( 'editthispage' );
405 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
406 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
407 $a +
= array ('ondblclick' => $s);
410 $a['onload'] = $wgOut->getOnloadHandler();
411 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
412 if( $a['onload'] != '' ) {
415 $a['onload'] .= 'setupRightClickEdit()';
429 * This will be called immediately after the <body> tag. Split into
430 * two functions to make it easier to subclass.
432 function beforeContent() {
433 return $this->doBeforeContent();
436 function doBeforeContent() {
438 $fname = 'Skin::doBeforeContent';
439 wfProfileIn( $fname );
442 $qb = $this->qbSetting();
444 if( $langlinks = $this->otherLanguages() ) {
450 $borderhack = 'class="top"';
453 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
454 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
457 $left = ($qb == 1 ||
$qb == 3);
458 if($wgContLang->isRTL()) $left = !$left;
461 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
462 $this->logoText() . '</td>';
464 $s .= $this->getQuickbarCompensator( $rows );
466 $l = $wgContLang->isRTL() ?
'right' : 'left';
467 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
469 $s .= $this->topLinks() ;
470 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
472 $r = $wgContLang->isRTL() ?
"left" : "right";
473 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
474 $s .= $this->nameAndLogin();
475 $s .= "\n<br />" . $this->searchForm() . "</td>";
478 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
481 if ( $shove && !$left ) { # Right
482 $s .= $this->getQuickbarCompensator( $rows );
484 $s .= "</tr>\n</table>\n</div>\n";
485 $s .= "\n<div id='article'>\n";
487 $notice = wfGetSiteNotice();
489 $s .= "\n<div id='siteNotice'>$notice</div>\n";
491 $s .= $this->pageTitle();
492 $s .= $this->pageSubtitle() ;
493 $s .= $this->getCategories();
494 wfProfileOut( $fname );
499 function getCategoryLinks () {
500 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
503 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
506 $sep = wfMsgHtml( 'catseparator' );
508 // Use Unicode bidi embedding override characters,
509 // to make sure links don't smash each other up in ugly ways.
510 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
511 $embed = "<span dir='$dir'>";
513 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
515 $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks
));
516 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
517 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
520 # optional 'dmoz-like' category browser. Will be shown under the list
521 # of categories an article belong to
522 if($wgUseCategoryBrowser) {
523 $s .= '<br /><hr />';
525 # get a big array of the parents tree
526 $parenttree = $wgTitle->getParentCategoryTree();
527 # Skin object passed by reference cause it can not be
528 # accessed under the method subfunction drawCategoryBrowser
529 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
530 # Clean out bogus first entry and sort them
533 # Output one per line
534 $s .= implode("<br />\n", $tempout);
540 /** Render the array as a serie of links.
541 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
542 * @param &skin Object: skin passed by reference
543 * @return String separated by >, terminate with "\n"
545 function drawCategoryBrowser($tree, &$skin) {
547 foreach ($tree as $element => $parent) {
548 if (empty($parent)) {
549 # element start a new list
552 # grab the others elements
553 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
555 # add our current element to the list
556 $eltitle = Title
::NewFromText($element);
557 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
562 function getCategories() {
563 $catlinks=$this->getCategoryLinks();
564 if(!empty($catlinks)) {
565 return "<p class='catlinks'>{$catlinks}</p>";
569 function getQuickbarCompensator( $rows = 1 ) {
570 return "<td width='152' rowspan='{$rows}'> </td>";
574 * This gets called immediately before the \</body\> tag.
575 * @return String HTML to be put after \</body\> ???
577 function afterContent() {
578 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
579 return $printfooter . $this->doAfterContent();
582 /** @return string Retrievied from HTML text */
583 function printSource() {
585 $url = htmlspecialchars( $wgTitle->getFullURL() );
586 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
589 function printFooter() {
590 return "<p>" . $this->printSource() .
591 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
594 /** overloaded by derived classes */
595 function doAfterContent() { }
597 function pageTitleLinks() {
598 global $wgOut, $wgTitle, $wgUser, $wgRequest;
600 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
601 $action = $wgRequest->getText( 'action' );
603 $s = $this->printableLink();
604 $disclaimer = $this->disclaimerLink(); # may be empty
606 $s .= ' | ' . $disclaimer;
608 $privacy = $this->privacyLink(); # may be empty too
610 $s .= ' | ' . $privacy;
613 if ( $wgOut->isArticleRelated() ) {
614 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
615 $name = $wgTitle->getDBkey();
616 $image = new Image( $wgTitle );
617 if( $image->exists() ) {
618 $link = htmlspecialchars( $image->getURL() );
619 $style = $this->getInternalLinkAttributes( $link, $name );
620 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
624 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
625 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
626 wfMsg( 'currentrev' ) );
629 if ( $wgUser->getNewtalk() ) {
630 # do not show "You have new messages" text when we are viewing our
632 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
633 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
634 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
635 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
637 $wgOut->setSquidMaxage(0);
638 $wgOut->enableClientCache(false);
642 $undelete = $this->getUndeleteLink();
643 if( !empty( $undelete ) ) {
644 $s .= ' | '.$undelete;
649 function getUndeleteLink() {
650 global $wgUser, $wgTitle, $wgContLang, $action;
651 if( $wgUser->isAllowed( 'deletedhistory' ) &&
652 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
653 ($n = $wgTitle->isDeleted() ) )
655 if ( $wgUser->isAllowed( 'delete' ) ) {
656 $msg = 'thisisdeleted';
658 $msg = 'viewdeleted';
661 $this->makeKnownLink(
662 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
663 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
668 function printableLink() {
669 global $wgOut, $wgFeedClasses, $wgRequest;
671 $baseurl = $_SERVER['REQUEST_URI'];
672 if( strpos( '?', $baseurl ) == false ) {
677 $baseurl = htmlspecialchars( $baseurl );
678 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
680 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
681 if( $wgOut->isSyndicated() ) {
682 foreach( $wgFeedClasses as $format => $class ) {
683 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
684 $s .= " | <a href=\"$feedurl\">{$format}</a>";
690 function pageTitle() {
692 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
696 function pageSubtitle() {
699 $sub = $wgOut->getSubtitle();
701 global $wgExtraSubtitle;
702 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
704 $subpages = $this->subPageSubtitle();
705 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
706 $s = "<p class='subtitle'>{$sub}</p>\n";
710 function subPageSubtitle() {
711 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
713 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
714 $ptext=$wgTitle->getPrefixedText();
715 if(preg_match('/\//',$ptext)) {
716 $links = explode('/',$ptext);
719 foreach($links as $link) {
721 if ($c<count($links)) {
722 $growinglink .= $link;
723 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
724 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
728 $subpages .= '< ';
730 $subpages .= $getlink;
739 function nameAndLogin() {
740 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
742 $li = $wgContLang->specialPage( 'Userlogin' );
743 $lo = $wgContLang->specialPage( 'Userlogout' );
746 if ( $wgUser->isAnon() ) {
747 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
750 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
751 $wgLang->getNsText( NS_TALK
) );
753 $s .= $n . ' ('.$tl.')';
755 $s .= wfMsg('notloggedin');
758 $rt = $wgTitle->getPrefixedURL();
759 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
761 } else { $q = "returnto={$rt}"; }
763 $s .= "\n<br />" . $this->makeKnownLinkObj(
764 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
765 wfMsg( 'login' ), $q );
767 $n = $wgUser->getName();
768 $rt = $wgTitle->getPrefixedURL();
769 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
770 $wgLang->getNsText( NS_TALK
) );
774 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
775 $n ) . "{$tl}<br />" .
776 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
777 "returnto={$rt}" ) . ' | ' .
778 $this->specialLink( 'preferences' );
780 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
786 function getSearchLink() {
787 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
788 return $searchPage->getLocalURL();
791 function escapeSearchLink() {
792 return htmlspecialchars( $this->getSearchLink() );
795 function searchForm() {
797 $search = $wgRequest->getText( 'search' );
799 $s = '<form name="search" class="inline" method="post" action="'
800 . $this->escapeSearchLink() . "\">\n"
801 . '<input type="text" name="search" size="19" value="'
802 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
803 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" /> '
804 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
809 function topLinks() {
813 $s = $this->mainPageLink() . $sep
814 . $this->specialLink( 'recentchanges' );
816 if ( $wgOut->isArticleRelated() ) {
817 $s .= $sep . $this->editThisPage()
818 . $sep . $this->historyLink();
820 # Many people don't like this dropdown box
821 #$s .= $sep . $this->specialPagesList();
823 /* show links to different language variants */
824 global $wgDisableLangConversion, $wgContLang, $wgTitle;
825 $variants = $wgContLang->getVariants();
826 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
827 foreach( $variants as $code ) {
828 $varname = $wgContLang->getVariantname( $code );
829 if( $varname == 'disable' )
831 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
838 function bottomLinks() {
839 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
843 if ( $wgOut->isArticleRelated() ) {
844 $s .= '<strong>' . $this->editThisPage() . '</strong>';
845 if ( $wgUser->isLoggedIn() ) {
846 $s .= $sep . $this->watchThisPage();
848 $s .= $sep . $this->talkLink()
849 . $sep . $this->historyLink()
850 . $sep . $this->whatLinksHere()
851 . $sep . $this->watchPageLinksLink();
853 if ($wgUseTrackbacks)
854 $s .= $sep . $this->trackbackLink();
856 if ( $wgTitle->getNamespace() == NS_USER
857 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
860 $id=User
::idFromName($wgTitle->getText());
861 $ip=User
::isIP($wgTitle->getText());
863 if($id ||
$ip) { # both anons and non-anons have contri list
864 $s .= $sep . $this->userContribsLink();
866 if( $this->showEmailUser( $id ) ) {
867 $s .= $sep . $this->emailUserLink();
870 if ( $wgTitle->getArticleId() ) {
872 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
873 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
874 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
876 $s .= "<br />\n" . $this->otherLanguages();
881 function pageStats() {
882 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
883 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
885 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
886 if ( ! $wgOut->isArticle() ) { return ''; }
887 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
888 if ( 0 == $wgArticle->getID() ) { return ''; }
891 if ( !$wgDisableCounters ) {
892 $count = $wgLang->formatNum( $wgArticle->getCount() );
894 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
898 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
899 require_once('Credits.php');
900 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
902 $s .= $this->lastModified();
905 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
906 $dbr =& wfGetDB( DB_SLAVE
);
907 extract( $dbr->tableNames( 'watchlist' ) );
908 $sql = "SELECT COUNT(*) AS n FROM $watchlist
909 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
910 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
911 $res = $dbr->query( $sql, 'Skin::pageStats');
912 $x = $dbr->fetchObject( $res );
913 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
916 return $s . ' ' . $this->getCopyright();
919 function getCopyright( $type = 'detect' ) {
920 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
922 if ( $type == 'detect' ) {
923 $oldid = $wgRequest->getVal( 'oldid' );
924 $diff = $wgRequest->getVal( 'diff' );
926 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
933 if ( $type == 'history' ) {
934 $msg = 'history_copyright';
940 if( $wgRightsPage ) {
941 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
942 } elseif( $wgRightsUrl ) {
943 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
948 $out .= wfMsgForContent( $msg, $link );
952 function getCopyrightIcon() {
953 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
955 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
956 $out = $wgCopyrightIcon;
957 } else if ( $wgRightsIcon ) {
958 $icon = htmlspecialchars( $wgRightsIcon );
959 if ( $wgRightsUrl ) {
960 $url = htmlspecialchars( $wgRightsUrl );
961 $out .= '<a href="'.$url.'">';
963 $text = htmlspecialchars( $wgRightsText );
964 $out .= "<img src=\"$icon\" alt='$text' />";
965 if ( $wgRightsUrl ) {
972 function getPoweredBy() {
974 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
975 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
979 function lastModified() {
980 global $wgLang, $wgArticle, $wgLoadBalancer;
982 $timestamp = $wgArticle->getTimestamp();
984 $d = $wgLang->timeanddate( $timestamp, true );
985 $s = ' ' . wfMsg( 'lastmodified', $d );
989 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
990 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
995 function logoText( $align = '' ) {
996 if ( '' != $align ) { $a = " align='{$align}'"; }
999 $mp = wfMsg( 'mainpage' );
1000 $titleObj = Title
::newFromText( $mp );
1001 if ( is_object( $titleObj ) ) {
1002 $url = $titleObj->escapeLocalURL();
1007 $logourl = $this->getLogo();
1008 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1013 * show a drop-down box of special pages
1014 * @TODO crash bug913. Need to be rewrote completly.
1016 function specialPagesList() {
1017 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
1018 require_once('SpecialPage.php');
1020 $pages = SpecialPage
::getPages();
1022 // special pages without access restriction
1023 foreach ( $pages[''] as $name => $page ) {
1024 $a[$name] = $page->getDescription();
1027 // Other special pages that are restricted.
1028 // Copied from SpecialSpecialpages.php
1029 foreach($wgAvailableRights as $right) {
1030 if( $wgUser->isAllowed($right) ) {
1031 /** Add all pages for this right */
1032 if(isset($pages[$right])) {
1033 foreach($pages[$right] as $name => $page) {
1034 $a[$name] = $page->getDescription();
1040 $go = wfMsg( 'go' );
1041 $sp = wfMsg( 'specialpages' );
1042 $spp = $wgContLang->specialPage( 'Specialpages' );
1044 $s = '<form id="specialpages" method="get" class="inline" ' .
1045 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1046 $s .= "<select name=\"wpDropdown\">\n";
1047 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1050 foreach ( $a as $name => $desc ) {
1051 $p = $wgContLang->specialPage( $name );
1052 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1054 $s .= "</select>\n";
1055 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1060 function mainPageLink() {
1061 $mp = wfMsgForContent( 'mainpage' );
1062 $mptxt = wfMsg( 'mainpage');
1063 $s = $this->makeKnownLink( $mp, $mptxt );
1067 function copyrightLink() {
1068 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1069 wfMsg( 'copyrightpagename' ) );
1073 function privacyLink() {
1074 $privacy = wfMsg( 'privacy' );
1075 if ($privacy == '-') {
1078 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1082 function aboutLink() {
1083 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1084 wfMsg( 'aboutsite' ) );
1088 function disclaimerLink() {
1089 $disclaimers = wfMsg( 'disclaimers' );
1090 if ($disclaimers == '-') {
1093 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1098 function editThisPage() {
1099 global $wgOut, $wgTitle;
1101 if ( ! $wgOut->isArticleRelated() ) {
1102 $s = wfMsg( 'protectedpage' );
1104 if ( $wgTitle->userCanEdit() ) {
1105 $t = wfMsg( 'editthispage' );
1107 $t = wfMsg( 'viewsource' );
1110 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1116 * Return URL options for the 'edit page' link.
1117 * This may include an 'oldid' specifier, if the current page view is such.
1122 function editUrlOptions() {
1125 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1126 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1128 return "action=edit";
1132 function deleteThisPage() {
1133 global $wgUser, $wgTitle, $wgRequest;
1135 $diff = $wgRequest->getVal( 'diff' );
1136 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1137 $t = wfMsg( 'deletethispage' );
1139 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1146 function protectThisPage() {
1147 global $wgUser, $wgTitle, $wgRequest;
1149 $diff = $wgRequest->getVal( 'diff' );
1150 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1151 if ( $wgTitle->isProtected() ) {
1152 $t = wfMsg( 'unprotectthispage' );
1153 $q = 'action=unprotect';
1155 $t = wfMsg( 'protectthispage' );
1156 $q = 'action=protect';
1158 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1165 function watchThisPage() {
1166 global $wgOut, $wgTitle;
1168 if ( $wgOut->isArticleRelated() ) {
1169 if ( $wgTitle->userIsWatching() ) {
1170 $t = wfMsg( 'unwatchthispage' );
1171 $q = 'action=unwatch';
1173 $t = wfMsg( 'watchthispage' );
1174 $q = 'action=watch';
1176 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1178 $s = wfMsg( 'notanarticle' );
1183 function moveThisPage() {
1186 if ( $wgTitle->userCanMove() ) {
1187 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1188 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1190 // no message if page is protected - would be redundant
1195 function historyLink() {
1198 return $this->makeKnownLinkObj( $wgTitle,
1199 wfMsg( 'history' ), 'action=history' );
1202 function whatLinksHere() {
1205 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1206 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1209 function userContribsLink() {
1212 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1213 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1216 function showEmailUser( $id ) {
1217 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1218 return $wgEnableEmail &&
1219 $wgEnableUserEmail &&
1220 $wgUser->isLoggedIn() && # show only to signed in users
1221 0 != $id; # we can only email to non-anons ..
1222 # '' != $id->getEmail() && # who must have an email address stored ..
1223 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1224 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1227 function emailUserLink() {
1230 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1231 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1234 function watchPageLinksLink() {
1235 global $wgOut, $wgTitle;
1237 if ( ! $wgOut->isArticleRelated() ) {
1238 return '(' . wfMsg( 'notanarticle' ) . ')';
1240 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1241 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1242 'target=' . $wgTitle->getPrefixedURL() );
1246 function trackbackLink() {
1249 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1250 . wfMsg('trackbacklink') . "</a>";
1253 function otherLanguages() {
1254 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1256 if ( $wgHideInterlanguageLinks ) {
1260 $a = $wgOut->getLanguageLinks();
1261 if ( 0 == count( $a ) ) {
1265 $s = wfMsg( 'otherlanguages' ) . ': ';
1267 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1268 foreach( $a as $l ) {
1269 if ( ! $first ) { $s .= ' | '; }
1272 $nt = Title
::newFromText( $l );
1273 $url = $nt->escapeFullURL();
1274 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1276 if ( '' == $text ) { $text = $l; }
1277 $style = $this->getExternalLinkAttributes( $l, $text );
1278 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1280 if($wgContLang->isRTL()) $s .= '</span>';
1284 function bugReportsLink() {
1285 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1286 wfMsg( 'bugreports' ) );
1290 function dateLink() {
1291 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1292 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1294 $id = $t1->getArticleID();
1297 $s = $this->makeBrokenLink( $t1->getText() );
1299 $s = $this->makeKnownLink( $t1->getText() );
1303 $id = $t2->getArticleID();
1306 $s .= $this->makeBrokenLink( $t2->getText() );
1308 $s .= $this->makeKnownLink( $t2->getText() );
1313 function talkLink() {
1316 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1317 # No discussion links for special pages
1321 if( $wgTitle->isTalkPage() ) {
1322 $link = $wgTitle->getSubjectPage();
1323 switch( $link->getNamespace() ) {
1325 $text = wfMsg('articlepage');
1328 $text = wfMsg('userpage');
1331 $text = wfMsg('projectpage');
1334 $text = wfMsg('imagepage');
1337 $text= wfMsg('articlepage');
1340 $link = $wgTitle->getTalkPage();
1341 $text = wfMsg( 'talkpage' );
1344 $s = $this->makeLinkObj( $link, $text );
1349 function commentLink() {
1350 global $wgTitle, $wgOut;
1352 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1356 # __NEWSECTIONLINK___ changes behaviour here
1357 # If it's present, the link points to this page, otherwise
1358 # it points to the talk page
1359 if( $wgTitle->isTalkPage() ) {
1361 } elseif( $wgOut->showNewSectionLink() ) {
1364 $title =& $wgTitle->getTalkPage();
1367 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1370 /* these are used extensively in SkinTemplate, but also some other places */
1371 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1372 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1373 return $title->getLocalURL( $urlaction );
1376 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1377 $title = Title
::newFromText( wfMsgForContent($name) );
1378 $this->checkTitle($title, $name);
1379 return $title->getLocalURL( $urlaction );
1382 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1383 $title = Title
::newFromText( $name );
1384 $this->checkTitle($title, $name);
1385 return $title->getLocalURL( $urlaction );
1388 # If url string starts with http, consider as external URL, else
1390 /*static*/ function makeInternalOrExternalUrl( $name ) {
1391 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1394 return $this->makeUrl( $name );
1398 # this can be passed the NS number as defined in Language.php
1399 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN
) {
1400 $title = Title
::makeTitleSafe( $namespace, $name );
1401 $this->checkTitle($title, $name);
1402 return $title->getLocalURL( $urlaction );
1405 /* these return an array with the 'href' and boolean 'exists' */
1406 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1407 $title = Title
::newFromText( $name );
1408 $this->checkTitle($title, $name);
1410 'href' => $title->getLocalURL( $urlaction ),
1411 'exists' => $title->getArticleID() != 0?
true:false
1416 * Make URL details where the article exists (or at least it's convenient to think so)
1418 function makeKnownUrlDetails( $name, $urlaction='' ) {
1419 $title = Title
::newFromText( $name );
1420 $this->checkTitle($title, $name);
1422 'href' => $title->getLocalURL( $urlaction ),
1427 # make sure we have some title to operate on
1428 /*static*/ function checkTitle ( &$title, &$name ) {
1429 if(!is_object($title)) {
1430 $title = Title
::newFromText( $name );
1431 if(!is_object($title)) {
1432 $title = Title
::newFromText( '--error: link target missing--' );
1438 * Build an array that represents the sidebar(s), the navigation bar among them
1443 function buildSidebar() {
1444 global $wgDBname, $parserMemc, $wgEnableSidebarCache;
1445 global $wgLanguageCode, $wgContLanguageCode;
1447 $fname = 'SkinTemplate::buildSidebar';
1449 wfProfileIn( $fname );
1451 $key = "{$wgDBname}:sidebar";
1452 $cacheSidebar = $wgEnableSidebarCache &&
1453 ($wgLanguageCode == $wgContLanguageCode);
1455 if ($cacheSidebar) {
1456 $cachedsidebar = $parserMemc->get( $key );
1457 if ($cachedsidebar!="") {
1458 wfProfileOut($fname);
1459 return $cachedsidebar;
1464 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1465 foreach ($lines as $line) {
1466 if (strpos($line, '*') !== 0)
1468 if (strpos($line, '**') !== 0) {
1469 $line = trim($line, '* ');
1472 if (strpos($line, '|') !== false) { // sanity check
1473 $line = explode( '|' , trim($line, '* '), 2 );
1474 $link = wfMsgForContent( $line[0] );
1477 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1479 if (wfEmptyMsg($line[0], $link))
1481 $href = $this->makeInternalOrExternalUrl( $link );
1482 $bar[$heading][] = array(
1485 'id' => 'n-' . strtr($line[1], ' ', '-'),
1488 } else { continue; }
1492 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1493 wfProfileOut( $fname );