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