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