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