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, $wgLang, $wgContLang, $wgSquidMaxage;
301 $sheet = $this->getStylesheet();
302 $action = $wgRequest->getText('action');
303 $s = "@import \"$wgStylePath/$sheet\";\n";
304 if($wgLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
305 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_content_rtl.css\";\n";
307 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
308 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
309 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
311 $s .= $this->doGetUserStyles();
316 * placeholder, returns generated js in monobook
318 function getUserJs() { return; }
321 * Return html code that include User stylesheets
323 function getUserStyles() {
324 $s = "<style type='text/css'>\n";
325 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
326 $s .= $this->getUserStylesheet();
327 $s .= "/*]]>*/ /* */\n";
333 * Some styles that are set by user through the user settings interface.
335 function doGetUserStyles() {
336 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
340 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
341 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
342 $s .= $wgRequest->getText('wpTextbox1');
344 $userpage = $wgUser->getUserPage();
345 $s.= '@import "'.$this->makeUrl(
346 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
347 'action=raw&ctype=text/css').'";'."\n";
351 return $s . $this->reallyDoGetUserStyles();
354 function reallyDoGetUserStyles() {
357 if (($undopt = $wgUser->getOption("underline")) != 2) {
358 $underline = $undopt ?
'underline' : 'none';
359 $s .= "a { text-decoration: $underline; }\n";
361 if( $wgUser->getOption( 'highlightbroken' ) ) {
362 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
365 a.new, #quickbar a.new,
366 a.stub, #quickbar a.stub {
368 text-decoration: inherit;
370 a.new:after, #quickbar a.new:after {
373 text-decoration: $underline;
375 a.stub:after, #quickbar a.stub:after {
378 text-decoration: $underline;
382 if( $wgUser->getOption( 'justify' ) ) {
383 $s .= "#article, #bodyContent { text-align: justify; }\n";
385 if( !$wgUser->getOption( 'showtoc' ) ) {
386 $s .= "#toc { display: none; }\n";
388 if( !$wgUser->getOption( 'editsection' ) ) {
389 $s .= ".editsection { display: none; }\n";
394 function getBodyOptions() {
395 global $wgUser, $wgTitle, $wgOut, $wgRequest;
397 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
399 if ( 0 != $wgTitle->getNamespace() ) {
400 $a = array( 'bgcolor' => '#ffffec' );
402 else $a = array( 'bgcolor' => '#FFFFFF' );
403 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
404 $wgTitle->userCanEdit() ) {
405 $t = wfMsg( 'editthispage' );
406 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
407 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
408 $a +
= array ('ondblclick' => $s);
411 $a['onload'] = $wgOut->getOnloadHandler();
412 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
413 if( $a['onload'] != '' ) {
416 $a['onload'] .= 'setupRightClickEdit()';
430 * This will be called immediately after the <body> tag. Split into
431 * two functions to make it easier to subclass.
433 function beforeContent() {
434 return $this->doBeforeContent();
437 function doBeforeContent() {
439 $fname = 'Skin::doBeforeContent';
440 wfProfileIn( $fname );
443 $qb = $this->qbSetting();
445 if( $langlinks = $this->otherLanguages() ) {
451 $borderhack = 'class="top"';
454 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
455 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
458 $left = ($qb == 1 ||
$qb == 3);
459 if($wgLang->isRTL()) $left = !$left;
462 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
463 $this->logoText() . '</td>';
465 $s .= $this->getQuickbarCompensator( $rows );
467 $l = $wgLang->isRTL() ?
'right' : 'left';
468 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
470 $s .= $this->topLinks() ;
471 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
473 $r = $wgLang->isRTL() ?
"left" : "right";
474 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
475 $s .= $this->nameAndLogin();
476 $s .= "\n<br />" . $this->searchForm() . "</td>";
479 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
482 if ( $shove && !$left ) { # Right
483 $s .= $this->getQuickbarCompensator( $rows );
485 $s .= "</tr>\n</table>\n</div>\n";
486 $s .= "\n<div id='article'>\n";
488 $notice = wfGetSiteNotice();
490 $s .= "\n<div id='siteNotice'>$notice</div>\n";
492 $s .= $this->pageTitle();
493 $s .= $this->pageSubtitle() ;
494 $s .= $this->getCategories();
495 wfProfileOut( $fname );
500 function getCategoryLinks () {
501 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
504 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
507 $sep = wfMsgHtml( 'catseparator' );
509 // Use Unicode bidi embedding override characters,
510 // to make sure links don't smash each other up in ugly ways.
511 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
512 $embed = "<span dir='$dir'>";
514 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
516 $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks
));
517 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
518 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
521 # optional 'dmoz-like' category browser. Will be shown under the list
522 # of categories an article belong to
523 if($wgUseCategoryBrowser) {
524 $s .= '<br /><hr />';
526 # get a big array of the parents tree
527 $parenttree = $wgTitle->getParentCategoryTree();
528 # Skin object passed by reference cause it can not be
529 # accessed under the method subfunction drawCategoryBrowser
530 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
531 # Clean out bogus first entry and sort them
534 # Output one per line
535 $s .= implode("<br />\n", $tempout);
541 /** Render the array as a serie of links.
542 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
543 * @param &skin Object: skin passed by reference
544 * @return String separated by >, terminate with "\n"
546 function drawCategoryBrowser($tree, &$skin) {
548 foreach ($tree as $element => $parent) {
549 if (empty($parent)) {
550 # element start a new list
553 # grab the others elements
554 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
556 # add our current element to the list
557 $eltitle = Title
::NewFromText($element);
558 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
563 function getCategories() {
564 $catlinks=$this->getCategoryLinks();
565 if(!empty($catlinks)) {
566 return "<p class='catlinks'>{$catlinks}</p>";
570 function getQuickbarCompensator( $rows = 1 ) {
571 return "<td width='152' rowspan='{$rows}'> </td>";
575 * This gets called immediately before the \</body\> tag.
576 * @return String HTML to be put after \</body\> ???
578 function afterContent() {
579 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
580 return $printfooter . $this->doAfterContent();
583 /** @return string Retrievied from HTML text */
584 function printSource() {
586 $url = htmlspecialchars( $wgTitle->getFullURL() );
587 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
590 function printFooter() {
591 return "<p>" . $this->printSource() .
592 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
595 /** overloaded by derived classes */
596 function doAfterContent() { }
598 function pageTitleLinks() {
599 global $wgOut, $wgTitle, $wgUser, $wgRequest;
601 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
602 $action = $wgRequest->getText( 'action' );
604 $s = $this->printableLink();
605 $disclaimer = $this->disclaimerLink(); # may be empty
607 $s .= ' | ' . $disclaimer;
609 $privacy = $this->privacyLink(); # may be empty too
611 $s .= ' | ' . $privacy;
614 if ( $wgOut->isArticleRelated() ) {
615 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
616 $name = $wgTitle->getDBkey();
617 $image = new Image( $wgTitle );
618 if( $image->exists() ) {
619 $link = htmlspecialchars( $image->getURL() );
620 $style = $this->getInternalLinkAttributes( $link, $name );
621 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
625 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
626 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
627 wfMsg( 'currentrev' ) );
630 if ( $wgUser->getNewtalk() ) {
631 # do not show "You have new messages" text when we are viewing our
633 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
634 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
635 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
636 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
638 $wgOut->setSquidMaxage(0);
639 $wgOut->enableClientCache(false);
643 $undelete = $this->getUndeleteLink();
644 if( !empty( $undelete ) ) {
645 $s .= ' | '.$undelete;
650 function getUndeleteLink() {
651 global $wgUser, $wgTitle, $wgContLang, $action;
652 if( $wgUser->isAllowed( 'deletedhistory' ) &&
653 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
654 ($n = $wgTitle->isDeleted() ) )
656 if ( $wgUser->isAllowed( 'delete' ) ) {
657 $msg = 'thisisdeleted';
659 $msg = 'viewdeleted';
662 $this->makeKnownLink(
663 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
664 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
669 function printableLink() {
670 global $wgOut, $wgFeedClasses, $wgRequest;
672 $baseurl = $_SERVER['REQUEST_URI'];
673 if( strpos( '?', $baseurl ) == false ) {
678 $baseurl = htmlspecialchars( $baseurl );
679 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
681 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
682 if( $wgOut->isSyndicated() ) {
683 foreach( $wgFeedClasses as $format => $class ) {
684 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
685 $s .= " | <a href=\"$feedurl\">{$format}</a>";
691 function pageTitle() {
693 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
697 function pageSubtitle() {
700 $sub = $wgOut->getSubtitle();
702 global $wgExtraSubtitle;
703 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
705 $subpages = $this->subPageSubtitle();
706 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
707 $s = "<p class='subtitle'>{$sub}</p>\n";
711 function subPageSubtitle() {
712 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
714 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
715 $ptext=$wgTitle->getPrefixedText();
716 if(preg_match('/\//',$ptext)) {
717 $links = explode('/',$ptext);
720 foreach($links as $link) {
722 if ($c<count($links)) {
723 $growinglink .= $link;
724 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
725 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
729 $subpages .= '< ';
731 $subpages .= $getlink;
740 function nameAndLogin() {
741 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
743 $li = $wgContLang->specialPage( 'Userlogin' );
744 $lo = $wgContLang->specialPage( 'Userlogout' );
747 if ( $wgUser->isAnon() ) {
748 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
751 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
752 $wgLang->getNsText( NS_TALK
) );
754 $s .= $n . ' ('.$tl.')';
756 $s .= wfMsg('notloggedin');
759 $rt = $wgTitle->getPrefixedURL();
760 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
762 } else { $q = "returnto={$rt}"; }
764 $s .= "\n<br />" . $this->makeKnownLinkObj(
765 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
766 wfMsg( 'login' ), $q );
768 $n = $wgUser->getName();
769 $rt = $wgTitle->getPrefixedURL();
770 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
771 $wgLang->getNsText( NS_TALK
) );
775 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
776 $n ) . "{$tl}<br />" .
777 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
778 "returnto={$rt}" ) . ' | ' .
779 $this->specialLink( 'preferences' );
781 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
787 function getSearchLink() {
788 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
789 return $searchPage->getLocalURL();
792 function escapeSearchLink() {
793 return htmlspecialchars( $this->getSearchLink() );
796 function searchForm() {
798 $search = $wgRequest->getText( 'search' );
800 $s = '<form name="search" class="inline" method="post" action="'
801 . $this->escapeSearchLink() . "\">\n"
802 . '<input type="text" name="search" size="19" value="'
803 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
804 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" /> '
805 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
810 function topLinks() {
814 $s = $this->mainPageLink() . $sep
815 . $this->specialLink( 'recentchanges' );
817 if ( $wgOut->isArticleRelated() ) {
818 $s .= $sep . $this->editThisPage()
819 . $sep . $this->historyLink();
821 # Many people don't like this dropdown box
822 #$s .= $sep . $this->specialPagesList();
824 /* show links to different language variants */
825 global $wgDisableLangConversion, $wgContLang, $wgTitle;
826 $variants = $wgContLang->getVariants();
827 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
828 foreach( $variants as $code ) {
829 $varname = $wgContLang->getVariantname( $code );
830 if( $varname == 'disable' )
832 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
839 function bottomLinks() {
840 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
844 if ( $wgOut->isArticleRelated() ) {
845 $s .= '<strong>' . $this->editThisPage() . '</strong>';
846 if ( $wgUser->isLoggedIn() ) {
847 $s .= $sep . $this->watchThisPage();
849 $s .= $sep . $this->talkLink()
850 . $sep . $this->historyLink()
851 . $sep . $this->whatLinksHere()
852 . $sep . $this->watchPageLinksLink();
854 if ($wgUseTrackbacks)
855 $s .= $sep . $this->trackbackLink();
857 if ( $wgTitle->getNamespace() == NS_USER
858 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
861 $id=User
::idFromName($wgTitle->getText());
862 $ip=User
::isIP($wgTitle->getText());
864 if($id ||
$ip) { # both anons and non-anons have contri list
865 $s .= $sep . $this->userContribsLink();
867 if( $this->showEmailUser( $id ) ) {
868 $s .= $sep . $this->emailUserLink();
871 if ( $wgTitle->getArticleId() ) {
873 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
874 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
875 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
877 $s .= "<br />\n" . $this->otherLanguages();
882 function pageStats() {
883 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
884 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
886 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
887 if ( ! $wgOut->isArticle() ) { return ''; }
888 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
889 if ( 0 == $wgArticle->getID() ) { return ''; }
892 if ( !$wgDisableCounters ) {
893 $count = $wgLang->formatNum( $wgArticle->getCount() );
895 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
899 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
900 require_once('Credits.php');
901 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
903 $s .= $this->lastModified();
906 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
907 $dbr =& wfGetDB( DB_SLAVE
);
908 extract( $dbr->tableNames( 'watchlist' ) );
909 $sql = "SELECT COUNT(*) AS n FROM $watchlist
910 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
911 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
912 $res = $dbr->query( $sql, 'Skin::pageStats');
913 $x = $dbr->fetchObject( $res );
914 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
917 return $s . ' ' . $this->getCopyright();
920 function getCopyright( $type = 'detect' ) {
921 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
923 if ( $type == 'detect' ) {
924 $oldid = $wgRequest->getVal( 'oldid' );
925 $diff = $wgRequest->getVal( 'diff' );
927 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
934 if ( $type == 'history' ) {
935 $msg = 'history_copyright';
941 if( $wgRightsPage ) {
942 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
943 } elseif( $wgRightsUrl ) {
944 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
949 $out .= wfMsgForContent( $msg, $link );
953 function getCopyrightIcon() {
954 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
956 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
957 $out = $wgCopyrightIcon;
958 } else if ( $wgRightsIcon ) {
959 $icon = htmlspecialchars( $wgRightsIcon );
960 if ( $wgRightsUrl ) {
961 $url = htmlspecialchars( $wgRightsUrl );
962 $out .= '<a href="'.$url.'">';
964 $text = htmlspecialchars( $wgRightsText );
965 $out .= "<img src=\"$icon\" alt='$text' />";
966 if ( $wgRightsUrl ) {
973 function getPoweredBy() {
975 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
976 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
980 function lastModified() {
981 global $wgLang, $wgArticle, $wgLoadBalancer;
983 $timestamp = $wgArticle->getTimestamp();
985 $d = $wgLang->timeanddate( $timestamp, true );
986 $s = ' ' . wfMsg( 'lastmodified', $d );
990 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
991 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
996 function logoText( $align = '' ) {
997 if ( '' != $align ) { $a = " align='{$align}'"; }
1000 $mp = wfMsgForContent( 'mainpage' );
1001 $titleObj = Title
::newFromText( $mp );
1002 if ( is_object( $titleObj ) ) {
1003 $url = $titleObj->escapeLocalURL();
1008 $logourl = $this->getLogo();
1009 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1014 * show a drop-down box of special pages
1015 * @TODO crash bug913. Need to be rewrote completly.
1017 function specialPagesList() {
1018 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
1019 require_once('SpecialPage.php');
1021 $pages = SpecialPage
::getPages();
1023 // special pages without access restriction
1024 foreach ( $pages[''] as $name => $page ) {
1025 $a[$name] = $page->getDescription();
1028 // Other special pages that are restricted.
1029 // Copied from SpecialSpecialpages.php
1030 foreach($wgAvailableRights as $right) {
1031 if( $wgUser->isAllowed($right) ) {
1032 /** Add all pages for this right */
1033 if(isset($pages[$right])) {
1034 foreach($pages[$right] as $name => $page) {
1035 $a[$name] = $page->getDescription();
1041 $go = wfMsg( 'go' );
1042 $sp = wfMsg( 'specialpages' );
1043 $spp = $wgContLang->specialPage( 'Specialpages' );
1045 $s = '<form id="specialpages" method="get" class="inline" ' .
1046 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1047 $s .= "<select name=\"wpDropdown\">\n";
1048 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1051 foreach ( $a as $name => $desc ) {
1052 $p = $wgContLang->specialPage( $name );
1053 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1055 $s .= "</select>\n";
1056 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1061 function mainPageLink() {
1062 $mp = wfMsgForContent( 'mainpage' );
1063 $mptxt = wfMsg( 'mainpage');
1064 $s = $this->makeKnownLink( $mp, $mptxt );
1068 function copyrightLink() {
1069 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1070 wfMsg( 'copyrightpagename' ) );
1074 function privacyLink() {
1075 $privacy = wfMsg( 'privacy' );
1076 if ($privacy == '-') {
1079 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1083 function aboutLink() {
1084 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1085 wfMsg( 'aboutsite' ) );
1089 function disclaimerLink() {
1090 $disclaimers = wfMsg( 'disclaimers' );
1091 if ($disclaimers == '-') {
1094 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1099 function editThisPage() {
1100 global $wgOut, $wgTitle;
1102 if ( ! $wgOut->isArticleRelated() ) {
1103 $s = wfMsg( 'protectedpage' );
1105 if ( $wgTitle->userCanEdit() ) {
1106 $t = wfMsg( 'editthispage' );
1108 $t = wfMsg( 'viewsource' );
1111 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1117 * Return URL options for the 'edit page' link.
1118 * This may include an 'oldid' specifier, if the current page view is such.
1123 function editUrlOptions() {
1126 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1127 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1129 return "action=edit";
1133 function deleteThisPage() {
1134 global $wgUser, $wgTitle, $wgRequest;
1136 $diff = $wgRequest->getVal( 'diff' );
1137 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1138 $t = wfMsg( 'deletethispage' );
1140 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1147 function protectThisPage() {
1148 global $wgUser, $wgTitle, $wgRequest;
1150 $diff = $wgRequest->getVal( 'diff' );
1151 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1152 if ( $wgTitle->isProtected() ) {
1153 $t = wfMsg( 'unprotectthispage' );
1154 $q = 'action=unprotect';
1156 $t = wfMsg( 'protectthispage' );
1157 $q = 'action=protect';
1159 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1166 function watchThisPage() {
1167 global $wgOut, $wgTitle;
1169 if ( $wgOut->isArticleRelated() ) {
1170 if ( $wgTitle->userIsWatching() ) {
1171 $t = wfMsg( 'unwatchthispage' );
1172 $q = 'action=unwatch';
1174 $t = wfMsg( 'watchthispage' );
1175 $q = 'action=watch';
1177 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1179 $s = wfMsg( 'notanarticle' );
1184 function moveThisPage() {
1187 if ( $wgTitle->userCanMove() ) {
1188 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1189 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1191 // no message if page is protected - would be redundant
1196 function historyLink() {
1199 return $this->makeKnownLinkObj( $wgTitle,
1200 wfMsg( 'history' ), 'action=history' );
1203 function whatLinksHere() {
1206 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1207 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1210 function userContribsLink() {
1213 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1214 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1217 function showEmailUser( $id ) {
1218 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1219 return $wgEnableEmail &&
1220 $wgEnableUserEmail &&
1221 $wgUser->isLoggedIn() && # show only to signed in users
1222 0 != $id; # we can only email to non-anons ..
1223 # '' != $id->getEmail() && # who must have an email address stored ..
1224 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1225 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1228 function emailUserLink() {
1231 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1232 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1235 function watchPageLinksLink() {
1236 global $wgOut, $wgTitle;
1238 if ( ! $wgOut->isArticleRelated() ) {
1239 return '(' . wfMsg( 'notanarticle' ) . ')';
1241 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1242 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1243 'target=' . $wgTitle->getPrefixedURL() );
1247 function trackbackLink() {
1250 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1251 . wfMsg('trackbacklink') . "</a>";
1254 function otherLanguages() {
1255 global $wgOut, $wgLang, $wgHideInterlanguageLinks;
1257 if ( $wgHideInterlanguageLinks ) {
1261 $a = $wgOut->getLanguageLinks();
1262 if ( 0 == count( $a ) ) {
1266 $s = wfMsg( 'otherlanguages' ) . ': ';
1268 if($wgLang->isRTL()) $s .= '<span dir="LTR">';
1269 foreach( $a as $l ) {
1270 if ( ! $first ) { $s .= ' | '; }
1273 $nt = Title
::newFromText( $l );
1274 $url = $nt->escapeFullURL();
1275 $text = $wgLang->getLanguageName( $nt->getInterwiki() );
1277 if ( '' == $text ) { $text = $l; }
1278 $style = $this->getExternalLinkAttributes( $l, $text );
1279 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1281 if($wgLang->isRTL()) $s .= '</span>';
1285 function bugReportsLink() {
1286 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1287 wfMsg( 'bugreports' ) );
1291 function dateLink() {
1292 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1293 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1295 $id = $t1->getArticleID();
1298 $s = $this->makeBrokenLink( $t1->getText() );
1300 $s = $this->makeKnownLink( $t1->getText() );
1304 $id = $t2->getArticleID();
1307 $s .= $this->makeBrokenLink( $t2->getText() );
1309 $s .= $this->makeKnownLink( $t2->getText() );
1314 function talkLink() {
1317 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1318 # No discussion links for special pages
1322 if( $wgTitle->isTalkPage() ) {
1323 $link = $wgTitle->getSubjectPage();
1324 switch( $link->getNamespace() ) {
1326 $text = wfMsg('articlepage');
1329 $text = wfMsg('userpage');
1332 $text = wfMsg('projectpage');
1335 $text = wfMsg('imagepage');
1338 $text= wfMsg('articlepage');
1341 $link = $wgTitle->getTalkPage();
1342 $text = wfMsg( 'talkpage' );
1345 $s = $this->makeLinkObj( $link, $text );
1350 function commentLink() {
1351 global $wgTitle, $wgOut;
1353 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1357 # __NEWSECTIONLINK___ changes behaviour here
1358 # If it's present, the link points to this page, otherwise
1359 # it points to the talk page
1360 if( $wgTitle->isTalkPage() ) {
1362 } elseif( $wgOut->showNewSectionLink() ) {
1365 $title =& $wgTitle->getTalkPage();
1368 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1371 /* these are used extensively in SkinTemplate, but also some other places */
1372 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1373 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1374 return $title->getLocalURL( $urlaction );
1377 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1378 $title = Title
::newFromText( wfMsgForContent($name) );
1379 $this->checkTitle($title, $name);
1380 return $title->getLocalURL( $urlaction );
1383 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1384 $title = Title
::newFromText( $name );
1385 $this->checkTitle($title, $name);
1386 return $title->getLocalURL( $urlaction );
1389 # If url string starts with http, consider as external URL, else
1391 /*static*/ function makeInternalOrExternalUrl( $name ) {
1392 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1395 return $this->makeUrl( $name );
1399 # this can be passed the NS number as defined in Language.php
1400 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN
) {
1401 $title = Title
::makeTitleSafe( $namespace, $name );
1402 $this->checkTitle($title, $name);
1403 return $title->getLocalURL( $urlaction );
1406 /* these return an array with the 'href' and boolean 'exists' */
1407 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1408 $title = Title
::newFromText( $name );
1409 $this->checkTitle($title, $name);
1411 'href' => $title->getLocalURL( $urlaction ),
1412 'exists' => $title->getArticleID() != 0?
true:false
1417 * Make URL details where the article exists (or at least it's convenient to think so)
1419 function makeKnownUrlDetails( $name, $urlaction='' ) {
1420 $title = Title
::newFromText( $name );
1421 $this->checkTitle($title, $name);
1423 'href' => $title->getLocalURL( $urlaction ),
1428 # make sure we have some title to operate on
1429 /*static*/ function checkTitle ( &$title, &$name ) {
1430 if(!is_object($title)) {
1431 $title = Title
::newFromText( $name );
1432 if(!is_object($title)) {
1433 $title = Title
::newFromText( '--error: link target missing--' );
1439 * Build an array that represents the sidebar(s), the navigation bar among them
1444 function buildSidebar() {
1445 global $wgDBname, $parserMemc, $wgEnableSidebarCache;
1446 global $wgLanguageCode, $wgContLanguageCode;
1448 $fname = 'SkinTemplate::buildSidebar';
1450 wfProfileIn( $fname );
1452 $key = "{$wgDBname}:sidebar";
1453 $cacheSidebar = $wgEnableSidebarCache &&
1454 ($wgLanguageCode == $wgContLanguageCode);
1456 if ($cacheSidebar) {
1457 $cachedsidebar = $parserMemc->get( $key );
1458 if ($cachedsidebar!="") {
1459 wfProfileOut($fname);
1460 return $cachedsidebar;
1465 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1466 foreach ($lines as $line) {
1467 if (strpos($line, '*') !== 0)
1469 if (strpos($line, '**') !== 0) {
1470 $line = trim($line, '* ');
1473 if (strpos($line, '|') !== false) { // sanity check
1474 $line = explode( '|' , trim($line, '* '), 2 );
1475 $link = wfMsgForContent( $line[0] );
1478 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1480 if (wfEmptyMsg($line[0], $link))
1482 $href = $this->makeInternalOrExternalUrl( $link );
1483 $bar[$heading][] = array(
1486 'id' => 'n-' . strtr($line[1], ' ', '-'),
1489 } else { continue; }
1493 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1494 wfProfileOut( $fname );