d8dbc16ac001d91db7d1feaea19e55e08acb416a
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 ) {
162 $fname = 'Skin::initPage';
163 wfProfileIn( $fname );
165 if( false !== $wgFavicon ) {
166 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
169 $this->addMetadataLinks($out);
171 $this->mRevisionId
= $out->mRevisionId
;
173 $this->preloadExistence();
175 wfProfileOut( $fname );
179 * Preload the existence of three commonly-requested pages in a single query
181 function preloadExistence() {
182 global $wgUser, $wgTitle;
184 if ( $wgTitle->isTalkPage() ) {
185 $otherTab = $wgTitle->getSubjectPage();
187 $otherTab = $wgTitle->getTalkPage();
189 $lb = new LinkBatch( array(
190 $wgUser->getUserPage(),
191 $wgUser->getTalkPage(),
197 function addMetadataLinks( &$out ) {
198 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
199 global $wgRightsPage, $wgRightsUrl;
201 if( $out->isArticleRelated() ) {
202 # note: buggy CC software only reads first "meta" link
203 if( $wgEnableCreativeCommonsRdf ) {
204 $out->addMetadataLink( array(
205 'title' => 'Creative Commons',
206 'type' => 'application/rdf+xml',
207 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
209 if( $wgEnableDublinCoreRdf ) {
210 $out->addMetadataLink( array(
211 'title' => 'Dublin Core',
212 'type' => 'application/rdf+xml',
213 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
217 if( $wgRightsPage ) {
218 $copy = Title
::newFromText( $wgRightsPage );
220 $copyright = $copy->getLocalURL();
223 if( !$copyright && $wgRightsUrl ) {
224 $copyright = $wgRightsUrl;
227 $out->addLink( array(
228 'rel' => 'copyright',
229 'href' => $copyright ) );
233 function outputPage( &$out ) {
234 global $wgDebugComments;
236 wfProfileIn( 'Skin::outputPage' );
237 $this->initPage( $out );
239 $out->out( $out->headElement() );
241 $out->out( "\n<body" );
242 $ops = $this->getBodyOptions();
243 foreach ( $ops as $name => $val ) {
244 $out->out( " $name='$val'" );
247 if ( $wgDebugComments ) {
248 $out->out( "<!-- Wiki debugging output:\n" .
249 $out->mDebugtext
. "-->\n" );
252 $out->out( $this->beforeContent() );
254 $out->out( $out->mBodytext
. "\n" );
256 $out->out( $this->afterContent() );
258 $out->out( $out->reportTime() );
260 $out->out( "\n</body></html>" );
263 /*static*/ function makeGlobalVariablesScript( $data ) {
264 $r = '<script type= "' . $data['jsmimetype'] . '">
265 var skin = "' . Xml
::escapeJsString( $data['skinname'] ) . '";
266 var stylepath = "' . Xml
::escapeJsString( $data['stylepath'] ) . '";
268 var wgArticlePath = "' . Xml
::escapeJsString( $data['articlepath'] ) . '";
269 var wgScriptPath = "' . Xml
::escapeJsString( $data['scriptpath'] ) . '";
270 var wgServer = "' . Xml
::escapeJsString( $data['serverurl'] ) . '";
272 var wgCanonicalNamespace = "' . Xml
::escapeJsString( $data['nscanonical'] ) . '";
273 var wgPageName = "' . Xml
::escapeJsString( $data['titleprefixeddbkey'] ) . '";
274 var wgTitle = "' . Xml
::escapeJsString( $data['titletext'] ) . '";
275 var wgArticleId = ' . (int)$data['articleid'] . ';
277 var wgUserName = ' . ( $data['username'] == NULL ?
'null' : ( '"' . Xml
::escapeJsString( $data['username'] ) . '"' ) ) . ';
278 var wgUserLanguage = "' . Xml
::escapeJsString( $data['userlang'] ) . '";
279 var wgContentLanguage = "' . Xml
::escapeJsString( $data['lang'] ) . '";
286 function getHeadScripts() {
287 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
288 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
289 global $wgTitle, $wgCanonicalNamespaceNames;
291 $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
292 if ( $nsname === NULL ) $nsname = $wgTitle->getNsText();
295 'jsmimetype' => $wgJsMimeType,
296 'skinname' => $this->getSkinName(),
297 'stylepath' => $wgStylePath,
298 'articlepath' => $wgArticlePath,
299 'scriptpath' => $wgScriptPath,
300 'serverurl' => $wgServer,
301 'nscanonical' => $nsname,
302 'titleprefixeddbkey' => $wgTitle->getPrefixedDBKey(),
303 'titletext' => $wgTitle->getText(),
304 'articleid' => $wgTitle->getArticleId(),
305 'username' => $wgUser->isAnon() ?
NULL : $wgUser->getName(),
306 'userlang' => $wgLang->getCode(),
307 'lang' => $wgContLang->getCode(),
310 $r = Skin
::makeGlobalVariablesScript( $vars );
312 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
313 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
314 $userpage = $wgUser->getUserPage();
315 $userjs = htmlspecialchars( $this->makeUrl(
316 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
317 'action=raw&ctype='.$wgJsMimeType));
318 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
324 * To make it harder for someone to slip a user a fake
325 * user-JavaScript or user-CSS preview, a random token
326 * is associated with the login session. If it's not
327 * passed back with the preview request, we won't render
330 * @param string $action
334 function userCanPreview( $action ) {
335 global $wgTitle, $wgRequest, $wgUser;
337 if( $action != 'submit' )
339 if( !$wgRequest->wasPosted() )
341 if( !$wgTitle->userCanEditCssJsSubpage() )
343 return $wgUser->matchEditToken(
344 $wgRequest->getVal( 'wpEditToken' ) );
347 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
348 function getUserStylesheet() {
349 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
350 $sheet = $this->getStylesheet();
351 $action = $wgRequest->getText('action');
352 $s = "@import \"$wgStylePath/$sheet\";\n";
353 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
355 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
356 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI
) . "\";\n" .
357 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI
) . "\";\n";
359 $s .= $this->doGetUserStyles();
364 * placeholder, returns generated js in monobook
366 function getUserJs() { return; }
369 * Return html code that include User stylesheets
371 function getUserStyles() {
372 $s = "<style type='text/css'>\n";
373 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
374 $s .= $this->getUserStylesheet();
375 $s .= "/*]]>*/ /* */\n";
381 * Some styles that are set by user through the user settings interface.
383 function doGetUserStyles() {
384 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
388 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
389 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
390 $s .= $wgRequest->getText('wpTextbox1');
392 $userpage = $wgUser->getUserPage();
393 $s.= '@import "'.$this->makeUrl(
394 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
395 'action=raw&ctype=text/css').'";'."\n";
399 return $s . $this->reallyDoGetUserStyles();
402 function reallyDoGetUserStyles() {
405 if (($undopt = $wgUser->getOption("underline")) != 2) {
406 $underline = $undopt ?
'underline' : 'none';
407 $s .= "a { text-decoration: $underline; }\n";
409 if( $wgUser->getOption( 'highlightbroken' ) ) {
410 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
413 a.new, #quickbar a.new,
414 a.stub, #quickbar a.stub {
416 text-decoration: inherit;
418 a.new:after, #quickbar a.new:after {
421 text-decoration: $underline;
423 a.stub:after, #quickbar a.stub:after {
426 text-decoration: $underline;
430 if( $wgUser->getOption( 'justify' ) ) {
431 $s .= "#article, #bodyContent { text-align: justify; }\n";
433 if( !$wgUser->getOption( 'showtoc' ) ) {
434 $s .= "#toc { display: none; }\n";
436 if( !$wgUser->getOption( 'editsection' ) ) {
437 $s .= ".editsection { display: none; }\n";
442 function getBodyOptions() {
443 global $wgUser, $wgTitle, $wgOut, $wgRequest;
445 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
447 if ( 0 != $wgTitle->getNamespace() ) {
448 $a = array( 'bgcolor' => '#ffffec' );
450 else $a = array( 'bgcolor' => '#FFFFFF' );
451 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
452 $wgTitle->userCanEdit() ) {
453 $t = wfMsg( 'editthispage' );
454 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
455 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
456 $a +
= array ('ondblclick' => $s);
459 $a['onload'] = $wgOut->getOnloadHandler();
460 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
461 if( $a['onload'] != '' ) {
464 $a['onload'] .= 'setupRightClickEdit()';
478 * This will be called immediately after the <body> tag. Split into
479 * two functions to make it easier to subclass.
481 function beforeContent() {
482 return $this->doBeforeContent();
485 function doBeforeContent() {
487 $fname = 'Skin::doBeforeContent';
488 wfProfileIn( $fname );
491 $qb = $this->qbSetting();
493 if( $langlinks = $this->otherLanguages() ) {
499 $borderhack = 'class="top"';
502 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
503 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
506 $left = ($qb == 1 ||
$qb == 3);
507 if($wgContLang->isRTL()) $left = !$left;
510 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
511 $this->logoText() . '</td>';
513 $s .= $this->getQuickbarCompensator( $rows );
515 $l = $wgContLang->isRTL() ?
'right' : 'left';
516 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
518 $s .= $this->topLinks() ;
519 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
521 $r = $wgContLang->isRTL() ?
"left" : "right";
522 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
523 $s .= $this->nameAndLogin();
524 $s .= "\n<br />" . $this->searchForm() . "</td>";
527 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
530 if ( $shove && !$left ) { # Right
531 $s .= $this->getQuickbarCompensator( $rows );
533 $s .= "</tr>\n</table>\n</div>\n";
534 $s .= "\n<div id='article'>\n";
536 $notice = wfGetSiteNotice();
538 $s .= "\n<div id='siteNotice'>$notice</div>\n";
540 $s .= $this->pageTitle();
541 $s .= $this->pageSubtitle() ;
542 $s .= $this->getCategories();
543 wfProfileOut( $fname );
548 function getCategoryLinks () {
549 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
552 if( count( $wgOut->mCategoryLinks
) == 0 ) return '';
555 $sep = wfMsgHtml( 'catseparator' );
557 // Use Unicode bidi embedding override characters,
558 // to make sure links don't smash each other up in ugly ways.
559 $dir = $wgContLang->isRTL() ?
'rtl' : 'ltr';
560 $embed = "<span dir='$dir'>";
562 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks
) . $pop;
564 $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks
));
565 $s = $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Categories' ),
566 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
569 # optional 'dmoz-like' category browser. Will be shown under the list
570 # of categories an article belong to
571 if($wgUseCategoryBrowser) {
572 $s .= '<br /><hr />';
574 # get a big array of the parents tree
575 $parenttree = $wgTitle->getParentCategoryTree();
576 # Skin object passed by reference cause it can not be
577 # accessed under the method subfunction drawCategoryBrowser
578 $tempout = explode("\n", Skin
::drawCategoryBrowser($parenttree, $this) );
579 # Clean out bogus first entry and sort them
582 # Output one per line
583 $s .= implode("<br />\n", $tempout);
589 /** Render the array as a serie of links.
590 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
591 * @param &skin Object: skin passed by reference
592 * @return String separated by >, terminate with "\n"
594 function drawCategoryBrowser($tree, &$skin) {
596 foreach ($tree as $element => $parent) {
597 if (empty($parent)) {
598 # element start a new list
601 # grab the others elements
602 $return .= Skin
::drawCategoryBrowser($parent, $skin) . ' > ';
604 # add our current element to the list
605 $eltitle = Title
::NewFromText($element);
606 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
611 function getCategories() {
612 $catlinks=$this->getCategoryLinks();
613 if(!empty($catlinks)) {
614 return "<p class='catlinks'>{$catlinks}</p>";
618 function getQuickbarCompensator( $rows = 1 ) {
619 return "<td width='152' rowspan='{$rows}'> </td>";
623 * This gets called immediately before the \</body\> tag.
624 * @return String HTML to be put after \</body\> ???
626 function afterContent() {
627 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
628 return $printfooter . $this->doAfterContent();
631 /** @return string Retrievied from HTML text */
632 function printSource() {
634 $url = htmlspecialchars( $wgTitle->getFullURL() );
635 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
638 function printFooter() {
639 return "<p>" . $this->printSource() .
640 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
643 /** overloaded by derived classes */
644 function doAfterContent() { }
646 function pageTitleLinks() {
647 global $wgOut, $wgTitle, $wgUser, $wgRequest;
649 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
650 $action = $wgRequest->getText( 'action' );
652 $s = $this->printableLink();
653 $disclaimer = $this->disclaimerLink(); # may be empty
655 $s .= ' | ' . $disclaimer;
657 $privacy = $this->privacyLink(); # may be empty too
659 $s .= ' | ' . $privacy;
662 if ( $wgOut->isArticleRelated() ) {
663 if ( $wgTitle->getNamespace() == NS_IMAGE
) {
664 $name = $wgTitle->getDBkey();
665 $image = new Image( $wgTitle );
666 if( $image->exists() ) {
667 $link = htmlspecialchars( $image->getURL() );
668 $style = $this->getInternalLinkAttributes( $link, $name );
669 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
673 if ( 'history' == $action ||
isset( $diff ) ||
isset( $oldid ) ) {
674 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
675 wfMsg( 'currentrev' ) );
678 if ( $wgUser->getNewtalk() ) {
679 # do not show "You have new messages" text when we are viewing our
681 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
682 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
683 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
684 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
686 $wgOut->setSquidMaxage(0);
687 $wgOut->enableClientCache(false);
691 $undelete = $this->getUndeleteLink();
692 if( !empty( $undelete ) ) {
693 $s .= ' | '.$undelete;
698 function getUndeleteLink() {
699 global $wgUser, $wgTitle, $wgContLang, $action;
700 if( $wgUser->isAllowed( 'deletedhistory' ) &&
701 (($wgTitle->getArticleId() == 0) ||
($action == "history")) &&
702 ($n = $wgTitle->isDeleted() ) )
704 if ( $wgUser->isAllowed( 'delete' ) ) {
705 $msg = 'thisisdeleted';
707 $msg = 'viewdeleted';
710 $this->makeKnownLink(
711 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
712 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
717 function printableLink() {
718 global $wgOut, $wgFeedClasses, $wgRequest;
720 $baseurl = $_SERVER['REQUEST_URI'];
721 if( strpos( '?', $baseurl ) == false ) {
726 $baseurl = htmlspecialchars( $baseurl );
727 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
729 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
730 if( $wgOut->isSyndicated() ) {
731 foreach( $wgFeedClasses as $format => $class ) {
732 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
733 $s .= " | <a href=\"$feedurl\">{$format}</a>";
739 function pageTitle() {
741 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
745 function pageSubtitle() {
748 $sub = $wgOut->getSubtitle();
750 global $wgExtraSubtitle;
751 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
753 $subpages = $this->subPageSubtitle();
754 $sub .= !empty($subpages)?
"</p><p class='subpages'>$subpages":'';
755 $s = "<p class='subtitle'>{$sub}</p>\n";
759 function subPageSubtitle() {
760 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
762 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
763 $ptext=$wgTitle->getPrefixedText();
764 if(preg_match('/\//',$ptext)) {
765 $links = explode('/',$ptext);
768 foreach($links as $link) {
770 if ($c<count($links)) {
771 $growinglink .= $link;
772 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
773 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
777 $subpages .= '< ';
779 $subpages .= $getlink;
788 function nameAndLogin() {
789 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
791 $li = $wgContLang->specialPage( 'Userlogin' );
792 $lo = $wgContLang->specialPage( 'Userlogout' );
795 if ( $wgUser->isAnon() ) {
796 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
799 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
800 $wgLang->getNsText( NS_TALK
) );
802 $s .= $n . ' ('.$tl.')';
804 $s .= wfMsg('notloggedin');
807 $rt = $wgTitle->getPrefixedURL();
808 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
810 } else { $q = "returnto={$rt}"; }
812 $s .= "\n<br />" . $this->makeKnownLinkObj(
813 Title
::makeTitle( NS_SPECIAL
, 'Userlogin' ),
814 wfMsg( 'login' ), $q );
816 $n = $wgUser->getName();
817 $rt = $wgTitle->getPrefixedURL();
818 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
819 $wgLang->getNsText( NS_TALK
) );
823 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
824 $n ) . "{$tl}<br />" .
825 $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Userlogout' ), wfMsg( 'logout' ),
826 "returnto={$rt}" ) . ' | ' .
827 $this->specialLink( 'preferences' );
829 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
835 function getSearchLink() {
836 $searchPage =& Title
::makeTitle( NS_SPECIAL
, 'Search' );
837 return $searchPage->getLocalURL();
840 function escapeSearchLink() {
841 return htmlspecialchars( $this->getSearchLink() );
844 function searchForm() {
846 $search = $wgRequest->getText( 'search' );
848 $s = '<form name="search" class="inline" method="post" action="'
849 . $this->escapeSearchLink() . "\">\n"
850 . '<input type="text" name="search" size="19" value="'
851 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
852 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" /> '
853 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
858 function topLinks() {
862 $s = $this->mainPageLink() . $sep
863 . $this->specialLink( 'recentchanges' );
865 if ( $wgOut->isArticleRelated() ) {
866 $s .= $sep . $this->editThisPage()
867 . $sep . $this->historyLink();
869 # Many people don't like this dropdown box
870 #$s .= $sep . $this->specialPagesList();
872 /* show links to different language variants */
873 global $wgDisableLangConversion, $wgContLang, $wgTitle;
874 $variants = $wgContLang->getVariants();
875 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
876 foreach( $variants as $code ) {
877 $varname = $wgContLang->getVariantname( $code );
878 if( $varname == 'disable' )
880 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
887 function bottomLinks() {
888 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
892 if ( $wgOut->isArticleRelated() ) {
893 $s .= '<strong>' . $this->editThisPage() . '</strong>';
894 if ( $wgUser->isLoggedIn() ) {
895 $s .= $sep . $this->watchThisPage();
897 $s .= $sep . $this->talkLink()
898 . $sep . $this->historyLink()
899 . $sep . $this->whatLinksHere()
900 . $sep . $this->watchPageLinksLink();
902 if ($wgUseTrackbacks)
903 $s .= $sep . $this->trackbackLink();
905 if ( $wgTitle->getNamespace() == NS_USER
906 ||
$wgTitle->getNamespace() == NS_USER_TALK
)
909 $id=User
::idFromName($wgTitle->getText());
910 $ip=User
::isIP($wgTitle->getText());
912 if($id ||
$ip) { # both anons and non-anons have contri list
913 $s .= $sep . $this->userContribsLink();
915 if( $this->showEmailUser( $id ) ) {
916 $s .= $sep . $this->emailUserLink();
919 if ( $wgTitle->getArticleId() ) {
921 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
922 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
923 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
925 $s .= "<br />\n" . $this->otherLanguages();
930 function pageStats() {
931 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
932 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
934 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
935 if ( ! $wgOut->isArticle() ) { return ''; }
936 if ( isset( $oldid ) ||
isset( $diff ) ) { return ''; }
937 if ( 0 == $wgArticle->getID() ) { return ''; }
940 if ( !$wgDisableCounters ) {
941 $count = $wgLang->formatNum( $wgArticle->getCount() );
943 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
947 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
948 require_once('Credits.php');
949 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
951 $s .= $this->lastModified();
954 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
955 $dbr =& wfGetDB( DB_SLAVE
);
956 extract( $dbr->tableNames( 'watchlist' ) );
957 $sql = "SELECT COUNT(*) AS n FROM $watchlist
958 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
959 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
960 $res = $dbr->query( $sql, 'Skin::pageStats');
961 $x = $dbr->fetchObject( $res );
962 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n
);
965 return $s . ' ' . $this->getCopyright();
968 function getCopyright( $type = 'detect' ) {
969 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
971 if ( $type == 'detect' ) {
972 $oldid = $wgRequest->getVal( 'oldid' );
973 $diff = $wgRequest->getVal( 'diff' );
975 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
982 if ( $type == 'history' ) {
983 $msg = 'history_copyright';
989 if( $wgRightsPage ) {
990 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
991 } elseif( $wgRightsUrl ) {
992 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
997 $out .= wfMsgForContent( $msg, $link );
1001 function getCopyrightIcon() {
1002 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1004 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1005 $out = $wgCopyrightIcon;
1006 } else if ( $wgRightsIcon ) {
1007 $icon = htmlspecialchars( $wgRightsIcon );
1008 if ( $wgRightsUrl ) {
1009 $url = htmlspecialchars( $wgRightsUrl );
1010 $out .= '<a href="'.$url.'">';
1012 $text = htmlspecialchars( $wgRightsText );
1013 $out .= "<img src=\"$icon\" alt='$text' />";
1014 if ( $wgRightsUrl ) {
1021 function getPoweredBy() {
1022 global $wgStylePath;
1023 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1024 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1028 function lastModified() {
1029 global $wgLang, $wgArticle, $wgLoadBalancer;
1031 $timestamp = $wgArticle->getTimestamp();
1033 $d = $wgLang->timeanddate( $timestamp, true );
1034 $s = ' ' . wfMsg( 'lastmodified', $d );
1038 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1039 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1044 function logoText( $align = '' ) {
1045 if ( '' != $align ) { $a = " align='{$align}'"; }
1048 $mp = wfMsg( 'mainpage' );
1049 $titleObj = Title
::newFromText( $mp );
1050 if ( is_object( $titleObj ) ) {
1051 $url = $titleObj->escapeLocalURL();
1056 $logourl = $this->getLogo();
1057 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1062 * show a drop-down box of special pages
1063 * @TODO crash bug913. Need to be rewrote completly.
1065 function specialPagesList() {
1066 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1067 require_once('SpecialPage.php');
1069 $pages = SpecialPage
::getPages();
1071 // special pages without access restriction
1072 foreach ( $pages[''] as $name => $page ) {
1073 $a[$name] = $page->getDescription();
1076 // Other special pages that are restricted.
1077 foreach ( $pages['restricted'] as $name => $page ) {
1078 if( $wgUser->isAllowed( $page->getRestriction() ) ) {
1079 $a[$name] = $page->getDescription();
1083 $go = wfMsg( 'go' );
1084 $sp = wfMsg( 'specialpages' );
1085 $spp = $wgContLang->specialPage( 'Specialpages' );
1087 $s = '<form id="specialpages" method="get" class="inline" ' .
1088 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1089 $s .= "<select name=\"wpDropdown\">\n";
1090 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1093 foreach ( $a as $name => $desc ) {
1094 $p = $wgContLang->specialPage( $name );
1095 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1097 $s .= "</select>\n";
1098 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1103 function mainPageLink() {
1104 $mp = wfMsgForContent( 'mainpage' );
1105 $mptxt = wfMsg( 'mainpage');
1106 $s = $this->makeKnownLink( $mp, $mptxt );
1110 function copyrightLink() {
1111 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1112 wfMsg( 'copyrightpagename' ) );
1116 function privacyLink() {
1117 $privacy = wfMsg( 'privacy' );
1118 if ($privacy == '-') {
1121 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1125 function aboutLink() {
1126 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1127 wfMsg( 'aboutsite' ) );
1131 function disclaimerLink() {
1132 $disclaimers = wfMsg( 'disclaimers' );
1133 if ($disclaimers == '-') {
1136 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1141 function editThisPage() {
1142 global $wgOut, $wgTitle;
1144 if ( ! $wgOut->isArticleRelated() ) {
1145 $s = wfMsg( 'protectedpage' );
1147 if ( $wgTitle->userCanEdit() ) {
1148 $t = wfMsg( 'editthispage' );
1150 $t = wfMsg( 'viewsource' );
1153 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1159 * Return URL options for the 'edit page' link.
1160 * This may include an 'oldid' specifier, if the current page view is such.
1165 function editUrlOptions() {
1168 if( $this->mRevisionId
&& ! $wgArticle->isCurrent() ) {
1169 return "action=edit&oldid=" . intval( $this->mRevisionId
);
1171 return "action=edit";
1175 function deleteThisPage() {
1176 global $wgUser, $wgTitle, $wgRequest;
1178 $diff = $wgRequest->getVal( 'diff' );
1179 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1180 $t = wfMsg( 'deletethispage' );
1182 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1189 function protectThisPage() {
1190 global $wgUser, $wgTitle, $wgRequest;
1192 $diff = $wgRequest->getVal( 'diff' );
1193 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1194 if ( $wgTitle->isProtected() ) {
1195 $t = wfMsg( 'unprotectthispage' );
1196 $q = 'action=unprotect';
1198 $t = wfMsg( 'protectthispage' );
1199 $q = 'action=protect';
1201 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1208 function watchThisPage() {
1209 global $wgOut, $wgTitle;
1211 if ( $wgOut->isArticleRelated() ) {
1212 if ( $wgTitle->userIsWatching() ) {
1213 $t = wfMsg( 'unwatchthispage' );
1214 $q = 'action=unwatch';
1216 $t = wfMsg( 'watchthispage' );
1217 $q = 'action=watch';
1219 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1221 $s = wfMsg( 'notanarticle' );
1226 function moveThisPage() {
1229 if ( $wgTitle->userCanMove() ) {
1230 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Movepage' ),
1231 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1233 // no message if page is protected - would be redundant
1238 function historyLink() {
1241 return $this->makeKnownLinkObj( $wgTitle,
1242 wfMsg( 'history' ), 'action=history' );
1245 function whatLinksHere() {
1248 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Whatlinkshere' ),
1249 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1252 function userContribsLink() {
1255 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Contributions' ),
1256 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1259 function showEmailUser( $id ) {
1260 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1261 return $wgEnableEmail &&
1262 $wgEnableUserEmail &&
1263 $wgUser->isLoggedIn() && # show only to signed in users
1264 0 != $id; # we can only email to non-anons ..
1265 # '' != $id->getEmail() && # who must have an email address stored ..
1266 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1267 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1270 function emailUserLink() {
1273 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
, 'Emailuser' ),
1274 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1277 function watchPageLinksLink() {
1278 global $wgOut, $wgTitle;
1280 if ( ! $wgOut->isArticleRelated() ) {
1281 return '(' . wfMsg( 'notanarticle' ) . ')';
1283 return $this->makeKnownLinkObj( Title
::makeTitle( NS_SPECIAL
,
1284 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1285 'target=' . $wgTitle->getPrefixedURL() );
1289 function trackbackLink() {
1292 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1293 . wfMsg('trackbacklink') . "</a>";
1296 function otherLanguages() {
1297 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1299 if ( $wgHideInterlanguageLinks ) {
1303 $a = $wgOut->getLanguageLinks();
1304 if ( 0 == count( $a ) ) {
1308 $s = wfMsg( 'otherlanguages' ) . ': ';
1310 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1311 foreach( $a as $l ) {
1312 if ( ! $first ) { $s .= ' | '; }
1315 $nt = Title
::newFromText( $l );
1316 $url = $nt->escapeFullURL();
1317 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1319 if ( '' == $text ) { $text = $l; }
1320 $style = $this->getExternalLinkAttributes( $l, $text );
1321 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1323 if($wgContLang->isRTL()) $s .= '</span>';
1327 function bugReportsLink() {
1328 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1329 wfMsg( 'bugreports' ) );
1333 function dateLink() {
1334 $t1 = Title
::newFromText( gmdate( 'F j' ) );
1335 $t2 = Title
::newFromText( gmdate( 'Y' ) );
1337 $id = $t1->getArticleID();
1340 $s = $this->makeBrokenLink( $t1->getText() );
1342 $s = $this->makeKnownLink( $t1->getText() );
1346 $id = $t2->getArticleID();
1349 $s .= $this->makeBrokenLink( $t2->getText() );
1351 $s .= $this->makeKnownLink( $t2->getText() );
1356 function talkLink() {
1359 if ( NS_SPECIAL
== $wgTitle->getNamespace() ) {
1360 # No discussion links for special pages
1364 if( $wgTitle->isTalkPage() ) {
1365 $link = $wgTitle->getSubjectPage();
1366 switch( $link->getNamespace() ) {
1368 $text = wfMsg('articlepage');
1371 $text = wfMsg('userpage');
1374 $text = wfMsg('projectpage');
1377 $text = wfMsg('imagepage');
1380 $text= wfMsg('articlepage');
1383 $link = $wgTitle->getTalkPage();
1384 $text = wfMsg( 'talkpage' );
1387 $s = $this->makeLinkObj( $link, $text );
1392 function commentLink() {
1393 global $wgTitle, $wgOut;
1395 if ( $wgTitle->getNamespace() == NS_SPECIAL
) {
1399 # __NEWSECTIONLINK___ changes behaviour here
1400 # If it's present, the link points to this page, otherwise
1401 # it points to the talk page
1402 if( $wgTitle->isTalkPage() ) {
1404 } elseif( $wgOut->showNewSectionLink() ) {
1407 $title =& $wgTitle->getTalkPage();
1410 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit§ion=new' );
1413 /* these are used extensively in SkinTemplate, but also some other places */
1414 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1415 $title = Title
::makeTitle( NS_SPECIAL
, $name );
1416 return $title->getLocalURL( $urlaction );
1419 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1420 $title = Title
::newFromText( wfMsgForContent($name) );
1421 $this->checkTitle($title, $name);
1422 return $title->getLocalURL( $urlaction );
1425 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1426 $title = Title
::newFromText( $name );
1427 $this->checkTitle($title, $name);
1428 return $title->getLocalURL( $urlaction );
1431 # If url string starts with http, consider as external URL, else
1433 /*static*/ function makeInternalOrExternalUrl( $name ) {
1434 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1437 return $this->makeUrl( $name );
1441 # this can be passed the NS number as defined in Language.php
1442 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN
) {
1443 $title = Title
::makeTitleSafe( $namespace, $name );
1444 $this->checkTitle($title, $name);
1445 return $title->getLocalURL( $urlaction );
1448 /* these return an array with the 'href' and boolean 'exists' */
1449 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1450 $title = Title
::newFromText( $name );
1451 $this->checkTitle($title, $name);
1453 'href' => $title->getLocalURL( $urlaction ),
1454 'exists' => $title->getArticleID() != 0?
true:false
1459 * Make URL details where the article exists (or at least it's convenient to think so)
1461 function makeKnownUrlDetails( $name, $urlaction='' ) {
1462 $title = Title
::newFromText( $name );
1463 $this->checkTitle($title, $name);
1465 'href' => $title->getLocalURL( $urlaction ),
1470 # make sure we have some title to operate on
1471 /*static*/ function checkTitle ( &$title, &$name ) {
1472 if(!is_object($title)) {
1473 $title = Title
::newFromText( $name );
1474 if(!is_object($title)) {
1475 $title = Title
::newFromText( '--error: link target missing--' );
1481 * Build an array that represents the sidebar(s), the navigation bar among them
1486 function buildSidebar() {
1487 global $wgDBname, $parserMemc, $wgEnableSidebarCache;
1488 global $wgLang, $wgContLang;
1490 $fname = 'SkinTemplate::buildSidebar';
1492 wfProfileIn( $fname );
1494 $key = "{$wgDBname}:sidebar";
1495 $cacheSidebar = $wgEnableSidebarCache &&
1496 ($wgLang->getCode() == $wgContLang->getCode());
1498 if ($cacheSidebar) {
1499 $cachedsidebar = $parserMemc->get( $key );
1500 if ($cachedsidebar!="") {
1501 wfProfileOut($fname);
1502 return $cachedsidebar;
1507 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1508 foreach ($lines as $line) {
1509 if (strpos($line, '*') !== 0)
1511 if (strpos($line, '**') !== 0) {
1512 $line = trim($line, '* ');
1515 if (strpos($line, '|') !== false) { // sanity check
1516 $line = explode( '|' , trim($line, '* '), 2 );
1517 $link = wfMsgForContent( $line[0] );
1520 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1522 if (wfEmptyMsg($line[0], $link))
1524 $href = $this->makeInternalOrExternalUrl( $link );
1525 $bar[$heading][] = array(
1528 'id' => 'n-' . strtr($line[1], ' ', '-'),
1531 } else { continue; }
1535 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1536 wfProfileOut( $fname );