BUG#1610 Add Old Norse stub
[mediawiki.git] / includes / Skin.php
blob9baec636cd9d25b9d365d236ce32be08376c8df8
1 <?php
3 /**
5 * @package MediaWiki
6 * @subpackage Skins
7 */
9 /**
10 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
12 if( defined( "MEDIAWIKI" ) ) {
14 # See skin.doc
15 require_once( 'Linker.php' );
16 require_once( 'Image.php' );
18 # Get a list of all skins available in /skins/
19 # Build using the regular expression '^(.*).php$'
20 # Array keys are all lower case, array value keep the case used by filename
23 $skinDir = dir($IP.'/skins');
25 # while code from www.php.net
26 while (false !== ($file = $skinDir->read())) {
27 if(preg_match('/^([^.].*)\.php$/',$file, $matches)) {
28 $aSkin = $matches[1];
29 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
32 $skinDir->close();
33 unset($matches);
35 require_once( 'RecentChange.php' );
37 global $wgLinkHolders;
38 $wgLinkHolders = array(
39 'namespaces' => array(),
40 'dbkeys' => array(),
41 'queries' => array(),
42 'texts' => array(),
43 'titles' => array()
45 global $wgInterwikiLinkHolders;
46 $wgInterwikiLinkHolders = array();
48 /**
49 * @todo document
50 * @package MediaWiki
52 class RCCacheEntry extends RecentChange
54 var $secureName, $link;
55 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
56 var $userlink, $timestamp, $watched;
58 function newFromParent( $rc )
60 $rc2 = new RCCacheEntry;
61 $rc2->mAttribs = $rc->mAttribs;
62 $rc2->mExtra = $rc->mExtra;
63 return $rc2;
65 } ;
68 /**
69 * The main skin class that provide methods and properties for all other skins
70 * including PHPTal skins.
71 * This base class is also the "Standard" skin.
72 * @package MediaWiki
74 class Skin extends Linker {
75 /**#@+
76 * @access private
78 var $lastdate, $lastline;
79 var $rc_cache ; # Cache for Enhanced Recent Changes
80 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
81 var $rcMoveIndex;
82 /**#@-*/
84 function Skin() {
85 parent::Linker();
88 function getSkinNames() {
89 global $wgValidSkinNames;
90 return $wgValidSkinNames;
93 function getStylesheet() {
94 return 'common/wikistandard.css';
97 function getSkinName() {
98 return 'standard';
101 function qbSetting() {
102 global $wgOut, $wgUser;
104 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
105 $q = $wgUser->getOption( 'quickbar' );
106 if ( '' == $q ) { $q = 0; }
107 return $q;
110 function initPage( &$out ) {
111 $fname = 'Skin::initPage';
112 wfProfileIn( $fname );
114 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => '/favicon.ico' ) );
116 $this->addMetadataLinks($out);
118 wfProfileOut( $fname );
121 function addMetadataLinks( &$out ) {
122 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
123 global $wgRightsPage, $wgRightsUrl;
125 if( $out->isArticleRelated() ) {
126 # note: buggy CC software only reads first "meta" link
127 if( $wgEnableCreativeCommonsRdf ) {
128 $out->addMetadataLink( array(
129 'title' => 'Creative Commons',
130 'type' => 'application/rdf+xml',
131 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
133 if( $wgEnableDublinCoreRdf ) {
134 $out->addMetadataLink( array(
135 'title' => 'Dublin Core',
136 'type' => 'application/rdf+xml',
137 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
140 $copyright = '';
141 if( $wgRightsPage ) {
142 $copy = Title::newFromText( $wgRightsPage );
143 if( $copy ) {
144 $copyright = $copy->getLocalURL();
147 if( !$copyright && $wgRightsUrl ) {
148 $copyright = $wgRightsUrl;
150 if( $copyright ) {
151 $out->addLink( array(
152 'rel' => 'copyright',
153 'href' => $copyright ) );
157 function outputPage( &$out ) {
158 global $wgDebugComments;
160 wfProfileIn( 'Skin::outputPage' );
161 $this->initPage( $out );
162 $out->out( $out->headElement() );
164 $out->out( "\n<body" );
165 $ops = $this->getBodyOptions();
166 foreach ( $ops as $name => $val ) {
167 $out->out( " $name='$val'" );
169 $out->out( ">\n" );
170 if ( $wgDebugComments ) {
171 $out->out( "<!-- Wiki debugging output:\n" .
172 $out->mDebugtext . "-->\n" );
174 $out->out( $this->beforeContent() );
176 $out->out( $out->mBodytext . "\n" );
178 $out->out( $this->afterContent() );
180 wfProfileClose();
181 $out->out( $out->reportTime() );
183 $out->out( "\n</body></html>" );
186 function getHeadScripts() {
187 global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs;
188 $r = "<script type=\"text/javascript\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
189 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
190 $userpage = $wgUser->getUserPage();
191 $userjs = htmlspecialchars( $this->makeUrl(
192 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
193 'action=raw&ctype=text/javascript'));
194 $r .= '<script type="text/javascript" src="'.$userjs."\"></script>\n";
196 return $r;
200 * To make it harder for someone to slip a user a fake
201 * user-JavaScript or user-CSS preview, a random token
202 * is associated with the login session. If it's not
203 * passed back with the preview request, we won't render
204 * the code.
206 * @param string $action
207 * @return bool
208 * @access private
210 function userCanPreview( $action ) {
211 global $wgTitle, $wgRequest, $wgUser;
213 if( $action != 'submit' )
214 return false;
215 if( !$wgRequest->wasPosted() )
216 return false;
217 if( !$wgTitle->userCanEditCssJsSubpage() )
218 return false;
219 return $wgUser->matchEditToken(
220 $wgRequest->getVal( 'wpEditToken' ) );
223 # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
224 function getUserStylesheet() {
225 global $wgOut, $wgStylePath, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
226 $sheet = $this->getStylesheet();
227 $action = $wgRequest->getText('action');
228 $s = "@import \"$wgStylePath/$sheet\";\n";
229 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
230 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
231 if($wgTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
232 $s .= $wgRequest->getText('wpTextbox1');
233 } else {
234 $userpage = $wgUser->getUserPage();
235 $s.= '@import "'.$this->makeUrl(
236 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
237 'action=raw&ctype=text/css').'";'."\n";
240 $s .= $this->doGetUserStyles();
241 return $s."\n";
245 * placeholder, returns generated js in monobook
247 function getUserJs() { return; }
250 * Return html code that include User stylesheets
252 function getUserStyles() {
253 global $wgOut, $wgStylePath, $wgLang;
254 $s = "<style type='text/css'>\n";
255 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
256 $s .= $this->getUserStylesheet();
257 $s .= "/*]]>*/ /* */\n";
258 $s .= "</style>\n";
259 return $s;
263 * Some styles that are set by user through the user settings interface.
265 function doGetUserStyles() {
266 global $wgUser, $wgContLang;
268 $csspage = $wgContLang->getNsText( NS_MEDIAWIKI ) . ':' . $this->getSkinName() . '.css';
269 $s = '@import "'.$this->makeUrl($csspage, 'action=raw&ctype=text/css')."\";\n";
271 if ( 1 == $wgUser->getOption( 'underline' ) ) {
272 # Don't override browser settings
273 } else {
274 # CHECK MERGE @@@
275 # Force no underline
276 $s .= "a { text-decoration: none; }\n";
278 if ( 1 == $this->mOptions['highlightbroken'] ) {
279 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
281 if ( 1 == $wgUser->getOption( 'justify' ) ) {
282 $s .= "#article { text-align: justify; }\n";
284 return $s;
287 function getBodyOptions() {
288 global $wgUser, $wgTitle, $wgNamespaceBackgrounds, $wgOut, $wgRequest;
290 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
292 if ( 0 != $wgTitle->getNamespace() ) {
293 $a = array( 'bgcolor' => '#ffffec' );
295 else $a = array( 'bgcolor' => '#FFFFFF' );
296 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
297 (!$wgTitle->isProtected() || $wgUser->isAllowed('protect')) ) {
298 $t = wfMsg( 'editthispage' );
299 $oid = $red = '';
300 if ( !empty($redirect) && $redirect == 'no' ) {
301 $red = "&redirect={$redirect}";
303 if ( !empty($oldid) && ! isset( $diff ) ) {
304 $oid = "&oldid=" . IntVal( $oldid );
306 $s = $wgTitle->getFullURL( "action=edit{$oid}{$red}" );
307 $s = 'document.location = "' .$s .'";';
308 $a += array ('ondblclick' => $s);
311 $a['onload'] = $wgOut->getOnloadHandler();
312 return $a;
316 * URL to the logo
318 function getLogo() {
319 global $wgLogo;
320 return $wgLogo;
324 * This will be called immediately after the <body> tag. Split into
325 * two functions to make it easier to subclass.
327 function beforeContent() {
328 return $this->doBeforeContent();
331 function doBeforeContent() {
332 global $wgOut, $wgTitle, $wgContLang, $wgSiteNotice;
333 $fname = 'Skin::doBeforeContent';
334 wfProfileIn( $fname );
336 $s = '';
337 $qb = $this->qbSetting();
339 if( $langlinks = $this->otherLanguages() ) {
340 $rows = 2;
341 $borderhack = '';
342 } else {
343 $rows = 1;
344 $langlinks = false;
345 $borderhack = 'class="top"';
348 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
349 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
351 $shove = ($qb != 0);
352 $left = ($qb == 1 || $qb == 3);
353 if($wgContLang->isRTL()) $left = !$left;
355 if ( !$shove ) {
356 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
357 $this->logoText() . '</td>';
358 } elseif( $left ) {
359 $s .= $this->getQuickbarCompensator( $rows );
361 $l = $wgContLang->isRTL() ? 'right' : 'left';
362 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
364 $s .= $this->topLinks() ;
365 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
367 $r = $wgContLang->isRTL() ? "left" : "right";
368 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
369 $s .= $this->nameAndLogin();
370 $s .= "\n<br />" . $this->searchForm() . "</td>";
372 if ( $langlinks ) {
373 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
376 if ( $shove && !$left ) { # Right
377 $s .= $this->getQuickbarCompensator( $rows );
379 $s .= "</tr>\n</table>\n</div>\n";
380 $s .= "\n<div id='article'>\n";
382 if( $wgSiteNotice ) {
383 $s .= "\n<div id='siteNotice'>$wgSiteNotice</div>\n";
385 $s .= $this->pageTitle();
386 $s .= $this->pageSubtitle() ;
387 $s .= $this->getCategories();
388 wfProfileOut( $fname );
389 return $s;
393 function getCategoryLinks () {
394 global $wgOut, $wgTitle, $wgParser;
395 global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
397 if( !$wgUseCategoryMagic ) return '' ;
398 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
400 # Taken out so that they will be displayed in previews -- TS
401 #if( !$wgOut->isArticle() ) return '';
403 $t = implode ( ' | ' , $wgOut->mCategoryLinks ) ;
404 $s = $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Categories' ),
405 wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
406 . ': ' . $t;
408 # optional 'dmoz-like' category browser. Will be shown under the list
409 # of categories an article belong to
410 if($wgUseCategoryBrowser) {
411 $s .= '<br /><hr />';
413 # get a big array of the parents tree
414 $parenttree = $wgTitle->getParentCategoryTree();
416 # Render the array as a serie of links
417 # Need to give skin cause $this is undefined at this level
418 function walkThrough ($tree, &$skin) {
419 $return = '';
420 foreach($tree as $element => $parent) {
421 if(empty($parent)) {
422 # element start a new list
423 $return .= '<br />';
424 } else {
425 # grab the others elements
426 $return .= walkThrough($parent, $skin);
428 # add our current element to the list
429 $eltitle = Title::NewFromText($element);
430 # FIXME : should be makeLink() [AV]
431 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) . ' &gt; ';
433 return $return;
436 # Skin object passed by reference cause it can not be
437 # accessed under the method subfunction walkThrough.
438 $s .= walkThrough($parenttree, $this);
441 return $s;
444 function getCategories() {
445 $catlinks=$this->getCategoryLinks();
446 if(!empty($catlinks)) {
447 return "<p class='catlinks'>{$catlinks}</p>";
451 function getQuickbarCompensator( $rows = 1 ) {
452 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
455 # This gets called immediately before the </body> tag.
457 function afterContent() {
458 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
459 return $printfooter . $this->doAfterContent();
462 function printSource() {
463 global $wgTitle;
464 $url = htmlspecialchars( $wgTitle->getFullURL() );
465 return wfMsg( "retrievedfrom", "<a href=\"$url\">$url</a>" );
468 function printFooter() {
469 return "<p>" . $this->printSource() .
470 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
473 function doAfterContent() {
474 # overloaded by derived classes
477 function pageTitleLinks() {
478 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgUseApproval, $wgRequest;
480 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
481 $action = $wgRequest->getText( 'action' );
483 $s = $this->printableLink();
484 $disclaimer = $this->disclaimerLink(); # may be empty
485 if( $disclaimer ) {
486 $s .= ' | ' . $disclaimer;
489 if ( $wgOut->isArticleRelated() ) {
490 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
491 $name = $wgTitle->getDBkey();
492 $image = new Image( $wgTitle->getDBkey() );
493 if( $image->exists() ) {
494 $link = htmlspecialchars( $image->getURL() );
495 $style = $this->getInternalLinkAttributes( $link, $name );
496 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
499 # This will show the "Approve" link if $wgUseApproval=true;
500 if ( isset ( $wgUseApproval ) && $wgUseApproval )
502 $t = $wgTitle->getDBkey();
503 $name = 'Approve this article' ;
504 $link = "http://test.wikipedia.org/w/magnus/wiki.phtml?title={$t}&action=submit&doit=1" ;
505 #htmlspecialchars( wfImageUrl( $name ) );
506 $style = $this->getExternalLinkAttributes( $link, $name );
507 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>" ;
510 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
511 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
512 wfMsg( 'currentrev' ) );
515 if ( $wgUser->getNewtalk() ) {
516 # do not show "You have new messages" text when we are viewing our
517 # own talk page
519 if( $wgTitle->equals( $wgUser->getTalkPage() ) ) {
520 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
521 wfMsg('newmessageslink') );
522 $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
523 # disable caching
524 $wgOut->setSquidMaxage(0);
525 $wgOut->enableClientCache(false);
529 $undelete = $this->getUndeleteLink();
530 if( !empty( $undelete ) ) {
531 $s .= ' | '.$undelete;
533 return $s;
536 function getUndeleteLink() {
537 global $wgUser, $wgTitle, $wgContLang, $action;
538 if( $wgUser->isAllowed('rollback') &&
539 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
540 ($n = $wgTitle->isDeleted() ) ) {
541 return wfMsg( 'thisisdeleted',
542 $this->makeKnownLink(
543 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
544 wfMsg( 'restorelink', $n ) ) );
546 return '';
549 function printableLink() {
550 global $wgOut, $wgFeedClasses, $wgRequest;
552 $baseurl = $_SERVER['REQUEST_URI'];
553 if( strpos( '?', $baseurl ) == false ) {
554 $baseurl .= '?';
555 } else {
556 $baseurl .= '&';
558 $baseurl = htmlspecialchars( $baseurl );
559 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
561 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
562 if( $wgOut->isSyndicated() ) {
563 foreach( $wgFeedClasses as $format => $class ) {
564 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
565 $s .= " | <a href=\"$feedurl\">{$format}</a>";
568 return $s;
571 function pageTitle() {
572 global $wgOut, $wgTitle, $wgUser;
574 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
575 if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);}
576 return $s;
579 function pageSubtitle() {
580 global $wgOut;
582 $sub = $wgOut->getSubtitle();
583 if ( '' == $sub ) {
584 global $wgExtraSubtitle;
585 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
587 $subpages = $this->subPageSubtitle();
588 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
589 $s = "<p class='subtitle'>{$sub}</p>\n";
590 return $s;
593 function subPageSubtitle() {
594 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
595 $subpages = '';
596 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
597 $ptext=$wgTitle->getPrefixedText();
598 if(preg_match('/\//',$ptext)) {
599 $links = explode('/',$ptext);
600 $c = 0;
601 $growinglink = '';
602 foreach($links as $link) {
603 $c++;
604 if ($c<count($links)) {
605 $growinglink .= $link;
606 $getlink = $this->makeLink( $growinglink, $link );
607 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
608 if ($c>1) {
609 $subpages .= ' | ';
610 } else {
611 $subpages .= '&lt; ';
613 $subpages .= $getlink;
614 $growinglink .= '/';
619 return $subpages;
622 function nameAndLogin() {
623 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
625 $li = $wgContLang->specialPage( 'Userlogin' );
626 $lo = $wgContLang->specialPage( 'Userlogout' );
628 $s = '';
629 if ( $wgUser->isAnon() ) {
630 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
631 $n = $wgIP;
633 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
634 $wgContLang->getNsText( NS_TALK ) );
636 $s .= $n . ' ('.$tl.')';
637 } else {
638 $s .= wfMsg('notloggedin');
641 $rt = $wgTitle->getPrefixedURL();
642 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
643 $q = '';
644 } else { $q = "returnto={$rt}"; }
646 $s .= "\n<br />" . $this->makeKnownLinkObj(
647 Title::makeTitle( NS_SPECIAL, 'Userlogin' ),
648 wfMsg( 'login' ), $q );
649 } else {
650 $n = $wgUser->getName();
651 $rt = $wgTitle->getPrefixedURL();
652 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
653 $wgContLang->getNsText( NS_TALK ) );
655 $tl = " ({$tl})";
657 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
658 $n ) . "{$tl}<br />" .
659 $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogout' ), wfMsg( 'logout' ),
660 "returnto={$rt}" ) . ' | ' .
661 $this->specialLink( 'preferences' );
663 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
664 wfMsg( 'help' ) );
666 return $s;
669 function getSearchLink() {
670 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
671 return $searchPage->getLocalURL();
674 function escapeSearchLink() {
675 return htmlspecialchars( $this->getSearchLink() );
678 function searchForm() {
679 global $wgRequest;
680 $search = $wgRequest->getText( 'search' );
682 $s = '<form name="search" class="inline" method="post" action="'
683 . $this->escapeSearchLink() . "\">\n"
684 . '<input type="text" name="search" size="19" value="'
685 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
686 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
687 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
689 return $s;
692 function topLinks() {
693 global $wgOut;
694 $sep = " |\n";
696 $s = $this->mainPageLink() . $sep
697 . $this->specialLink( 'recentchanges' );
699 if ( $wgOut->isArticleRelated() ) {
700 $s .= $sep . $this->editThisPage()
701 . $sep . $this->historyLink();
703 # Many people don't like this dropdown box
704 #$s .= $sep . $this->specialPagesList();
706 /* show links to different language variants */
707 global $wgDisableLangConversion, $wgContLang, $wgTitle;
708 $variants = $wgContLang->getVariants();
709 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
710 foreach( $variants as $code ) {
711 $varname = $wgContLang->getVariantname( $code );
712 if( $varname == 'disable' )
713 continue;
714 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
720 return $s;
723 function bottomLinks() {
724 global $wgOut, $wgUser, $wgTitle;
725 $sep = " |\n";
727 $s = '';
728 if ( $wgOut->isArticleRelated() ) {
729 $s .= '<strong>' . $this->editThisPage() . '</strong>';
730 if ( $wgUser->isLoggedIn() ) {
731 $s .= $sep . $this->watchThisPage();
733 $s .= $sep . $this->talkLink()
734 . $sep . $this->historyLink()
735 . $sep . $this->whatLinksHere()
736 . $sep . $this->watchPageLinksLink();
738 if ( $wgTitle->getNamespace() == NS_USER
739 || $wgTitle->getNamespace() == NS_USER_TALK )
742 $id=User::idFromName($wgTitle->getText());
743 $ip=User::isIP($wgTitle->getText());
745 if($id || $ip) { # both anons and non-anons have contri list
746 $s .= $sep . $this->userContribsLink();
748 if( $this->showEmailUser( $id ) ) {
749 $s .= $sep . $this->emailUserLink();
752 if ( $wgTitle->getArticleId() ) {
753 $s .= "\n<br />";
754 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
755 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
756 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
758 $s .= "<br />\n" . $this->otherLanguages();
760 return $s;
763 function pageStats() {
764 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
765 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
767 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
768 if ( ! $wgOut->isArticle() ) { return ''; }
769 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
770 if ( 0 == $wgArticle->getID() ) { return ''; }
772 $s = '';
773 if ( !$wgDisableCounters ) {
774 $count = $wgLang->formatNum( $wgArticle->getCount() );
775 if ( $count ) {
776 $s = wfMsg( 'viewcount', $count );
780 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
781 require_once("Credits.php");
782 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
783 } else {
784 $s .= $this->lastModified();
787 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
788 $dbr =& wfGetDB( DB_SLAVE );
789 extract( $dbr->tableNames( 'watchlist' ) );
790 $sql = "SELECT COUNT(*) AS n FROM $watchlist
791 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
792 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
793 $res = $dbr->query( $sql, 'Skin::pageStats');
794 $x = $dbr->fetchObject( $res );
795 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
798 return $s . ' ' . $this->getCopyright();
801 function getCopyright() {
802 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
805 $oldid = $wgRequest->getVal( 'oldid' );
806 $diff = $wgRequest->getVal( 'diff' );
808 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
809 $msg = 'history_copyright';
810 } else {
811 $msg = 'copyright';
814 $out = '';
815 if( $wgRightsPage ) {
816 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
817 } elseif( $wgRightsUrl ) {
818 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
819 } else {
820 # Give up now
821 return $out;
823 $out .= wfMsgForContent( $msg, $link );
824 return $out;
827 function getCopyrightIcon() {
828 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
829 $out = '';
830 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
831 $out = $wgCopyrightIcon;
832 } else if ( $wgRightsIcon ) {
833 $icon = htmlspecialchars( $wgRightsIcon );
834 if ( $wgRightsUrl ) {
835 $url = htmlspecialchars( $wgRightsUrl );
836 $out .= '<a href="'.$url.'">';
838 $text = htmlspecialchars( $wgRightsText );
839 $out .= "<img src=\"$icon\" alt='$text' />";
840 if ( $wgRightsUrl ) {
841 $out .= '</a>';
844 return $out;
847 function getPoweredBy() {
848 global $wgStylePath;
849 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
850 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
851 return $img;
854 function lastModified() {
855 global $wgLang, $wgArticle, $wgLoadBalancer;
857 $timestamp = $wgArticle->getTimestamp();
858 if ( $timestamp ) {
859 $d = $wgLang->timeanddate( $wgArticle->getTimestamp(), true );
860 $s = ' ' . wfMsg( 'lastmodified', $d );
861 } else {
862 $s = '';
864 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
865 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
867 return $s;
870 function logoText( $align = '' ) {
871 if ( '' != $align ) { $a = " align='{$align}'"; }
872 else { $a = ''; }
874 $mp = wfMsg( 'mainpage' );
875 $titleObj = Title::newFromText( $mp );
876 if ( is_object( $titleObj ) ) {
877 $url = $titleObj->escapeLocalURL();
878 } else {
879 $url = '';
882 $logourl = $this->getLogo();
883 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
884 return $s;
888 * show a drop-down box of special pages
889 * @TODO crash bug913. Need to be rewrote completly.
891 function specialPagesList() {
892 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
893 require_once('SpecialPage.php');
894 $a = array();
895 $pages = SpecialPage::getPages();
897 // special pages without access restriction
898 foreach ( $pages[''] as $name => $page ) {
899 $a[$name] = $page->getDescription();
902 // Other special pages that are restricted.
903 // Copied from SpecialSpecialpages.php
904 foreach($wgAvailableRights as $right) {
905 if( $wgUser->isAllowed($right) ) {
906 /** Add all pages for this right */
907 if(isset($pages[$right])) {
908 foreach($pages[$right] as $name => $page) {
909 $a[$name] = $page->getDescription();
915 $go = wfMsg( 'go' );
916 $sp = wfMsg( 'specialpages' );
917 $spp = $wgContLang->specialPage( 'Specialpages' );
919 $s = '<form id="specialpages" method="get" class="inline" ' .
920 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
921 $s .= "<select name=\"wpDropdown\">\n";
922 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
925 foreach ( $a as $name => $desc ) {
926 $p = $wgContLang->specialPage( $name );
927 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
929 $s .= "</select>\n";
930 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
931 $s .= "</form>\n";
932 return $s;
935 function mainPageLink() {
936 $mp = wfMsgForContent( 'mainpage' );
937 $mptxt = wfMsg( 'mainpage');
938 $s = $this->makeKnownLink( $mp, $mptxt );
939 return $s;
942 function copyrightLink() {
943 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
944 wfMsg( 'copyrightpagename' ) );
945 return $s;
948 function aboutLink() {
949 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
950 wfMsg( 'aboutsite' ) );
951 return $s;
955 function disclaimerLink() {
956 $disclaimers = wfMsg( 'disclaimers' );
957 if ($disclaimers == '-') {
958 return "";
959 } else {
960 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
961 $disclaimers );
965 function editThisPage() {
966 global $wgOut, $wgTitle, $wgRequest;
968 $oldid = $wgRequest->getVal( 'oldid' );
969 $diff = $wgRequest->getVal( 'diff' );
970 $redirect = $wgRequest->getVal( 'redirect' );
972 if ( ! $wgOut->isArticleRelated() ) {
973 $s = wfMsg( 'protectedpage' );
974 } else {
975 if ( $wgTitle->userCanEdit() ) {
976 $t = wfMsg( 'editthispage' );
977 } else {
978 $t = wfMsg( 'viewsource' );
980 $oid = $red = '';
982 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
983 if ( $oldid && ! isset( $diff ) ) {
984 $oid = '&oldid='.$oldid;
986 $s = $this->makeKnownLinkObj( $wgTitle, $t, "action=edit{$oid}{$red}" );
988 return $s;
991 function deleteThisPage() {
992 global $wgUser, $wgOut, $wgTitle, $wgRequest;
994 $diff = $wgRequest->getVal( 'diff' );
995 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
996 $t = wfMsg( 'deletethispage' );
998 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
999 } else {
1000 $s = '';
1002 return $s;
1005 function protectThisPage() {
1006 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1008 $diff = $wgRequest->getVal( 'diff' );
1009 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1010 if ( $wgTitle->isProtected() ) {
1011 $t = wfMsg( 'unprotectthispage' );
1012 $q = 'action=unprotect';
1013 } else {
1014 $t = wfMsg( 'protectthispage' );
1015 $q = 'action=protect';
1017 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1018 } else {
1019 $s = '';
1021 return $s;
1024 function watchThisPage() {
1025 global $wgUser, $wgOut, $wgTitle;
1027 if ( $wgOut->isArticleRelated() ) {
1028 if ( $wgTitle->userIsWatching() ) {
1029 $t = wfMsg( 'unwatchthispage' );
1030 $q = 'action=unwatch';
1031 } else {
1032 $t = wfMsg( 'watchthispage' );
1033 $q = 'action=watch';
1035 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1036 } else {
1037 $s = wfMsg( 'notanarticle' );
1039 return $s;
1042 function moveThisPage() {
1043 global $wgTitle;
1045 if ( $wgTitle->userCanMove() ) {
1046 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
1047 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1048 } else {
1049 // no message if page is protected - would be redundant
1050 return '';
1054 function historyLink() {
1055 global $wgTitle;
1057 return $this->makeKnownLinkObj( $wgTitle,
1058 wfMsg( 'history' ), 'action=history' );
1061 function whatLinksHere() {
1062 global $wgTitle;
1064 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
1065 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1068 function userContribsLink() {
1069 global $wgTitle;
1071 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
1072 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1075 function showEmailUser( $id ) {
1076 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1077 return $wgEnableEmail &&
1078 $wgEnableUserEmail &&
1079 $wgUser->isLoggedIn() && # show only to signed in users
1080 0 != $id; # we can only email to non-anons ..
1081 # '' != $id->getEmail() && # who must have an email address stored ..
1082 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1083 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1086 function emailUserLink() {
1087 global $wgTitle;
1089 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
1090 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1093 function watchPageLinksLink() {
1094 global $wgOut, $wgTitle;
1096 if ( ! $wgOut->isArticleRelated() ) {
1097 return '(' . wfMsg( 'notanarticle' ) . ')';
1098 } else {
1099 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
1100 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1101 'target=' . $wgTitle->getPrefixedURL() );
1105 function otherLanguages() {
1106 global $wgOut, $wgContLang, $wgTitle;
1108 $a = $wgOut->getLanguageLinks();
1109 if ( 0 == count( $a ) ) {
1110 return '';
1113 $s = wfMsg( 'otherlanguages' ) . ': ';
1114 $first = true;
1115 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1116 foreach( $a as $l ) {
1117 if ( ! $first ) { $s .= ' | '; }
1118 $first = false;
1120 $nt = Title::newFromText( $l );
1121 $url = $nt->escapeFullURL();
1122 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1124 if ( '' == $text ) { $text = $l; }
1125 $style = $this->getExternalLinkAttributes( $l, $text );
1126 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1128 if($wgContLang->isRTL()) $s .= '</span>';
1129 return $s;
1132 function bugReportsLink() {
1133 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1134 wfMsg( 'bugreports' ) );
1135 return $s;
1138 function dateLink() {
1139 global $wgLinkCache;
1140 $t1 = Title::newFromText( gmdate( 'F j' ) );
1141 $t2 = Title::newFromText( gmdate( 'Y' ) );
1143 $wgLinkCache->suspend();
1144 $id = $t1->getArticleID();
1145 $wgLinkCache->resume();
1147 if ( 0 == $id ) {
1148 $s = $this->makeBrokenLink( $t1->getText() );
1149 } else {
1150 $s = $this->makeKnownLink( $t1->getText() );
1152 $s .= ', ';
1154 $wgLinkCache->suspend();
1155 $id = $t2->getArticleID();
1156 $wgLinkCache->resume();
1158 if ( 0 == $id ) {
1159 $s .= $this->makeBrokenLink( $t2->getText() );
1160 } else {
1161 $s .= $this->makeKnownLink( $t2->getText() );
1163 return $s;
1166 function talkLink() {
1167 global $wgTitle, $wgLinkCache;
1169 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1170 # No discussion links for special pages
1171 return '';
1174 if( $wgTitle->isTalkPage() ) {
1175 $link = $wgTitle->getSubjectPage();
1176 switch( $link->getNamespace() ) {
1177 case NS_MAIN:
1178 $text = wfMsg('articlepage');
1179 break;
1180 case NS_USER:
1181 $text = wfMsg('userpage');
1182 break;
1183 case NS_PROJECT:
1184 $text = wfMsg('wikipediapage');
1185 break;
1186 case NS_IMAGE:
1187 $text = wfMsg('imagepage');
1188 break;
1189 default:
1190 $text= wfMsg('articlepage');
1192 } else {
1193 $link = $wgTitle->getTalkPage();
1194 $text = wfMsg( 'talkpage' );
1197 $wgLinkCache->suspend();
1198 $s = $this->makeLinkObj( $link, $text );
1199 $wgLinkCache->resume();
1201 return $s;
1204 function commentLink() {
1205 global $wgContLang, $wgTitle, $wgLinkCache;
1207 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1208 return '';
1210 return $this->makeKnownLinkObj( $wgTitle->getTalkPage(),
1211 wfMsg( 'postcomment' ), 'action=edit&section=new' );
1214 /* these are used extensively in SkinPHPTal, but also some other places */
1215 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1216 $title = Title::makeTitle( NS_SPECIAL, $name );
1217 return $title->getLocalURL( $urlaction );
1220 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1221 $title = Title::newFromText( wfMsgForContent($name) );
1222 $this->checkTitle($title, $name);
1223 return $title->getLocalURL( $urlaction );
1226 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1227 $title = Title::newFromText( $name );
1228 $this->checkTitle($title, $name);
1229 return $title->getLocalURL( $urlaction );
1232 # If url string starts with http, consider as external URL, else
1233 # internal
1234 /*static*/ function makeInternalOrExternalUrl( $name ) {
1235 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1236 return $name;
1237 } else {
1238 return $this->makeUrl( $name );
1242 # this can be passed the NS number as defined in Language.php
1243 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) {
1244 $title = Title::makeTitleSafe( $namespace, $name );
1245 $this->checkTitle($title, $name);
1246 return $title->getLocalURL( $urlaction );
1249 /* these return an array with the 'href' and boolean 'exists' */
1250 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1251 $title = Title::newFromText( $name );
1252 $this->checkTitle($title, $name);
1253 return array(
1254 'href' => $title->getLocalURL( $urlaction ),
1255 'exists' => $title->getArticleID() != 0?true:false
1259 # make sure we have some title to operate on
1260 /*static*/ function checkTitle ( &$title, &$name ) {
1261 if(!is_object($title)) {
1262 $title = Title::newFromText( $name );
1263 if(!is_object($title)) {
1264 $title = Title::newFromText( '--error: link target missing--' );