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