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 = self
::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( self
::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 = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
369 $s .= '@import "' . self
::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
370 '@import "' . self
::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 "'.self
::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, $wgContLang;
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()';
479 $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ?
"rtl" : "ltr");
492 * This will be called immediately after the <body> tag. Split into
493 * two functions to make it easier to subclass.
495 function beforeContent() {
496 return $this->doBeforeContent();
499 function doBeforeContent() {
501 $fname = 'Skin::doBeforeContent';
502 wfProfileIn( $fname );
505 $qb = $this->qbSetting();
507 if( $langlinks = $this->otherLanguages() ) {
513 $borderhack = 'class="top"';
516 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
517 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
520 $left = ($qb == 1 ||
$qb == 3);
521 if($wgContLang->isRTL()) $left = !$left;
524 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
525 $this->logoText() . '</td>';
527 $s .= $this->getQuickbarCompensator( $rows );
529 $l = $wgContLang->isRTL() ?
'right' : 'left';
530 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
532 $s .= $this->topLinks() ;
533 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
535 $r = $wgContLang->isRTL() ?
"left" : "right";
536 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
537 $s .= $this->nameAndLogin();
538 $s .= "\n<br />" . $this->searchForm() . "</td>";
541 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
544 if ( $shove && !$left ) { # Right
545 $s .= $this->getQuickbarCompensator( $rows );
547 $s .= "</tr>\n</table>\n</div>\n";
548 $s .= "\n<div id='article'>\n";
550 $notice = wfGetSiteNotice();
552 $s .= "\n<div id='siteNotice'>$notice</div>\n";
554 $s .= $this->pageTitle();
555 $s .= $this->pageSubtitle() ;
556 $s .= $this->getCategories();
557 wfProfileOut( $fname );
562 function getCategoryLinks () {
563 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
566 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
569 $sep = wfMsgHtml( 'catseparator' );
571 // Use Unicode bidi embedding override characters,
572 // to make sure links don't smash each other up in ugly ways.
573 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
574 $embed = "<span dir='$dir'>";
576 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
578 $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks
));
579 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
580 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
583 # optional 'dmoz-like' category browser. Will be shown under the list
584 # of categories an article belong to
585 if($wgUseCategoryBrowser) {
586 $s .= '<br /><hr />';
588 # get a big array of the parents tree
589 $parenttree = $wgTitle->getParentCategoryTree();
590 # Skin object passed by reference cause it can not be
591 # accessed under the method subfunction drawCategoryBrowser
592 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
593 # Clean out bogus first entry and sort them
596 # Output one per line
597 $s .= implode("<br />\n", $tempout);
603 /** Render the array as a serie of links.
604 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
605 * @param &skin Object: skin passed by reference
606 * @return String separated by >, terminate with "\n"
608 function drawCategoryBrowser($tree, &$skin) {
610 foreach ($tree as $element => $parent) {
611 if (empty($parent)) {
612 # element start a new list
615 # grab the others elements
616 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
618 # add our current element to the list
619 $eltitle = Title
::NewFromText($element);
620 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
625 function getCategories() {
626 $catlinks=$this->getCategoryLinks();
627 if(!empty($catlinks)) {
628 return "<p class='catlinks'>{$catlinks}</p>";
632 function getQuickbarCompensator( $rows = 1 ) {
633 return "<td width='152' rowspan='{$rows}'> </td>";
637 * This gets called shortly before the \</body\> tag.
638 * @return String HTML to be put before \</body\>
640 function afterContent() {
641 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
642 return $printfooter . $this->doAfterContent();
646 * This gets called shortly before the \</body\> tag.
647 * @return String HTML-wrapped JS code to be put before \</body\>
649 function bottomScripts() {
650 global $wgJsMimeType;
651 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
654 /** @return string Retrievied from HTML text */
655 function printSource() {
657 $url = htmlspecialchars( $wgTitle->getFullURL() );
658 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
661 function printFooter() {
662 return "<p>" . $this->printSource() .
663 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
666 /** overloaded by derived classes */
667 function doAfterContent() { }
669 function pageTitleLinks() {
670 global $wgOut, $wgTitle, $wgUser, $wgRequest;
672 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
673 $action = $wgRequest->getText( 'action' );
675 $s = $this->printableLink();
676 $disclaimer = $this->disclaimerLink(); # may be empty
678 $s .= ' | ' . $disclaimer;
680 $privacy = $this->privacyLink(); # may be empty too
682 $s .= ' | ' . $privacy;
685 if ( $wgOut->isArticleRelated() ) {
686 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
687 $name = $wgTitle->getDBkey();
688 $image = new Image( $wgTitle );
689 if( $image->exists() ) {
690 $link = htmlspecialchars( $image->getURL() );
691 $style = $this->getInternalLinkAttributes( $link, $name );
692 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
696 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
697 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
698 wfMsg( 'currentrev' ) );
701 if ( $wgUser->getNewtalk() ) {
702 # do not show "You have new messages" text when we are viewing our
704 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
705 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
706 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
707 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
709 $wgOut->setSquidMaxage(0);
710 $wgOut->enableClientCache(false);
714 $undelete = $this->getUndeleteLink();
715 if( !empty( $undelete ) ) {
716 $s .= ' | '.$undelete;
721 function getUndeleteLink() {
722 global $wgUser, $wgTitle, $wgContLang, $action;
723 if( $wgUser->isAllowed( 'deletedhistory' ) &&
724 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
725 ($n = $wgTitle->isDeleted() ) )
727 if ( $wgUser->isAllowed( 'delete' ) ) {
728 $msg = 'thisisdeleted';
730 $msg = 'viewdeleted';
733 $this->makeKnownLink(
734 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
735 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
740 function printableLink() {
741 global $wgOut, $wgFeedClasses, $wgRequest;
743 $baseurl = $_SERVER['REQUEST_URI'];
744 if( strpos( '?', $baseurl ) == false ) {
749 $baseurl = htmlspecialchars( $baseurl );
750 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
752 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
753 if( $wgOut->isSyndicated() ) {
754 foreach( $wgFeedClasses as $format => $class ) {
755 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
756 $s .= " | <a href=\"$feedurl\">{$format}</a>";
762 function pageTitle() {
764 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
768 function pageSubtitle() {
771 $sub = $wgOut->getSubtitle();
773 global $wgExtraSubtitle;
774 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
776 $subpages = $this->subPageSubtitle();
777 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
778 $s = "<p class='subtitle'>{$sub}</p>\n";
782 function subPageSubtitle() {
783 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
785 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
786 $ptext=$wgTitle->getPrefixedText();
787 if(preg_match('/\//',$ptext)) {
788 $links = explode('/',$ptext);
791 foreach($links as $link) {
793 if ($c<count($links)) {
794 $growinglink .= $link;
795 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
796 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
800 $subpages .= '< ';
802 $subpages .= $getlink;
811 function nameAndLogin() {
812 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
814 $li = $wgContLang->specialPage( 'Userlogin' );
815 $lo = $wgContLang->specialPage( 'Userlogout' );
818 if ( $wgUser->isAnon() ) {
819 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
822 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
823 $wgLang->getNsText( NS_TALK
) );
825 $s .= $n . ' ('.$tl.')';
827 $s .= wfMsg('notloggedin');
830 $rt = $wgTitle->getPrefixedURL();
831 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
833 } else { $q = "returnto={$rt}"; }
835 $s .= "\n<br />" . $this->makeKnownLinkObj(
836 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
837 wfMsg( 'login' ), $q );
839 $n = $wgUser->getName();
840 $rt = $wgTitle->getPrefixedURL();
841 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
842 $wgLang->getNsText( NS_TALK
) );
846 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
847 $n ) . "{$tl}<br />" .
848 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
849 "returnto={$rt}" ) . ' | ' .
850 $this->specialLink( 'preferences' );
852 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
858 function getSearchLink() {
859 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
860 return $searchPage->getLocalURL();
863 function escapeSearchLink() {
864 return htmlspecialchars( $this->getSearchLink() );
867 function searchForm() {
869 $search = $wgRequest->getText( 'search' );
871 $s = '<form name="search" class="inline" method="post" action="'
872 . $this->escapeSearchLink() . "\">\n"
873 . '<input type="text" name="search" size="19" value="'
874 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
875 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" /> '
876 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
881 function topLinks() {
885 $s = $this->mainPageLink() . $sep
886 . $this->specialLink( 'recentchanges' );
888 if ( $wgOut->isArticleRelated() ) {
889 $s .= $sep . $this->editThisPage()
890 . $sep . $this->historyLink();
892 # Many people don't like this dropdown box
893 #$s .= $sep . $this->specialPagesList();
895 /* show links to different language variants */
896 global $wgDisableLangConversion, $wgContLang, $wgTitle;
897 $variants = $wgContLang->getVariants();
898 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
899 foreach( $variants as $code ) {
900 $varname = $wgContLang->getVariantname( $code );
901 if( $varname == 'disable' )
903 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
910 function bottomLinks() {
911 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
915 if ( $wgOut->isArticleRelated() ) {
916 $s .= '<strong>' . $this->editThisPage() . '</strong>';
917 if ( $wgUser->isLoggedIn() ) {
918 $s .= $sep . $this->watchThisPage();
920 $s .= $sep . $this->talkLink()
921 . $sep . $this->historyLink()
922 . $sep . $this->whatLinksHere()
923 . $sep . $this->watchPageLinksLink();
925 if ($wgUseTrackbacks)
926 $s .= $sep . $this->trackbackLink();
928 if ( $wgTitle->getNamespace() == NS_USER
929 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
932 $id=User
::idFromName($wgTitle->getText());
933 $ip=User
::isIP($wgTitle->getText());
935 if($id ||
$ip) { # both anons and non-anons have contri list
936 $s .= $sep . $this->userContribsLink();
938 if( $this->showEmailUser( $id ) ) {
939 $s .= $sep . $this->emailUserLink();
942 if ( $wgTitle->getArticleId() ) {
944 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
945 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
946 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
948 $s .= "<br />\n" . $this->otherLanguages();
953 function pageStats() {
954 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
955 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
957 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
958 if ( ! $wgOut->isArticle() ) { return ''; }
959 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
960 if ( 0 == $wgArticle->getID() ) { return ''; }
963 if ( !$wgDisableCounters ) {
964 $count = $wgLang->formatNum( $wgArticle->getCount() );
966 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
970 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
971 require_once('Credits.php');
972 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
974 $s .= $this->lastModified();
977 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
978 $dbr =& wfGetDB( DB_SLAVE
);
979 extract( $dbr->tableNames( 'watchlist' ) );
980 $sql = "SELECT COUNT(*) AS n FROM $watchlist
981 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
982 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
983 $res = $dbr->query( $sql, 'Skin::pageStats');
984 $x = $dbr->fetchObject( $res );
985 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
988 return $s . ' ' . $this->getCopyright();
991 function getCopyright( $type = 'detect' ) {
992 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
994 if ( $type == 'detect' ) {
995 $oldid = $wgRequest->getVal( 'oldid' );
996 $diff = $wgRequest->getVal( 'diff' );
998 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1005 if ( $type == 'history' ) {
1006 $msg = 'history_copyright';
1012 if( $wgRightsPage ) {
1013 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1014 } elseif( $wgRightsUrl ) {
1015 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1020 $out .= wfMsgForContent( $msg, $link );
1024 function getCopyrightIcon() {
1025 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1027 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1028 $out = $wgCopyrightIcon;
1029 } else if ( $wgRightsIcon ) {
1030 $icon = htmlspecialchars( $wgRightsIcon );
1031 if ( $wgRightsUrl ) {
1032 $url = htmlspecialchars( $wgRightsUrl );
1033 $out .= '<a href="'.$url.'">';
1035 $text = htmlspecialchars( $wgRightsText );
1036 $out .= "<img src=\"$icon\" alt='$text' />";
1037 if ( $wgRightsUrl ) {
1044 function getPoweredBy() {
1045 global $wgStylePath;
1046 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1047 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1051 function lastModified() {
1052 global $wgLang, $wgArticle, $wgLoadBalancer;
1054 $timestamp = $wgArticle->getTimestamp();
1056 $d = $wgLang->date( $timestamp, true );
1057 $t = $wgLang->time( $timestamp, true );
1058 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1062 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1063 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1068 function logoText( $align = '' ) {
1069 if ( '' != $align ) { $a = " align='{$align}'"; }
1072 $mp = wfMsg( 'mainpage' );
1073 $titleObj = Title
::newFromText( $mp );
1074 if ( is_object( $titleObj ) ) {
1075 $url = $titleObj->escapeLocalURL();
1080 $logourl = $this->getLogo();
1081 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1086 * show a drop-down box of special pages
1088 function specialPagesList() {
1089 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1091 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1092 foreach ( $pages as $name => $page ) {
1093 $pages[$name] = $page->getDescription();
1096 $go = wfMsg( 'go' );
1097 $sp = wfMsg( 'specialpages' );
1098 $spp = $wgContLang->specialPage( 'Specialpages' );
1100 $s = '<form id="specialpages" method="get" class="inline" ' .
1101 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1102 $s .= "<select name=\"wpDropdown\">\n";
1103 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1106 foreach ( $pages as $name => $desc ) {
1107 $p = $wgContLang->specialPage( $name );
1108 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1110 $s .= "</select>\n";
1111 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1116 function mainPageLink() {
1117 $mp = wfMsgForContent( 'mainpage' );
1118 $mptxt = wfMsg( 'mainpage');
1119 $s = $this->makeKnownLink( $mp, $mptxt );
1123 function copyrightLink() {
1124 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1125 wfMsg( 'copyrightpagename' ) );
1129 function privacyLink() {
1130 $privacy = wfMsg( 'privacy' );
1131 if ($privacy == '-') {
1134 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1138 function aboutLink() {
1139 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1140 wfMsg( 'aboutsite' ) );
1144 function disclaimerLink() {
1145 $disclaimers = wfMsg( 'disclaimers' );
1146 if ($disclaimers == '-') {
1149 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1154 function editThisPage() {
1155 global $wgOut, $wgTitle;
1157 if ( ! $wgOut->isArticleRelated() ) {
1158 $s = wfMsg( 'protectedpage' );
1160 if ( $wgTitle->userCanEdit() ) {
1161 $t = wfMsg( 'editthispage' );
1163 $t = wfMsg( 'viewsource' );
1166 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1172 * Return URL options for the 'edit page' link.
1173 * This may include an 'oldid' specifier, if the current page view is such.
1178 function editUrlOptions() {
1181 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1182 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1184 return "action=edit";
1188 function deleteThisPage() {
1189 global $wgUser, $wgTitle, $wgRequest;
1191 $diff = $wgRequest->getVal( 'diff' );
1192 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1193 $t = wfMsg( 'deletethispage' );
1195 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1202 function protectThisPage() {
1203 global $wgUser, $wgTitle, $wgRequest;
1205 $diff = $wgRequest->getVal( 'diff' );
1206 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1207 if ( $wgTitle->isProtected() ) {
1208 $t = wfMsg( 'unprotectthispage' );
1209 $q = 'action=unprotect';
1211 $t = wfMsg( 'protectthispage' );
1212 $q = 'action=protect';
1214 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1221 function watchThisPage() {
1222 global $wgOut, $wgTitle;
1224 if ( $wgOut->isArticleRelated() ) {
1225 if ( $wgTitle->userIsWatching() ) {
1226 $t = wfMsg( 'unwatchthispage' );
1227 $q = 'action=unwatch';
1229 $t = wfMsg( 'watchthispage' );
1230 $q = 'action=watch';
1232 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1234 $s = wfMsg( 'notanarticle' );
1239 function moveThisPage() {
1242 if ( $wgTitle->userCanMove() ) {
1243 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1244 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1246 // no message if page is protected - would be redundant
1251 function historyLink() {
1254 return $this->makeKnownLinkObj( $wgTitle,
1255 wfMsg( 'history' ), 'action=history' );
1258 function whatLinksHere() {
1261 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1262 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1265 function userContribsLink() {
1268 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1269 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1272 function showEmailUser( $id ) {
1273 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1274 return $wgEnableEmail &&
1275 $wgEnableUserEmail &&
1276 $wgUser->isLoggedIn() && # show only to signed in users
1277 0 != $id; # we can only email to non-anons ..
1278 # '' != $id->getEmail() && # who must have an email address stored ..
1279 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1280 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1283 function emailUserLink() {
1286 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1287 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1290 function watchPageLinksLink() {
1291 global $wgOut, $wgTitle;
1293 if ( ! $wgOut->isArticleRelated() ) {
1294 return '(' . wfMsg( 'notanarticle' ) . ')';
1296 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1297 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1298 'target=' . $wgTitle->getPrefixedURL() );
1302 function trackbackLink() {
1305 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1306 . wfMsg('trackbacklink') . "</a>";
1309 function otherLanguages() {
1310 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1312 if ( $wgHideInterlanguageLinks ) {
1316 $a = $wgOut->getLanguageLinks();
1317 if ( 0 == count( $a ) ) {
1321 $s = wfMsg( 'otherlanguages' ) . ': ';
1323 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1324 foreach( $a as $l ) {
1325 if ( ! $first ) { $s .= ' | '; }
1328 $nt = Title
::newFromText( $l );
1329 $url = $nt->escapeFullURL();
1330 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1332 if ( '' == $text ) { $text = $l; }
1333 $style = $this->getExternalLinkAttributes( $l, $text );
1334 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1336 if($wgContLang->isRTL()) $s .= '</span>';
1340 function bugReportsLink() {
1341 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1342 wfMsg( 'bugreports' ) );
1346 function dateLink() {
1347 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1348 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1350 $id = $t1->getArticleID();
1353 $s = $this->makeBrokenLink( $t1->getText() );
1355 $s = $this->makeKnownLink( $t1->getText() );
1359 $id = $t2->getArticleID();
1362 $s .= $this->makeBrokenLink( $t2->getText() );
1364 $s .= $this->makeKnownLink( $t2->getText() );
1369 function talkLink() {
1372 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1373 # No discussion links for special pages
1377 if( $wgTitle->isTalkPage() ) {
1378 $link = $wgTitle->getSubjectPage();
1379 switch( $link->getNamespace() ) {
1381 $text = wfMsg( 'articlepage' );
1384 $text = wfMsg( 'userpage' );
1387 $text = wfMsg( 'projectpage' );
1390 $text = wfMsg( 'imagepage' );
1393 $text = wfMsg( 'mediawikipage' );
1396 $text = wfMsg( 'templatepage' );
1399 $text = wfMsg( 'viewhelppage' );
1402 $text = wfMsg( 'categorypage' );
1405 $text = wfMsg( 'articlepage' );
1408 $link = $wgTitle->getTalkPage();
1409 $text = wfMsg( 'talkpage' );
1412 $s = $this->makeLinkObj( $link, $text );
1417 function commentLink() {
1418 global $wgTitle, $wgOut;
1420 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1424 # __NEWSECTIONLINK___ changes behaviour here
1425 # If it's present, the link points to this page, otherwise
1426 # it points to the talk page
1427 if( $wgTitle->isTalkPage() ) {
1429 } elseif( $wgOut->showNewSectionLink() ) {
1432 $title =& $wgTitle->getTalkPage();
1435 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1438 /* these are used extensively in SkinTemplate, but also some other places */
1439 static function makeSpecialUrl( $name, $urlaction = '' ) {
1440 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1441 return $title->getLocalURL( $urlaction );
1444 static function makeI18nUrl( $name, $urlaction = '' ) {
1445 $title = Title
::newFromText( wfMsgForContent( $name ) );
1446 self
::checkTitle( $title, $name );
1447 return $title->getLocalURL( $urlaction );
1450 static function makeUrl( $name, $urlaction = '' ) {
1451 $title = Title
::newFromText( $name );
1452 self
::checkTitle( $title, $name );
1453 return $title->getLocalURL( $urlaction );
1456 # If url string starts with http, consider as external URL, else
1458 static function makeInternalOrExternalUrl( $name ) {
1459 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1462 return self
::makeUrl( $name );
1466 # this can be passed the NS number as defined in Language.php
1467 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN
) {
1468 $title = Title
::makeTitleSafe( $namespace, $name );
1469 self
::checkTitle( $title, $name );
1470 return $title->getLocalURL( $urlaction );
1473 /* these return an array with the 'href' and boolean 'exists' */
1474 static function makeUrlDetails( $name, $urlaction = '' ) {
1475 $title = Title
::newFromText( $name );
1476 self
::checkTitle( $title, $name );
1478 'href' => $title->getLocalURL( $urlaction ),
1479 'exists' => $title->getArticleID() != 0 ?
true : false
1484 * Make URL details where the article exists (or at least it's convenient to think so)
1486 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1487 $title = Title
::newFromText( $name );
1488 self
::checkTitle( $title, $name );
1490 'href' => $title->getLocalURL( $urlaction ),
1495 # make sure we have some title to operate on
1496 static function checkTitle( &$title, &$name ) {
1497 if( !is_object( $title ) ) {
1498 $title = Title
::newFromText( $name );
1499 if( !is_object( $title ) ) {
1500 $title = Title
::newFromText( '--error: link target missing--' );
1506 * Build an array that represents the sidebar(s), the navigation bar among them
1511 function buildSidebar() {
1512 global $parserMemc, $wgEnableSidebarCache;
1513 global $wgLang, $wgContLang;
1515 $fname = 'SkinTemplate::buildSidebar';
1517 wfProfileIn( $fname );
1519 $key = wfMemcKey( 'sidebar' );
1520 $cacheSidebar = $wgEnableSidebarCache &&
1521 ($wgLang->getCode() == $wgContLang->getCode());
1523 if ($cacheSidebar) {
1524 $cachedsidebar = $parserMemc->get( $key );
1525 if ($cachedsidebar!="") {
1526 wfProfileOut($fname);
1527 return $cachedsidebar;
1532 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1533 foreach ($lines as $line) {
1534 if (strpos($line, '*') !== 0)
1536 if (strpos($line, '**') !== 0) {
1537 $line = trim($line, '* ');
1540 if (strpos($line, '|') !== false) { // sanity check
1541 $line = explode( '|' , trim($line, '* '), 2 );
1542 $link = wfMsgForContent( $line[0] );
1545 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1547 if (wfEmptyMsg($line[0], $link))
1549 $href = self
::makeInternalOrExternalUrl( $link );
1550 $bar[$heading][] = array(
1553 'id' => 'n-' . strtr($line[1], ' ', '-'),
1556 } else { continue; }
1560 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1561 wfProfileOut( $fname );