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