introduced $wgHideInterlanguageLinks, needed for dumpHTML
[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 { 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 # Render the array as a serie of links
434 # Need to give skin cause $this is undefined at this level
435 function walkThrough ($tree, &$skin) {
436 $return = '';
437 foreach($tree as $element => $parent) {
438 if(empty($parent)) {
439 # element start a new list
440 $return .= '<br />';
441 } else {
442 # grab the others elements
443 $return .= walkThrough($parent, $skin);
444 }
445 # add our current element to the list
446 $eltitle = Title::NewFromText($element);
447 if(!empty($parent)) $return .= ' &gt; ';
448 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
449 }
450 return $return;
451 }
452
453 # Skin object passed by reference cause it can not be
454 # accessed under the method subfunction walkThrough.
455 $s .= walkThrough($parenttree, $this);
456 }
457
458 return $s;
459 }
460
461 function getCategories() {
462 $catlinks=$this->getCategoryLinks();
463 if(!empty($catlinks)) {
464 return "<p class='catlinks'>{$catlinks}</p>";
465 }
466 }
467
468 function getQuickbarCompensator( $rows = 1 ) {
469 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
470 }
471
472 /**
473 * This gets called immediately before the </body> tag.
474 * @return string HTML to be put after </body> ???
475 */
476 function afterContent() {
477 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
478 return $printfooter . $this->doAfterContent();
479 }
480
481 /** @return string Retrievied from HTML text */
482 function printSource() {
483 global $wgTitle;
484 $url = htmlspecialchars( $wgTitle->getFullURL() );
485 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
486 }
487
488 function printFooter() {
489 return "<p>" . $this->printSource() .
490 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
491 }
492
493 /** overloaded by derived classes */
494 function doAfterContent() { }
495
496 function pageTitleLinks() {
497 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgUseApproval, $wgRequest;
498
499 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
500 $action = $wgRequest->getText( 'action' );
501
502 $s = $this->printableLink();
503 $disclaimer = $this->disclaimerLink(); # may be empty
504 if( $disclaimer ) {
505 $s .= ' | ' . $disclaimer;
506 }
507
508 if ( $wgOut->isArticleRelated() ) {
509 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
510 $name = $wgTitle->getDBkey();
511 $image = new Image( $wgTitle );
512 if( $image->exists() ) {
513 $link = htmlspecialchars( $image->getURL() );
514 $style = $this->getInternalLinkAttributes( $link, $name );
515 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
516 }
517 }
518 # This will show the "Approve" link if $wgUseApproval=true;
519 if ( isset ( $wgUseApproval ) && $wgUseApproval )
520 {
521 $t = $wgTitle->getDBkey();
522 $name = 'Approve this article' ;
523 $link = "http://test.wikipedia.org/w/magnus/wiki.phtml?title={$t}&action=submit&doit=1" ;
524 #htmlspecialchars( wfImageUrl( $name ) );
525 $style = $this->getExternalLinkAttributes( $link, $name );
526 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>" ;
527 }
528 }
529 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
530 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
531 wfMsg( 'currentrev' ) );
532 }
533
534 if ( $wgUser->getNewtalk() ) {
535 # do not show "You have new messages" text when we are viewing our
536 # own talk page
537
538 if( $wgTitle->equals( $wgUser->getTalkPage() ) ) {
539 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
540 wfMsg('newmessageslink') );
541 $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
542 # disable caching
543 $wgOut->setSquidMaxage(0);
544 $wgOut->enableClientCache(false);
545 }
546 }
547
548 $undelete = $this->getUndeleteLink();
549 if( !empty( $undelete ) ) {
550 $s .= ' | '.$undelete;
551 }
552 return $s;
553 }
554
555 function getUndeleteLink() {
556 global $wgUser, $wgTitle, $wgContLang, $action;
557 if( $wgUser->isAllowed('rollback') &&
558 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
559 ($n = $wgTitle->isDeleted() ) ) {
560 return wfMsg( 'thisisdeleted',
561 $this->makeKnownLink(
562 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
563 wfMsg( 'restorelink', $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 $wgContLang->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 $wgContLang->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;
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 ( $wgTitle->getNamespace() == NS_USER
755 || $wgTitle->getNamespace() == NS_USER_TALK )
756
757 {
758 $id=User::idFromName($wgTitle->getText());
759 $ip=User::isIP($wgTitle->getText());
760
761 if($id || $ip) { # both anons and non-anons have contri list
762 $s .= $sep . $this->userContribsLink();
763 }
764 if( $this->showEmailUser( $id ) ) {
765 $s .= $sep . $this->emailUserLink();
766 }
767 }
768 if ( $wgTitle->getArticleId() ) {
769 $s .= "\n<br />";
770 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
771 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
772 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
773 }
774 $s .= "<br />\n" . $this->otherLanguages();
775 }
776 return $s;
777 }
778
779 function pageStats() {
780 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
781 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
782
783 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
784 if ( ! $wgOut->isArticle() ) { return ''; }
785 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
786 if ( 0 == $wgArticle->getID() ) { return ''; }
787
788 $s = '';
789 if ( !$wgDisableCounters ) {
790 $count = $wgLang->formatNum( $wgArticle->getCount() );
791 if ( $count ) {
792 $s = wfMsg( 'viewcount', $count );
793 }
794 }
795
796 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
797 require_once('Credits.php');
798 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
799 } else {
800 $s .= $this->lastModified();
801 }
802
803 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
804 $dbr =& wfGetDB( DB_SLAVE );
805 extract( $dbr->tableNames( 'watchlist' ) );
806 $sql = "SELECT COUNT(*) AS n FROM $watchlist
807 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
808 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
809 $res = $dbr->query( $sql, 'Skin::pageStats');
810 $x = $dbr->fetchObject( $res );
811 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
812 }
813
814 return $s . ' ' . $this->getCopyright();
815 }
816
817 function getCopyright() {
818 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
819
820
821 $oldid = $wgRequest->getVal( 'oldid' );
822 $diff = $wgRequest->getVal( 'diff' );
823
824 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
825 $msg = 'history_copyright';
826 } else {
827 $msg = 'copyright';
828 }
829
830 $out = '';
831 if( $wgRightsPage ) {
832 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
833 } elseif( $wgRightsUrl ) {
834 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
835 } else {
836 # Give up now
837 return $out;
838 }
839 $out .= wfMsgForContent( $msg, $link );
840 return $out;
841 }
842
843 function getCopyrightIcon() {
844 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
845 $out = '';
846 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
847 $out = $wgCopyrightIcon;
848 } else if ( $wgRightsIcon ) {
849 $icon = htmlspecialchars( $wgRightsIcon );
850 if ( $wgRightsUrl ) {
851 $url = htmlspecialchars( $wgRightsUrl );
852 $out .= '<a href="'.$url.'">';
853 }
854 $text = htmlspecialchars( $wgRightsText );
855 $out .= "<img src=\"$icon\" alt='$text' />";
856 if ( $wgRightsUrl ) {
857 $out .= '</a>';
858 }
859 }
860 return $out;
861 }
862
863 function getPoweredBy() {
864 global $wgStylePath;
865 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
866 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
867 return $img;
868 }
869
870 function lastModified() {
871 global $wgLang, $wgArticle, $wgLoadBalancer;
872
873 $timestamp = $wgArticle->getTimestamp();
874 if ( $timestamp ) {
875 $d = $wgLang->timeanddate( $timestamp, true );
876 $s = ' ' . wfMsg( 'lastmodified', $d );
877 } else {
878 $s = '';
879 }
880 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
881 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
882 }
883 return $s;
884 }
885
886 function logoText( $align = '' ) {
887 if ( '' != $align ) { $a = " align='{$align}'"; }
888 else { $a = ''; }
889
890 $mp = wfMsg( 'mainpage' );
891 $titleObj = Title::newFromText( $mp );
892 if ( is_object( $titleObj ) ) {
893 $url = $titleObj->escapeLocalURL();
894 } else {
895 $url = '';
896 }
897
898 $logourl = $this->getLogo();
899 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
900 return $s;
901 }
902
903 /**
904 * show a drop-down box of special pages
905 * @TODO crash bug913. Need to be rewrote completly.
906 */
907 function specialPagesList() {
908 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
909 require_once('SpecialPage.php');
910 $a = array();
911 $pages = SpecialPage::getPages();
912
913 // special pages without access restriction
914 foreach ( $pages[''] as $name => $page ) {
915 $a[$name] = $page->getDescription();
916 }
917
918 // Other special pages that are restricted.
919 // Copied from SpecialSpecialpages.php
920 foreach($wgAvailableRights as $right) {
921 if( $wgUser->isAllowed($right) ) {
922 /** Add all pages for this right */
923 if(isset($pages[$right])) {
924 foreach($pages[$right] as $name => $page) {
925 $a[$name] = $page->getDescription();
926 }
927 }
928 }
929 }
930
931 $go = wfMsg( 'go' );
932 $sp = wfMsg( 'specialpages' );
933 $spp = $wgContLang->specialPage( 'Specialpages' );
934
935 $s = '<form id="specialpages" method="get" class="inline" ' .
936 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
937 $s .= "<select name=\"wpDropdown\">\n";
938 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
939
940
941 foreach ( $a as $name => $desc ) {
942 $p = $wgContLang->specialPage( $name );
943 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
944 }
945 $s .= "</select>\n";
946 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
947 $s .= "</form>\n";
948 return $s;
949 }
950
951 function mainPageLink() {
952 $mp = wfMsgForContent( 'mainpage' );
953 $mptxt = wfMsg( 'mainpage');
954 $s = $this->makeKnownLink( $mp, $mptxt );
955 return $s;
956 }
957
958 function copyrightLink() {
959 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
960 wfMsg( 'copyrightpagename' ) );
961 return $s;
962 }
963
964 function aboutLink() {
965 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
966 wfMsg( 'aboutsite' ) );
967 return $s;
968 }
969
970
971 function disclaimerLink() {
972 $disclaimers = wfMsg( 'disclaimers' );
973 if ($disclaimers == '-') {
974 return '';
975 } else {
976 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
977 $disclaimers );
978 }
979 }
980
981 function editThisPage() {
982 global $wgOut, $wgTitle, $wgRequest;
983
984 $oldid = $wgRequest->getVal( 'oldid' );
985 $diff = $wgRequest->getVal( 'diff' );
986 $redirect = $wgRequest->getVal( 'redirect' );
987
988 if ( ! $wgOut->isArticleRelated() ) {
989 $s = wfMsg( 'protectedpage' );
990 } else {
991 if ( $wgTitle->userCanEdit() ) {
992 $t = wfMsg( 'editthispage' );
993 } else {
994 $t = wfMsg( 'viewsource' );
995 }
996 $oid = $red = '';
997
998 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
999 if ( $oldid && ! isset( $diff ) ) {
1000 $oid = '&oldid='.$oldid;
1001 }
1002 $s = $this->makeKnownLinkObj( $wgTitle, $t, "action=edit{$oid}{$red}" );
1003 }
1004 return $s;
1005 }
1006
1007 function deleteThisPage() {
1008 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1009
1010 $diff = $wgRequest->getVal( 'diff' );
1011 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1012 $t = wfMsg( 'deletethispage' );
1013
1014 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1015 } else {
1016 $s = '';
1017 }
1018 return $s;
1019 }
1020
1021 function protectThisPage() {
1022 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1023
1024 $diff = $wgRequest->getVal( 'diff' );
1025 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1026 if ( $wgTitle->isProtected() ) {
1027 $t = wfMsg( 'unprotectthispage' );
1028 $q = 'action=unprotect';
1029 } else {
1030 $t = wfMsg( 'protectthispage' );
1031 $q = 'action=protect';
1032 }
1033 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1034 } else {
1035 $s = '';
1036 }
1037 return $s;
1038 }
1039
1040 function watchThisPage() {
1041 global $wgUser, $wgOut, $wgTitle;
1042
1043 if ( $wgOut->isArticleRelated() ) {
1044 if ( $wgTitle->userIsWatching() ) {
1045 $t = wfMsg( 'unwatchthispage' );
1046 $q = 'action=unwatch';
1047 } else {
1048 $t = wfMsg( 'watchthispage' );
1049 $q = 'action=watch';
1050 }
1051 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1052 } else {
1053 $s = wfMsg( 'notanarticle' );
1054 }
1055 return $s;
1056 }
1057
1058 function moveThisPage() {
1059 global $wgTitle;
1060
1061 if ( $wgTitle->userCanMove() ) {
1062 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
1063 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1064 } else {
1065 // no message if page is protected - would be redundant
1066 return '';
1067 }
1068 }
1069
1070 function historyLink() {
1071 global $wgTitle;
1072
1073 return $this->makeKnownLinkObj( $wgTitle,
1074 wfMsg( 'history' ), 'action=history' );
1075 }
1076
1077 function whatLinksHere() {
1078 global $wgTitle;
1079
1080 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
1081 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1082 }
1083
1084 function userContribsLink() {
1085 global $wgTitle;
1086
1087 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
1088 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1089 }
1090
1091 function showEmailUser( $id ) {
1092 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1093 return $wgEnableEmail &&
1094 $wgEnableUserEmail &&
1095 $wgUser->isLoggedIn() && # show only to signed in users
1096 0 != $id; # we can only email to non-anons ..
1097 # '' != $id->getEmail() && # who must have an email address stored ..
1098 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1099 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1100 }
1101
1102 function emailUserLink() {
1103 global $wgTitle;
1104
1105 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
1106 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1107 }
1108
1109 function watchPageLinksLink() {
1110 global $wgOut, $wgTitle;
1111
1112 if ( ! $wgOut->isArticleRelated() ) {
1113 return '(' . wfMsg( 'notanarticle' ) . ')';
1114 } else {
1115 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
1116 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1117 'target=' . $wgTitle->getPrefixedURL() );
1118 }
1119 }
1120
1121 function otherLanguages() {
1122 global $wgOut, $wgContLang, $wgTitle, $wgHideInterlanguageLinks;
1123
1124 if ( $wgHideInterlanguageLinks ) {
1125 return '';
1126 }
1127
1128 $a = $wgOut->getLanguageLinks();
1129 if ( 0 == count( $a ) ) {
1130 return '';
1131 }
1132
1133 $s = wfMsg( 'otherlanguages' ) . ': ';
1134 $first = true;
1135 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1136 foreach( $a as $l ) {
1137 if ( ! $first ) { $s .= ' | '; }
1138 $first = false;
1139
1140 $nt = Title::newFromText( $l );
1141 $url = $nt->escapeFullURL();
1142 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1143
1144 if ( '' == $text ) { $text = $l; }
1145 $style = $this->getExternalLinkAttributes( $l, $text );
1146 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1147 }
1148 if($wgContLang->isRTL()) $s .= '</span>';
1149 return $s;
1150 }
1151
1152 function bugReportsLink() {
1153 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1154 wfMsg( 'bugreports' ) );
1155 return $s;
1156 }
1157
1158 function dateLink() {
1159 global $wgLinkCache;
1160 $t1 = Title::newFromText( gmdate( 'F j' ) );
1161 $t2 = Title::newFromText( gmdate( 'Y' ) );
1162
1163 $wgLinkCache->suspend();
1164 $id = $t1->getArticleID();
1165 $wgLinkCache->resume();
1166
1167 if ( 0 == $id ) {
1168 $s = $this->makeBrokenLink( $t1->getText() );
1169 } else {
1170 $s = $this->makeKnownLink( $t1->getText() );
1171 }
1172 $s .= ', ';
1173
1174 $wgLinkCache->suspend();
1175 $id = $t2->getArticleID();
1176 $wgLinkCache->resume();
1177
1178 if ( 0 == $id ) {
1179 $s .= $this->makeBrokenLink( $t2->getText() );
1180 } else {
1181 $s .= $this->makeKnownLink( $t2->getText() );
1182 }
1183 return $s;
1184 }
1185
1186 function talkLink() {
1187 global $wgTitle, $wgLinkCache;
1188
1189 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1190 # No discussion links for special pages
1191 return '';
1192 }
1193
1194 if( $wgTitle->isTalkPage() ) {
1195 $link = $wgTitle->getSubjectPage();
1196 switch( $link->getNamespace() ) {
1197 case NS_MAIN:
1198 $text = wfMsg('articlepage');
1199 break;
1200 case NS_USER:
1201 $text = wfMsg('userpage');
1202 break;
1203 case NS_PROJECT:
1204 $text = wfMsg('wikipediapage');
1205 break;
1206 case NS_IMAGE:
1207 $text = wfMsg('imagepage');
1208 break;
1209 default:
1210 $text= wfMsg('articlepage');
1211 }
1212 } else {
1213 $link = $wgTitle->getTalkPage();
1214 $text = wfMsg( 'talkpage' );
1215 }
1216
1217 $wgLinkCache->suspend();
1218 $s = $this->makeLinkObj( $link, $text );
1219 $wgLinkCache->resume();
1220
1221 return $s;
1222 }
1223
1224 function commentLink() {
1225 global $wgContLang, $wgTitle, $wgLinkCache;
1226
1227 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1228 return '';
1229 }
1230 return $this->makeKnownLinkObj( $wgTitle->getTalkPage(),
1231 wfMsg( 'postcomment' ), 'action=edit&section=new' );
1232 }
1233
1234 /* these are used extensively in SkinPHPTal, but also some other places */
1235 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1236 $title = Title::makeTitle( NS_SPECIAL, $name );
1237 return $title->getLocalURL( $urlaction );
1238 }
1239
1240 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1241 $title = Title::newFromText( wfMsgForContent($name) );
1242 $this->checkTitle($title, $name);
1243 return $title->getLocalURL( $urlaction );
1244 }
1245
1246 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1247 $title = Title::newFromText( $name );
1248 $this->checkTitle($title, $name);
1249 return $title->getLocalURL( $urlaction );
1250 }
1251
1252 # If url string starts with http, consider as external URL, else
1253 # internal
1254 /*static*/ function makeInternalOrExternalUrl( $name ) {
1255 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1256 return $name;
1257 } else {
1258 return $this->makeUrl( $name );
1259 }
1260 }
1261
1262 # this can be passed the NS number as defined in Language.php
1263 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) {
1264 $title = Title::makeTitleSafe( $namespace, $name );
1265 $this->checkTitle($title, $name);
1266 return $title->getLocalURL( $urlaction );
1267 }
1268
1269 /* these return an array with the 'href' and boolean 'exists' */
1270 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1271 $title = Title::newFromText( $name );
1272 $this->checkTitle($title, $name);
1273 return array(
1274 'href' => $title->getLocalURL( $urlaction ),
1275 'exists' => $title->getArticleID() != 0?true:false
1276 );
1277 }
1278
1279 # make sure we have some title to operate on
1280 /*static*/ function checkTitle ( &$title, &$name ) {
1281 if(!is_object($title)) {
1282 $title = Title::newFromText( $name );
1283 if(!is_object($title)) {
1284 $title = Title::newFromText( '--error: link target missing--' );
1285 }
1286 }
1287 }
1288
1289 }
1290
1291 }
1292 ?>