9d63c40d020b0a77297aed83ba07f940de6694d7
[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 return $a;
334 }
335
336 /**
337 * URL to the logo
338 */
339 function getLogo() {
340 global $wgLogo;
341 return $wgLogo;
342 }
343
344 /**
345 * This will be called immediately after the <body> tag. Split into
346 * two functions to make it easier to subclass.
347 */
348 function beforeContent() {
349 return $this->doBeforeContent();
350 }
351
352 function doBeforeContent() {
353 global $wgOut, $wgTitle, $wgContLang, $wgSiteNotice;
354 $fname = 'Skin::doBeforeContent';
355 wfProfileIn( $fname );
356
357 $s = '';
358 $qb = $this->qbSetting();
359
360 if( $langlinks = $this->otherLanguages() ) {
361 $rows = 2;
362 $borderhack = '';
363 } else {
364 $rows = 1;
365 $langlinks = false;
366 $borderhack = 'class="top"';
367 }
368
369 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
370 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
371
372 $shove = ($qb != 0);
373 $left = ($qb == 1 || $qb == 3);
374 if($wgContLang->isRTL()) $left = !$left;
375
376 if ( !$shove ) {
377 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
378 $this->logoText() . '</td>';
379 } elseif( $left ) {
380 $s .= $this->getQuickbarCompensator( $rows );
381 }
382 $l = $wgContLang->isRTL() ? 'right' : 'left';
383 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
384
385 $s .= $this->topLinks() ;
386 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
387
388 $r = $wgContLang->isRTL() ? "left" : "right";
389 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
390 $s .= $this->nameAndLogin();
391 $s .= "\n<br />" . $this->searchForm() . "</td>";
392
393 if ( $langlinks ) {
394 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
395 }
396
397 if ( $shove && !$left ) { # Right
398 $s .= $this->getQuickbarCompensator( $rows );
399 }
400 $s .= "</tr>\n</table>\n</div>\n";
401 $s .= "\n<div id='article'>\n";
402
403 if( $wgSiteNotice ) {
404 $s .= "\n<div id='siteNotice'>$wgSiteNotice</div>\n";
405 }
406 $s .= $this->pageTitle();
407 $s .= $this->pageSubtitle() ;
408 $s .= $this->getCategories();
409 wfProfileOut( $fname );
410 return $s;
411 }
412
413
414 function getCategoryLinks () {
415 global $wgOut, $wgTitle, $wgParser;
416 global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
417
418 if( !$wgUseCategoryMagic ) return '' ;
419 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
420
421 # Taken out so that they will be displayed in previews -- TS
422 #if( !$wgOut->isArticle() ) return '';
423
424 $t = implode ( ' | ' , $wgOut->mCategoryLinks ) ;
425 $s = $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Categories' ),
426 wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
427 . ': ' . $t;
428
429 # optional 'dmoz-like' category browser. Will be shown under the list
430 # of categories an article belong to
431 if($wgUseCategoryBrowser) {
432 $s .= '<br /><hr />';
433
434 # get a big array of the parents tree
435 $parenttree = $wgTitle->getParentCategoryTree();
436
437 # Render the array as a serie of links
438 # Need to give skin cause $this is undefined at this level
439 function walkThrough ($tree, &$skin) {
440 $return = '';
441 foreach($tree as $element => $parent) {
442 if(empty($parent)) {
443 # element start a new list
444 $return .= '<br />';
445 } else {
446 # grab the others elements
447 $return .= walkThrough($parent, $skin);
448 }
449 # add our current element to the list
450 $eltitle = Title::NewFromText($element);
451 if(!empty($parent)) $return .= ' &gt; ';
452 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
453 }
454 return $return;
455 }
456
457 # Skin object passed by reference cause it can not be
458 # accessed under the method subfunction walkThrough.
459 $s .= walkThrough($parenttree, $this);
460 }
461
462 return $s;
463 }
464
465 function getCategories() {
466 $catlinks=$this->getCategoryLinks();
467 if(!empty($catlinks)) {
468 return "<p class='catlinks'>{$catlinks}</p>";
469 }
470 }
471
472 function getQuickbarCompensator( $rows = 1 ) {
473 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
474 }
475
476 /**
477 * This gets called immediately before the </body> tag.
478 * @return string HTML to be put after </body> ???
479 */
480 function afterContent() {
481 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
482 return $printfooter . $this->doAfterContent();
483 }
484
485 /** @return string Retrievied from HTML text */
486 function printSource() {
487 global $wgTitle;
488 $url = htmlspecialchars( $wgTitle->getFullURL() );
489 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
490 }
491
492 function printFooter() {
493 return "<p>" . $this->printSource() .
494 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
495 }
496
497 /** overloaded by derived classes */
498 function doAfterContent() { }
499
500 function pageTitleLinks() {
501 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgUseApproval, $wgRequest;
502
503 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
504 $action = $wgRequest->getText( 'action' );
505
506 $s = $this->printableLink();
507 $disclaimer = $this->disclaimerLink(); # may be empty
508 if( $disclaimer ) {
509 $s .= ' | ' . $disclaimer;
510 }
511
512 if ( $wgOut->isArticleRelated() ) {
513 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
514 $name = $wgTitle->getDBkey();
515 $image = new Image( $wgTitle->getDBkey() );
516 if( $image->exists() ) {
517 $link = htmlspecialchars( $image->getURL() );
518 $style = $this->getInternalLinkAttributes( $link, $name );
519 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
520 }
521 }
522 # This will show the "Approve" link if $wgUseApproval=true;
523 if ( isset ( $wgUseApproval ) && $wgUseApproval )
524 {
525 $t = $wgTitle->getDBkey();
526 $name = 'Approve this article' ;
527 $link = "http://test.wikipedia.org/w/magnus/wiki.phtml?title={$t}&action=submit&doit=1" ;
528 #htmlspecialchars( wfImageUrl( $name ) );
529 $style = $this->getExternalLinkAttributes( $link, $name );
530 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>" ;
531 }
532 }
533 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
534 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
535 wfMsg( 'currentrev' ) );
536 }
537
538 if ( $wgUser->getNewtalk() ) {
539 # do not show "You have new messages" text when we are viewing our
540 # own talk page
541
542 if( $wgTitle->equals( $wgUser->getTalkPage() ) ) {
543 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
544 wfMsg('newmessageslink') );
545 $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
546 # disable caching
547 $wgOut->setSquidMaxage(0);
548 $wgOut->enableClientCache(false);
549 }
550 }
551
552 $undelete = $this->getUndeleteLink();
553 if( !empty( $undelete ) ) {
554 $s .= ' | '.$undelete;
555 }
556 return $s;
557 }
558
559 function getUndeleteLink() {
560 global $wgUser, $wgTitle, $wgContLang, $action;
561 if( $wgUser->isAllowed('rollback') &&
562 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
563 ($n = $wgTitle->isDeleted() ) ) {
564 return wfMsg( 'thisisdeleted',
565 $this->makeKnownLink(
566 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
567 wfMsg( 'restorelink', $n ) ) );
568 }
569 return '';
570 }
571
572 function printableLink() {
573 global $wgOut, $wgFeedClasses, $wgRequest;
574
575 $baseurl = $_SERVER['REQUEST_URI'];
576 if( strpos( '?', $baseurl ) == false ) {
577 $baseurl .= '?';
578 } else {
579 $baseurl .= '&';
580 }
581 $baseurl = htmlspecialchars( $baseurl );
582 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
583
584 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
585 if( $wgOut->isSyndicated() ) {
586 foreach( $wgFeedClasses as $format => $class ) {
587 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
588 $s .= " | <a href=\"$feedurl\">{$format}</a>";
589 }
590 }
591 return $s;
592 }
593
594 function pageTitle() {
595 global $wgOut, $wgTitle, $wgUser;
596
597 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
598 if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);}
599 return $s;
600 }
601
602 function pageSubtitle() {
603 global $wgOut;
604
605 $sub = $wgOut->getSubtitle();
606 if ( '' == $sub ) {
607 global $wgExtraSubtitle;
608 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
609 }
610 $subpages = $this->subPageSubtitle();
611 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
612 $s = "<p class='subtitle'>{$sub}</p>\n";
613 return $s;
614 }
615
616 function subPageSubtitle() {
617 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
618 $subpages = '';
619 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
620 $ptext=$wgTitle->getPrefixedText();
621 if(preg_match('/\//',$ptext)) {
622 $links = explode('/',$ptext);
623 $c = 0;
624 $growinglink = '';
625 foreach($links as $link) {
626 $c++;
627 if ($c<count($links)) {
628 $growinglink .= $link;
629 $getlink = $this->makeLink( $growinglink, $link );
630 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
631 if ($c>1) {
632 $subpages .= ' | ';
633 } else {
634 $subpages .= '&lt; ';
635 }
636 $subpages .= $getlink;
637 $growinglink .= '/';
638 }
639 }
640 }
641 }
642 return $subpages;
643 }
644
645 function nameAndLogin() {
646 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
647
648 $li = $wgContLang->specialPage( 'Userlogin' );
649 $lo = $wgContLang->specialPage( 'Userlogout' );
650
651 $s = '';
652 if ( $wgUser->isAnon() ) {
653 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
654 $n = $wgIP;
655
656 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
657 $wgContLang->getNsText( NS_TALK ) );
658
659 $s .= $n . ' ('.$tl.')';
660 } else {
661 $s .= wfMsg('notloggedin');
662 }
663
664 $rt = $wgTitle->getPrefixedURL();
665 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
666 $q = '';
667 } else { $q = "returnto={$rt}"; }
668
669 $s .= "\n<br />" . $this->makeKnownLinkObj(
670 Title::makeTitle( NS_SPECIAL, 'Userlogin' ),
671 wfMsg( 'login' ), $q );
672 } else {
673 $n = $wgUser->getName();
674 $rt = $wgTitle->getPrefixedURL();
675 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
676 $wgContLang->getNsText( NS_TALK ) );
677
678 $tl = " ({$tl})";
679
680 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
681 $n ) . "{$tl}<br />" .
682 $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogout' ), wfMsg( 'logout' ),
683 "returnto={$rt}" ) . ' | ' .
684 $this->specialLink( 'preferences' );
685 }
686 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
687 wfMsg( 'help' ) );
688
689 return $s;
690 }
691
692 function getSearchLink() {
693 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
694 return $searchPage->getLocalURL();
695 }
696
697 function escapeSearchLink() {
698 return htmlspecialchars( $this->getSearchLink() );
699 }
700
701 function searchForm() {
702 global $wgRequest;
703 $search = $wgRequest->getText( 'search' );
704
705 $s = '<form name="search" class="inline" method="post" action="'
706 . $this->escapeSearchLink() . "\">\n"
707 . '<input type="text" name="search" size="19" value="'
708 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
709 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
710 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
711
712 return $s;
713 }
714
715 function topLinks() {
716 global $wgOut;
717 $sep = " |\n";
718
719 $s = $this->mainPageLink() . $sep
720 . $this->specialLink( 'recentchanges' );
721
722 if ( $wgOut->isArticleRelated() ) {
723 $s .= $sep . $this->editThisPage()
724 . $sep . $this->historyLink();
725 }
726 # Many people don't like this dropdown box
727 #$s .= $sep . $this->specialPagesList();
728
729 /* show links to different language variants */
730 global $wgDisableLangConversion, $wgContLang, $wgTitle;
731 $variants = $wgContLang->getVariants();
732 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
733 foreach( $variants as $code ) {
734 $varname = $wgContLang->getVariantname( $code );
735 if( $varname == 'disable' )
736 continue;
737 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
738 }
739 }
740
741 return $s;
742 }
743
744 function bottomLinks() {
745 global $wgOut, $wgUser, $wgTitle;
746 $sep = " |\n";
747
748 $s = '';
749 if ( $wgOut->isArticleRelated() ) {
750 $s .= '<strong>' . $this->editThisPage() . '</strong>';
751 if ( $wgUser->isLoggedIn() ) {
752 $s .= $sep . $this->watchThisPage();
753 }
754 $s .= $sep . $this->talkLink()
755 . $sep . $this->historyLink()
756 . $sep . $this->whatLinksHere()
757 . $sep . $this->watchPageLinksLink();
758
759 if ( $wgTitle->getNamespace() == NS_USER
760 || $wgTitle->getNamespace() == NS_USER_TALK )
761
762 {
763 $id=User::idFromName($wgTitle->getText());
764 $ip=User::isIP($wgTitle->getText());
765
766 if($id || $ip) { # both anons and non-anons have contri list
767 $s .= $sep . $this->userContribsLink();
768 }
769 if( $this->showEmailUser( $id ) ) {
770 $s .= $sep . $this->emailUserLink();
771 }
772 }
773 if ( $wgTitle->getArticleId() ) {
774 $s .= "\n<br />";
775 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
776 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
777 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
778 }
779 $s .= "<br />\n" . $this->otherLanguages();
780 }
781 return $s;
782 }
783
784 function pageStats() {
785 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
786 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
787
788 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
789 if ( ! $wgOut->isArticle() ) { return ''; }
790 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
791 if ( 0 == $wgArticle->getID() ) { return ''; }
792
793 $s = '';
794 if ( !$wgDisableCounters ) {
795 $count = $wgLang->formatNum( $wgArticle->getCount() );
796 if ( $count ) {
797 $s = wfMsg( 'viewcount', $count );
798 }
799 }
800
801 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
802 require_once('Credits.php');
803 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
804 } else {
805 $s .= $this->lastModified();
806 }
807
808 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
809 $dbr =& wfGetDB( DB_SLAVE );
810 extract( $dbr->tableNames( 'watchlist' ) );
811 $sql = "SELECT COUNT(*) AS n FROM $watchlist
812 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
813 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
814 $res = $dbr->query( $sql, 'Skin::pageStats');
815 $x = $dbr->fetchObject( $res );
816 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
817 }
818
819 return $s . ' ' . $this->getCopyright();
820 }
821
822 function getCopyright() {
823 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
824
825
826 $oldid = $wgRequest->getVal( 'oldid' );
827 $diff = $wgRequest->getVal( 'diff' );
828
829 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
830 $msg = 'history_copyright';
831 } else {
832 $msg = 'copyright';
833 }
834
835 $out = '';
836 if( $wgRightsPage ) {
837 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
838 } elseif( $wgRightsUrl ) {
839 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
840 } else {
841 # Give up now
842 return $out;
843 }
844 $out .= wfMsgForContent( $msg, $link );
845 return $out;
846 }
847
848 function getCopyrightIcon() {
849 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
850 $out = '';
851 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
852 $out = $wgCopyrightIcon;
853 } else if ( $wgRightsIcon ) {
854 $icon = htmlspecialchars( $wgRightsIcon );
855 if ( $wgRightsUrl ) {
856 $url = htmlspecialchars( $wgRightsUrl );
857 $out .= '<a href="'.$url.'">';
858 }
859 $text = htmlspecialchars( $wgRightsText );
860 $out .= "<img src=\"$icon\" alt='$text' />";
861 if ( $wgRightsUrl ) {
862 $out .= '</a>';
863 }
864 }
865 return $out;
866 }
867
868 function getPoweredBy() {
869 global $wgStylePath;
870 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
871 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
872 return $img;
873 }
874
875 function lastModified() {
876 global $wgLang, $wgArticle, $wgLoadBalancer;
877
878 $timestamp = $wgArticle->getTimestamp();
879 if ( $timestamp ) {
880 $d = $wgLang->timeanddate( $timestamp, true );
881 $s = ' ' . wfMsg( 'lastmodified', $d );
882 } else {
883 $s = '';
884 }
885 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
886 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
887 }
888 return $s;
889 }
890
891 function logoText( $align = '' ) {
892 if ( '' != $align ) { $a = " align='{$align}'"; }
893 else { $a = ''; }
894
895 $mp = wfMsg( 'mainpage' );
896 $titleObj = Title::newFromText( $mp );
897 if ( is_object( $titleObj ) ) {
898 $url = $titleObj->escapeLocalURL();
899 } else {
900 $url = '';
901 }
902
903 $logourl = $this->getLogo();
904 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
905 return $s;
906 }
907
908 /**
909 * show a drop-down box of special pages
910 * @TODO crash bug913. Need to be rewrote completly.
911 */
912 function specialPagesList() {
913 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
914 require_once('SpecialPage.php');
915 $a = array();
916 $pages = SpecialPage::getPages();
917
918 // special pages without access restriction
919 foreach ( $pages[''] as $name => $page ) {
920 $a[$name] = $page->getDescription();
921 }
922
923 // Other special pages that are restricted.
924 // Copied from SpecialSpecialpages.php
925 foreach($wgAvailableRights as $right) {
926 if( $wgUser->isAllowed($right) ) {
927 /** Add all pages for this right */
928 if(isset($pages[$right])) {
929 foreach($pages[$right] as $name => $page) {
930 $a[$name] = $page->getDescription();
931 }
932 }
933 }
934 }
935
936 $go = wfMsg( 'go' );
937 $sp = wfMsg( 'specialpages' );
938 $spp = $wgContLang->specialPage( 'Specialpages' );
939
940 $s = '<form id="specialpages" method="get" class="inline" ' .
941 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
942 $s .= "<select name=\"wpDropdown\">\n";
943 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
944
945
946 foreach ( $a as $name => $desc ) {
947 $p = $wgContLang->specialPage( $name );
948 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
949 }
950 $s .= "</select>\n";
951 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
952 $s .= "</form>\n";
953 return $s;
954 }
955
956 function mainPageLink() {
957 $mp = wfMsgForContent( 'mainpage' );
958 $mptxt = wfMsg( 'mainpage');
959 $s = $this->makeKnownLink( $mp, $mptxt );
960 return $s;
961 }
962
963 function copyrightLink() {
964 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
965 wfMsg( 'copyrightpagename' ) );
966 return $s;
967 }
968
969 function aboutLink() {
970 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
971 wfMsg( 'aboutsite' ) );
972 return $s;
973 }
974
975
976 function disclaimerLink() {
977 $disclaimers = wfMsg( 'disclaimers' );
978 if ($disclaimers == '-') {
979 return '';
980 } else {
981 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
982 $disclaimers );
983 }
984 }
985
986 function editThisPage() {
987 global $wgOut, $wgTitle, $wgRequest;
988
989 $oldid = $wgRequest->getVal( 'oldid' );
990 $diff = $wgRequest->getVal( 'diff' );
991 $redirect = $wgRequest->getVal( 'redirect' );
992
993 if ( ! $wgOut->isArticleRelated() ) {
994 $s = wfMsg( 'protectedpage' );
995 } else {
996 if ( $wgTitle->userCanEdit() ) {
997 $t = wfMsg( 'editthispage' );
998 } else {
999 $t = wfMsg( 'viewsource' );
1000 }
1001 $oid = $red = '';
1002
1003 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
1004 if ( $oldid && ! isset( $diff ) ) {
1005 $oid = '&oldid='.$oldid;
1006 }
1007 $s = $this->makeKnownLinkObj( $wgTitle, $t, "action=edit{$oid}{$red}" );
1008 }
1009 return $s;
1010 }
1011
1012 function deleteThisPage() {
1013 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1014
1015 $diff = $wgRequest->getVal( 'diff' );
1016 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1017 $t = wfMsg( 'deletethispage' );
1018
1019 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1020 } else {
1021 $s = '';
1022 }
1023 return $s;
1024 }
1025
1026 function protectThisPage() {
1027 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1028
1029 $diff = $wgRequest->getVal( 'diff' );
1030 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1031 if ( $wgTitle->isProtected() ) {
1032 $t = wfMsg( 'unprotectthispage' );
1033 $q = 'action=unprotect';
1034 } else {
1035 $t = wfMsg( 'protectthispage' );
1036 $q = 'action=protect';
1037 }
1038 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1039 } else {
1040 $s = '';
1041 }
1042 return $s;
1043 }
1044
1045 function watchThisPage() {
1046 global $wgUser, $wgOut, $wgTitle;
1047
1048 if ( $wgOut->isArticleRelated() ) {
1049 if ( $wgTitle->userIsWatching() ) {
1050 $t = wfMsg( 'unwatchthispage' );
1051 $q = 'action=unwatch';
1052 } else {
1053 $t = wfMsg( 'watchthispage' );
1054 $q = 'action=watch';
1055 }
1056 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1057 } else {
1058 $s = wfMsg( 'notanarticle' );
1059 }
1060 return $s;
1061 }
1062
1063 function moveThisPage() {
1064 global $wgTitle;
1065
1066 if ( $wgTitle->userCanMove() ) {
1067 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
1068 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1069 } else {
1070 // no message if page is protected - would be redundant
1071 return '';
1072 }
1073 }
1074
1075 function historyLink() {
1076 global $wgTitle;
1077
1078 return $this->makeKnownLinkObj( $wgTitle,
1079 wfMsg( 'history' ), 'action=history' );
1080 }
1081
1082 function whatLinksHere() {
1083 global $wgTitle;
1084
1085 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
1086 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1087 }
1088
1089 function userContribsLink() {
1090 global $wgTitle;
1091
1092 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
1093 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1094 }
1095
1096 function showEmailUser( $id ) {
1097 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1098 return $wgEnableEmail &&
1099 $wgEnableUserEmail &&
1100 $wgUser->isLoggedIn() && # show only to signed in users
1101 0 != $id; # we can only email to non-anons ..
1102 # '' != $id->getEmail() && # who must have an email address stored ..
1103 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1104 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1105 }
1106
1107 function emailUserLink() {
1108 global $wgTitle;
1109
1110 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
1111 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1112 }
1113
1114 function watchPageLinksLink() {
1115 global $wgOut, $wgTitle;
1116
1117 if ( ! $wgOut->isArticleRelated() ) {
1118 return '(' . wfMsg( 'notanarticle' ) . ')';
1119 } else {
1120 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
1121 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1122 'target=' . $wgTitle->getPrefixedURL() );
1123 }
1124 }
1125
1126 function otherLanguages() {
1127 global $wgOut, $wgContLang, $wgTitle;
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
1292 }
1293 ?>