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