Lessons learnt from installing MediaWiki with safe_mode, especially support for uploa...
[mediawiki.git] / includes / Skin.php
blobbe60733968fba14fc5737063f428e6dabedaa967
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.txt
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 /** Constructor, call parent constructor */
85 function Skin() { parent::Linker(); }
87 function getSkinNames() {
88 global $wgValidSkinNames;
89 return $wgValidSkinNames;
92 /** @return string path to the skin stylesheet */
93 function getStylesheet() { return 'common/wikistandard.css'; }
95 /** @return string skin name */
96 function getSkinName() {
97 return 'standard';
100 function qbSetting() {
101 global $wgOut, $wgUser;
103 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
104 $q = $wgUser->getOption( 'quickbar' );
105 if ( '' == $q ) { $q = 0; }
106 return $q;
109 function initPage( &$out ) {
110 $fname = 'Skin::initPage';
111 wfProfileIn( $fname );
113 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => '/favicon.ico' ) );
115 $this->addMetadataLinks($out);
117 wfProfileOut( $fname );
120 function addMetadataLinks( &$out ) {
121 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
122 global $wgRightsPage, $wgRightsUrl;
124 if( $out->isArticleRelated() ) {
125 # note: buggy CC software only reads first "meta" link
126 if( $wgEnableCreativeCommonsRdf ) {
127 $out->addMetadataLink( array(
128 'title' => 'Creative Commons',
129 'type' => 'application/rdf+xml',
130 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
132 if( $wgEnableDublinCoreRdf ) {
133 $out->addMetadataLink( array(
134 'title' => 'Dublin Core',
135 'type' => 'application/rdf+xml',
136 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
139 $copyright = '';
140 if( $wgRightsPage ) {
141 $copy = Title::newFromText( $wgRightsPage );
142 if( $copy ) {
143 $copyright = $copy->getLocalURL();
146 if( !$copyright && $wgRightsUrl ) {
147 $copyright = $wgRightsUrl;
149 if( $copyright ) {
150 $out->addLink( array(
151 'rel' => 'copyright',
152 'href' => $copyright ) );
156 function outputPage( &$out ) {
157 global $wgDebugComments;
159 wfProfileIn( 'Skin::outputPage' );
160 $this->initPage( $out );
161 $out->out( $out->headElement() );
163 $out->out( "\n<body" );
164 $ops = $this->getBodyOptions();
165 foreach ( $ops as $name => $val ) {
166 $out->out( " $name='$val'" );
168 $out->out( ">\n" );
169 if ( $wgDebugComments ) {
170 $out->out( "<!-- Wiki debugging output:\n" .
171 $out->mDebugtext . "-->\n" );
173 $out->out( $this->beforeContent() );
175 $out->out( $out->mBodytext . "\n" );
177 $out->out( $this->afterContent() );
179 wfProfileClose();
180 $out->out( $out->reportTime() );
182 $out->out( "\n</body></html>" );
185 function getHeadScripts() {
186 global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs;
187 $r = "<script type=\"text/javascript\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
188 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
189 $userpage = $wgUser->getUserPage();
190 $userjs = htmlspecialchars( $this->makeUrl(
191 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
192 'action=raw&ctype=text/javascript'));
193 $r .= '<script type="text/javascript" src="'.$userjs."\"></script>\n";
195 return $r;
199 * To make it harder for someone to slip a user a fake
200 * user-JavaScript or user-CSS preview, a random token
201 * is associated with the login session. If it's not
202 * passed back with the preview request, we won't render
203 * the code.
205 * @param string $action
206 * @return bool
207 * @access private
209 function userCanPreview( $action ) {
210 global $wgTitle, $wgRequest, $wgUser;
212 if( $action != 'submit' )
213 return false;
214 if( !$wgRequest->wasPosted() )
215 return false;
216 if( !$wgTitle->userCanEditCssJsSubpage() )
217 return false;
218 return $wgUser->matchEditToken(
219 $wgRequest->getVal( 'wpEditToken' ) );
222 # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
223 function getUserStylesheet() {
224 global $wgOut, $wgStylePath, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
225 $sheet = $this->getStylesheet();
226 $action = $wgRequest->getText('action');
227 $s = "@import \"$wgStylePath/$sheet\";\n";
228 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
229 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
230 if($wgTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
231 $s .= $wgRequest->getText('wpTextbox1');
232 } else {
233 $userpage = $wgUser->getUserPage();
234 $s.= '@import "'.$this->makeUrl(
235 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
236 'action=raw&ctype=text/css').'";'."\n";
239 $s .= $this->doGetUserStyles();
240 return $s."\n";
244 * placeholder, returns generated js in monobook
246 function getUserJs() { return; }
249 * Return html code that include User stylesheets
251 function getUserStyles() {
252 global $wgOut, $wgStylePath, $wgLang;
253 $s = "<style type='text/css'>\n";
254 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
255 $s .= $this->getUserStylesheet();
256 $s .= "/*]]>*/ /* */\n";
257 $s .= "</style>\n";
258 return $s;
262 * Some styles that are set by user through the user settings interface.
264 function doGetUserStyles() {
265 global $wgUser, $wgContLang;
267 $csspage = $wgContLang->getNsText( NS_MEDIAWIKI ) . ':' . $this->getSkinName() . '.css';
268 $s = '@import "'.$this->makeUrl($csspage, 'action=raw&ctype=text/css')."\";\n";
270 return $s . $this->reallyDoGetUserStyles();
273 function reallyDoGetUserStyles() {
274 global $wgUser;
275 $s = '';
276 $underline = $wgUser->getOption( "underline" ) ? 'underline' : 'none';
277 $s .= "a { text-decoration: $underline; }\n";
278 if( $wgUser->getOption( 'highlightbroken' ) ) {
279 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
280 } else {
281 $s .= <<<END
282 a.new, #quickbar a.new,
283 a.stub, #quickbar a.stub {
284 color: inherit;
285 text-decoration: inherit;
287 a.new:after, #quickbar a.new:after {
288 content: "?";
289 color: #CC2200;
290 text-decoration: $underline;
292 a.stub:after, #quickbar a.stub:after {
293 content: "!";
294 color: #772233;
295 text-decoration: $underline;
297 END;
299 if( $wgUser->getOption( 'justify' ) ) {
300 $s .= "#article { text-align: justify; }\n";
302 if( !$wgUser->getOption( 'showtoc' ) ) {
303 $s .= "#toc { display: none; }\n";
305 return $s;
308 function getBodyOptions() {
309 global $wgUser, $wgTitle, $wgNamespaceBackgrounds, $wgOut, $wgRequest;
311 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
313 if ( 0 != $wgTitle->getNamespace() ) {
314 $a = array( 'bgcolor' => '#ffffec' );
316 else $a = array( 'bgcolor' => '#FFFFFF' );
317 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
318 (!$wgTitle->isProtected() || $wgUser->isAllowed('protect')) ) {
319 $t = wfMsg( 'editthispage' );
320 $oid = $red = '';
321 if ( !empty($redirect) && $redirect == 'no' ) {
322 $red = "&redirect={$redirect}";
324 if ( !empty($oldid) && ! isset( $diff ) ) {
325 $oid = "&oldid=" . IntVal( $oldid );
327 $s = $wgTitle->getFullURL( "action=edit{$oid}{$red}" );
328 $s = 'document.location = "' .$s .'";';
329 $a += array ('ondblclick' => $s);
332 $a['onload'] = $wgOut->getOnloadHandler();
333 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
334 if( $a['onload'] != '' ) {
335 $a['onload'] .= ';';
337 $a['onload'] .= 'setupRightClickEdit()';
339 return $a;
343 * URL to the logo
345 function getLogo() {
346 global $wgLogo;
347 return $wgLogo;
351 * This will be called immediately after the <body> tag. Split into
352 * two functions to make it easier to subclass.
354 function beforeContent() {
355 return $this->doBeforeContent();
358 function doBeforeContent() {
359 global $wgOut, $wgTitle, $wgContLang;
360 $fname = 'Skin::doBeforeContent';
361 wfProfileIn( $fname );
363 $s = '';
364 $qb = $this->qbSetting();
366 if( $langlinks = $this->otherLanguages() ) {
367 $rows = 2;
368 $borderhack = '';
369 } else {
370 $rows = 1;
371 $langlinks = false;
372 $borderhack = 'class="top"';
375 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
376 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
378 $shove = ($qb != 0);
379 $left = ($qb == 1 || $qb == 3);
380 if($wgContLang->isRTL()) $left = !$left;
382 if ( !$shove ) {
383 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
384 $this->logoText() . '</td>';
385 } elseif( $left ) {
386 $s .= $this->getQuickbarCompensator( $rows );
388 $l = $wgContLang->isRTL() ? 'right' : 'left';
389 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
391 $s .= $this->topLinks() ;
392 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
394 $r = $wgContLang->isRTL() ? "left" : "right";
395 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
396 $s .= $this->nameAndLogin();
397 $s .= "\n<br />" . $this->searchForm() . "</td>";
399 if ( $langlinks ) {
400 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
403 if ( $shove && !$left ) { # Right
404 $s .= $this->getQuickbarCompensator( $rows );
406 $s .= "</tr>\n</table>\n</div>\n";
407 $s .= "\n<div id='article'>\n";
409 $notice = wfGetSiteNotice();
410 if( $notice ) {
411 $s .= "\n<div id='siteNotice'>$notice</div>\n";
413 $s .= $this->pageTitle();
414 $s .= $this->pageSubtitle() ;
415 $s .= $this->getCategories();
416 wfProfileOut( $fname );
417 return $s;
421 function getCategoryLinks () {
422 global $wgOut, $wgTitle, $wgParser;
423 global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
425 if( !$wgUseCategoryMagic ) return '' ;
426 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
428 # Taken out so that they will be displayed in previews -- TS
429 #if( !$wgOut->isArticle() ) return '';
431 $t = implode ( ' | ' , $wgOut->mCategoryLinks ) ;
432 $s = $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Categories' ),
433 wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
434 . ': ' . $t;
436 # optional 'dmoz-like' category browser. Will be shown under the list
437 # of categories an article belong to
438 if($wgUseCategoryBrowser) {
439 $s .= '<br /><hr />';
441 # get a big array of the parents tree
442 $parenttree = $wgTitle->getParentCategoryTree();
444 # Render the array as a serie of links
445 # Need to give skin cause $this is undefined at this level
446 function walkThrough ($tree, &$skin) {
447 $return = '';
448 foreach($tree as $element => $parent) {
449 if(empty($parent)) {
450 # element start a new list
451 $return .= '<br />';
452 } else {
453 # grab the others elements
454 $return .= walkThrough($parent, $skin);
456 # add our current element to the list
457 $eltitle = Title::NewFromText($element);
458 if(!empty($parent)) $return .= ' &gt; ';
459 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
461 return $return;
464 # Skin object passed by reference cause it can not be
465 # accessed under the method subfunction walkThrough.
466 $s .= walkThrough($parenttree, $this);
469 return $s;
472 function getCategories() {
473 $catlinks=$this->getCategoryLinks();
474 if(!empty($catlinks)) {
475 return "<p class='catlinks'>{$catlinks}</p>";
479 function getQuickbarCompensator( $rows = 1 ) {
480 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
484 * This gets called immediately before the </body> tag.
485 * @return string HTML to be put after </body> ???
487 function afterContent() {
488 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
489 return $printfooter . $this->doAfterContent();
492 /** @return string Retrievied from HTML text */
493 function printSource() {
494 global $wgTitle;
495 $url = htmlspecialchars( $wgTitle->getFullURL() );
496 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
499 function printFooter() {
500 return "<p>" . $this->printSource() .
501 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
504 /** overloaded by derived classes */
505 function doAfterContent() { }
507 function pageTitleLinks() {
508 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgUseApproval, $wgRequest;
510 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
511 $action = $wgRequest->getText( 'action' );
513 $s = $this->printableLink();
514 $disclaimer = $this->disclaimerLink(); # may be empty
515 if( $disclaimer ) {
516 $s .= ' | ' . $disclaimer;
519 if ( $wgOut->isArticleRelated() ) {
520 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
521 $name = $wgTitle->getDBkey();
522 $image = new Image( $wgTitle );
523 if( $image->exists() ) {
524 $link = htmlspecialchars( $image->getURL() );
525 $style = $this->getInternalLinkAttributes( $link, $name );
526 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
529 # This will show the "Approve" link if $wgUseApproval=true;
530 if ( isset ( $wgUseApproval ) && $wgUseApproval )
532 $t = $wgTitle->getDBkey();
533 $name = 'Approve this article' ;
534 $link = "http://test.wikipedia.org/w/magnus/wiki.phtml?title={$t}&action=submit&doit=1" ;
535 #htmlspecialchars( wfImageUrl( $name ) );
536 $style = $this->getExternalLinkAttributes( $link, $name );
537 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>" ;
540 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
541 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
542 wfMsg( 'currentrev' ) );
545 if ( $wgUser->getNewtalk() ) {
546 # do not show "You have new messages" text when we are viewing our
547 # own talk page
549 if( $wgTitle->equals( $wgUser->getTalkPage() ) ) {
550 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
551 wfMsg('newmessageslink') );
552 $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
553 # disable caching
554 $wgOut->setSquidMaxage(0);
555 $wgOut->enableClientCache(false);
559 $undelete = $this->getUndeleteLink();
560 if( !empty( $undelete ) ) {
561 $s .= ' | '.$undelete;
563 return $s;
566 function getUndeleteLink() {
567 global $wgUser, $wgTitle, $wgContLang, $action;
568 if( $wgUser->isAllowed('rollback') &&
569 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
570 ($n = $wgTitle->isDeleted() ) ) {
571 return wfMsg( 'thisisdeleted',
572 $this->makeKnownLink(
573 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
574 wfMsg( 'restorelink', $n ) ) );
576 return '';
579 function printableLink() {
580 global $wgOut, $wgFeedClasses, $wgRequest;
582 $baseurl = $_SERVER['REQUEST_URI'];
583 if( strpos( '?', $baseurl ) == false ) {
584 $baseurl .= '?';
585 } else {
586 $baseurl .= '&';
588 $baseurl = htmlspecialchars( $baseurl );
589 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
591 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
592 if( $wgOut->isSyndicated() ) {
593 foreach( $wgFeedClasses as $format => $class ) {
594 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
595 $s .= " | <a href=\"$feedurl\">{$format}</a>";
598 return $s;
601 function pageTitle() {
602 global $wgOut, $wgTitle, $wgUser;
604 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
605 return $s;
608 function pageSubtitle() {
609 global $wgOut;
611 $sub = $wgOut->getSubtitle();
612 if ( '' == $sub ) {
613 global $wgExtraSubtitle;
614 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
616 $subpages = $this->subPageSubtitle();
617 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
618 $s = "<p class='subtitle'>{$sub}</p>\n";
619 return $s;
622 function subPageSubtitle() {
623 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
624 $subpages = '';
625 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
626 $ptext=$wgTitle->getPrefixedText();
627 if(preg_match('/\//',$ptext)) {
628 $links = explode('/',$ptext);
629 $c = 0;
630 $growinglink = '';
631 foreach($links as $link) {
632 $c++;
633 if ($c<count($links)) {
634 $growinglink .= $link;
635 $getlink = $this->makeLink( $growinglink, $link );
636 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
637 if ($c>1) {
638 $subpages .= ' | ';
639 } else {
640 $subpages .= '&lt; ';
642 $subpages .= $getlink;
643 $growinglink .= '/';
648 return $subpages;
651 function nameAndLogin() {
652 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
654 $li = $wgContLang->specialPage( 'Userlogin' );
655 $lo = $wgContLang->specialPage( 'Userlogout' );
657 $s = '';
658 if ( $wgUser->isAnon() ) {
659 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
660 $n = $wgIP;
662 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
663 $wgContLang->getNsText( NS_TALK ) );
665 $s .= $n . ' ('.$tl.')';
666 } else {
667 $s .= wfMsg('notloggedin');
670 $rt = $wgTitle->getPrefixedURL();
671 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
672 $q = '';
673 } else { $q = "returnto={$rt}"; }
675 $s .= "\n<br />" . $this->makeKnownLinkObj(
676 Title::makeTitle( NS_SPECIAL, 'Userlogin' ),
677 wfMsg( 'login' ), $q );
678 } else {
679 $n = $wgUser->getName();
680 $rt = $wgTitle->getPrefixedURL();
681 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
682 $wgContLang->getNsText( NS_TALK ) );
684 $tl = " ({$tl})";
686 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
687 $n ) . "{$tl}<br />" .
688 $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogout' ), wfMsg( 'logout' ),
689 "returnto={$rt}" ) . ' | ' .
690 $this->specialLink( 'preferences' );
692 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
693 wfMsg( 'help' ) );
695 return $s;
698 function getSearchLink() {
699 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
700 return $searchPage->getLocalURL();
703 function escapeSearchLink() {
704 return htmlspecialchars( $this->getSearchLink() );
707 function searchForm() {
708 global $wgRequest;
709 $search = $wgRequest->getText( 'search' );
711 $s = '<form name="search" class="inline" method="post" action="'
712 . $this->escapeSearchLink() . "\">\n"
713 . '<input type="text" name="search" size="19" value="'
714 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
715 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
716 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
718 return $s;
721 function topLinks() {
722 global $wgOut;
723 $sep = " |\n";
725 $s = $this->mainPageLink() . $sep
726 . $this->specialLink( 'recentchanges' );
728 if ( $wgOut->isArticleRelated() ) {
729 $s .= $sep . $this->editThisPage()
730 . $sep . $this->historyLink();
732 # Many people don't like this dropdown box
733 #$s .= $sep . $this->specialPagesList();
735 /* show links to different language variants */
736 global $wgDisableLangConversion, $wgContLang, $wgTitle;
737 $variants = $wgContLang->getVariants();
738 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
739 foreach( $variants as $code ) {
740 $varname = $wgContLang->getVariantname( $code );
741 if( $varname == 'disable' )
742 continue;
743 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
747 return $s;
750 function bottomLinks() {
751 global $wgOut, $wgUser, $wgTitle;
752 $sep = " |\n";
754 $s = '';
755 if ( $wgOut->isArticleRelated() ) {
756 $s .= '<strong>' . $this->editThisPage() . '</strong>';
757 if ( $wgUser->isLoggedIn() ) {
758 $s .= $sep . $this->watchThisPage();
760 $s .= $sep . $this->talkLink()
761 . $sep . $this->historyLink()
762 . $sep . $this->whatLinksHere()
763 . $sep . $this->watchPageLinksLink();
765 if ( $wgTitle->getNamespace() == NS_USER
766 || $wgTitle->getNamespace() == NS_USER_TALK )
769 $id=User::idFromName($wgTitle->getText());
770 $ip=User::isIP($wgTitle->getText());
772 if($id || $ip) { # both anons and non-anons have contri list
773 $s .= $sep . $this->userContribsLink();
775 if( $this->showEmailUser( $id ) ) {
776 $s .= $sep . $this->emailUserLink();
779 if ( $wgTitle->getArticleId() ) {
780 $s .= "\n<br />";
781 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
782 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
783 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
785 $s .= "<br />\n" . $this->otherLanguages();
787 return $s;
790 function pageStats() {
791 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
792 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
794 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
795 if ( ! $wgOut->isArticle() ) { return ''; }
796 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
797 if ( 0 == $wgArticle->getID() ) { return ''; }
799 $s = '';
800 if ( !$wgDisableCounters ) {
801 $count = $wgLang->formatNum( $wgArticle->getCount() );
802 if ( $count ) {
803 $s = wfMsg( 'viewcount', $count );
807 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
808 require_once('Credits.php');
809 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
810 } else {
811 $s .= $this->lastModified();
814 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
815 $dbr =& wfGetDB( DB_SLAVE );
816 extract( $dbr->tableNames( 'watchlist' ) );
817 $sql = "SELECT COUNT(*) AS n FROM $watchlist
818 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
819 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
820 $res = $dbr->query( $sql, 'Skin::pageStats');
821 $x = $dbr->fetchObject( $res );
822 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
825 return $s . ' ' . $this->getCopyright();
828 function getCopyright() {
829 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
832 $oldid = $wgRequest->getVal( 'oldid' );
833 $diff = $wgRequest->getVal( 'diff' );
835 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
836 $msg = 'history_copyright';
837 } else {
838 $msg = 'copyright';
841 $out = '';
842 if( $wgRightsPage ) {
843 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
844 } elseif( $wgRightsUrl ) {
845 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
846 } else {
847 # Give up now
848 return $out;
850 $out .= wfMsgForContent( $msg, $link );
851 return $out;
854 function getCopyrightIcon() {
855 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
856 $out = '';
857 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
858 $out = $wgCopyrightIcon;
859 } else if ( $wgRightsIcon ) {
860 $icon = htmlspecialchars( $wgRightsIcon );
861 if ( $wgRightsUrl ) {
862 $url = htmlspecialchars( $wgRightsUrl );
863 $out .= '<a href="'.$url.'">';
865 $text = htmlspecialchars( $wgRightsText );
866 $out .= "<img src=\"$icon\" alt='$text' />";
867 if ( $wgRightsUrl ) {
868 $out .= '</a>';
871 return $out;
874 function getPoweredBy() {
875 global $wgStylePath;
876 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
877 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
878 return $img;
881 function lastModified() {
882 global $wgLang, $wgArticle, $wgLoadBalancer;
884 $timestamp = $wgArticle->getTimestamp();
885 if ( $timestamp ) {
886 $d = $wgLang->timeanddate( $timestamp, true );
887 $s = ' ' . wfMsg( 'lastmodified', $d );
888 } else {
889 $s = '';
891 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
892 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
894 return $s;
897 function logoText( $align = '' ) {
898 if ( '' != $align ) { $a = " align='{$align}'"; }
899 else { $a = ''; }
901 $mp = wfMsg( 'mainpage' );
902 $titleObj = Title::newFromText( $mp );
903 if ( is_object( $titleObj ) ) {
904 $url = $titleObj->escapeLocalURL();
905 } else {
906 $url = '';
909 $logourl = $this->getLogo();
910 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
911 return $s;
915 * show a drop-down box of special pages
916 * @TODO crash bug913. Need to be rewrote completly.
918 function specialPagesList() {
919 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
920 require_once('SpecialPage.php');
921 $a = array();
922 $pages = SpecialPage::getPages();
924 // special pages without access restriction
925 foreach ( $pages[''] as $name => $page ) {
926 $a[$name] = $page->getDescription();
929 // Other special pages that are restricted.
930 // Copied from SpecialSpecialpages.php
931 foreach($wgAvailableRights as $right) {
932 if( $wgUser->isAllowed($right) ) {
933 /** Add all pages for this right */
934 if(isset($pages[$right])) {
935 foreach($pages[$right] as $name => $page) {
936 $a[$name] = $page->getDescription();
942 $go = wfMsg( 'go' );
943 $sp = wfMsg( 'specialpages' );
944 $spp = $wgContLang->specialPage( 'Specialpages' );
946 $s = '<form id="specialpages" method="get" class="inline" ' .
947 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
948 $s .= "<select name=\"wpDropdown\">\n";
949 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
952 foreach ( $a as $name => $desc ) {
953 $p = $wgContLang->specialPage( $name );
954 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
956 $s .= "</select>\n";
957 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
958 $s .= "</form>\n";
959 return $s;
962 function mainPageLink() {
963 $mp = wfMsgForContent( 'mainpage' );
964 $mptxt = wfMsg( 'mainpage');
965 $s = $this->makeKnownLink( $mp, $mptxt );
966 return $s;
969 function copyrightLink() {
970 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
971 wfMsg( 'copyrightpagename' ) );
972 return $s;
975 function aboutLink() {
976 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
977 wfMsg( 'aboutsite' ) );
978 return $s;
982 function disclaimerLink() {
983 $disclaimers = wfMsg( 'disclaimers' );
984 if ($disclaimers == '-') {
985 return '';
986 } else {
987 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
988 $disclaimers );
992 function editThisPage() {
993 global $wgOut, $wgTitle, $wgRequest;
995 $oldid = $wgRequest->getVal( 'oldid' );
996 $diff = $wgRequest->getVal( 'diff' );
997 $redirect = $wgRequest->getVal( 'redirect' );
999 if ( ! $wgOut->isArticleRelated() ) {
1000 $s = wfMsg( 'protectedpage' );
1001 } else {
1002 if ( $wgTitle->userCanEdit() ) {
1003 $t = wfMsg( 'editthispage' );
1004 } else {
1005 $t = wfMsg( 'viewsource' );
1007 $oid = $red = '';
1009 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
1010 if ( $oldid && ! isset( $diff ) ) {
1011 $oid = '&oldid='.$oldid;
1013 $s = $this->makeKnownLinkObj( $wgTitle, $t, "action=edit{$oid}{$red}" );
1015 return $s;
1018 function deleteThisPage() {
1019 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1021 $diff = $wgRequest->getVal( 'diff' );
1022 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1023 $t = wfMsg( 'deletethispage' );
1025 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1026 } else {
1027 $s = '';
1029 return $s;
1032 function protectThisPage() {
1033 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1035 $diff = $wgRequest->getVal( 'diff' );
1036 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1037 if ( $wgTitle->isProtected() ) {
1038 $t = wfMsg( 'unprotectthispage' );
1039 $q = 'action=unprotect';
1040 } else {
1041 $t = wfMsg( 'protectthispage' );
1042 $q = 'action=protect';
1044 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1045 } else {
1046 $s = '';
1048 return $s;
1051 function watchThisPage() {
1052 global $wgUser, $wgOut, $wgTitle;
1054 if ( $wgOut->isArticleRelated() ) {
1055 if ( $wgTitle->userIsWatching() ) {
1056 $t = wfMsg( 'unwatchthispage' );
1057 $q = 'action=unwatch';
1058 } else {
1059 $t = wfMsg( 'watchthispage' );
1060 $q = 'action=watch';
1062 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1063 } else {
1064 $s = wfMsg( 'notanarticle' );
1066 return $s;
1069 function moveThisPage() {
1070 global $wgTitle;
1072 if ( $wgTitle->userCanMove() ) {
1073 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
1074 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1075 } else {
1076 // no message if page is protected - would be redundant
1077 return '';
1081 function historyLink() {
1082 global $wgTitle;
1084 return $this->makeKnownLinkObj( $wgTitle,
1085 wfMsg( 'history' ), 'action=history' );
1088 function whatLinksHere() {
1089 global $wgTitle;
1091 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
1092 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1095 function userContribsLink() {
1096 global $wgTitle;
1098 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
1099 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1102 function showEmailUser( $id ) {
1103 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1104 return $wgEnableEmail &&
1105 $wgEnableUserEmail &&
1106 $wgUser->isLoggedIn() && # show only to signed in users
1107 0 != $id; # we can only email to non-anons ..
1108 # '' != $id->getEmail() && # who must have an email address stored ..
1109 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1110 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1113 function emailUserLink() {
1114 global $wgTitle;
1116 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
1117 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1120 function watchPageLinksLink() {
1121 global $wgOut, $wgTitle;
1123 if ( ! $wgOut->isArticleRelated() ) {
1124 return '(' . wfMsg( 'notanarticle' ) . ')';
1125 } else {
1126 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
1127 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1128 'target=' . $wgTitle->getPrefixedURL() );
1132 function otherLanguages() {
1133 global $wgOut, $wgContLang, $wgTitle;
1135 $a = $wgOut->getLanguageLinks();
1136 if ( 0 == count( $a ) ) {
1137 return '';
1140 $s = wfMsg( 'otherlanguages' ) . ': ';
1141 $first = true;
1142 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1143 foreach( $a as $l ) {
1144 if ( ! $first ) { $s .= ' | '; }
1145 $first = false;
1147 $nt = Title::newFromText( $l );
1148 $url = $nt->escapeFullURL();
1149 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1151 if ( '' == $text ) { $text = $l; }
1152 $style = $this->getExternalLinkAttributes( $l, $text );
1153 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1155 if($wgContLang->isRTL()) $s .= '</span>';
1156 return $s;
1159 function bugReportsLink() {
1160 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1161 wfMsg( 'bugreports' ) );
1162 return $s;
1165 function dateLink() {
1166 global $wgLinkCache;
1167 $t1 = Title::newFromText( gmdate( 'F j' ) );
1168 $t2 = Title::newFromText( gmdate( 'Y' ) );
1170 $wgLinkCache->suspend();
1171 $id = $t1->getArticleID();
1172 $wgLinkCache->resume();
1174 if ( 0 == $id ) {
1175 $s = $this->makeBrokenLink( $t1->getText() );
1176 } else {
1177 $s = $this->makeKnownLink( $t1->getText() );
1179 $s .= ', ';
1181 $wgLinkCache->suspend();
1182 $id = $t2->getArticleID();
1183 $wgLinkCache->resume();
1185 if ( 0 == $id ) {
1186 $s .= $this->makeBrokenLink( $t2->getText() );
1187 } else {
1188 $s .= $this->makeKnownLink( $t2->getText() );
1190 return $s;
1193 function talkLink() {
1194 global $wgTitle, $wgLinkCache;
1196 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1197 # No discussion links for special pages
1198 return '';
1201 if( $wgTitle->isTalkPage() ) {
1202 $link = $wgTitle->getSubjectPage();
1203 switch( $link->getNamespace() ) {
1204 case NS_MAIN:
1205 $text = wfMsg('articlepage');
1206 break;
1207 case NS_USER:
1208 $text = wfMsg('userpage');
1209 break;
1210 case NS_PROJECT:
1211 $text = wfMsg('wikipediapage');
1212 break;
1213 case NS_IMAGE:
1214 $text = wfMsg('imagepage');
1215 break;
1216 default:
1217 $text= wfMsg('articlepage');
1219 } else {
1220 $link = $wgTitle->getTalkPage();
1221 $text = wfMsg( 'talkpage' );
1224 $wgLinkCache->suspend();
1225 $s = $this->makeLinkObj( $link, $text );
1226 $wgLinkCache->resume();
1228 return $s;
1231 function commentLink() {
1232 global $wgContLang, $wgTitle, $wgLinkCache;
1234 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1235 return '';
1237 return $this->makeKnownLinkObj( $wgTitle->getTalkPage(),
1238 wfMsg( 'postcomment' ), 'action=edit&section=new' );
1241 /* these are used extensively in SkinPHPTal, but also some other places */
1242 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1243 $title = Title::makeTitle( NS_SPECIAL, $name );
1244 return $title->getLocalURL( $urlaction );
1247 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1248 $title = Title::newFromText( wfMsgForContent($name) );
1249 $this->checkTitle($title, $name);
1250 return $title->getLocalURL( $urlaction );
1253 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1254 $title = Title::newFromText( $name );
1255 $this->checkTitle($title, $name);
1256 return $title->getLocalURL( $urlaction );
1259 # If url string starts with http, consider as external URL, else
1260 # internal
1261 /*static*/ function makeInternalOrExternalUrl( $name ) {
1262 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1263 return $name;
1264 } else {
1265 return $this->makeUrl( $name );
1269 # this can be passed the NS number as defined in Language.php
1270 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) {
1271 $title = Title::makeTitleSafe( $namespace, $name );
1272 $this->checkTitle($title, $name);
1273 return $title->getLocalURL( $urlaction );
1276 /* these return an array with the 'href' and boolean 'exists' */
1277 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1278 $title = Title::newFromText( $name );
1279 $this->checkTitle($title, $name);
1280 return array(
1281 'href' => $title->getLocalURL( $urlaction ),
1282 'exists' => $title->getArticleID() != 0?true:false
1286 # make sure we have some title to operate on
1287 /*static*/ function checkTitle ( &$title, &$name ) {
1288 if(!is_object($title)) {
1289 $title = Title::newFromText( $name );
1290 if(!is_object($title)) {
1291 $title = Title::newFromText( '--error: link target missing--' );