permalink
[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 />\n";
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( (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
553 ($n = $wgTitle->isDeleted() ) )
554 {
555 if ( $wgUser->isAllowed( 'delete' ) ) {
556 $msg = 'thisisdeleted';
557 } else {
558 $msg = 'viewdeleted';
559 }
560 return wfMsg( $msg,
561 $this->makeKnownLink(
562 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
563 wfMsg( 'restorelink' . ($n == 1 ? '1' : ''), $n ) ) );
564 }
565 return '';
566 }
567
568 function printableLink() {
569 global $wgOut, $wgFeedClasses, $wgRequest;
570
571 $baseurl = $_SERVER['REQUEST_URI'];
572 if( strpos( '?', $baseurl ) == false ) {
573 $baseurl .= '?';
574 } else {
575 $baseurl .= '&';
576 }
577 $baseurl = htmlspecialchars( $baseurl );
578 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
579
580 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
581 if( $wgOut->isSyndicated() ) {
582 foreach( $wgFeedClasses as $format => $class ) {
583 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
584 $s .= " | <a href=\"$feedurl\">{$format}</a>";
585 }
586 }
587 return $s;
588 }
589
590 function pageTitle() {
591 global $wgOut, $wgTitle, $wgUser;
592
593 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
594 return $s;
595 }
596
597 function pageSubtitle() {
598 global $wgOut;
599
600 $sub = $wgOut->getSubtitle();
601 if ( '' == $sub ) {
602 global $wgExtraSubtitle;
603 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
604 }
605 $subpages = $this->subPageSubtitle();
606 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
607 $s = "<p class='subtitle'>{$sub}</p>\n";
608 return $s;
609 }
610
611 function subPageSubtitle() {
612 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
613 $subpages = '';
614 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
615 $ptext=$wgTitle->getPrefixedText();
616 if(preg_match('/\//',$ptext)) {
617 $links = explode('/',$ptext);
618 $c = 0;
619 $growinglink = '';
620 foreach($links as $link) {
621 $c++;
622 if ($c<count($links)) {
623 $growinglink .= $link;
624 $getlink = $this->makeLink( $growinglink, $link );
625 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
626 if ($c>1) {
627 $subpages .= ' | ';
628 } else {
629 $subpages .= '&lt; ';
630 }
631 $subpages .= $getlink;
632 $growinglink .= '/';
633 }
634 }
635 }
636 }
637 return $subpages;
638 }
639
640 function nameAndLogin() {
641 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
642
643 $li = $wgContLang->specialPage( 'Userlogin' );
644 $lo = $wgContLang->specialPage( 'Userlogout' );
645
646 $s = '';
647 if ( $wgUser->isAnon() ) {
648 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
649 $n = $wgIP;
650
651 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
652 $wgLang->getNsText( NS_TALK ) );
653
654 $s .= $n . ' ('.$tl.')';
655 } else {
656 $s .= wfMsg('notloggedin');
657 }
658
659 $rt = $wgTitle->getPrefixedURL();
660 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
661 $q = '';
662 } else { $q = "returnto={$rt}"; }
663
664 $s .= "\n<br />" . $this->makeKnownLinkObj(
665 Title::makeTitle( NS_SPECIAL, 'Userlogin' ),
666 wfMsg( 'login' ), $q );
667 } else {
668 $n = $wgUser->getName();
669 $rt = $wgTitle->getPrefixedURL();
670 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
671 $wgLang->getNsText( NS_TALK ) );
672
673 $tl = " ({$tl})";
674
675 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
676 $n ) . "{$tl}<br />" .
677 $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogout' ), wfMsg( 'logout' ),
678 "returnto={$rt}" ) . ' | ' .
679 $this->specialLink( 'preferences' );
680 }
681 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
682 wfMsg( 'help' ) );
683
684 return $s;
685 }
686
687 function getSearchLink() {
688 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
689 return $searchPage->getLocalURL();
690 }
691
692 function escapeSearchLink() {
693 return htmlspecialchars( $this->getSearchLink() );
694 }
695
696 function searchForm() {
697 global $wgRequest;
698 $search = $wgRequest->getText( 'search' );
699
700 $s = '<form name="search" class="inline" method="post" action="'
701 . $this->escapeSearchLink() . "\">\n"
702 . '<input type="text" name="search" size="19" value="'
703 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
704 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
705 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
706
707 return $s;
708 }
709
710 function topLinks() {
711 global $wgOut;
712 $sep = " |\n";
713
714 $s = $this->mainPageLink() . $sep
715 . $this->specialLink( 'recentchanges' );
716
717 if ( $wgOut->isArticleRelated() ) {
718 $s .= $sep . $this->editThisPage()
719 . $sep . $this->historyLink();
720 }
721 # Many people don't like this dropdown box
722 #$s .= $sep . $this->specialPagesList();
723
724 /* show links to different language variants */
725 global $wgDisableLangConversion, $wgContLang, $wgTitle;
726 $variants = $wgContLang->getVariants();
727 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
728 foreach( $variants as $code ) {
729 $varname = $wgContLang->getVariantname( $code );
730 if( $varname == 'disable' )
731 continue;
732 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
733 }
734 }
735
736 return $s;
737 }
738
739 function bottomLinks() {
740 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
741 $sep = " |\n";
742
743 $s = '';
744 if ( $wgOut->isArticleRelated() ) {
745 $s .= '<strong>' . $this->editThisPage() . '</strong>';
746 if ( $wgUser->isLoggedIn() ) {
747 $s .= $sep . $this->watchThisPage();
748 }
749 $s .= $sep . $this->talkLink()
750 . $sep . $this->historyLink()
751 . $sep . $this->whatLinksHere()
752 . $sep . $this->watchPageLinksLink();
753
754 if ($wgUseTrackbacks)
755 $s .= $sep . $this->trackbackLink();
756
757 if ( $wgTitle->getNamespace() == NS_USER
758 || $wgTitle->getNamespace() == NS_USER_TALK )
759
760 {
761 $id=User::idFromName($wgTitle->getText());
762 $ip=User::isIP($wgTitle->getText());
763
764 if($id || $ip) { # both anons and non-anons have contri list
765 $s .= $sep . $this->userContribsLink();
766 }
767 if( $this->showEmailUser( $id ) ) {
768 $s .= $sep . $this->emailUserLink();
769 }
770 }
771 if ( $wgTitle->getArticleId() ) {
772 $s .= "\n<br />";
773 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
774 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
775 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
776 }
777 $s .= "<br />\n" . $this->otherLanguages();
778 }
779 return $s;
780 }
781
782 function pageStats() {
783 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
784 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
785
786 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
787 if ( ! $wgOut->isArticle() ) { return ''; }
788 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
789 if ( 0 == $wgArticle->getID() ) { return ''; }
790
791 $s = '';
792 if ( !$wgDisableCounters ) {
793 $count = $wgLang->formatNum( $wgArticle->getCount() );
794 if ( $count ) {
795 $s = wfMsg( 'viewcount', $count );
796 }
797 }
798
799 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
800 require_once('Credits.php');
801 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
802 } else {
803 $s .= $this->lastModified();
804 }
805
806 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
807 $dbr =& wfGetDB( DB_SLAVE );
808 extract( $dbr->tableNames( 'watchlist' ) );
809 $sql = "SELECT COUNT(*) AS n FROM $watchlist
810 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
811 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
812 $res = $dbr->query( $sql, 'Skin::pageStats');
813 $x = $dbr->fetchObject( $res );
814 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
815 }
816
817 return $s . ' ' . $this->getCopyright();
818 }
819
820 function getCopyright() {
821 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
822
823
824 $oldid = $wgRequest->getVal( 'oldid' );
825 $diff = $wgRequest->getVal( 'diff' );
826
827 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
828 $msg = 'history_copyright';
829 } else {
830 $msg = 'copyright';
831 }
832
833 $out = '';
834 if( $wgRightsPage ) {
835 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
836 } elseif( $wgRightsUrl ) {
837 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
838 } else {
839 # Give up now
840 return $out;
841 }
842 $out .= wfMsgForContent( $msg, $link );
843 return $out;
844 }
845
846 function getCopyrightIcon() {
847 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
848 $out = '';
849 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
850 $out = $wgCopyrightIcon;
851 } else if ( $wgRightsIcon ) {
852 $icon = htmlspecialchars( $wgRightsIcon );
853 if ( $wgRightsUrl ) {
854 $url = htmlspecialchars( $wgRightsUrl );
855 $out .= '<a href="'.$url.'">';
856 }
857 $text = htmlspecialchars( $wgRightsText );
858 $out .= "<img src=\"$icon\" alt='$text' />";
859 if ( $wgRightsUrl ) {
860 $out .= '</a>';
861 }
862 }
863 return $out;
864 }
865
866 function getPoweredBy() {
867 global $wgStylePath;
868 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
869 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
870 return $img;
871 }
872
873 function lastModified() {
874 global $wgLang, $wgArticle, $wgLoadBalancer;
875
876 $timestamp = $wgArticle->getTimestamp();
877 if ( $timestamp ) {
878 $d = $wgLang->timeanddate( $timestamp, true );
879 $s = ' ' . wfMsg( 'lastmodified', $d );
880 } else {
881 $s = '';
882 }
883 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
884 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
885 }
886 return $s;
887 }
888
889 function logoText( $align = '' ) {
890 if ( '' != $align ) { $a = " align='{$align}'"; }
891 else { $a = ''; }
892
893 $mp = wfMsg( 'mainpage' );
894 $titleObj = Title::newFromText( $mp );
895 if ( is_object( $titleObj ) ) {
896 $url = $titleObj->escapeLocalURL();
897 } else {
898 $url = '';
899 }
900
901 $logourl = $this->getLogo();
902 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
903 return $s;
904 }
905
906 /**
907 * show a drop-down box of special pages
908 * @TODO crash bug913. Need to be rewrote completly.
909 */
910 function specialPagesList() {
911 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
912 require_once('SpecialPage.php');
913 $a = array();
914 $pages = SpecialPage::getPages();
915
916 // special pages without access restriction
917 foreach ( $pages[''] as $name => $page ) {
918 $a[$name] = $page->getDescription();
919 }
920
921 // Other special pages that are restricted.
922 // Copied from SpecialSpecialpages.php
923 foreach($wgAvailableRights as $right) {
924 if( $wgUser->isAllowed($right) ) {
925 /** Add all pages for this right */
926 if(isset($pages[$right])) {
927 foreach($pages[$right] as $name => $page) {
928 $a[$name] = $page->getDescription();
929 }
930 }
931 }
932 }
933
934 $go = wfMsg( 'go' );
935 $sp = wfMsg( 'specialpages' );
936 $spp = $wgContLang->specialPage( 'Specialpages' );
937
938 $s = '<form id="specialpages" method="get" class="inline" ' .
939 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
940 $s .= "<select name=\"wpDropdown\">\n";
941 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
942
943
944 foreach ( $a as $name => $desc ) {
945 $p = $wgContLang->specialPage( $name );
946 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
947 }
948 $s .= "</select>\n";
949 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
950 $s .= "</form>\n";
951 return $s;
952 }
953
954 function mainPageLink() {
955 $mp = wfMsgForContent( 'mainpage' );
956 $mptxt = wfMsg( 'mainpage');
957 $s = $this->makeKnownLink( $mp, $mptxt );
958 return $s;
959 }
960
961 function copyrightLink() {
962 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
963 wfMsg( 'copyrightpagename' ) );
964 return $s;
965 }
966
967 function aboutLink() {
968 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
969 wfMsg( 'aboutsite' ) );
970 return $s;
971 }
972
973
974 function disclaimerLink() {
975 $disclaimers = wfMsg( 'disclaimers' );
976 if ($disclaimers == '-') {
977 return '';
978 } else {
979 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
980 $disclaimers );
981 }
982 }
983
984 function editThisPage() {
985 global $wgOut, $wgTitle, $wgRequest;
986
987 $oldid = $wgRequest->getVal( 'oldid' );
988 $diff = $wgRequest->getVal( 'diff' );
989 $redirect = $wgRequest->getVal( 'redirect' );
990
991 if ( ! $wgOut->isArticleRelated() ) {
992 $s = wfMsg( 'protectedpage' );
993 } else {
994 if ( $wgTitle->userCanEdit() ) {
995 $t = wfMsg( 'editthispage' );
996 } else {
997 $t = wfMsg( 'viewsource' );
998 }
999 $oid = $red = '';
1000
1001 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
1002 if ( $oldid && ! isset( $diff ) ) {
1003 $oid = '&oldid='.$oldid;
1004 }
1005 $s = $this->makeKnownLinkObj( $wgTitle, $t, "action=edit{$oid}{$red}" );
1006 }
1007 return $s;
1008 }
1009
1010 function deleteThisPage() {
1011 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1012
1013 $diff = $wgRequest->getVal( 'diff' );
1014 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1015 $t = wfMsg( 'deletethispage' );
1016
1017 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1018 } else {
1019 $s = '';
1020 }
1021 return $s;
1022 }
1023
1024 function protectThisPage() {
1025 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1026
1027 $diff = $wgRequest->getVal( 'diff' );
1028 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1029 if ( $wgTitle->isProtected() ) {
1030 $t = wfMsg( 'unprotectthispage' );
1031 $q = 'action=unprotect';
1032 } else {
1033 $t = wfMsg( 'protectthispage' );
1034 $q = 'action=protect';
1035 }
1036 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1037 } else {
1038 $s = '';
1039 }
1040 return $s;
1041 }
1042
1043 function watchThisPage() {
1044 global $wgUser, $wgOut, $wgTitle;
1045
1046 if ( $wgOut->isArticleRelated() ) {
1047 if ( $wgTitle->userIsWatching() ) {
1048 $t = wfMsg( 'unwatchthispage' );
1049 $q = 'action=unwatch';
1050 } else {
1051 $t = wfMsg( 'watchthispage' );
1052 $q = 'action=watch';
1053 }
1054 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1055 } else {
1056 $s = wfMsg( 'notanarticle' );
1057 }
1058 return $s;
1059 }
1060
1061 function moveThisPage() {
1062 global $wgTitle;
1063
1064 if ( $wgTitle->userCanMove() ) {
1065 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
1066 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1067 } else {
1068 // no message if page is protected - would be redundant
1069 return '';
1070 }
1071 }
1072
1073 function historyLink() {
1074 global $wgTitle;
1075
1076 return $this->makeKnownLinkObj( $wgTitle,
1077 wfMsg( 'history' ), 'action=history' );
1078 }
1079
1080 function whatLinksHere() {
1081 global $wgTitle;
1082
1083 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
1084 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1085 }
1086
1087 function userContribsLink() {
1088 global $wgTitle;
1089
1090 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
1091 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1092 }
1093
1094 function showEmailUser( $id ) {
1095 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1096 return $wgEnableEmail &&
1097 $wgEnableUserEmail &&
1098 $wgUser->isLoggedIn() && # show only to signed in users
1099 0 != $id; # we can only email to non-anons ..
1100 # '' != $id->getEmail() && # who must have an email address stored ..
1101 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1102 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1103 }
1104
1105 function emailUserLink() {
1106 global $wgTitle;
1107
1108 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
1109 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1110 }
1111
1112 function watchPageLinksLink() {
1113 global $wgOut, $wgTitle;
1114
1115 if ( ! $wgOut->isArticleRelated() ) {
1116 return '(' . wfMsg( 'notanarticle' ) . ')';
1117 } else {
1118 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
1119 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1120 'target=' . $wgTitle->getPrefixedURL() );
1121 }
1122 }
1123
1124 function trackbackLink() {
1125 global $wgTitle;
1126
1127 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1128 . wfMsg('trackbacklink') . "</a>";
1129 }
1130
1131 function otherLanguages() {
1132 global $wgOut, $wgContLang, $wgTitle, $wgHideInterlanguageLinks;
1133
1134 if ( $wgHideInterlanguageLinks ) {
1135 return '';
1136 }
1137
1138 $a = $wgOut->getLanguageLinks();
1139 if ( 0 == count( $a ) ) {
1140 return '';
1141 }
1142
1143 $s = wfMsg( 'otherlanguages' ) . ': ';
1144 $first = true;
1145 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1146 foreach( $a as $l ) {
1147 if ( ! $first ) { $s .= ' | '; }
1148 $first = false;
1149
1150 $nt = Title::newFromText( $l );
1151 $url = $nt->escapeFullURL();
1152 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1153
1154 if ( '' == $text ) { $text = $l; }
1155 $style = $this->getExternalLinkAttributes( $l, $text );
1156 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1157 }
1158 if($wgContLang->isRTL()) $s .= '</span>';
1159 return $s;
1160 }
1161
1162 function bugReportsLink() {
1163 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1164 wfMsg( 'bugreports' ) );
1165 return $s;
1166 }
1167
1168 function dateLink() {
1169 global $wgLinkCache;
1170 $t1 = Title::newFromText( gmdate( 'F j' ) );
1171 $t2 = Title::newFromText( gmdate( 'Y' ) );
1172
1173 $wgLinkCache->suspend();
1174 $id = $t1->getArticleID();
1175 $wgLinkCache->resume();
1176
1177 if ( 0 == $id ) {
1178 $s = $this->makeBrokenLink( $t1->getText() );
1179 } else {
1180 $s = $this->makeKnownLink( $t1->getText() );
1181 }
1182 $s .= ', ';
1183
1184 $wgLinkCache->suspend();
1185 $id = $t2->getArticleID();
1186 $wgLinkCache->resume();
1187
1188 if ( 0 == $id ) {
1189 $s .= $this->makeBrokenLink( $t2->getText() );
1190 } else {
1191 $s .= $this->makeKnownLink( $t2->getText() );
1192 }
1193 return $s;
1194 }
1195
1196 function talkLink() {
1197 global $wgTitle, $wgLinkCache;
1198
1199 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1200 # No discussion links for special pages
1201 return '';
1202 }
1203
1204 if( $wgTitle->isTalkPage() ) {
1205 $link = $wgTitle->getSubjectPage();
1206 switch( $link->getNamespace() ) {
1207 case NS_MAIN:
1208 $text = wfMsg('articlepage');
1209 break;
1210 case NS_USER:
1211 $text = wfMsg('userpage');
1212 break;
1213 case NS_PROJECT:
1214 $text = wfMsg('wikipediapage');
1215 break;
1216 case NS_IMAGE:
1217 $text = wfMsg('imagepage');
1218 break;
1219 default:
1220 $text= wfMsg('articlepage');
1221 }
1222 } else {
1223 $link = $wgTitle->getTalkPage();
1224 $text = wfMsg( 'talkpage' );
1225 }
1226
1227 $wgLinkCache->suspend();
1228 $s = $this->makeLinkObj( $link, $text );
1229 $wgLinkCache->resume();
1230
1231 return $s;
1232 }
1233
1234 function commentLink() {
1235 global $wgContLang, $wgTitle, $wgLinkCache;
1236
1237 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1238 return '';
1239 }
1240 return $this->makeKnownLinkObj( $wgTitle->getTalkPage(),
1241 wfMsg( 'postcomment' ), 'action=edit&section=new' );
1242 }
1243
1244 /* these are used extensively in SkinPHPTal, but also some other places */
1245 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1246 $title = Title::makeTitle( NS_SPECIAL, $name );
1247 return $title->getLocalURL( $urlaction );
1248 }
1249
1250 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1251 $title = Title::newFromText( wfMsgForContent($name) );
1252 $this->checkTitle($title, $name);
1253 return $title->getLocalURL( $urlaction );
1254 }
1255
1256 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1257 $title = Title::newFromText( $name );
1258 $this->checkTitle($title, $name);
1259 return $title->getLocalURL( $urlaction );
1260 }
1261
1262 # If url string starts with http, consider as external URL, else
1263 # internal
1264 /*static*/ function makeInternalOrExternalUrl( $name ) {
1265 global $wgUrlProtocols;
1266 if ( preg_match( '/^(?:' . $wgUrlProtocols . ')/', $name ) ) {
1267 return $name;
1268 } else {
1269 return $this->makeUrl( $name );
1270 }
1271 }
1272
1273 # this can be passed the NS number as defined in Language.php
1274 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) {
1275 $title = Title::makeTitleSafe( $namespace, $name );
1276 $this->checkTitle($title, $name);
1277 return $title->getLocalURL( $urlaction );
1278 }
1279
1280 /* these return an array with the 'href' and boolean 'exists' */
1281 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1282 $title = Title::newFromText( $name );
1283 $this->checkTitle($title, $name);
1284 return array(
1285 'href' => $title->getLocalURL( $urlaction ),
1286 'exists' => $title->getArticleID() != 0?true:false
1287 );
1288 }
1289
1290 # make sure we have some title to operate on
1291 /*static*/ function checkTitle ( &$title, &$name ) {
1292 if(!is_object($title)) {
1293 $title = Title::newFromText( $name );
1294 if(!is_object($title)) {
1295 $title = Title::newFromText( '--error: link target missing--' );
1296 }
1297 }
1298 }
1299
1300 /**
1301 * Build an array that represents the sidebar(s), the navigation bar among them
1302 *
1303 * @return array
1304 * @access private
1305 */
1306 function buildSidebar() {
1307 $fname = 'SkinTemplate::buildSidebar';
1308 wfProfileIn( $fname );
1309
1310 $bar = array();
1311 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1312 foreach ($lines as $line) {
1313 if (strpos($line, '*') !== 0)
1314 continue;
1315 if (strpos($line, '**') !== 0) {
1316 $line = trim($line, '* ');
1317 $heading = $line;
1318 } else {
1319 if (strpos($line, '|') !== false) { // sanity check
1320 $line = explode( '|' , trim($line, '* '), 2 );
1321 $link = wfMsgForContent( $line[0] );
1322 if ($link == '-')
1323 continue;
1324 if (wfNoMsg($line[1], $text = wfMsg($line[1])))
1325 $text = $line[1];
1326 if (wfNoMsg($line[0], $link))
1327 $link = $line[0];
1328 $bar[$heading][] = array(
1329 'text' => $text,
1330 'href' => $this->makeInternalOrExternalUrl( $link ),
1331 'id' => 'n-' . strtr($line[1], ' ', '-'),
1332 );
1333 } else { continue; }
1334 }
1335 }
1336
1337 wfProfileOut( $fname );
1338 return $bar;
1339 }
1340 }
1341
1342 }
1343 ?>