2 if ( ! defined( 'MEDIAWIKI' ) )
14 * The main skin class that provide methods and properties for all other skins.
15 * This base class is also the "Standard" skin.
18 class Skin
extends Linker
{
22 var $lastdate, $lastline;
23 var $rc_cache ; # Cache for Enhanced Recent Changes
24 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
28 /** Constructor, call parent constructor */
29 function Skin() { parent
::Linker(); }
32 * Fetch the set of available skins.
33 * @return array of strings
36 static function &getSkinNames() {
37 global $wgValidSkinNames;
38 static $skinsInitialised = false;
39 if ( !$skinsInitialised ) {
40 # Get a list of available skins
41 # Build using the regular expression '^(.*).php$'
42 # Array keys are all lower case, array value keep the case used by filename
44 wfProfileIn( __METHOD__
. '-init' );
45 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
48 # while code from www.php.net
49 while (false !== ($file = $skinDir->read())) {
50 // Skip non-PHP files, hidden files, and '.dep' includes
51 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
53 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
57 $skinsInitialised = true;
58 wfProfileOut( __METHOD__
. '-init' );
60 return $wgValidSkinNames;
64 * Normalize a skin preference value to a form that can be loaded.
65 * If a skin can't be found, it will fall back to the configured
66 * default (or the old 'Classic' skin if that's broken).
71 static function normalizeKey( $key ) {
72 global $wgDefaultSkin;
73 $skinNames = Skin
::getSkinNames();
76 // Don't return the default immediately;
77 // in a misconfiguration we need to fall back.
78 $key = $wgDefaultSkin;
81 if( isset( $skinNames[$key] ) ) {
85 // Older versions of the software used a numeric setting
86 // in the user preferences.
92 if( isset( $fallback[$key] ) ){
93 $key = $fallback[$key];
96 if( isset( $skinNames[$key] ) ) {
99 // The old built-in skin
105 * Factory method for loading a skin of a given type
106 * @param string $key 'monobook', 'standard', etc
110 static function &newFromKey( $key ) {
111 global $wgStyleDirectory;
113 $key = Skin
::normalizeKey( $key );
115 $skinNames = Skin
::getSkinNames();
116 $skinName = $skinNames[$key];
118 # Grab the skin class and initialise it.
119 wfSuppressWarnings();
120 // Preload base classes to work around APC/PHP5 bug
121 include_once( "{$wgStyleDirectory}/{$skinName}.deps.php" );
123 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
125 # Check if we got if not failback to default skin
126 $className = 'Skin'.$skinName;
127 if( !class_exists( $className ) ) {
128 # DO NOT die if the class isn't found. This breaks maintenance
129 # scripts and can cause a user account to be unrecoverable
130 # except by SQL manipulation if a previously valid skin name
131 # is no longer valid.
132 wfDebug( "Skin class does not exist: $className\n" );
133 $className = 'SkinStandard';
134 require_once( "{$wgStyleDirectory}/Standard.php" );
136 $skin = new $className;
140 /** @return string path to the skin stylesheet */
141 function getStylesheet() {
142 return 'common/wikistandard.css?1';
145 /** @return string skin name */
146 function getSkinName() {
150 function qbSetting() {
151 global $wgOut, $wgUser;
153 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
154 $q = $wgUser->getOption( 'quickbar' );
155 if ( '' == $q ) { $q = 0; }
159 function initPage( &$out ) {
160 global $wgFavicon, $wgScriptPath;
162 $fname = 'Skin::initPage';
163 wfProfileIn( $fname );
165 if( false !== $wgFavicon ) {
166 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
169 # OpenSearch description link
170 $out->addLink( array(
172 'type' => 'application/opensearchdescription+xml',
173 'href' => "$wgScriptPath/opensearch_desc.php"
176 $this->addMetadataLinks($out);
178 $this->mRevisionId
= $out->mRevisionId
;
180 $this->preloadExistence();
182 wfProfileOut( $fname );
186 * Preload the existence of three commonly-requested pages in a single query
188 function preloadExistence() {
189 global $wgUser, $wgTitle;
191 if ( $wgTitle->isTalkPage() ) {
192 $otherTab = $wgTitle->getSubjectPage();
194 $otherTab = $wgTitle->getTalkPage();
196 $lb = new LinkBatch( array(
197 $wgUser->getUserPage(),
198 $wgUser->getTalkPage(),
204 function addMetadataLinks( &$out ) {
205 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
206 global $wgRightsPage, $wgRightsUrl;
208 if( $out->isArticleRelated() ) {
209 # note: buggy CC software only reads first "meta" link
210 if( $wgEnableCreativeCommonsRdf ) {
211 $out->addMetadataLink( array(
212 'title' => 'Creative Commons',
213 'type' => 'application/rdf+xml',
214 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
216 if( $wgEnableDublinCoreRdf ) {
217 $out->addMetadataLink( array(
218 'title' => 'Dublin Core',
219 'type' => 'application/rdf+xml',
220 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
224 if( $wgRightsPage ) {
225 $copy = Title
::newFromText( $wgRightsPage );
227 $copyright = $copy->getLocalURL();
230 if( !$copyright && $wgRightsUrl ) {
231 $copyright = $wgRightsUrl;
234 $out->addLink( array(
235 'rel' => 'copyright',
236 'href' => $copyright ) );
240 function outputPage( &$out ) {
241 global $wgDebugComments;
243 wfProfileIn( 'Skin::outputPage' );
244 $this->initPage( $out );
246 $out->out( $out->headElement() );
248 $out->out( "\n<body" );
249 $ops = $this->getBodyOptions();
250 foreach ( $ops as $name => $val ) {
251 $out->out( " $name='$val'" );
254 if ( $wgDebugComments ) {
255 $out->out( "<!-- Wiki debugging output:\n" .
256 $out->mDebugtext
. "-->\n" );
259 $out->out( $this->beforeContent() );
261 $out->out( $out->mBodytext
. "\n" );
263 $out->out( $this->afterContent() );
265 $out->out( $this->bottomScripts() );
267 $out->out( $out->reportTime() );
269 $out->out( "\n</body></html>" );
272 /*static*/ function makeGlobalVariablesScript( $data ) {
273 $r = '<script type= "' . $data['jsmimetype'] . '">
274 var skin = "' . Xml
::escapeJsString( $data['skinname'] ) . '";
275 var stylepath = "' . Xml
::escapeJsString( $data['stylepath'] ) . '";
277 var wgArticlePath = "' . Xml
::escapeJsString( $data['articlepath'] ) . '";
278 var wgScriptPath = "' . Xml
::escapeJsString( $data['scriptpath'] ) . '";
279 var wgServer = "' . Xml
::escapeJsString( $data['serverurl'] ) . '";
281 var wgCanonicalNamespace = "' . Xml
::escapeJsString( $data['nscanonical'] ) . '";
282 var wgNamespaceNumber = ' . (int)$data['nsnumber'] . ';
283 var wgPageName = "' . Xml
::escapeJsString( $data['titleprefixeddbkey'] ) . '";
284 var wgTitle = "' . Xml
::escapeJsString( $data['titletext'] ) . '";
285 var wgArticleId = ' . (int)$data['articleid'] . ';
286 var wgIsArticle = ' . ( $data['isarticle'] ?
'true' : 'false' ) . ';
288 var wgUserName = ' . ( $data['username'] == NULL ?
'null' : ( '"' . Xml
::escapeJsString( $data['username'] ) . '"' ) ) . ';
289 var wgUserLanguage = "' . Xml
::escapeJsString( $data['userlang'] ) . '";
290 var wgContentLanguage = "' . Xml
::escapeJsString( $data['lang'] ) . '";
297 function getHeadScripts() {
298 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
299 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
300 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut;
302 $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
303 if ( $nsname === NULL ) $nsname = $wgTitle->getNsText();
306 'jsmimetype' => $wgJsMimeType,
307 'skinname' => $this->getSkinName(),
308 'stylepath' => $wgStylePath,
309 'articlepath' => $wgArticlePath,
310 'scriptpath' => $wgScriptPath,
311 'serverurl' => $wgServer,
312 'nscanonical' => $nsname,
313 'nsnumber' => $wgTitle->getNamespace(),
314 'titleprefixeddbkey' => $wgTitle->getPrefixedDBKey(),
315 'titletext' => $wgTitle->getText(),
316 'articleid' => $wgTitle->getArticleId(),
317 'isarticle' => $wgOut->isArticle(),
318 'username' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
319 'userlang' => $wgLang->getCode(),
320 'lang' => $wgContLang->getCode(),
323 $r = Skin
::makeGlobalVariablesScript( $vars );
325 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
326 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
327 $userpage = $wgUser->getUserPage();
328 $userjs = htmlspecialchars( $this->makeUrl(
329 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
330 'action=raw&ctype='.$wgJsMimeType));
331 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
337 * To make it harder for someone to slip a user a fake
338 * user-JavaScript or user-CSS preview, a random token
339 * is associated with the login session. If it's not
340 * passed back with the preview request, we won't render
343 * @param string $action
347 function userCanPreview( $action ) {
348 global $wgTitle, $wgRequest, $wgUser;
350 if( $action != 'submit' )
352 if( !$wgRequest->wasPosted() )
354 if( !$wgTitle->userCanEditCssJsSubpage() )
356 return $wgUser->matchEditToken(
357 $wgRequest->getVal( 'wpEditToken' ) );
360 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
361 function getUserStylesheet() {
362 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
363 $sheet = $this->getStylesheet();
364 $action = $wgRequest->getText('action');
365 $s = "@import \"$wgStylePath/$sheet\";\n";
366 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
368 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
369 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
370 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
372 $s .= $this->doGetUserStyles();
377 * placeholder, returns generated js in monobook
379 function getUserJs() { return; }
382 * Return html code that include User stylesheets
384 function getUserStyles() {
385 $s = "<style type='text/css'>\n";
386 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
387 $s .= $this->getUserStylesheet();
388 $s .= "/*]]>*/ /* */\n";
394 * Some styles that are set by user through the user settings interface.
396 function doGetUserStyles() {
397 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
401 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
402 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
403 $s .= $wgRequest->getText('wpTextbox1');
405 $userpage = $wgUser->getUserPage();
406 $s.= '@import "'.$this->makeUrl(
407 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
408 'action=raw&ctype=text/css').'";'."\n";
412 return $s . $this->reallyDoGetUserStyles();
415 function reallyDoGetUserStyles() {
418 if (($undopt = $wgUser->getOption("underline")) != 2) {
419 $underline = $undopt ?
'underline' : 'none';
420 $s .= "a { text-decoration: $underline; }\n";
422 if( $wgUser->getOption( 'highlightbroken' ) ) {
423 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
426 a.new, #quickbar a.new,
427 a.stub, #quickbar a.stub {
429 text-decoration: inherit;
431 a.new:after, #quickbar a.new:after {
434 text-decoration: $underline;
436 a.stub:after, #quickbar a.stub:after {
439 text-decoration: $underline;
443 if( $wgUser->getOption( 'justify' ) ) {
444 $s .= "#article, #bodyContent { text-align: justify; }\n";
446 if( !$wgUser->getOption( 'showtoc' ) ) {
447 $s .= "#toc { display: none; }\n";
449 if( !$wgUser->getOption( 'editsection' ) ) {
450 $s .= ".editsection { display: none; }\n";
455 function getBodyOptions() {
456 global $wgUser, $wgTitle, $wgOut, $wgRequest;
458 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
460 if ( 0 != $wgTitle->getNamespace() ) {
461 $a = array( 'bgcolor' => '#ffffec' );
463 else $a = array( 'bgcolor' => '#FFFFFF' );
464 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
465 $wgTitle->userCanEdit() ) {
466 $t = wfMsg( 'editthispage' );
467 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
468 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
469 $a +
= array ('ondblclick' => $s);
472 $a['onload'] = $wgOut->getOnloadHandler();
473 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
474 if( $a['onload'] != '' ) {
477 $a['onload'] .= 'setupRightClickEdit()';
491 * This will be called immediately after the <body> tag. Split into
492 * two functions to make it easier to subclass.
494 function beforeContent() {
495 return $this->doBeforeContent();
498 function doBeforeContent() {
500 $fname = 'Skin::doBeforeContent';
501 wfProfileIn( $fname );
504 $qb = $this->qbSetting();
506 if( $langlinks = $this->otherLanguages() ) {
512 $borderhack = 'class="top"';
515 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
516 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
519 $left = ($qb == 1 ||
$qb == 3);
520 if($wgContLang->isRTL()) $left = !$left;
523 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
524 $this->logoText() . '</td>';
526 $s .= $this->getQuickbarCompensator( $rows );
528 $l = $wgContLang->isRTL() ?
'right' : 'left';
529 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
531 $s .= $this->topLinks() ;
532 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
534 $r = $wgContLang->isRTL() ?
"left" : "right";
535 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
536 $s .= $this->nameAndLogin();
537 $s .= "\n<br />" . $this->searchForm() . "</td>";
540 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
543 if ( $shove && !$left ) { # Right
544 $s .= $this->getQuickbarCompensator( $rows );
546 $s .= "</tr>\n</table>\n</div>\n";
547 $s .= "\n<div id='article'>\n";
549 $notice = wfGetSiteNotice();
551 $s .= "\n<div id='siteNotice'>$notice</div>\n";
553 $s .= $this->pageTitle();
554 $s .= $this->pageSubtitle() ;
555 $s .= $this->getCategories();
556 wfProfileOut( $fname );
561 function getCategoryLinks () {
562 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
565 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
568 $sep = wfMsgHtml( 'catseparator' );
570 // Use Unicode bidi embedding override characters,
571 // to make sure links don't smash each other up in ugly ways.
572 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
573 $embed = "<span dir='$dir'>";
575 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
577 $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks
));
578 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
579 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
582 # optional 'dmoz-like' category browser. Will be shown under the list
583 # of categories an article belong to
584 if($wgUseCategoryBrowser) {
585 $s .= '<br /><hr />';
587 # get a big array of the parents tree
588 $parenttree = $wgTitle->getParentCategoryTree();
589 # Skin object passed by reference cause it can not be
590 # accessed under the method subfunction drawCategoryBrowser
591 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
592 # Clean out bogus first entry and sort them
595 # Output one per line
596 $s .= implode("<br />\n", $tempout);
602 /** Render the array as a serie of links.
603 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
604 * @param &skin Object: skin passed by reference
605 * @return String separated by >, terminate with "\n"
607 function drawCategoryBrowser($tree, &$skin) {
609 foreach ($tree as $element => $parent) {
610 if (empty($parent)) {
611 # element start a new list
614 # grab the others elements
615 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
617 # add our current element to the list
618 $eltitle = Title
::NewFromText($element);
619 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
624 function getCategories() {
625 $catlinks=$this->getCategoryLinks();
626 if(!empty($catlinks)) {
627 return "<p class='catlinks'>{$catlinks}</p>";
631 function getQuickbarCompensator( $rows = 1 ) {
632 return "<td width='152' rowspan='{$rows}'> </td>";
636 * This gets called shortly before the \</body\> tag.
637 * @return String HTML to be put before \</body\>
639 function afterContent() {
640 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
641 return $printfooter . $this->doAfterContent();
645 * This gets called shortly before the \</body\> tag.
646 * @return String HTML-wrapped JS code to be put before \</body\>
648 function bottomScripts() {
649 global $wgJsMimeType;
650 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
653 /** @return string Retrievied from HTML text */
654 function printSource() {
656 $url = htmlspecialchars( $wgTitle->getFullURL() );
657 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
660 function printFooter() {
661 return "<p>" . $this->printSource() .
662 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
665 /** overloaded by derived classes */
666 function doAfterContent() { }
668 function pageTitleLinks() {
669 global $wgOut, $wgTitle, $wgUser, $wgRequest;
671 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
672 $action = $wgRequest->getText( 'action' );
674 $s = $this->printableLink();
675 $disclaimer = $this->disclaimerLink(); # may be empty
677 $s .= ' | ' . $disclaimer;
679 $privacy = $this->privacyLink(); # may be empty too
681 $s .= ' | ' . $privacy;
684 if ( $wgOut->isArticleRelated() ) {
685 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
686 $name = $wgTitle->getDBkey();
687 $image = new Image( $wgTitle );
688 if( $image->exists() ) {
689 $link = htmlspecialchars( $image->getURL() );
690 $style = $this->getInternalLinkAttributes( $link, $name );
691 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
695 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
696 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
697 wfMsg( 'currentrev' ) );
700 if ( $wgUser->getNewtalk() ) {
701 # do not show "You have new messages" text when we are viewing our
703 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
704 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
705 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
706 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
708 $wgOut->setSquidMaxage(0);
709 $wgOut->enableClientCache(false);
713 $undelete = $this->getUndeleteLink();
714 if( !empty( $undelete ) ) {
715 $s .= ' | '.$undelete;
720 function getUndeleteLink() {
721 global $wgUser, $wgTitle, $wgContLang, $action;
722 if( $wgUser->isAllowed( 'deletedhistory' ) &&
723 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
724 ($n = $wgTitle->isDeleted() ) )
726 if ( $wgUser->isAllowed( 'delete' ) ) {
727 $msg = 'thisisdeleted';
729 $msg = 'viewdeleted';
732 $this->makeKnownLink(
733 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
734 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
739 function printableLink() {
740 global $wgOut, $wgFeedClasses, $wgRequest;
742 $baseurl = $_SERVER['REQUEST_URI'];
743 if( strpos( '?', $baseurl ) == false ) {
748 $baseurl = htmlspecialchars( $baseurl );
749 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
751 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
752 if( $wgOut->isSyndicated() ) {
753 foreach( $wgFeedClasses as $format => $class ) {
754 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
755 $s .= " | <a href=\"$feedurl\">{$format}</a>";
761 function pageTitle() {
763 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
767 function pageSubtitle() {
770 $sub = $wgOut->getSubtitle();
772 global $wgExtraSubtitle;
773 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
775 $subpages = $this->subPageSubtitle();
776 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
777 $s = "<p class='subtitle'>{$sub}</p>\n";
781 function subPageSubtitle() {
782 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
784 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
785 $ptext=$wgTitle->getPrefixedText();
786 if(preg_match('/\//',$ptext)) {
787 $links = explode('/',$ptext);
790 foreach($links as $link) {
792 if ($c<count($links)) {
793 $growinglink .= $link;
794 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
795 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
799 $subpages .= '< ';
801 $subpages .= $getlink;
810 function nameAndLogin() {
811 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
813 $li = $wgContLang->specialPage( 'Userlogin' );
814 $lo = $wgContLang->specialPage( 'Userlogout' );
817 if ( $wgUser->isAnon() ) {
818 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
821 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
822 $wgLang->getNsText( NS_TALK
) );
824 $s .= $n . ' ('.$tl.')';
826 $s .= wfMsg('notloggedin');
829 $rt = $wgTitle->getPrefixedURL();
830 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
832 } else { $q = "returnto={$rt}"; }
834 $s .= "\n<br />" . $this->makeKnownLinkObj(
835 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
836 wfMsg( 'login' ), $q );
838 $n = $wgUser->getName();
839 $rt = $wgTitle->getPrefixedURL();
840 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
841 $wgLang->getNsText( NS_TALK
) );
845 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
846 $n ) . "{$tl}<br />" .
847 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
848 "returnto={$rt}" ) . ' | ' .
849 $this->specialLink( 'preferences' );
851 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
857 function getSearchLink() {
858 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
859 return $searchPage->getLocalURL();
862 function escapeSearchLink() {
863 return htmlspecialchars( $this->getSearchLink() );
866 function searchForm() {
868 $search = $wgRequest->getText( 'search' );
870 $s = '<form name="search" class="inline" method="post" action="'
871 . $this->escapeSearchLink() . "\">\n"
872 . '<input type="text" name="search" size="19" value="'
873 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
874 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" /> '
875 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
880 function topLinks() {
884 $s = $this->mainPageLink() . $sep
885 . $this->specialLink( 'recentchanges' );
887 if ( $wgOut->isArticleRelated() ) {
888 $s .= $sep . $this->editThisPage()
889 . $sep . $this->historyLink();
891 # Many people don't like this dropdown box
892 #$s .= $sep . $this->specialPagesList();
894 /* show links to different language variants */
895 global $wgDisableLangConversion, $wgContLang, $wgTitle;
896 $variants = $wgContLang->getVariants();
897 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
898 foreach( $variants as $code ) {
899 $varname = $wgContLang->getVariantname( $code );
900 if( $varname == 'disable' )
902 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
909 function bottomLinks() {
910 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
914 if ( $wgOut->isArticleRelated() ) {
915 $s .= '<strong>' . $this->editThisPage() . '</strong>';
916 if ( $wgUser->isLoggedIn() ) {
917 $s .= $sep . $this->watchThisPage();
919 $s .= $sep . $this->talkLink()
920 . $sep . $this->historyLink()
921 . $sep . $this->whatLinksHere()
922 . $sep . $this->watchPageLinksLink();
924 if ($wgUseTrackbacks)
925 $s .= $sep . $this->trackbackLink();
927 if ( $wgTitle->getNamespace() == NS_USER
928 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
931 $id=User
::idFromName($wgTitle->getText());
932 $ip=User
::isIP($wgTitle->getText());
934 if($id ||
$ip) { # both anons and non-anons have contri list
935 $s .= $sep . $this->userContribsLink();
937 if( $this->showEmailUser( $id ) ) {
938 $s .= $sep . $this->emailUserLink();
941 if ( $wgTitle->getArticleId() ) {
943 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
944 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
945 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
947 $s .= "<br />\n" . $this->otherLanguages();
952 function pageStats() {
953 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
954 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
956 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
957 if ( ! $wgOut->isArticle() ) { return ''; }
958 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
959 if ( 0 == $wgArticle->getID() ) { return ''; }
962 if ( !$wgDisableCounters ) {
963 $count = $wgLang->formatNum( $wgArticle->getCount() );
965 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
969 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
970 require_once('Credits.php');
971 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
973 $s .= $this->lastModified();
976 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
977 $dbr =& wfGetDB( DB_SLAVE
);
978 extract( $dbr->tableNames( 'watchlist' ) );
979 $sql = "SELECT COUNT(*) AS n FROM $watchlist
980 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
981 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
982 $res = $dbr->query( $sql, 'Skin::pageStats');
983 $x = $dbr->fetchObject( $res );
984 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
987 return $s . ' ' . $this->getCopyright();
990 function getCopyright( $type = 'detect' ) {
991 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
993 if ( $type == 'detect' ) {
994 $oldid = $wgRequest->getVal( 'oldid' );
995 $diff = $wgRequest->getVal( 'diff' );
997 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1004 if ( $type == 'history' ) {
1005 $msg = 'history_copyright';
1011 if( $wgRightsPage ) {
1012 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1013 } elseif( $wgRightsUrl ) {
1014 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1019 $out .= wfMsgForContent( $msg, $link );
1023 function getCopyrightIcon() {
1024 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1026 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1027 $out = $wgCopyrightIcon;
1028 } else if ( $wgRightsIcon ) {
1029 $icon = htmlspecialchars( $wgRightsIcon );
1030 if ( $wgRightsUrl ) {
1031 $url = htmlspecialchars( $wgRightsUrl );
1032 $out .= '<a href="'.$url.'">';
1034 $text = htmlspecialchars( $wgRightsText );
1035 $out .= "<img src=\"$icon\" alt='$text' />";
1036 if ( $wgRightsUrl ) {
1043 function getPoweredBy() {
1044 global $wgStylePath;
1045 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1046 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1050 function lastModified() {
1051 global $wgLang, $wgArticle, $wgLoadBalancer;
1053 $timestamp = $wgArticle->getTimestamp();
1055 $d = $wgLang->timeanddate( $timestamp, true );
1056 $s = ' ' . wfMsg( 'lastmodified', $d );
1060 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1061 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1066 function logoText( $align = '' ) {
1067 if ( '' != $align ) { $a = " align='{$align}'"; }
1070 $mp = wfMsg( 'mainpage' );
1071 $titleObj = Title
::newFromText( $mp );
1072 if ( is_object( $titleObj ) ) {
1073 $url = $titleObj->escapeLocalURL();
1078 $logourl = $this->getLogo();
1079 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1084 * show a drop-down box of special pages
1086 function specialPagesList() {
1087 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1088 require_once('SpecialPage.php');
1090 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1091 foreach ( $pages as $name => $page ) {
1092 $pages[$name] = $page->getDescription();
1095 $go = wfMsg( 'go' );
1096 $sp = wfMsg( 'specialpages' );
1097 $spp = $wgContLang->specialPage( 'Specialpages' );
1099 $s = '<form id="specialpages" method="get" class="inline" ' .
1100 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1101 $s .= "<select name=\"wpDropdown\">\n";
1102 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1105 foreach ( $pages as $name => $desc ) {
1106 $p = $wgContLang->specialPage( $name );
1107 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1109 $s .= "</select>\n";
1110 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1115 function mainPageLink() {
1116 $mp = wfMsgForContent( 'mainpage' );
1117 $mptxt = wfMsg( 'mainpage');
1118 $s = $this->makeKnownLink( $mp, $mptxt );
1122 function copyrightLink() {
1123 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1124 wfMsg( 'copyrightpagename' ) );
1128 function privacyLink() {
1129 $privacy = wfMsg( 'privacy' );
1130 if ($privacy == '-') {
1133 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1137 function aboutLink() {
1138 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1139 wfMsg( 'aboutsite' ) );
1143 function disclaimerLink() {
1144 $disclaimers = wfMsg( 'disclaimers' );
1145 if ($disclaimers == '-') {
1148 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1153 function editThisPage() {
1154 global $wgOut, $wgTitle;
1156 if ( ! $wgOut->isArticleRelated() ) {
1157 $s = wfMsg( 'protectedpage' );
1159 if ( $wgTitle->userCanEdit() ) {
1160 $t = wfMsg( 'editthispage' );
1162 $t = wfMsg( 'viewsource' );
1165 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1171 * Return URL options for the 'edit page' link.
1172 * This may include an 'oldid' specifier, if the current page view is such.
1177 function editUrlOptions() {
1180 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1181 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1183 return "action=edit";
1187 function deleteThisPage() {
1188 global $wgUser, $wgTitle, $wgRequest;
1190 $diff = $wgRequest->getVal( 'diff' );
1191 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1192 $t = wfMsg( 'deletethispage' );
1194 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1201 function protectThisPage() {
1202 global $wgUser, $wgTitle, $wgRequest;
1204 $diff = $wgRequest->getVal( 'diff' );
1205 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1206 if ( $wgTitle->isProtected() ) {
1207 $t = wfMsg( 'unprotectthispage' );
1208 $q = 'action=unprotect';
1210 $t = wfMsg( 'protectthispage' );
1211 $q = 'action=protect';
1213 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1220 function watchThisPage() {
1221 global $wgOut, $wgTitle;
1223 if ( $wgOut->isArticleRelated() ) {
1224 if ( $wgTitle->userIsWatching() ) {
1225 $t = wfMsg( 'unwatchthispage' );
1226 $q = 'action=unwatch';
1228 $t = wfMsg( 'watchthispage' );
1229 $q = 'action=watch';
1231 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1233 $s = wfMsg( 'notanarticle' );
1238 function moveThisPage() {
1241 if ( $wgTitle->userCanMove() ) {
1242 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1243 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1245 // no message if page is protected - would be redundant
1250 function historyLink() {
1253 return $this->makeKnownLinkObj( $wgTitle,
1254 wfMsg( 'history' ), 'action=history' );
1257 function whatLinksHere() {
1260 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1261 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1264 function userContribsLink() {
1267 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1268 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1271 function showEmailUser( $id ) {
1272 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1273 return $wgEnableEmail &&
1274 $wgEnableUserEmail &&
1275 $wgUser->isLoggedIn() && # show only to signed in users
1276 0 != $id; # we can only email to non-anons ..
1277 # '' != $id->getEmail() && # who must have an email address stored ..
1278 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1279 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1282 function emailUserLink() {
1285 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1286 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1289 function watchPageLinksLink() {
1290 global $wgOut, $wgTitle;
1292 if ( ! $wgOut->isArticleRelated() ) {
1293 return '(' . wfMsg( 'notanarticle' ) . ')';
1295 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1296 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1297 'target=' . $wgTitle->getPrefixedURL() );
1301 function trackbackLink() {
1304 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1305 . wfMsg('trackbacklink') . "</a>";
1308 function otherLanguages() {
1309 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1311 if ( $wgHideInterlanguageLinks ) {
1315 $a = $wgOut->getLanguageLinks();
1316 if ( 0 == count( $a ) ) {
1320 $s = wfMsg( 'otherlanguages' ) . ': ';
1322 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1323 foreach( $a as $l ) {
1324 if ( ! $first ) { $s .= ' | '; }
1327 $nt = Title
::newFromText( $l );
1328 $url = $nt->escapeFullURL();
1329 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1331 if ( '' == $text ) { $text = $l; }
1332 $style = $this->getExternalLinkAttributes( $l, $text );
1333 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1335 if($wgContLang->isRTL()) $s .= '</span>';
1339 function bugReportsLink() {
1340 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1341 wfMsg( 'bugreports' ) );
1345 function dateLink() {
1346 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1347 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1349 $id = $t1->getArticleID();
1352 $s = $this->makeBrokenLink( $t1->getText() );
1354 $s = $this->makeKnownLink( $t1->getText() );
1358 $id = $t2->getArticleID();
1361 $s .= $this->makeBrokenLink( $t2->getText() );
1363 $s .= $this->makeKnownLink( $t2->getText() );
1368 function talkLink() {
1371 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1372 # No discussion links for special pages
1376 if( $wgTitle->isTalkPage() ) {
1377 $link = $wgTitle->getSubjectPage();
1378 switch( $link->getNamespace() ) {
1380 $text = wfMsg( 'articlepage' );
1383 $text = wfMsg( 'userpage' );
1386 $text = wfMsg( 'projectpage' );
1389 $text = wfMsg( 'imagepage' );
1392 $text = wfMsg( 'mediawikipage' );
1395 $text = wfMsg( 'templatepage' );
1398 $text = wfMsg( 'viewhelppage' );
1401 $text = wfMsg( 'categorypage' );
1404 $text = wfMsg( 'articlepage' );
1407 $link = $wgTitle->getTalkPage();
1408 $text = wfMsg( 'talkpage' );
1411 $s = $this->makeLinkObj( $link, $text );
1416 function commentLink() {
1417 global $wgTitle, $wgOut;
1419 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1423 # __NEWSECTIONLINK___ changes behaviour here
1424 # If it's present, the link points to this page, otherwise
1425 # it points to the talk page
1426 if( $wgTitle->isTalkPage() ) {
1428 } elseif( $wgOut->showNewSectionLink() ) {
1431 $title =& $wgTitle->getTalkPage();
1434 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1437 /* these are used extensively in SkinTemplate, but also some other places */
1438 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1439 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1440 return $title->getLocalURL( $urlaction );
1443 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1444 $title = Title
::newFromText( wfMsgForContent($name) );
1445 $this->checkTitle($title, $name);
1446 return $title->getLocalURL( $urlaction );
1449 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1450 $title = Title
::newFromText( $name );
1451 $this->checkTitle($title, $name);
1452 return $title->getLocalURL( $urlaction );
1455 # If url string starts with http, consider as external URL, else
1457 /*static*/ function makeInternalOrExternalUrl( $name ) {
1458 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1461 return $this->makeUrl( $name );
1465 # this can be passed the NS number as defined in Language.php
1466 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN
) {
1467 $title = Title
::makeTitleSafe( $namespace, $name );
1468 $this->checkTitle($title, $name);
1469 return $title->getLocalURL( $urlaction );
1472 /* these return an array with the 'href' and boolean 'exists' */
1473 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1474 $title = Title
::newFromText( $name );
1475 $this->checkTitle($title, $name);
1477 'href' => $title->getLocalURL( $urlaction ),
1478 'exists' => $title->getArticleID() != 0?
true:false
1483 * Make URL details where the article exists (or at least it's convenient to think so)
1485 function makeKnownUrlDetails( $name, $urlaction='' ) {
1486 $title = Title
::newFromText( $name );
1487 $this->checkTitle($title, $name);
1489 'href' => $title->getLocalURL( $urlaction ),
1494 # make sure we have some title to operate on
1495 /*static*/ function checkTitle ( &$title, &$name ) {
1496 if(!is_object($title)) {
1497 $title = Title
::newFromText( $name );
1498 if(!is_object($title)) {
1499 $title = Title
::newFromText( '--error: link target missing--' );
1505 * Build an array that represents the sidebar(s), the navigation bar among them
1510 function buildSidebar() {
1511 global $wgDBname, $parserMemc, $wgEnableSidebarCache;
1512 global $wgLang, $wgContLang;
1514 $fname = 'SkinTemplate::buildSidebar';
1516 wfProfileIn( $fname );
1518 $key = "{$wgDBname}:sidebar";
1519 $cacheSidebar = $wgEnableSidebarCache &&
1520 ($wgLang->getCode() == $wgContLang->getCode());
1522 if ($cacheSidebar) {
1523 $cachedsidebar = $parserMemc->get( $key );
1524 if ($cachedsidebar!="") {
1525 wfProfileOut($fname);
1526 return $cachedsidebar;
1531 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1532 foreach ($lines as $line) {
1533 if (strpos($line, '*') !== 0)
1535 if (strpos($line, '**') !== 0) {
1536 $line = trim($line, '* ');
1539 if (strpos($line, '|') !== false) { // sanity check
1540 $line = explode( '|' , trim($line, '* '), 2 );
1541 $link = wfMsgForContent( $line[0] );
1544 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1546 if (wfEmptyMsg($line[0], $link))
1548 $href = $this->makeInternalOrExternalUrl( $link );
1549 $bar[$heading][] = array(
1552 'id' => 'n-' . strtr($line[1], ' ', '-'),
1555 } else { continue; }
1559 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1560 wfProfileOut( $fname );