Implement #2001 by Avar and www.kryogenix.org (see .js file for full credit)
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2
3 /**
4 *
5 * @package MediaWiki
6 * @subpackage Skins
7 */
8
9 /**
10 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
11 */
12 if( defined( "MEDIAWIKI" ) ) {
13
14 # See skin.txt
15 require_once( 'Linker.php' );
16 require_once( 'Image.php' );
17
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
21 #
22
23 $skinDir = dir($IP.'/skins');
24
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;
30 }
31 }
32 $skinDir->close();
33 unset($matches);
34
35 require_once( 'RecentChange.php' );
36
37 /**
38 * @todo document
39 * @package MediaWiki
40 */
41 class RCCacheEntry extends RecentChange
42 {
43 var $secureName, $link;
44 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
45 var $userlink, $timestamp, $watched;
46
47 function newFromParent( $rc )
48 {
49 $rc2 = new RCCacheEntry;
50 $rc2->mAttribs = $rc->mAttribs;
51 $rc2->mExtra = $rc->mExtra;
52 return $rc2;
53 }
54 } ;
55
56
57 /**
58 * The main skin class that provide methods and properties for all other skins
59 * including PHPTal skins.
60 * This base class is also the "Standard" skin.
61 * @package MediaWiki
62 */
63 class Skin extends Linker {
64 /**#@+
65 * @access private
66 */
67 var $lastdate, $lastline;
68 var $rc_cache ; # Cache for Enhanced Recent Changes
69 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
70 var $rcMoveIndex;
71 /**#@-*/
72
73 /** Constructor, call parent constructor */
74 function Skin() { parent::Linker(); }
75
76 function getSkinNames() {
77 global $wgValidSkinNames;
78 return $wgValidSkinNames;
79 }
80
81 /** @return string path to the skin stylesheet */
82 function getStylesheet() { return 'common/wikistandard.css'; }
83
84 /** @return string skin name */
85 function getSkinName() {
86 return 'standard';
87 }
88
89 function qbSetting() {
90 global $wgOut, $wgUser;
91
92 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
93 $q = $wgUser->getOption( 'quickbar' );
94 if ( '' == $q ) { $q = 0; }
95 return $q;
96 }
97
98 function initPage( &$out ) {
99 $fname = 'Skin::initPage';
100 wfProfileIn( $fname );
101
102 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => '/favicon.ico' ) );
103
104 $this->addMetadataLinks($out);
105
106 wfProfileOut( $fname );
107 }
108
109 function addMetadataLinks( &$out ) {
110 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
111 global $wgRightsPage, $wgRightsUrl;
112
113 if( $out->isArticleRelated() ) {
114 # note: buggy CC software only reads first "meta" link
115 if( $wgEnableCreativeCommonsRdf ) {
116 $out->addMetadataLink( array(
117 'title' => 'Creative Commons',
118 'type' => 'application/rdf+xml',
119 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
120 }
121 if( $wgEnableDublinCoreRdf ) {
122 $out->addMetadataLink( array(
123 'title' => 'Dublin Core',
124 'type' => 'application/rdf+xml',
125 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
126 }
127 }
128 $copyright = '';
129 if( $wgRightsPage ) {
130 $copy = Title::newFromText( $wgRightsPage );
131 if( $copy ) {
132 $copyright = $copy->getLocalURL();
133 }
134 }
135 if( !$copyright && $wgRightsUrl ) {
136 $copyright = $wgRightsUrl;
137 }
138 if( $copyright ) {
139 $out->addLink( array(
140 'rel' => 'copyright',
141 'href' => $copyright ) );
142 }
143 }
144
145 function outputPage( &$out ) {
146 global $wgDebugComments;
147
148 wfProfileIn( 'Skin::outputPage' );
149 $this->initPage( $out );
150
151 $out->out( $out->headElement() );
152
153 $out->out( "\n<body" );
154 $ops = $this->getBodyOptions();
155 foreach ( $ops as $name => $val ) {
156 $out->out( " $name='$val'" );
157 }
158 $out->out( ">\n" );
159 if ( $wgDebugComments ) {
160 $out->out( "<!-- Wiki debugging output:\n" .
161 $out->mDebugtext . "-->\n" );
162 }
163
164 $out->out( $this->beforeContent() );
165
166 $out->out( $out->mBodytext . "\n" );
167
168 $out->out( $this->afterContent() );
169
170 wfProfileClose();
171 $out->out( $out->reportTime() );
172
173 $out->out( "\n</body></html>" );
174 }
175
176 function getHeadScripts() {
177 global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs, $wgJsMimeType;
178 $r = "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
179 $r.= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/sorttable.js\"></script>\n";
180 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
181 $userpage = $wgUser->getUserPage();
182 $userjs = htmlspecialchars( $this->makeUrl(
183 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
184 'action=raw&ctype='.$wgJsMimeType));
185 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
186 }
187 return $r;
188 }
189
190 /**
191 * To make it harder for someone to slip a user a fake
192 * user-JavaScript or user-CSS preview, a random token
193 * is associated with the login session. If it's not
194 * passed back with the preview request, we won't render
195 * the code.
196 *
197 * @param string $action
198 * @return bool
199 * @access private
200 */
201 function userCanPreview( $action ) {
202 global $wgTitle, $wgRequest, $wgUser;
203
204 if( $action != 'submit' )
205 return false;
206 if( !$wgRequest->wasPosted() )
207 return false;
208 if( !$wgTitle->userCanEditCssJsSubpage() )
209 return false;
210 return $wgUser->matchEditToken(
211 $wgRequest->getVal( 'wpEditToken' ) );
212 }
213
214 # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
215 function getUserStylesheet() {
216 global $wgOut, $wgStylePath, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
217 $sheet = $this->getStylesheet();
218 $action = $wgRequest->getText('action');
219 $s = "@import \"$wgStylePath/$sheet\";\n";
220 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
221 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
222 if($wgTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
223 $s .= $wgRequest->getText('wpTextbox1');
224 } else {
225 $userpage = $wgUser->getUserPage();
226 $s.= '@import "'.$this->makeUrl(
227 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
228 'action=raw&ctype=text/css').'";'."\n";
229 }
230 }
231 $s .= $this->doGetUserStyles();
232 return $s."\n";
233 }
234
235 /**
236 * placeholder, returns generated js in monobook
237 */
238 function getUserJs() { return; }
239
240 /**
241 * Return html code that include User stylesheets
242 */
243 function getUserStyles() {
244 global $wgOut, $wgStylePath, $wgLang;
245 $s = "<style type='text/css'>\n";
246 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
247 $s .= $this->getUserStylesheet();
248 $s .= "/*]]>*/ /* */\n";
249 $s .= "</style>\n";
250 return $s;
251 }
252
253 /**
254 * Some styles that are set by user through the user settings interface.
255 */
256 function doGetUserStyles() {
257 global $wgUser, $wgContLang;
258
259 $csspage = $wgContLang->getNsText( NS_MEDIAWIKI ) . ':' . $this->getSkinName() . '.css';
260 $s = '@import "'.$this->makeUrl($csspage, 'action=raw&ctype=text/css')."\";\n";
261
262 return $s . $this->reallyDoGetUserStyles();
263 }
264
265 function reallyDoGetUserStyles() {
266 global $wgUser;
267 $s = '';
268 if (($undopt = $wgUser->getOption("underline")) != 2) {
269 $underline = $undopt ? 'underline' : 'none';
270 $s .= "a { text-decoration: $underline; }\n";
271 }
272 if( $wgUser->getOption( 'highlightbroken' ) ) {
273 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
274 } else {
275 $s .= <<<END
276 a.new, #quickbar a.new,
277 a.stub, #quickbar a.stub {
278 color: inherit;
279 text-decoration: inherit;
280 }
281 a.new:after, #quickbar a.new:after {
282 content: "?";
283 color: #CC2200;
284 text-decoration: $underline;
285 }
286 a.stub:after, #quickbar a.stub:after {
287 content: "!";
288 color: #772233;
289 text-decoration: $underline;
290 }
291 END;
292 }
293 if( $wgUser->getOption( 'justify' ) ) {
294 $s .= "#article, #bodyContent { text-align: justify; }\n";
295 }
296 if( !$wgUser->getOption( 'showtoc' ) ) {
297 $s .= "#toc { display: none; }\n";
298 }
299 if( !$wgUser->getOption( 'editsection' ) ) {
300 $s .= ".editsection { display: none; }\n";
301 }
302 return $s;
303 }
304
305 function getBodyOptions() {
306 global $wgUser, $wgTitle, $wgNamespaceBackgrounds, $wgOut, $wgRequest;
307
308 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
309
310 if ( 0 != $wgTitle->getNamespace() ) {
311 $a = array( 'bgcolor' => '#ffffec' );
312 }
313 else $a = array( 'bgcolor' => '#FFFFFF' );
314 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
315 (!$wgTitle->isProtected() || $wgUser->isAllowed('protect')) ) {
316 $t = wfMsg( 'editthispage' );
317 $oid = $red = '';
318 if ( !empty($redirect) && $redirect == 'no' ) {
319 $red = "&redirect={$redirect}";
320 }
321 if ( !empty($oldid) && ! isset( $diff ) ) {
322 $oid = "&oldid=" . IntVal( $oldid );
323 }
324 $s = $wgTitle->getFullURL( "action=edit{$oid}{$red}" );
325 $s = 'document.location = "' .$s .'";';
326 $a += array ('ondblclick' => $s);
327
328 }
329 $a['onload'] = $wgOut->getOnloadHandler();
330 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
331 if( $a['onload'] != '' ) {
332 $a['onload'] .= ';';
333 }
334 $a['onload'] .= 'setupRightClickEdit()';
335 }
336 return $a;
337 }
338
339 /**
340 * URL to the logo
341 */
342 function getLogo() {
343 global $wgLogo;
344 return $wgLogo;
345 }
346
347 /**
348 * This will be called immediately after the <body> tag. Split into
349 * two functions to make it easier to subclass.
350 */
351 function beforeContent() {
352 return $this->doBeforeContent();
353 }
354
355 function doBeforeContent() {
356 global $wgOut, $wgTitle, $wgContLang;
357 $fname = 'Skin::doBeforeContent';
358 wfProfileIn( $fname );
359
360 $s = '';
361 $qb = $this->qbSetting();
362
363 if( $langlinks = $this->otherLanguages() ) {
364 $rows = 2;
365 $borderhack = '';
366 } else {
367 $rows = 1;
368 $langlinks = false;
369 $borderhack = 'class="top"';
370 }
371
372 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
373 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
374
375 $shove = ($qb != 0);
376 $left = ($qb == 1 || $qb == 3);
377 if($wgContLang->isRTL()) $left = !$left;
378
379 if ( !$shove ) {
380 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
381 $this->logoText() . '</td>';
382 } elseif( $left ) {
383 $s .= $this->getQuickbarCompensator( $rows );
384 }
385 $l = $wgContLang->isRTL() ? 'right' : 'left';
386 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
387
388 $s .= $this->topLinks() ;
389 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
390
391 $r = $wgContLang->isRTL() ? "left" : "right";
392 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
393 $s .= $this->nameAndLogin();
394 $s .= "\n<br />" . $this->searchForm() . "</td>";
395
396 if ( $langlinks ) {
397 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
398 }
399
400 if ( $shove && !$left ) { # Right
401 $s .= $this->getQuickbarCompensator( $rows );
402 }
403 $s .= "</tr>\n</table>\n</div>\n";
404 $s .= "\n<div id='article'>\n";
405
406 $notice = wfGetSiteNotice();
407 if( $notice ) {
408 $s .= "\n<div id='siteNotice'>$notice</div>\n";
409 }
410 $s .= $this->pageTitle();
411 $s .= $this->pageSubtitle() ;
412 $s .= $this->getCategories();
413 wfProfileOut( $fname );
414 return $s;
415 }
416
417
418 function getCategoryLinks () {
419 global $wgOut, $wgTitle, $wgParser;
420 global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
421
422 if( !$wgUseCategoryMagic ) return '' ;
423 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
424
425 # Taken out so that they will be displayed in previews -- TS
426 #if( !$wgOut->isArticle() ) return '';
427
428 $t = implode ( ' | ' , $wgOut->mCategoryLinks ) ;
429 $s = $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Categories' ),
430 wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
431 . ': ' . $t;
432
433 # optional 'dmoz-like' category browser. Will be shown under the list
434 # of categories an article belong to
435 if($wgUseCategoryBrowser) {
436 $s .= '<br /><hr />';
437
438 # get a big array of the parents tree
439 $parenttree = $wgTitle->getParentCategoryTree();
440
441 # Skin object passed by reference cause it can not be
442 # accessed under the method subfunction walkThrough.
443 $s .= Skin::drawCategoryBrowser($parenttree, $this);
444 }
445
446 return $s;
447 }
448
449 # Render the array as a serie of links
450 function drawCategoryBrowser ($tree, &$skin) {
451 $return = '';
452 foreach ($tree as $element => $parent) {
453 if (empty($parent)) {
454 # element start a new list
455 $return .= '<br />';
456 } else {
457 # grab the others elements
458 $return .= Skin::drawCategoryBrowser($parent, $skin);
459 }
460 # add our current element to the list
461 $eltitle = Title::NewFromText($element);
462 if (!empty($parent)) $return .= ' &gt; ';
463 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
464 }
465 return $return;
466 }
467
468 function getCategories() {
469 $catlinks=$this->getCategoryLinks();
470 if(!empty($catlinks)) {
471 return "<p class='catlinks'>{$catlinks}</p>";
472 }
473 }
474
475 function getQuickbarCompensator( $rows = 1 ) {
476 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
477 }
478
479 /**
480 * This gets called immediately before the </body> tag.
481 * @return string HTML to be put after </body> ???
482 */
483 function afterContent() {
484 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
485 return $printfooter . $this->doAfterContent();
486 }
487
488 /** @return string Retrievied from HTML text */
489 function printSource() {
490 global $wgTitle;
491 $url = htmlspecialchars( $wgTitle->getFullURL() );
492 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
493 }
494
495 function printFooter() {
496 return "<p>" . $this->printSource() .
497 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
498 }
499
500 /** overloaded by derived classes */
501 function doAfterContent() { }
502
503 function pageTitleLinks() {
504 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgRequest;
505
506 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
507 $action = $wgRequest->getText( 'action' );
508
509 $s = $this->printableLink();
510 $disclaimer = $this->disclaimerLink(); # may be empty
511 if( $disclaimer ) {
512 $s .= ' | ' . $disclaimer;
513 }
514
515 if ( $wgOut->isArticleRelated() ) {
516 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
517 $name = $wgTitle->getDBkey();
518 $image = new Image( $wgTitle );
519 if( $image->exists() ) {
520 $link = htmlspecialchars( $image->getURL() );
521 $style = $this->getInternalLinkAttributes( $link, $name );
522 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
523 }
524 }
525 }
526 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
527 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
528 wfMsg( 'currentrev' ) );
529 }
530
531 if ( $wgUser->getNewtalk() ) {
532 # do not show "You have new messages" text when we are viewing our
533 # own talk page
534
535 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
536 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
537 wfMsg('newmessageslink') );
538 $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
539 # disable caching
540 $wgOut->setSquidMaxage(0);
541 $wgOut->enableClientCache(false);
542 }
543 }
544
545 $undelete = $this->getUndeleteLink();
546 if( !empty( $undelete ) ) {
547 $s .= ' | '.$undelete;
548 }
549 return $s;
550 }
551
552 function getUndeleteLink() {
553 global $wgUser, $wgTitle, $wgContLang, $action;
554 if( $wgUser->isAllowed('rollback') &&
555 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
556 ($n = $wgTitle->isDeleted() ) ) {
557 return wfMsg( 'thisisdeleted',
558 $this->makeKnownLink(
559 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
560 wfMsg( 'restorelink', $n ) ) );
561 }
562 return '';
563 }
564
565 function printableLink() {
566 global $wgOut, $wgFeedClasses, $wgRequest;
567
568 $baseurl = $_SERVER['REQUEST_URI'];
569 if( strpos( '?', $baseurl ) == false ) {
570 $baseurl .= '?';
571 } else {
572 $baseurl .= '&';
573 }
574 $baseurl = htmlspecialchars( $baseurl );
575 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
576
577 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
578 if( $wgOut->isSyndicated() ) {
579 foreach( $wgFeedClasses as $format => $class ) {
580 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
581 $s .= " | <a href=\"$feedurl\">{$format}</a>";
582 }
583 }
584 return $s;
585 }
586
587 function pageTitle() {
588 global $wgOut, $wgTitle, $wgUser;
589
590 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
591 return $s;
592 }
593
594 function pageSubtitle() {
595 global $wgOut;
596
597 $sub = $wgOut->getSubtitle();
598 if ( '' == $sub ) {
599 global $wgExtraSubtitle;
600 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
601 }
602 $subpages = $this->subPageSubtitle();
603 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
604 $s = "<p class='subtitle'>{$sub}</p>\n";
605 return $s;
606 }
607
608 function subPageSubtitle() {
609 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
610 $subpages = '';
611 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
612 $ptext=$wgTitle->getPrefixedText();
613 if(preg_match('/\//',$ptext)) {
614 $links = explode('/',$ptext);
615 $c = 0;
616 $growinglink = '';
617 foreach($links as $link) {
618 $c++;
619 if ($c<count($links)) {
620 $growinglink .= $link;
621 $getlink = $this->makeLink( $growinglink, $link );
622 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
623 if ($c>1) {
624 $subpages .= ' | ';
625 } else {
626 $subpages .= '&lt; ';
627 }
628 $subpages .= $getlink;
629 $growinglink .= '/';
630 }
631 }
632 }
633 }
634 return $subpages;
635 }
636
637 function nameAndLogin() {
638 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
639
640 $li = $wgContLang->specialPage( 'Userlogin' );
641 $lo = $wgContLang->specialPage( 'Userlogout' );
642
643 $s = '';
644 if ( $wgUser->isAnon() ) {
645 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
646 $n = $wgIP;
647
648 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
649 $wgContLang->getNsText( NS_TALK ) );
650
651 $s .= $n . ' ('.$tl.')';
652 } else {
653 $s .= wfMsg('notloggedin');
654 }
655
656 $rt = $wgTitle->getPrefixedURL();
657 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
658 $q = '';
659 } else { $q = "returnto={$rt}"; }
660
661 $s .= "\n<br />" . $this->makeKnownLinkObj(
662 Title::makeTitle( NS_SPECIAL, 'Userlogin' ),
663 wfMsg( 'login' ), $q );
664 } else {
665 $n = $wgUser->getName();
666 $rt = $wgTitle->getPrefixedURL();
667 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
668 $wgContLang->getNsText( NS_TALK ) );
669
670 $tl = " ({$tl})";
671
672 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
673 $n ) . "{$tl}<br />" .
674 $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogout' ), wfMsg( 'logout' ),
675 "returnto={$rt}" ) . ' | ' .
676 $this->specialLink( 'preferences' );
677 }
678 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
679 wfMsg( 'help' ) );
680
681 return $s;
682 }
683
684 function getSearchLink() {
685 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
686 return $searchPage->getLocalURL();
687 }
688
689 function escapeSearchLink() {
690 return htmlspecialchars( $this->getSearchLink() );
691 }
692
693 function searchForm() {
694 global $wgRequest;
695 $search = $wgRequest->getText( 'search' );
696
697 $s = '<form name="search" class="inline" method="post" action="'
698 . $this->escapeSearchLink() . "\">\n"
699 . '<input type="text" name="search" size="19" value="'
700 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
701 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
702 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
703
704 return $s;
705 }
706
707 function topLinks() {
708 global $wgOut;
709 $sep = " |\n";
710
711 $s = $this->mainPageLink() . $sep
712 . $this->specialLink( 'recentchanges' );
713
714 if ( $wgOut->isArticleRelated() ) {
715 $s .= $sep . $this->editThisPage()
716 . $sep . $this->historyLink();
717 }
718 # Many people don't like this dropdown box
719 #$s .= $sep . $this->specialPagesList();
720
721 /* show links to different language variants */
722 global $wgDisableLangConversion, $wgContLang, $wgTitle;
723 $variants = $wgContLang->getVariants();
724 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
725 foreach( $variants as $code ) {
726 $varname = $wgContLang->getVariantname( $code );
727 if( $varname == 'disable' )
728 continue;
729 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
730 }
731 }
732
733 return $s;
734 }
735
736 function bottomLinks() {
737 global $wgOut, $wgUser, $wgTitle;
738 $sep = " |\n";
739
740 $s = '';
741 if ( $wgOut->isArticleRelated() ) {
742 $s .= '<strong>' . $this->editThisPage() . '</strong>';
743 if ( $wgUser->isLoggedIn() ) {
744 $s .= $sep . $this->watchThisPage();
745 }
746 $s .= $sep . $this->talkLink()
747 . $sep . $this->historyLink()
748 . $sep . $this->whatLinksHere()
749 . $sep . $this->watchPageLinksLink();
750
751 if ( $wgTitle->getNamespace() == NS_USER
752 || $wgTitle->getNamespace() == NS_USER_TALK )
753
754 {
755 $id=User::idFromName($wgTitle->getText());
756 $ip=User::isIP($wgTitle->getText());
757
758 if($id || $ip) { # both anons and non-anons have contri list
759 $s .= $sep . $this->userContribsLink();
760 }
761 if( $this->showEmailUser( $id ) ) {
762 $s .= $sep . $this->emailUserLink();
763 }
764 }
765 if ( $wgTitle->getArticleId() ) {
766 $s .= "\n<br />";
767 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
768 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
769 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
770 }
771 $s .= "<br />\n" . $this->otherLanguages();
772 }
773 return $s;
774 }
775
776 function pageStats() {
777 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
778 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
779
780 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
781 if ( ! $wgOut->isArticle() ) { return ''; }
782 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
783 if ( 0 == $wgArticle->getID() ) { return ''; }
784
785 $s = '';
786 if ( !$wgDisableCounters ) {
787 $count = $wgLang->formatNum( $wgArticle->getCount() );
788 if ( $count ) {
789 $s = wfMsg( 'viewcount', $count );
790 }
791 }
792
793 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
794 require_once('Credits.php');
795 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
796 } else {
797 $s .= $this->lastModified();
798 }
799
800 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
801 $dbr =& wfGetDB( DB_SLAVE );
802 extract( $dbr->tableNames( 'watchlist' ) );
803 $sql = "SELECT COUNT(*) AS n FROM $watchlist
804 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
805 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
806 $res = $dbr->query( $sql, 'Skin::pageStats');
807 $x = $dbr->fetchObject( $res );
808 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
809 }
810
811 return $s . ' ' . $this->getCopyright();
812 }
813
814 function getCopyright() {
815 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
816
817
818 $oldid = $wgRequest->getVal( 'oldid' );
819 $diff = $wgRequest->getVal( 'diff' );
820
821 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
822 $msg = 'history_copyright';
823 } else {
824 $msg = 'copyright';
825 }
826
827 $out = '';
828 if( $wgRightsPage ) {
829 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
830 } elseif( $wgRightsUrl ) {
831 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
832 } else {
833 # Give up now
834 return $out;
835 }
836 $out .= wfMsgForContent( $msg, $link );
837 return $out;
838 }
839
840 function getCopyrightIcon() {
841 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
842 $out = '';
843 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
844 $out = $wgCopyrightIcon;
845 } else if ( $wgRightsIcon ) {
846 $icon = htmlspecialchars( $wgRightsIcon );
847 if ( $wgRightsUrl ) {
848 $url = htmlspecialchars( $wgRightsUrl );
849 $out .= '<a href="'.$url.'">';
850 }
851 $text = htmlspecialchars( $wgRightsText );
852 $out .= "<img src=\"$icon\" alt='$text' />";
853 if ( $wgRightsUrl ) {
854 $out .= '</a>';
855 }
856 }
857 return $out;
858 }
859
860 function getPoweredBy() {
861 global $wgStylePath;
862 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
863 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
864 return $img;
865 }
866
867 function lastModified() {
868 global $wgLang, $wgArticle, $wgLoadBalancer;
869
870 $timestamp = $wgArticle->getTimestamp();
871 if ( $timestamp ) {
872 $d = $wgLang->timeanddate( $timestamp, true );
873 $s = ' ' . wfMsg( 'lastmodified', $d );
874 } else {
875 $s = '';
876 }
877 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
878 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
879 }
880 return $s;
881 }
882
883 function logoText( $align = '' ) {
884 if ( '' != $align ) { $a = " align='{$align}'"; }
885 else { $a = ''; }
886
887 $mp = wfMsg( 'mainpage' );
888 $titleObj = Title::newFromText( $mp );
889 if ( is_object( $titleObj ) ) {
890 $url = $titleObj->escapeLocalURL();
891 } else {
892 $url = '';
893 }
894
895 $logourl = $this->getLogo();
896 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
897 return $s;
898 }
899
900 /**
901 * show a drop-down box of special pages
902 * @TODO crash bug913. Need to be rewrote completly.
903 */
904 function specialPagesList() {
905 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
906 require_once('SpecialPage.php');
907 $a = array();
908 $pages = SpecialPage::getPages();
909
910 // special pages without access restriction
911 foreach ( $pages[''] as $name => $page ) {
912 $a[$name] = $page->getDescription();
913 }
914
915 // Other special pages that are restricted.
916 // Copied from SpecialSpecialpages.php
917 foreach($wgAvailableRights as $right) {
918 if( $wgUser->isAllowed($right) ) {
919 /** Add all pages for this right */
920 if(isset($pages[$right])) {
921 foreach($pages[$right] as $name => $page) {
922 $a[$name] = $page->getDescription();
923 }
924 }
925 }
926 }
927
928 $go = wfMsg( 'go' );
929 $sp = wfMsg( 'specialpages' );
930 $spp = $wgContLang->specialPage( 'Specialpages' );
931
932 $s = '<form id="specialpages" method="get" class="inline" ' .
933 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
934 $s .= "<select name=\"wpDropdown\">\n";
935 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
936
937
938 foreach ( $a as $name => $desc ) {
939 $p = $wgContLang->specialPage( $name );
940 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
941 }
942 $s .= "</select>\n";
943 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
944 $s .= "</form>\n";
945 return $s;
946 }
947
948 function mainPageLink() {
949 $mp = wfMsgForContent( 'mainpage' );
950 $mptxt = wfMsg( 'mainpage');
951 $s = $this->makeKnownLink( $mp, $mptxt );
952 return $s;
953 }
954
955 function copyrightLink() {
956 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
957 wfMsg( 'copyrightpagename' ) );
958 return $s;
959 }
960
961 function aboutLink() {
962 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
963 wfMsg( 'aboutsite' ) );
964 return $s;
965 }
966
967
968 function disclaimerLink() {
969 $disclaimers = wfMsg( 'disclaimers' );
970 if ($disclaimers == '-') {
971 return '';
972 } else {
973 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
974 $disclaimers );
975 }
976 }
977
978 function editThisPage() {
979 global $wgOut, $wgTitle, $wgRequest;
980
981 $oldid = $wgRequest->getVal( 'oldid' );
982 $diff = $wgRequest->getVal( 'diff' );
983 $redirect = $wgRequest->getVal( 'redirect' );
984
985 if ( ! $wgOut->isArticleRelated() ) {
986 $s = wfMsg( 'protectedpage' );
987 } else {
988 if ( $wgTitle->userCanEdit() ) {
989 $t = wfMsg( 'editthispage' );
990 } else {
991 $t = wfMsg( 'viewsource' );
992 }
993 $oid = $red = '';
994
995 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
996 if ( $oldid && ! isset( $diff ) ) {
997 $oid = '&oldid='.$oldid;
998 }
999 $s = $this->makeKnownLinkObj( $wgTitle, $t, "action=edit{$oid}{$red}" );
1000 }
1001 return $s;
1002 }
1003
1004 function deleteThisPage() {
1005 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1006
1007 $diff = $wgRequest->getVal( 'diff' );
1008 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1009 $t = wfMsg( 'deletethispage' );
1010
1011 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1012 } else {
1013 $s = '';
1014 }
1015 return $s;
1016 }
1017
1018 function protectThisPage() {
1019 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1020
1021 $diff = $wgRequest->getVal( 'diff' );
1022 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1023 if ( $wgTitle->isProtected() ) {
1024 $t = wfMsg( 'unprotectthispage' );
1025 $q = 'action=unprotect';
1026 } else {
1027 $t = wfMsg( 'protectthispage' );
1028 $q = 'action=protect';
1029 }
1030 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1031 } else {
1032 $s = '';
1033 }
1034 return $s;
1035 }
1036
1037 function watchThisPage() {
1038 global $wgUser, $wgOut, $wgTitle;
1039
1040 if ( $wgOut->isArticleRelated() ) {
1041 if ( $wgTitle->userIsWatching() ) {
1042 $t = wfMsg( 'unwatchthispage' );
1043 $q = 'action=unwatch';
1044 } else {
1045 $t = wfMsg( 'watchthispage' );
1046 $q = 'action=watch';
1047 }
1048 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1049 } else {
1050 $s = wfMsg( 'notanarticle' );
1051 }
1052 return $s;
1053 }
1054
1055 function moveThisPage() {
1056 global $wgTitle;
1057
1058 if ( $wgTitle->userCanMove() ) {
1059 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
1060 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1061 } else {
1062 // no message if page is protected - would be redundant
1063 return '';
1064 }
1065 }
1066
1067 function historyLink() {
1068 global $wgTitle;
1069
1070 return $this->makeKnownLinkObj( $wgTitle,
1071 wfMsg( 'history' ), 'action=history' );
1072 }
1073
1074 function whatLinksHere() {
1075 global $wgTitle;
1076
1077 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
1078 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1079 }
1080
1081 function userContribsLink() {
1082 global $wgTitle;
1083
1084 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
1085 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1086 }
1087
1088 function showEmailUser( $id ) {
1089 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1090 return $wgEnableEmail &&
1091 $wgEnableUserEmail &&
1092 $wgUser->isLoggedIn() && # show only to signed in users
1093 0 != $id; # we can only email to non-anons ..
1094 # '' != $id->getEmail() && # who must have an email address stored ..
1095 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1096 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1097 }
1098
1099 function emailUserLink() {
1100 global $wgTitle;
1101
1102 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
1103 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1104 }
1105
1106 function watchPageLinksLink() {
1107 global $wgOut, $wgTitle;
1108
1109 if ( ! $wgOut->isArticleRelated() ) {
1110 return '(' . wfMsg( 'notanarticle' ) . ')';
1111 } else {
1112 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
1113 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1114 'target=' . $wgTitle->getPrefixedURL() );
1115 }
1116 }
1117
1118 function otherLanguages() {
1119 global $wgOut, $wgContLang, $wgTitle, $wgHideInterlanguageLinks;
1120
1121 if ( $wgHideInterlanguageLinks ) {
1122 return '';
1123 }
1124
1125 $a = $wgOut->getLanguageLinks();
1126 if ( 0 == count( $a ) ) {
1127 return '';
1128 }
1129
1130 $s = wfMsg( 'otherlanguages' ) . ': ';
1131 $first = true;
1132 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1133 foreach( $a as $l ) {
1134 if ( ! $first ) { $s .= ' | '; }
1135 $first = false;
1136
1137 $nt = Title::newFromText( $l );
1138 $url = $nt->escapeFullURL();
1139 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1140
1141 if ( '' == $text ) { $text = $l; }
1142 $style = $this->getExternalLinkAttributes( $l, $text );
1143 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1144 }
1145 if($wgContLang->isRTL()) $s .= '</span>';
1146 return $s;
1147 }
1148
1149 function bugReportsLink() {
1150 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1151 wfMsg( 'bugreports' ) );
1152 return $s;
1153 }
1154
1155 function dateLink() {
1156 global $wgLinkCache;
1157 $t1 = Title::newFromText( gmdate( 'F j' ) );
1158 $t2 = Title::newFromText( gmdate( 'Y' ) );
1159
1160 $wgLinkCache->suspend();
1161 $id = $t1->getArticleID();
1162 $wgLinkCache->resume();
1163
1164 if ( 0 == $id ) {
1165 $s = $this->makeBrokenLink( $t1->getText() );
1166 } else {
1167 $s = $this->makeKnownLink( $t1->getText() );
1168 }
1169 $s .= ', ';
1170
1171 $wgLinkCache->suspend();
1172 $id = $t2->getArticleID();
1173 $wgLinkCache->resume();
1174
1175 if ( 0 == $id ) {
1176 $s .= $this->makeBrokenLink( $t2->getText() );
1177 } else {
1178 $s .= $this->makeKnownLink( $t2->getText() );
1179 }
1180 return $s;
1181 }
1182
1183 function talkLink() {
1184 global $wgTitle, $wgLinkCache;
1185
1186 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1187 # No discussion links for special pages
1188 return '';
1189 }
1190
1191 if( $wgTitle->isTalkPage() ) {
1192 $link = $wgTitle->getSubjectPage();
1193 switch( $link->getNamespace() ) {
1194 case NS_MAIN:
1195 $text = wfMsg('articlepage');
1196 break;
1197 case NS_USER:
1198 $text = wfMsg('userpage');
1199 break;
1200 case NS_PROJECT:
1201 $text = wfMsg('wikipediapage');
1202 break;
1203 case NS_IMAGE:
1204 $text = wfMsg('imagepage');
1205 break;
1206 default:
1207 $text= wfMsg('articlepage');
1208 }
1209 } else {
1210 $link = $wgTitle->getTalkPage();
1211 $text = wfMsg( 'talkpage' );
1212 }
1213
1214 $wgLinkCache->suspend();
1215 $s = $this->makeLinkObj( $link, $text );
1216 $wgLinkCache->resume();
1217
1218 return $s;
1219 }
1220
1221 function commentLink() {
1222 global $wgContLang, $wgTitle, $wgLinkCache;
1223
1224 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1225 return '';
1226 }
1227 return $this->makeKnownLinkObj( $wgTitle->getTalkPage(),
1228 wfMsg( 'postcomment' ), 'action=edit&section=new' );
1229 }
1230
1231 /* these are used extensively in SkinPHPTal, but also some other places */
1232 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1233 $title = Title::makeTitle( NS_SPECIAL, $name );
1234 return $title->getLocalURL( $urlaction );
1235 }
1236
1237 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1238 $title = Title::newFromText( wfMsgForContent($name) );
1239 $this->checkTitle($title, $name);
1240 return $title->getLocalURL( $urlaction );
1241 }
1242
1243 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1244 $title = Title::newFromText( $name );
1245 $this->checkTitle($title, $name);
1246 return $title->getLocalURL( $urlaction );
1247 }
1248
1249 # If url string starts with http, consider as external URL, else
1250 # internal
1251 /*static*/ function makeInternalOrExternalUrl( $name ) {
1252 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1253 return $name;
1254 } else {
1255 return $this->makeUrl( $name );
1256 }
1257 }
1258
1259 # this can be passed the NS number as defined in Language.php
1260 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) {
1261 $title = Title::makeTitleSafe( $namespace, $name );
1262 $this->checkTitle($title, $name);
1263 return $title->getLocalURL( $urlaction );
1264 }
1265
1266 /* these return an array with the 'href' and boolean 'exists' */
1267 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1268 $title = Title::newFromText( $name );
1269 $this->checkTitle($title, $name);
1270 return array(
1271 'href' => $title->getLocalURL( $urlaction ),
1272 'exists' => $title->getArticleID() != 0?true:false
1273 );
1274 }
1275
1276 # make sure we have some title to operate on
1277 /*static*/ function checkTitle ( &$title, &$name ) {
1278 if(!is_object($title)) {
1279 $title = Title::newFromText( $name );
1280 if(!is_object($title)) {
1281 $title = Title::newFromText( '--error: link target missing--' );
1282 }
1283 }
1284 }
1285
1286 /**
1287 * Build an array that represents the sidebar(s), the navigation bar among them
1288 *
1289 * @return array
1290 * @access private
1291 */
1292 function buildSidebar() {
1293 $fname = 'SkinTemplate::buildSidebar';
1294 wfProfileIn( $fname );
1295
1296 $bar = array();
1297 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1298 foreach ($lines as $line) {
1299 if (strpos($line, '*') !== 0)
1300 continue;
1301 if (strpos($line, '**') !== 0) {
1302 $line = trim($line, '* ');
1303 $heading = $line;
1304 } else {
1305 if (strpos($line, '|') !== false) { // sanity check
1306 $line = explode( '|' , trim($line, '* '), 2 );
1307 $link = wfMsgForContent( $line[0] );
1308 if ($link == '-')
1309 continue;
1310 $bar[$heading][] = array(
1311 'text' => wfMsg( $line[1] ),
1312 'href' => $this->makeInternalOrExternalUrl( $link ),
1313 'id' => 'n-' . strtr($line[1], ' ', '-'),
1314 );
1315 } else { continue; }
1316 }
1317 }
1318
1319 wfProfileOut( $fname );
1320 return $bar;
1321 }
1322 }
1323
1324 }
1325 ?>