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