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