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