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