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