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 wgPageName = "' . Xml
::escapeJsString( $data['titleprefixeddbkey'] ) . '";
283 var wgTitle = "' . Xml
::escapeJsString( $data['titletext'] ) . '";
284 var wgArticleId = ' . (int)$data['articleid'] . ';
286 var wgUserName = ' . ( $data['username'] == NULL ?
'null' : ( '"' . Xml
::escapeJsString( $data['username'] ) . '"' ) ) . ';
287 var wgUserLanguage = "' . Xml
::escapeJsString( $data['userlang'] ) . '";
288 var wgContentLanguage = "' . Xml
::escapeJsString( $data['lang'] ) . '";
295 function getHeadScripts() {
296 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
297 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
298 global $wgTitle, $wgCanonicalNamespaceNames;
300 $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
301 if ( $nsname === NULL ) $nsname = $wgTitle->getNsText();
304 'jsmimetype' => $wgJsMimeType,
305 'skinname' => $this->getSkinName(),
306 'stylepath' => $wgStylePath,
307 'articlepath' => $wgArticlePath,
308 'scriptpath' => $wgScriptPath,
309 'serverurl' => $wgServer,
310 'nscanonical' => $nsname,
311 'titleprefixeddbkey' => $wgTitle->getPrefixedDBKey(),
312 'titletext' => $wgTitle->getText(),
313 'articleid' => $wgTitle->getArticleId(),
314 'username' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
315 'userlang' => $wgLang->getCode(),
316 'lang' => $wgContLang->getCode(),
319 $r = Skin
::makeGlobalVariablesScript( $vars );
321 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
322 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
323 $userpage = $wgUser->getUserPage();
324 $userjs = htmlspecialchars( $this->makeUrl(
325 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
326 'action=raw&ctype='.$wgJsMimeType));
327 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
333 * To make it harder for someone to slip a user a fake
334 * user-JavaScript or user-CSS preview, a random token
335 * is associated with the login session. If it's not
336 * passed back with the preview request, we won't render
339 * @param string $action
343 function userCanPreview( $action ) {
344 global $wgTitle, $wgRequest, $wgUser;
346 if( $action != 'submit' )
348 if( !$wgRequest->wasPosted() )
350 if( !$wgTitle->userCanEditCssJsSubpage() )
352 return $wgUser->matchEditToken(
353 $wgRequest->getVal( 'wpEditToken' ) );
356 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
357 function getUserStylesheet() {
358 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
359 $sheet = $this->getStylesheet();
360 $action = $wgRequest->getText('action');
361 $s = "@import \"$wgStylePath/$sheet\";\n";
362 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
364 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
365 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
366 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
368 $s .= $this->doGetUserStyles();
373 * placeholder, returns generated js in monobook
375 function getUserJs() { return; }
378 * Return html code that include User stylesheets
380 function getUserStyles() {
381 $s = "<style type='text/css'>\n";
382 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
383 $s .= $this->getUserStylesheet();
384 $s .= "/*]]>*/ /* */\n";
390 * Some styles that are set by user through the user settings interface.
392 function doGetUserStyles() {
393 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
397 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
398 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
399 $s .= $wgRequest->getText('wpTextbox1');
401 $userpage = $wgUser->getUserPage();
402 $s.= '@import "'.$this->makeUrl(
403 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
404 'action=raw&ctype=text/css').'";'."\n";
408 return $s . $this->reallyDoGetUserStyles();
411 function reallyDoGetUserStyles() {
414 if (($undopt = $wgUser->getOption("underline")) != 2) {
415 $underline = $undopt ?
'underline' : 'none';
416 $s .= "a { text-decoration: $underline; }\n";
418 if( $wgUser->getOption( 'highlightbroken' ) ) {
419 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
422 a.new, #quickbar a.new,
423 a.stub, #quickbar a.stub {
425 text-decoration: inherit;
427 a.new:after, #quickbar a.new:after {
430 text-decoration: $underline;
432 a.stub:after, #quickbar a.stub:after {
435 text-decoration: $underline;
439 if( $wgUser->getOption( 'justify' ) ) {
440 $s .= "#article, #bodyContent { text-align: justify; }\n";
442 if( !$wgUser->getOption( 'showtoc' ) ) {
443 $s .= "#toc { display: none; }\n";
445 if( !$wgUser->getOption( 'editsection' ) ) {
446 $s .= ".editsection { display: none; }\n";
451 function getBodyOptions() {
452 global $wgUser, $wgTitle, $wgOut, $wgRequest;
454 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
456 if ( 0 != $wgTitle->getNamespace() ) {
457 $a = array( 'bgcolor' => '#ffffec' );
459 else $a = array( 'bgcolor' => '#FFFFFF' );
460 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
461 $wgTitle->userCanEdit() ) {
462 $t = wfMsg( 'editthispage' );
463 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
464 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
465 $a +
= array ('ondblclick' => $s);
468 $a['onload'] = $wgOut->getOnloadHandler();
469 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
470 if( $a['onload'] != '' ) {
473 $a['onload'] .= 'setupRightClickEdit()';
487 * This will be called immediately after the <body> tag. Split into
488 * two functions to make it easier to subclass.
490 function beforeContent() {
491 return $this->doBeforeContent();
494 function doBeforeContent() {
496 $fname = 'Skin::doBeforeContent';
497 wfProfileIn( $fname );
500 $qb = $this->qbSetting();
502 if( $langlinks = $this->otherLanguages() ) {
508 $borderhack = 'class="top"';
511 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
512 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
515 $left = ($qb == 1 ||
$qb == 3);
516 if($wgContLang->isRTL()) $left = !$left;
519 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
520 $this->logoText() . '</td>';
522 $s .= $this->getQuickbarCompensator( $rows );
524 $l = $wgContLang->isRTL() ?
'right' : 'left';
525 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
527 $s .= $this->topLinks() ;
528 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
530 $r = $wgContLang->isRTL() ?
"left" : "right";
531 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
532 $s .= $this->nameAndLogin();
533 $s .= "\n<br />" . $this->searchForm() . "</td>";
536 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
539 if ( $shove && !$left ) { # Right
540 $s .= $this->getQuickbarCompensator( $rows );
542 $s .= "</tr>\n</table>\n</div>\n";
543 $s .= "\n<div id='article'>\n";
545 $notice = wfGetSiteNotice();
547 $s .= "\n<div id='siteNotice'>$notice</div>\n";
549 $s .= $this->pageTitle();
550 $s .= $this->pageSubtitle() ;
551 $s .= $this->getCategories();
552 wfProfileOut( $fname );
557 function getCategoryLinks () {
558 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
561 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
564 $sep = wfMsgHtml( 'catseparator' );
566 // Use Unicode bidi embedding override characters,
567 // to make sure links don't smash each other up in ugly ways.
568 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
569 $embed = "<span dir='$dir'>";
571 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
573 $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks
));
574 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
575 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
578 # optional 'dmoz-like' category browser. Will be shown under the list
579 # of categories an article belong to
580 if($wgUseCategoryBrowser) {
581 $s .= '<br /><hr />';
583 # get a big array of the parents tree
584 $parenttree = $wgTitle->getParentCategoryTree();
585 # Skin object passed by reference cause it can not be
586 # accessed under the method subfunction drawCategoryBrowser
587 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
588 # Clean out bogus first entry and sort them
591 # Output one per line
592 $s .= implode("<br />\n", $tempout);
598 /** Render the array as a serie of links.
599 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
600 * @param &skin Object: skin passed by reference
601 * @return String separated by >, terminate with "\n"
603 function drawCategoryBrowser($tree, &$skin) {
605 foreach ($tree as $element => $parent) {
606 if (empty($parent)) {
607 # element start a new list
610 # grab the others elements
611 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
613 # add our current element to the list
614 $eltitle = Title
::NewFromText($element);
615 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
620 function getCategories() {
621 $catlinks=$this->getCategoryLinks();
622 if(!empty($catlinks)) {
623 return "<p class='catlinks'>{$catlinks}</p>";
627 function getQuickbarCompensator( $rows = 1 ) {
628 return "<td width='152' rowspan='{$rows}'> </td>";
632 * This gets called shortly before the \</body\> tag.
633 * @return String HTML to be put before \</body\>
635 function afterContent() {
636 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
637 return $printfooter . $this->doAfterContent();
641 * This gets called shortly before the \</body\> tag.
642 * @return String HTML-wrapped JS code to be put before \</body\>
644 function bottomScripts() {
645 global $wgJsMimeType;
646 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
649 /** @return string Retrievied from HTML text */
650 function printSource() {
652 $url = htmlspecialchars( $wgTitle->getFullURL() );
653 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
656 function printFooter() {
657 return "<p>" . $this->printSource() .
658 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
661 /** overloaded by derived classes */
662 function doAfterContent() { }
664 function pageTitleLinks() {
665 global $wgOut, $wgTitle, $wgUser, $wgRequest;
667 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
668 $action = $wgRequest->getText( 'action' );
670 $s = $this->printableLink();
671 $disclaimer = $this->disclaimerLink(); # may be empty
673 $s .= ' | ' . $disclaimer;
675 $privacy = $this->privacyLink(); # may be empty too
677 $s .= ' | ' . $privacy;
680 if ( $wgOut->isArticleRelated() ) {
681 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
682 $name = $wgTitle->getDBkey();
683 $image = new Image( $wgTitle );
684 if( $image->exists() ) {
685 $link = htmlspecialchars( $image->getURL() );
686 $style = $this->getInternalLinkAttributes( $link, $name );
687 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
691 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
692 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
693 wfMsg( 'currentrev' ) );
696 if ( $wgUser->getNewtalk() ) {
697 # do not show "You have new messages" text when we are viewing our
699 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
700 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
701 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
702 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
704 $wgOut->setSquidMaxage(0);
705 $wgOut->enableClientCache(false);
709 $undelete = $this->getUndeleteLink();
710 if( !empty( $undelete ) ) {
711 $s .= ' | '.$undelete;
716 function getUndeleteLink() {
717 global $wgUser, $wgTitle, $wgContLang, $action;
718 if( $wgUser->isAllowed( 'deletedhistory' ) &&
719 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
720 ($n = $wgTitle->isDeleted() ) )
722 if ( $wgUser->isAllowed( 'delete' ) ) {
723 $msg = 'thisisdeleted';
725 $msg = 'viewdeleted';
728 $this->makeKnownLink(
729 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
730 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
735 function printableLink() {
736 global $wgOut, $wgFeedClasses, $wgRequest;
738 $baseurl = $_SERVER['REQUEST_URI'];
739 if( strpos( '?', $baseurl ) == false ) {
744 $baseurl = htmlspecialchars( $baseurl );
745 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
747 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
748 if( $wgOut->isSyndicated() ) {
749 foreach( $wgFeedClasses as $format => $class ) {
750 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
751 $s .= " | <a href=\"$feedurl\">{$format}</a>";
757 function pageTitle() {
759 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
763 function pageSubtitle() {
766 $sub = $wgOut->getSubtitle();
768 global $wgExtraSubtitle;
769 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
771 $subpages = $this->subPageSubtitle();
772 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
773 $s = "<p class='subtitle'>{$sub}</p>\n";
777 function subPageSubtitle() {
778 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
780 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
781 $ptext=$wgTitle->getPrefixedText();
782 if(preg_match('/\//',$ptext)) {
783 $links = explode('/',$ptext);
786 foreach($links as $link) {
788 if ($c<count($links)) {
789 $growinglink .= $link;
790 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
791 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
795 $subpages .= '< ';
797 $subpages .= $getlink;
806 function nameAndLogin() {
807 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
809 $li = $wgContLang->specialPage( 'Userlogin' );
810 $lo = $wgContLang->specialPage( 'Userlogout' );
813 if ( $wgUser->isAnon() ) {
814 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
817 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
818 $wgLang->getNsText( NS_TALK
) );
820 $s .= $n . ' ('.$tl.')';
822 $s .= wfMsg('notloggedin');
825 $rt = $wgTitle->getPrefixedURL();
826 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
828 } else { $q = "returnto={$rt}"; }
830 $s .= "\n<br />" . $this->makeKnownLinkObj(
831 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
832 wfMsg( 'login' ), $q );
834 $n = $wgUser->getName();
835 $rt = $wgTitle->getPrefixedURL();
836 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
837 $wgLang->getNsText( NS_TALK
) );
841 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
842 $n ) . "{$tl}<br />" .
843 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
844 "returnto={$rt}" ) . ' | ' .
845 $this->specialLink( 'preferences' );
847 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
853 function getSearchLink() {
854 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
855 return $searchPage->getLocalURL();
858 function escapeSearchLink() {
859 return htmlspecialchars( $this->getSearchLink() );
862 function searchForm() {
864 $search = $wgRequest->getText( 'search' );
866 $s = '<form name="search" class="inline" method="post" action="'
867 . $this->escapeSearchLink() . "\">\n"
868 . '<input type="text" name="search" size="19" value="'
869 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
870 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" /> '
871 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
876 function topLinks() {
880 $s = $this->mainPageLink() . $sep
881 . $this->specialLink( 'recentchanges' );
883 if ( $wgOut->isArticleRelated() ) {
884 $s .= $sep . $this->editThisPage()
885 . $sep . $this->historyLink();
887 # Many people don't like this dropdown box
888 #$s .= $sep . $this->specialPagesList();
890 /* show links to different language variants */
891 global $wgDisableLangConversion, $wgContLang, $wgTitle;
892 $variants = $wgContLang->getVariants();
893 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
894 foreach( $variants as $code ) {
895 $varname = $wgContLang->getVariantname( $code );
896 if( $varname == 'disable' )
898 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
905 function bottomLinks() {
906 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
910 if ( $wgOut->isArticleRelated() ) {
911 $s .= '<strong>' . $this->editThisPage() . '</strong>';
912 if ( $wgUser->isLoggedIn() ) {
913 $s .= $sep . $this->watchThisPage();
915 $s .= $sep . $this->talkLink()
916 . $sep . $this->historyLink()
917 . $sep . $this->whatLinksHere()
918 . $sep . $this->watchPageLinksLink();
920 if ($wgUseTrackbacks)
921 $s .= $sep . $this->trackbackLink();
923 if ( $wgTitle->getNamespace() == NS_USER
924 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
927 $id=User
::idFromName($wgTitle->getText());
928 $ip=User
::isIP($wgTitle->getText());
930 if($id ||
$ip) { # both anons and non-anons have contri list
931 $s .= $sep . $this->userContribsLink();
933 if( $this->showEmailUser( $id ) ) {
934 $s .= $sep . $this->emailUserLink();
937 if ( $wgTitle->getArticleId() ) {
939 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
940 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
941 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
943 $s .= "<br />\n" . $this->otherLanguages();
948 function pageStats() {
949 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
950 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
952 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
953 if ( ! $wgOut->isArticle() ) { return ''; }
954 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
955 if ( 0 == $wgArticle->getID() ) { return ''; }
958 if ( !$wgDisableCounters ) {
959 $count = $wgLang->formatNum( $wgArticle->getCount() );
961 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
965 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
966 require_once('Credits.php');
967 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
969 $s .= $this->lastModified();
972 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
973 $dbr =& wfGetDB( DB_SLAVE
);
974 extract( $dbr->tableNames( 'watchlist' ) );
975 $sql = "SELECT COUNT(*) AS n FROM $watchlist
976 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
977 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
978 $res = $dbr->query( $sql, 'Skin::pageStats');
979 $x = $dbr->fetchObject( $res );
980 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
983 return $s . ' ' . $this->getCopyright();
986 function getCopyright( $type = 'detect' ) {
987 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
989 if ( $type == 'detect' ) {
990 $oldid = $wgRequest->getVal( 'oldid' );
991 $diff = $wgRequest->getVal( 'diff' );
993 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1000 if ( $type == 'history' ) {
1001 $msg = 'history_copyright';
1007 if( $wgRightsPage ) {
1008 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1009 } elseif( $wgRightsUrl ) {
1010 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1015 $out .= wfMsgForContent( $msg, $link );
1019 function getCopyrightIcon() {
1020 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1022 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1023 $out = $wgCopyrightIcon;
1024 } else if ( $wgRightsIcon ) {
1025 $icon = htmlspecialchars( $wgRightsIcon );
1026 if ( $wgRightsUrl ) {
1027 $url = htmlspecialchars( $wgRightsUrl );
1028 $out .= '<a href="'.$url.'">';
1030 $text = htmlspecialchars( $wgRightsText );
1031 $out .= "<img src=\"$icon\" alt='$text' />";
1032 if ( $wgRightsUrl ) {
1039 function getPoweredBy() {
1040 global $wgStylePath;
1041 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1042 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1046 function lastModified() {
1047 global $wgLang, $wgArticle, $wgLoadBalancer;
1049 $timestamp = $wgArticle->getTimestamp();
1051 $d = $wgLang->timeanddate( $timestamp, true );
1052 $s = ' ' . wfMsg( 'lastmodified', $d );
1056 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1057 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1062 function logoText( $align = '' ) {
1063 if ( '' != $align ) { $a = " align='{$align}'"; }
1066 $mp = wfMsg( 'mainpage' );
1067 $titleObj = Title
::newFromText( $mp );
1068 if ( is_object( $titleObj ) ) {
1069 $url = $titleObj->escapeLocalURL();
1074 $logourl = $this->getLogo();
1075 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1080 * show a drop-down box of special pages
1082 function specialPagesList() {
1083 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1084 require_once('SpecialPage.php');
1086 $pages = array_merge( SpecialPage
::getRegularPages(), SpecialPage
::getRestrictedPages() );
1087 foreach ( $pages as $name => $page ) {
1088 $pages[$name] = $page->getDescription();
1091 $go = wfMsg( 'go' );
1092 $sp = wfMsg( 'specialpages' );
1093 $spp = $wgContLang->specialPage( 'Specialpages' );
1095 $s = '<form id="specialpages" method="get" class="inline" ' .
1096 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1097 $s .= "<select name=\"wpDropdown\">\n";
1098 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1101 foreach ( $pages as $name => $desc ) {
1102 $p = $wgContLang->specialPage( $name );
1103 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1105 $s .= "</select>\n";
1106 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1111 function mainPageLink() {
1112 $mp = wfMsgForContent( 'mainpage' );
1113 $mptxt = wfMsg( 'mainpage');
1114 $s = $this->makeKnownLink( $mp, $mptxt );
1118 function copyrightLink() {
1119 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1120 wfMsg( 'copyrightpagename' ) );
1124 function privacyLink() {
1125 $privacy = wfMsg( 'privacy' );
1126 if ($privacy == '-') {
1129 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1133 function aboutLink() {
1134 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1135 wfMsg( 'aboutsite' ) );
1139 function disclaimerLink() {
1140 $disclaimers = wfMsg( 'disclaimers' );
1141 if ($disclaimers == '-') {
1144 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1149 function editThisPage() {
1150 global $wgOut, $wgTitle;
1152 if ( ! $wgOut->isArticleRelated() ) {
1153 $s = wfMsg( 'protectedpage' );
1155 if ( $wgTitle->userCanEdit() ) {
1156 $t = wfMsg( 'editthispage' );
1158 $t = wfMsg( 'viewsource' );
1161 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1167 * Return URL options for the 'edit page' link.
1168 * This may include an 'oldid' specifier, if the current page view is such.
1173 function editUrlOptions() {
1176 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1177 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1179 return "action=edit";
1183 function deleteThisPage() {
1184 global $wgUser, $wgTitle, $wgRequest;
1186 $diff = $wgRequest->getVal( 'diff' );
1187 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1188 $t = wfMsg( 'deletethispage' );
1190 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1197 function protectThisPage() {
1198 global $wgUser, $wgTitle, $wgRequest;
1200 $diff = $wgRequest->getVal( 'diff' );
1201 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1202 if ( $wgTitle->isProtected() ) {
1203 $t = wfMsg( 'unprotectthispage' );
1204 $q = 'action=unprotect';
1206 $t = wfMsg( 'protectthispage' );
1207 $q = 'action=protect';
1209 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1216 function watchThisPage() {
1217 global $wgOut, $wgTitle;
1219 if ( $wgOut->isArticleRelated() ) {
1220 if ( $wgTitle->userIsWatching() ) {
1221 $t = wfMsg( 'unwatchthispage' );
1222 $q = 'action=unwatch';
1224 $t = wfMsg( 'watchthispage' );
1225 $q = 'action=watch';
1227 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1229 $s = wfMsg( 'notanarticle' );
1234 function moveThisPage() {
1237 if ( $wgTitle->userCanMove() ) {
1238 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1239 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1241 // no message if page is protected - would be redundant
1246 function historyLink() {
1249 return $this->makeKnownLinkObj( $wgTitle,
1250 wfMsg( 'history' ), 'action=history' );
1253 function whatLinksHere() {
1256 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1257 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1260 function userContribsLink() {
1263 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1264 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1267 function showEmailUser( $id ) {
1268 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1269 return $wgEnableEmail &&
1270 $wgEnableUserEmail &&
1271 $wgUser->isLoggedIn() && # show only to signed in users
1272 0 != $id; # we can only email to non-anons ..
1273 # '' != $id->getEmail() && # who must have an email address stored ..
1274 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1275 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1278 function emailUserLink() {
1281 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1282 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1285 function watchPageLinksLink() {
1286 global $wgOut, $wgTitle;
1288 if ( ! $wgOut->isArticleRelated() ) {
1289 return '(' . wfMsg( 'notanarticle' ) . ')';
1291 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1292 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1293 'target=' . $wgTitle->getPrefixedURL() );
1297 function trackbackLink() {
1300 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1301 . wfMsg('trackbacklink') . "</a>";
1304 function otherLanguages() {
1305 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1307 if ( $wgHideInterlanguageLinks ) {
1311 $a = $wgOut->getLanguageLinks();
1312 if ( 0 == count( $a ) ) {
1316 $s = wfMsg( 'otherlanguages' ) . ': ';
1318 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1319 foreach( $a as $l ) {
1320 if ( ! $first ) { $s .= ' | '; }
1323 $nt = Title
::newFromText( $l );
1324 $url = $nt->escapeFullURL();
1325 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1327 if ( '' == $text ) { $text = $l; }
1328 $style = $this->getExternalLinkAttributes( $l, $text );
1329 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1331 if($wgContLang->isRTL()) $s .= '</span>';
1335 function bugReportsLink() {
1336 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1337 wfMsg( 'bugreports' ) );
1341 function dateLink() {
1342 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1343 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1345 $id = $t1->getArticleID();
1348 $s = $this->makeBrokenLink( $t1->getText() );
1350 $s = $this->makeKnownLink( $t1->getText() );
1354 $id = $t2->getArticleID();
1357 $s .= $this->makeBrokenLink( $t2->getText() );
1359 $s .= $this->makeKnownLink( $t2->getText() );
1364 function talkLink() {
1367 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1368 # No discussion links for special pages
1372 if( $wgTitle->isTalkPage() ) {
1373 $link = $wgTitle->getSubjectPage();
1374 switch( $link->getNamespace() ) {
1376 $text = wfMsg( 'articlepage' );
1379 $text = wfMsg( 'userpage' );
1382 $text = wfMsg( 'projectpage' );
1385 $text = wfMsg( 'imagepage' );
1388 $text = wfMsg( 'mediawikipage' );
1391 $text = wfMsg( 'templatepage' );
1394 $text = wfMsg( 'viewhelppage' );
1397 $text = wfMsg( 'categorypage' );
1400 $text = wfMsg( 'articlepage' );
1403 $link = $wgTitle->getTalkPage();
1404 $text = wfMsg( 'talkpage' );
1407 $s = $this->makeLinkObj( $link, $text );
1412 function commentLink() {
1413 global $wgTitle, $wgOut;
1415 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1419 # __NEWSECTIONLINK___ changes behaviour here
1420 # If it's present, the link points to this page, otherwise
1421 # it points to the talk page
1422 if( $wgTitle->isTalkPage() ) {
1424 } elseif( $wgOut->showNewSectionLink() ) {
1427 $title =& $wgTitle->getTalkPage();
1430 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1433 /* these are used extensively in SkinTemplate, but also some other places */
1434 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1435 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1436 return $title->getLocalURL( $urlaction );
1439 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1440 $title = Title
::newFromText( wfMsgForContent($name) );
1441 $this->checkTitle($title, $name);
1442 return $title->getLocalURL( $urlaction );
1445 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1446 $title = Title
::newFromText( $name );
1447 $this->checkTitle($title, $name);
1448 return $title->getLocalURL( $urlaction );
1451 # If url string starts with http, consider as external URL, else
1453 /*static*/ function makeInternalOrExternalUrl( $name ) {
1454 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1457 return $this->makeUrl( $name );
1461 # this can be passed the NS number as defined in Language.php
1462 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN
) {
1463 $title = Title
::makeTitleSafe( $namespace, $name );
1464 $this->checkTitle($title, $name);
1465 return $title->getLocalURL( $urlaction );
1468 /* these return an array with the 'href' and boolean 'exists' */
1469 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1470 $title = Title
::newFromText( $name );
1471 $this->checkTitle($title, $name);
1473 'href' => $title->getLocalURL( $urlaction ),
1474 'exists' => $title->getArticleID() != 0?
true:false
1479 * Make URL details where the article exists (or at least it's convenient to think so)
1481 function makeKnownUrlDetails( $name, $urlaction='' ) {
1482 $title = Title
::newFromText( $name );
1483 $this->checkTitle($title, $name);
1485 'href' => $title->getLocalURL( $urlaction ),
1490 # make sure we have some title to operate on
1491 /*static*/ function checkTitle ( &$title, &$name ) {
1492 if(!is_object($title)) {
1493 $title = Title
::newFromText( $name );
1494 if(!is_object($title)) {
1495 $title = Title
::newFromText( '--error: link target missing--' );
1501 * Build an array that represents the sidebar(s), the navigation bar among them
1506 function buildSidebar() {
1507 global $wgDBname, $parserMemc, $wgEnableSidebarCache;
1508 global $wgLang, $wgContLang;
1510 $fname = 'SkinTemplate::buildSidebar';
1512 wfProfileIn( $fname );
1514 $key = "{$wgDBname}:sidebar";
1515 $cacheSidebar = $wgEnableSidebarCache &&
1516 ($wgLang->getCode() == $wgContLang->getCode());
1518 if ($cacheSidebar) {
1519 $cachedsidebar = $parserMemc->get( $key );
1520 if ($cachedsidebar!="") {
1521 wfProfileOut($fname);
1522 return $cachedsidebar;
1527 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1528 foreach ($lines as $line) {
1529 if (strpos($line, '*') !== 0)
1531 if (strpos($line, '**') !== 0) {
1532 $line = trim($line, '* ');
1535 if (strpos($line, '|') !== false) { // sanity check
1536 $line = explode( '|' , trim($line, '* '), 2 );
1537 $link = wfMsgForContent( $line[0] );
1540 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1542 if (wfEmptyMsg($line[0], $link))
1544 $href = $this->makeInternalOrExternalUrl( $link );
1545 $bar[$heading][] = array(
1548 'id' => 'n-' . strtr($line[1], ' ', '-'),
1551 } else { continue; }
1555 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1556 wfProfileOut( $fname );