(bug 454) Merge e-notif 2.00
[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( 'Image.php' );
16
17 # Get a list of all skins available in /skins/
18 # Build using the regular expression '^(.*).php$'
19 # Array keys are all lower case, array value keep the case used by filename
20 #
21
22 $skinDir = dir($IP.'/skins');
23
24 # while code from www.php.net
25 while (false !== ($file = $skinDir->read())) {
26 if(preg_match('/^([^.].*)\.php$/',$file, $matches)) {
27 $aSkin = $matches[1];
28 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
29 }
30 }
31 $skinDir->close();
32 unset($matches);
33
34 require_once( 'RecentChange.php' );
35
36 global $wgLinkHolders;
37 $wgLinkHolders = array(
38 'namespaces' => array(),
39 'dbkeys' => array(),
40 'queries' => array(),
41 'texts' => array(),
42 'titles' => array()
43 );
44 global $wgInterwikiLinkHolders;
45 $wgInterwikiLinkHolders = array();
46
47 /**
48 * @todo document
49 * @package MediaWiki
50 */
51 class RCCacheEntry extends RecentChange
52 {
53 var $secureName, $link;
54 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
55 var $userlink, $timestamp, $watched;
56
57 function newFromParent( $rc )
58 {
59 $rc2 = new RCCacheEntry;
60 $rc2->mAttribs = $rc->mAttribs;
61 $rc2->mExtra = $rc->mExtra;
62 return $rc2;
63 }
64 } ;
65
66
67 /**
68 * The main skin class that provide methods and properties for all other skins
69 * including PHPTal skins.
70 * This base class is also the "Standard" skin.
71 * @package MediaWiki
72 */
73 class Skin {
74 /**#@+
75 * @access private
76 */
77 var $lastdate, $lastline;
78 var $linktrail ; # linktrail regexp
79 var $rc_cache ; # Cache for Enhanced Recent Changes
80 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
81 var $rcMoveIndex;
82 var $postParseLinkColour = false;
83 /**#@-*/
84
85 function Skin() {
86 global $wgContLang;
87 $this->linktrail = $wgContLang->linkTrail();
88
89 # Cache option lookups done very frequently
90 $options = array( 'highlightbroken', 'hover' );
91 foreach( $options as $opt ) {
92 global $wgUser;
93 $this->mOptions[$opt] = $wgUser->getOption( $opt );
94 }
95 }
96
97 function getSkinNames() {
98 global $wgValidSkinNames;
99 return $wgValidSkinNames;
100 }
101
102 function getStylesheet() {
103 return 'common/wikistandard.css';
104 }
105
106 function getSkinName() {
107 return 'standard';
108 }
109
110 /**
111 * Get/set accessor for delayed link colouring
112 */
113 function postParseLinkColour( $setting = NULL ) {
114 return wfSetVar( $this->postParseLinkColour, $setting );
115 }
116
117 function qbSetting() {
118 global $wgOut, $wgUser;
119
120 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
121 $q = $wgUser->getOption( 'quickbar' );
122 if ( '' == $q ) { $q = 0; }
123 return $q;
124 }
125
126 function initPage( &$out ) {
127 $fname = 'Skin::initPage';
128 wfProfileIn( $fname );
129
130 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => '/favicon.ico' ) );
131
132 $this->addMetadataLinks($out);
133
134 wfProfileOut( $fname );
135 }
136
137 function addMetadataLinks( &$out ) {
138 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
139 global $wgRightsPage, $wgRightsUrl;
140
141 if( $out->isArticleRelated() ) {
142 # note: buggy CC software only reads first "meta" link
143 if( $wgEnableCreativeCommonsRdf ) {
144 $out->addMetadataLink( array(
145 'title' => 'Creative Commons',
146 'type' => 'application/rdf+xml',
147 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
148 }
149 if( $wgEnableDublinCoreRdf ) {
150 $out->addMetadataLink( array(
151 'title' => 'Dublin Core',
152 'type' => 'application/rdf+xml',
153 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
154 }
155 }
156 $copyright = '';
157 if( $wgRightsPage ) {
158 $copy = Title::newFromText( $wgRightsPage );
159 if( $copy ) {
160 $copyright = $copy->getLocalURL();
161 }
162 }
163 if( !$copyright && $wgRightsUrl ) {
164 $copyright = $wgRightsUrl;
165 }
166 if( $copyright ) {
167 $out->addLink( array(
168 'rel' => 'copyright',
169 'href' => $copyright ) );
170 }
171 }
172
173 function outputPage( &$out ) {
174 global $wgDebugComments;
175
176 wfProfileIn( 'Skin::outputPage' );
177 $this->initPage( $out );
178 $out->out( $out->headElement() );
179
180 $out->out( "\n<body" );
181 $ops = $this->getBodyOptions();
182 foreach ( $ops as $name => $val ) {
183 $out->out( " $name='$val'" );
184 }
185 $out->out( ">\n" );
186 if ( $wgDebugComments ) {
187 $out->out( "<!-- Wiki debugging output:\n" .
188 $out->mDebugtext . "-->\n" );
189 }
190 $out->out( $this->beforeContent() );
191
192 $out->out( $out->mBodytext . "\n" );
193
194 $out->out( $this->afterContent() );
195
196 wfProfileClose();
197 $out->out( $out->reportTime() );
198
199 $out->out( "\n</body></html>" );
200 }
201
202 function getHeadScripts() {
203 global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs;
204 $r = "<script type=\"text/javascript\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
205 if( $wgAllowUserJs && $wgUser->getID() != 0 ) { # logged in
206 $userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
207 $userjs = htmlspecialchars($this->makeUrl($userpage.'/'.$this->getSkinName().'.js', 'action=raw&ctype=text/javascript'));
208 $r .= '<script type="text/javascript" src="'.$userjs."\"></script>\n";
209 }
210 return $r;
211 }
212
213 # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
214 function getUserStylesheet() {
215 global $wgOut, $wgStylePath, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
216 $sheet = $this->getStylesheet();
217 $action = $wgRequest->getText('action');
218 $s = "@import \"$wgStylePath/$sheet\";\n";
219 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
220 if( $wgAllowUserCss && $wgUser->getID() != 0 ) { # logged in
221 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
222 $s .= $wgRequest->getText('wpTextbox1');
223 } else {
224 $userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
225 $s.= '@import "'.$this->makeUrl($userpage.'/'.$this->getSkinName().'.css', 'action=raw&ctype=text/css').'";'."\n";
226 }
227 }
228 $s .= $this->doGetUserStyles();
229 return $s."\n";
230 }
231
232 /**
233 * placeholder, returns generated js in monobook
234 */
235 function getUserJs() { return; }
236
237 /**
238 * Return html code that include User stylesheets
239 */
240 function getUserStyles() {
241 global $wgOut, $wgStylePath, $wgLang;
242 $s = "<style type='text/css'>\n";
243 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
244 $s .= $this->getUserStylesheet();
245 $s .= "/*]]>*/ /* */\n";
246 $s .= "</style>\n";
247 return $s;
248 }
249
250 /**
251 * Some styles that are set by user through the user settings interface.
252 */
253 function doGetUserStyles() {
254 global $wgUser, $wgContLang;
255
256 $csspage = $wgContLang->getNsText( NS_MEDIAWIKI ) . ':' . $this->getSkinName() . '.css';
257 $s = '@import "'.$this->makeUrl($csspage, 'action=raw&ctype=text/css')."\";\n";
258
259 if ( 1 == $wgUser->getOption( 'underline' ) ) {
260 # Don't override browser settings
261 } else {
262 # CHECK MERGE @@@
263 # Force no underline
264 $s .= "a { text-decoration: none; }\n";
265 }
266 if ( 1 == $this->mOptions['highlightbroken'] ) {
267 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
268 }
269 if ( 1 == $wgUser->getOption( 'justify' ) ) {
270 $s .= "#article { text-align: justify; }\n";
271 }
272 return $s;
273 }
274
275 function getBodyOptions() {
276 global $wgUser, $wgTitle, $wgNamespaceBackgrounds, $wgOut, $wgRequest;
277
278 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
279
280 if ( 0 != $wgTitle->getNamespace() ) {
281 $a = array( 'bgcolor' => '#ffffec' );
282 }
283 else $a = array( 'bgcolor' => '#FFFFFF' );
284 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
285 (!$wgTitle->isProtected() || $wgUser->isAllowed('protect')) ) {
286 $t = wfMsg( 'editthispage' );
287 $oid = $red = '';
288 if ( !empty($redirect) && $redirect == 'no' ) {
289 $red = "&redirect={$redirect}";
290 }
291 if ( !empty($oldid) && ! isset( $diff ) ) {
292 $oid = "&oldid=" . IntVal( $oldid );
293 }
294 $s = $wgTitle->getFullURL( "action=edit{$oid}{$red}" );
295 $s = 'document.location = "' .$s .'";';
296 $a += array ('ondblclick' => $s);
297
298 }
299 $a['onload'] = $wgOut->getOnloadHandler();
300 return $a;
301 }
302
303 function getExternalLinkAttributes( $link, $text, $class='' ) {
304 global $wgContLang;
305
306 $same = ($link == $text);
307 $link = urldecode( $link );
308 $link = $wgContLang->checkTitleEncoding( $link );
309 $link = str_replace( '_', ' ', $link );
310 $link = htmlspecialchars( $link );
311
312 $r = ($class != '') ? " class='$class'" : " class='external'";
313
314 if( !$same && $this->mOptions['hover'] ) {
315 $r .= " title=\"{$link}\"";
316 }
317 return $r;
318 }
319
320 function getInternalLinkAttributes( $link, $text, $broken = false ) {
321 $link = urldecode( $link );
322 $link = str_replace( '_', ' ', $link );
323 $link = htmlspecialchars( $link );
324
325 if( $broken == 'stub' ) {
326 $r = ' class="stub"';
327 } else if ( $broken == 'yes' ) {
328 $r = ' class="new"';
329 } else {
330 $r = '';
331 }
332
333 if( $this->mOptions['hover'] ) {
334 $r .= " title=\"{$link}\"";
335 }
336 return $r;
337 }
338
339 /**
340 * @param bool $broken
341 */
342 function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) {
343 if( $broken == 'stub' ) {
344 $r = ' class="stub"';
345 } else if ( $broken == 'yes' ) {
346 $r = ' class="new"';
347 } else {
348 $r = '';
349 }
350
351 if( $this->mOptions['hover'] ) {
352 $r .= ' title="' . $nt->getEscapedText() . '"';
353 }
354 return $r;
355 }
356
357 /**
358 * URL to the logo
359 */
360 function getLogo() {
361 global $wgLogo;
362 return $wgLogo;
363 }
364
365 /**
366 * This will be called immediately after the <body> tag. Split into
367 * two functions to make it easier to subclass.
368 */
369 function beforeContent() {
370 global $wgUser, $wgOut;
371
372 return $this->doBeforeContent();
373 }
374
375 function doBeforeContent() {
376 global $wgUser, $wgOut, $wgTitle, $wgContLang, $wgSiteNotice;
377 $fname = 'Skin::doBeforeContent';
378 wfProfileIn( $fname );
379
380 $s = '';
381 $qb = $this->qbSetting();
382
383 if( $langlinks = $this->otherLanguages() ) {
384 $rows = 2;
385 $borderhack = '';
386 } else {
387 $rows = 1;
388 $langlinks = false;
389 $borderhack = 'class="top"';
390 }
391
392 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
393 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
394
395 $shove = ($qb != 0);
396 $left = ($qb == 1 || $qb == 3);
397 if($wgContLang->isRTL()) $left = !$left;
398
399 if ( !$shove ) {
400 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
401 $this->logoText() . '</td>';
402 } elseif( $left ) {
403 $s .= $this->getQuickbarCompensator( $rows );
404 }
405 $l = $wgContLang->isRTL() ? 'right' : 'left';
406 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
407
408 $s .= $this->topLinks() ;
409 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
410
411 $r = $wgContLang->isRTL() ? "left" : "right";
412 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
413 $s .= $this->nameAndLogin();
414 $s .= "\n<br />" . $this->searchForm() . "</td>";
415
416 if ( $langlinks ) {
417 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
418 }
419
420 if ( $shove && !$left ) { # Right
421 $s .= $this->getQuickbarCompensator( $rows );
422 }
423 $s .= "</tr>\n</table>\n</div>\n";
424 $s .= "\n<div id='article'>\n";
425
426 if( $wgSiteNotice ) {
427 $s .= "\n<div id='siteNotice'>$wgSiteNotice</div>\n";
428 }
429 $s .= $this->pageTitle();
430 $s .= $this->pageSubtitle() ;
431 $s .= $this->getCategories();
432 wfProfileOut( $fname );
433 return $s;
434 }
435
436
437 function getCategoryLinks () {
438 global $wgOut, $wgTitle, $wgUser, $wgParser;
439 global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
440
441 if( !$wgUseCategoryMagic ) return '' ;
442 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
443
444 # Taken out so that they will be displayed in previews -- TS
445 #if( !$wgOut->isArticle() ) return '';
446
447 $t = implode ( ' | ' , $wgOut->mCategoryLinks ) ;
448 $s = $this->makeKnownLink( 'Special:Categories',
449 wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
450 . ': ' . $t;
451
452 # optional 'dmoz-like' category browser. Will be shown under the list
453 # of categories an article belong to
454 if($wgUseCategoryBrowser) {
455 $s .= '<br/><hr/>';
456
457 # get a big array of the parents tree
458 $parenttree = $wgTitle->getParentCategoryTree();
459
460 # Render the array as a serie of links
461 function walkThrough ($tree) {
462 global $wgUser;
463 $sk = $wgUser->getSkin();
464 $return = '';
465 foreach($tree as $element => $parent) {
466 if(empty($parent)) {
467 # element start a new list
468 $return .= '<br />';
469 } else {
470 # grab the others elements
471 $return .= walkThrough($parent);
472 }
473 # add our current element to the list
474 $eltitle = Title::NewFromText($element);
475 # FIXME : should be makeLink() [AV]
476 $return .= $sk->makeLink($element, $eltitle->getText()).' &gt; ';
477 }
478 return $return;
479 }
480
481 $s .= walkThrough($parenttree);
482 }
483
484 return $s;
485 }
486
487 function getCategories() {
488 $catlinks=$this->getCategoryLinks();
489 if(!empty($catlinks)) {
490 return "<p class='catlinks'>{$catlinks}</p>";
491 }
492 }
493
494 function getQuickbarCompensator( $rows = 1 ) {
495 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
496 }
497
498 # This gets called immediately before the </body> tag.
499 #
500 function afterContent() {
501 global $wgUser, $wgOut, $wgServer;
502 global $wgTitle, $wgLang;
503
504 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
505 return $printfooter . $this->doAfterContent();
506 }
507
508 function printSource() {
509 global $wgTitle;
510 $url = htmlspecialchars( $wgTitle->getFullURL() );
511 return wfMsg( "retrievedfrom", "<a href=\"$url\">$url</a>" );
512 }
513
514 function printFooter() {
515 return "<p>" . $this->printSource() .
516 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
517 }
518
519 function doAfterContent() {
520 # overloaded by derived classes
521 }
522
523 function pageTitleLinks() {
524 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgUseApproval, $wgRequest;
525
526 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
527 $action = $wgRequest->getText( 'action' );
528
529 $s = $this->printableLink();
530 $disclaimer = $this->disclaimerLink(); # may be empty
531 if( $disclaimer ) {
532 $s .= ' | ' . $disclaimer;
533 }
534
535 if ( $wgOut->isArticleRelated() ) {
536 if ( $wgTitle->getNamespace() == Namespace::getImage() ) {
537 $name = $wgTitle->getDBkey();
538 $image = new Image( $wgTitle->getDBkey() );
539 if( $image->exists() ) {
540 $link = htmlspecialchars( $image->getURL() );
541 $style = $this->getInternalLinkAttributes( $link, $name );
542 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
543 }
544 }
545 # This will show the "Approve" link if $wgUseApproval=true;
546 if ( isset ( $wgUseApproval ) && $wgUseApproval )
547 {
548 $t = $wgTitle->getDBkey();
549 $name = 'Approve this article' ;
550 $link = "http://test.wikipedia.org/w/magnus/wiki.phtml?title={$t}&action=submit&doit=1" ;
551 #htmlspecialchars( wfImageUrl( $name ) );
552 $style = $this->getExternalLinkAttributes( $link, $name );
553 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>" ;
554 }
555 }
556 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
557 $s .= ' | ' . $this->makeKnownLink( $wgTitle->getPrefixedText(),
558 wfMsg( 'currentrev' ) );
559 }
560
561 if ( $wgUser->getNewtalk() ) {
562 # do not show "You have new messages" text when we are viewing our
563 # own talk page
564
565 if(!(strcmp($wgTitle->getText(),$wgUser->getName()) == 0 &&
566 $wgTitle->getNamespace()==Namespace::getTalk(Namespace::getUser()))) {
567 $n =$wgUser->getName();
568 $tl = $this->makeKnownLink( $wgContLang->getNsText(
569 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
570 wfMsg('newmessageslink') );
571 $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
572 # disable caching
573 $wgOut->setSquidMaxage(0);
574 $wgOut->enableClientCache(false);
575 }
576 }
577
578 $undelete = $this->getUndeleteLink();
579 if( !empty( $undelete ) ) {
580 $s .= ' | '.$undelete;
581 }
582 return $s;
583 }
584
585 function getUndeleteLink() {
586 global $wgUser, $wgTitle, $wgContLang, $action;
587 if( $wgUser->isAllowed('rollback') &&
588 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
589 ($n = $wgTitle->isDeleted() ) ) {
590 return wfMsg( 'thisisdeleted',
591 $this->makeKnownLink(
592 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
593 wfMsg( 'restorelink', $n ) ) );
594 }
595 return '';
596 }
597
598 function printableLink() {
599 global $wgOut, $wgFeedClasses, $wgRequest;
600
601 $baseurl = $_SERVER['REQUEST_URI'];
602 if( strpos( '?', $baseurl ) == false ) {
603 $baseurl .= '?';
604 } else {
605 $baseurl .= '&';
606 }
607 $baseurl = htmlspecialchars( $baseurl );
608 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
609
610 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
611 if( $wgOut->isSyndicated() ) {
612 foreach( $wgFeedClasses as $format => $class ) {
613 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
614 $s .= " | <a href=\"$feedurl\">{$format}</a>";
615 }
616 }
617 return $s;
618 }
619
620 function pageTitle() {
621 global $wgOut, $wgTitle, $wgUser;
622
623 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
624 if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);}
625 return $s;
626 }
627
628 function pageSubtitle() {
629 global $wgOut;
630
631 $sub = $wgOut->getSubtitle();
632 if ( '' == $sub ) {
633 global $wgExtraSubtitle;
634 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
635 }
636 $subpages = $this->subPageSubtitle();
637 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
638 $s = "<p class='subtitle'>{$sub}</p>\n";
639 return $s;
640 }
641
642 function subPageSubtitle() {
643 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
644 $subpages = '';
645 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
646 $ptext=$wgTitle->getPrefixedText();
647 if(preg_match('/\//',$ptext)) {
648 $links = explode('/',$ptext);
649 $c = 0;
650 $growinglink = '';
651 foreach($links as $link) {
652 $c++;
653 if ($c<count($links)) {
654 $growinglink .= $link;
655 $getlink = $this->makeLink( $growinglink, $link );
656 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
657 if ($c>1) {
658 $subpages .= ' | ';
659 } else {
660 $subpages .= '&lt; ';
661 }
662 $subpages .= $getlink;
663 $growinglink .= '/';
664 }
665 }
666 }
667 }
668 return $subpages;
669 }
670
671 function nameAndLogin() {
672 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
673
674 $li = $wgContLang->specialPage( 'Userlogin' );
675 $lo = $wgContLang->specialPage( 'Userlogout' );
676
677 $s = '';
678 if ( 0 == $wgUser->getID() ) {
679 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
680 $n = $wgIP;
681
682 $tl = $this->makeKnownLink( $wgContLang->getNsText(
683 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
684 $wgContLang->getNsText( Namespace::getTalk( 0 ) ) );
685
686 $s .= $n . ' ('.$tl.')';
687 } else {
688 $s .= wfMsg('notloggedin');
689 }
690
691 $rt = $wgTitle->getPrefixedURL();
692 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
693 $q = '';
694 } else { $q = "returnto={$rt}"; }
695
696 $s .= "\n<br />" . $this->makeKnownLink( $li,
697 wfMsg( 'login' ), $q );
698 } else {
699 $n = $wgUser->getName();
700 $rt = $wgTitle->getPrefixedURL();
701 $tl = $this->makeKnownLink( $wgContLang->getNsText(
702 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
703 $wgContLang->getNsText( Namespace::getTalk( 0 ) ) );
704
705 $tl = " ({$tl})";
706
707 $s .= $this->makeKnownLink( $wgContLang->getNsText(
708 Namespace::getUser() ) . ":{$n}", $n ) . "{$tl}<br />" .
709 $this->makeKnownLink( $lo, wfMsg( 'logout' ),
710 "returnto={$rt}" ) . ' | ' .
711 $this->specialLink( 'preferences' );
712 }
713 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
714 wfMsg( 'help' ) );
715
716 return $s;
717 }
718
719 function getSearchLink() {
720 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
721 return $searchPage->getLocalURL();
722 }
723
724 function escapeSearchLink() {
725 return htmlspecialchars( $this->getSearchLink() );
726 }
727
728 function searchForm() {
729 global $wgRequest;
730 $search = $wgRequest->getText( 'search' );
731
732 $s = '<form name="search" class="inline" method="post" action="'
733 . $this->escapeSearchLink() . "\">\n"
734 . '<input type="text" name="search" size="19" value="'
735 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
736 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
737 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
738
739 return $s;
740 }
741
742 function topLinks() {
743 global $wgOut;
744 $sep = " |\n";
745
746 $s = $this->mainPageLink() . $sep
747 . $this->specialLink( 'recentchanges' );
748
749 if ( $wgOut->isArticleRelated() ) {
750 $s .= $sep . $this->editThisPage()
751 . $sep . $this->historyLink();
752 }
753 # Many people don't like this dropdown box
754 #$s .= $sep . $this->specialPagesList();
755
756 return $s;
757 }
758
759 function bottomLinks() {
760 global $wgOut, $wgUser, $wgTitle;
761 $sep = " |\n";
762
763 $s = '';
764 if ( $wgOut->isArticleRelated() ) {
765 $s .= '<strong>' . $this->editThisPage() . '</strong>';
766 if ( 0 != $wgUser->getID() ) {
767 $s .= $sep . $this->watchThisPage();
768 }
769 $s .= $sep . $this->talkLink()
770 . $sep . $this->historyLink()
771 . $sep . $this->whatLinksHere()
772 . $sep . $this->watchPageLinksLink();
773
774 if ( $wgTitle->getNamespace() == Namespace::getUser()
775 || $wgTitle->getNamespace() == Namespace::getTalk(Namespace::getUser()) )
776
777 {
778 $id=User::idFromName($wgTitle->getText());
779 $ip=User::isIP($wgTitle->getText());
780
781 if($id || $ip) { # both anons and non-anons have contri list
782 $s .= $sep . $this->userContribsLink();
783 }
784 if( $this->showEmailUser( $id ) ) {
785 $s .= $sep . $this->emailUserLink();
786 }
787 }
788 if ( $wgTitle->getArticleId() ) {
789 $s .= "\n<br />";
790 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
791 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
792 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
793 }
794 $s .= "<br />\n" . $this->otherLanguages();
795 }
796 return $s;
797 }
798
799 function pageStats() {
800 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
801 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
802
803 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
804 if ( ! $wgOut->isArticle() ) { return ''; }
805 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
806 if ( 0 == $wgArticle->getID() ) { return ''; }
807
808 $s = '';
809 if ( !$wgDisableCounters ) {
810 $count = $wgLang->formatNum( $wgArticle->getCount() );
811 if ( $count ) {
812 $s = wfMsg( 'viewcount', $count );
813 }
814 }
815
816 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
817 require_once("Credits.php");
818 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
819 } else {
820 $s .= $this->lastModified();
821 }
822
823 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
824 $dbr =& wfGetDB( DB_SLAVE );
825 extract( $dbr->tableNames( 'watchlist' ) );
826 $sql = "SELECT COUNT(*) AS n FROM $watchlist
827 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
828 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
829 $res = $dbr->query( $sql, 'Skin::pageStats');
830 $x = $dbr->fetchObject( $res );
831 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
832 }
833
834 return $s . ' ' . $this->getCopyright();
835 }
836
837 function getCopyright() {
838 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
839
840
841 $oldid = $wgRequest->getVal( 'oldid' );
842 $diff = $wgRequest->getVal( 'diff' );
843
844 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
845 $msg = 'history_copyright';
846 } else {
847 $msg = 'copyright';
848 }
849
850 $out = '';
851 if( $wgRightsPage ) {
852 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
853 } elseif( $wgRightsUrl ) {
854 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
855 } else {
856 # Give up now
857 return $out;
858 }
859 $out .= wfMsgForContent( $msg, $link );
860 return $out;
861 }
862
863 function getCopyrightIcon() {
864 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon;
865 $out = '';
866 if( $wgRightsIcon ) {
867 $icon = htmlspecialchars( $wgRightsIcon );
868 if( $wgRightsUrl ) {
869 $url = htmlspecialchars( $wgRightsUrl );
870 $out .= '<a href="'.$url.'">';
871 }
872 $text = htmlspecialchars( $wgRightsText );
873 $out .= "<img src=\"$icon\" alt='$text' />";
874 if( $wgRightsUrl ) {
875 $out .= '</a>';
876 }
877 }
878 return $out;
879 }
880
881 function getPoweredBy() {
882 global $wgStylePath;
883 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
884 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
885 return $img;
886 }
887
888 function lastModified() {
889 global $wgLang, $wgArticle;
890
891 $timestamp = $wgArticle->getTimestamp();
892 if ( $timestamp ) {
893 $d = $wgLang->timeanddate( $wgArticle->getTimestamp(), true );
894 $s = ' ' . wfMsg( 'lastmodified', $d );
895 } else {
896 $s = '';
897 }
898 return $s;
899 }
900
901 function logoText( $align = '' ) {
902 if ( '' != $align ) { $a = " align='{$align}'"; }
903 else { $a = ''; }
904
905 $mp = wfMsg( 'mainpage' );
906 $titleObj = Title::newFromText( $mp );
907 if ( is_object( $titleObj ) ) {
908 $url = $titleObj->escapeLocalURL();
909 } else {
910 $url = '';
911 }
912
913 $logourl = $this->getLogo();
914 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
915 return $s;
916 }
917
918 /**
919 * show a drop-down box of special pages
920 * @TODO crash bug913. Need to be rewrote completly.
921 */
922 function specialPagesList() {
923 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript;
924 require_once('SpecialPage.php');
925 $a = array();
926 $pages = SpecialPage::getPages();
927
928 foreach ( $pages[''] as $name => $page ) {
929 $a[$name] = $page->getDescription();
930 }
931 if ( $wgUser->isSysop() )
932 {
933 foreach ( $pages['sysop'] as $name => $page ) {
934 $a[$name] = $page->getDescription();
935 }
936 }
937 if ( $wgUser->isDeveloper() )
938 {
939 foreach ( $pages['developer'] as $name => $page ) {
940 $a[$name] = $page->getDescription() ;
941 }
942 }
943 $go = wfMsg( 'go' );
944 $sp = wfMsg( 'specialpages' );
945 $spp = $wgContLang->specialPage( 'Specialpages' );
946
947 $s = '<form id="specialpages" method="get" class="inline" ' .
948 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
949 $s .= "<select name=\"wpDropdown\">\n";
950 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
951
952 foreach ( $a as $name => $desc ) {
953 $p = $wgContLang->specialPage( $name );
954 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
955 }
956 $s .= "</select>\n";
957 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
958 $s .= "</form>\n";
959 return $s;
960 }
961
962 function mainPageLink() {
963 $mp = wfMsgForContent( 'mainpage' );
964 $mptxt = wfMsg( 'mainpage');
965 $s = $this->makeKnownLink( $mp, $mptxt );
966 return $s;
967 }
968
969 function copyrightLink() {
970 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
971 wfMsg( 'copyrightpagename' ) );
972 return $s;
973 }
974
975 function aboutLink() {
976 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
977 wfMsg( 'aboutsite' ) );
978 return $s;
979 }
980
981
982 function disclaimerLink() {
983 $disclaimers = wfMsg( 'disclaimers' );
984 if ($disclaimers == '-') {
985 return "";
986 } else {
987 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
988 $disclaimers );
989 }
990 }
991
992 function editThisPage() {
993 global $wgOut, $wgTitle, $wgRequest;
994
995 $oldid = $wgRequest->getVal( 'oldid' );
996 $diff = $wgRequest->getVal( 'diff' );
997 $redirect = $wgRequest->getVal( 'redirect' );
998
999 if ( ! $wgOut->isArticleRelated() ) {
1000 $s = wfMsg( 'protectedpage' );
1001 } else {
1002 $n = $wgTitle->getPrefixedText();
1003 if ( $wgTitle->userCanEdit() ) {
1004 $t = wfMsg( 'editthispage' );
1005 } else {
1006 #$t = wfMsg( "protectedpage" );
1007 $t = wfMsg( 'viewsource' );
1008 }
1009 $oid = $red = '';
1010
1011 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
1012 if ( $oldid && ! isset( $diff ) ) {
1013 $oid = '&oldid='.$oldid;
1014 }
1015 $s = $this->makeKnownLink( $n, $t, "action=edit{$oid}{$red}" );
1016 }
1017 return $s;
1018 }
1019
1020 function deleteThisPage() {
1021 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1022
1023 $diff = $wgRequest->getVal( 'diff' );
1024 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1025 $n = $wgTitle->getPrefixedText();
1026 $t = wfMsg( 'deletethispage' );
1027
1028 $s = $this->makeKnownLink( $n, $t, 'action=delete' );
1029 } else {
1030 $s = '';
1031 }
1032 return $s;
1033 }
1034
1035 function protectThisPage() {
1036 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1037
1038 $diff = $wgRequest->getVal( 'diff' );
1039 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1040 $n = $wgTitle->getPrefixedText();
1041
1042 if ( $wgTitle->isProtected() ) {
1043 $t = wfMsg( 'unprotectthispage' );
1044 $q = 'action=unprotect';
1045 } else {
1046 $t = wfMsg( 'protectthispage' );
1047 $q = 'action=protect';
1048 }
1049 $s = $this->makeKnownLink( $n, $t, $q );
1050 } else {
1051 $s = '';
1052 }
1053 return $s;
1054 }
1055
1056 function watchThisPage() {
1057 global $wgUser, $wgOut, $wgTitle;
1058
1059 if ( $wgOut->isArticleRelated() ) {
1060 $n = $wgTitle->getPrefixedText();
1061
1062 if ( $wgTitle->userIsWatching() ) {
1063 $t = wfMsg( 'unwatchthispage' );
1064 $q = 'action=unwatch';
1065 } else {
1066 $t = wfMsg( 'watchthispage' );
1067 $q = 'action=watch';
1068 }
1069 $s = $this->makeKnownLink( $n, $t, $q );
1070 } else {
1071 $s = wfMsg( 'notanarticle' );
1072 }
1073 return $s;
1074 }
1075
1076 function moveThisPage() {
1077 global $wgTitle, $wgContLang;
1078
1079 if ( $wgTitle->userCanMove() ) {
1080 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Movepage' ),
1081 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1082 } // no message if page is protected - would be redundant
1083 return $s;
1084 }
1085
1086 function historyLink() {
1087 global $wgTitle;
1088
1089 $s = $this->makeKnownLink( $wgTitle->getPrefixedText(),
1090 wfMsg( 'history' ), 'action=history' );
1091 return $s;
1092 }
1093
1094 function whatLinksHere() {
1095 global $wgTitle, $wgContLang;
1096
1097 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Whatlinkshere' ),
1098 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1099 return $s;
1100 }
1101
1102 function userContribsLink() {
1103 global $wgTitle, $wgContLang;
1104
1105 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
1106 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1107 return $s;
1108 }
1109
1110 function showEmailUser( $id ) {
1111 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1112 return $wgEnableEmail &&
1113 $wgEnableUserEmail &&
1114 0 != $wgUser->getID() && # show only to signed in users
1115 0 != $id; # we can only email to non-anons ..
1116 # '' != $id->getEmail() && # who must have an email address stored ..
1117 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1118 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1119 }
1120
1121 function emailUserLink() {
1122 global $wgTitle, $wgContLang;
1123
1124 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Emailuser' ),
1125 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1126 return $s;
1127 }
1128
1129 function watchPageLinksLink() {
1130 global $wgOut, $wgTitle, $wgContLang;
1131
1132 if ( ! $wgOut->isArticleRelated() ) {
1133 $s = '(' . wfMsg( 'notanarticle' ) . ')';
1134 } else {
1135 $s = $this->makeKnownLink( $wgContLang->specialPage(
1136 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1137 'target=' . $wgTitle->getPrefixedURL() );
1138 }
1139 return $s;
1140 }
1141
1142 function otherLanguages() {
1143 global $wgOut, $wgContLang, $wgTitle, $wgUseNewInterlanguage;
1144
1145 $a = $wgOut->getLanguageLinks();
1146 if ( 0 == count( $a ) ) {
1147 if ( !$wgUseNewInterlanguage ) return '';
1148 $ns = $wgContLang->getNsIndex ( $wgTitle->getNamespace () ) ;
1149 if ( $ns != 0 AND $ns != 1 ) return '' ;
1150 $pn = 'Intl' ;
1151 $x = 'mode=addlink&xt='.$wgTitle->getDBkey() ;
1152 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1153 wfMsg( 'intl' ) , $x );
1154 }
1155
1156 if ( !$wgUseNewInterlanguage ) {
1157 $s = wfMsg( 'otherlanguages' ) . ': ';
1158 } else {
1159 global $wgContLanguageCode ;
1160 $x = 'mode=zoom&xt='.$wgTitle->getDBkey() ;
1161 $x .= '&xl='.$wgContLanguageCode ;
1162 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Intl' ),
1163 wfMsg( 'otherlanguages' ) , $x ) . ': ' ;
1164 }
1165
1166 $s = wfMsg( 'otherlanguages' ) . ': ';
1167 $first = true;
1168 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1169 foreach( $a as $l ) {
1170 if ( ! $first ) { $s .= ' | '; }
1171 $first = false;
1172
1173 $nt = Title::newFromText( $l );
1174 $url = $nt->getFullURL();
1175 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1176
1177 if ( '' == $text ) { $text = $l; }
1178 $style = $this->getExternalLinkAttributes( $l, $text );
1179 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1180 }
1181 if($wgContLang->isRTL()) $s .= '</span>';
1182 return $s;
1183 }
1184
1185 function bugReportsLink() {
1186 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1187 wfMsg( 'bugreports' ) );
1188 return $s;
1189 }
1190
1191 function dateLink() {
1192 global $wgLinkCache;
1193 $t1 = Title::newFromText( gmdate( 'F j' ) );
1194 $t2 = Title::newFromText( gmdate( 'Y' ) );
1195
1196 $wgLinkCache->suspend();
1197 $id = $t1->getArticleID();
1198 $wgLinkCache->resume();
1199
1200 if ( 0 == $id ) {
1201 $s = $this->makeBrokenLink( $t1->getText() );
1202 } else {
1203 $s = $this->makeKnownLink( $t1->getText() );
1204 }
1205 $s .= ', ';
1206
1207 $wgLinkCache->suspend();
1208 $id = $t2->getArticleID();
1209 $wgLinkCache->resume();
1210
1211 if ( 0 == $id ) {
1212 $s .= $this->makeBrokenLink( $t2->getText() );
1213 } else {
1214 $s .= $this->makeKnownLink( $t2->getText() );
1215 }
1216 return $s;
1217 }
1218
1219 function talkLink() {
1220 global $wgContLang, $wgTitle, $wgLinkCache;
1221
1222 $tns = $wgTitle->getNamespace();
1223 if ( -1 == $tns ) { return ''; }
1224
1225 $pn = $wgTitle->getText();
1226 $tp = wfMsg( 'talkpage' );
1227 if ( Namespace::isTalk( $tns ) ) {
1228 $lns = Namespace::getSubject( $tns );
1229 switch($tns) {
1230 case 1:
1231 $text = wfMsg('articlepage');
1232 break;
1233 case 3:
1234 $text = wfMsg('userpage');
1235 break;
1236 case 5:
1237 $text = wfMsg('wikipediapage');
1238 break;
1239 case 7:
1240 $text = wfMsg('imagepage');
1241 break;
1242 default:
1243 $text= wfMsg('articlepage');
1244 }
1245 } else {
1246
1247 $lns = Namespace::getTalk( $tns );
1248 $text=$tp;
1249 }
1250 $n = $wgContLang->getNsText( $lns );
1251 if ( '' == $n ) { $link = $pn; }
1252 else { $link = $n.':'.$pn; }
1253
1254 $wgLinkCache->suspend();
1255 $s = $this->makeLink( $link, $text );
1256 $wgLinkCache->resume();
1257
1258 return $s;
1259 }
1260
1261 function commentLink() {
1262 global $wgContLang, $wgTitle, $wgLinkCache;
1263
1264 $tns = $wgTitle->getNamespace();
1265 if ( -1 == $tns ) { return ''; }
1266
1267 $lns = ( Namespace::isTalk( $tns ) ) ? $tns : Namespace::getTalk( $tns );
1268
1269 # assert Namespace::isTalk( $lns )
1270
1271 $n = $wgContLang->getNsText( $lns );
1272 $pn = $wgTitle->getText();
1273
1274 $link = $n.':'.$pn;
1275
1276 $wgLinkCache->suspend();
1277 $s = $this->makeKnownLink($link, wfMsg('postcomment'), 'action=edit&section=new');
1278 $wgLinkCache->resume();
1279
1280 return $s;
1281 }
1282
1283 /**
1284 * After all the page content is transformed into HTML, it makes
1285 * a final pass through here for things like table backgrounds.
1286 * @todo probably deprecated [AV]
1287 */
1288 function transformContent( $text ) {
1289 return $text;
1290 }
1291
1292 /**
1293 * Note: This function MUST call getArticleID() on the link,
1294 * otherwise the cache won't get updated properly. See LINKCACHE.DOC.
1295 */
1296 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
1297 wfProfileIn( 'Skin::makeLink' );
1298 $nt = Title::newFromText( $title );
1299 if ($nt) {
1300 $result = $this->makeLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1301 } else {
1302 wfDebug( 'Invalid title passed to Skin::makeLink(): "'.$title."\"\n" );
1303 $result = $text == "" ? $title : $text;
1304 }
1305
1306 wfProfileOut( 'Skin::makeLink' );
1307 return $result;
1308 }
1309
1310 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
1311 $nt = Title::newFromText( $title );
1312 if ($nt) {
1313 return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
1314 } else {
1315 wfDebug( 'Invalid title passed to Skin::makeKnownLink(): "'.$title."\"\n" );
1316 return $text == '' ? $title : $text;
1317 }
1318 }
1319
1320 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1321 $nt = Title::newFromText( $title );
1322 if ($nt) {
1323 return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1324 } else {
1325 wfDebug( 'Invalid title passed to Skin::makeBrokenLink(): "'.$title."\"\n" );
1326 return $text == '' ? $title : $text;
1327 }
1328 }
1329
1330 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
1331 $nt = Title::newFromText( $title );
1332 if ($nt) {
1333 return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1334 } else {
1335 wfDebug( 'Invalid title passed to Skin::makeStubLink(): "'.$title."\"\n" );
1336 return $text == '' ? $title : $text;
1337 }
1338 }
1339
1340 /**
1341 * Pass a title object, not a title string
1342 */
1343 function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
1344 global $wgOut, $wgUser, $wgLinkHolders;
1345 $fname = 'Skin::makeLinkObj';
1346 wfProfileIn( $fname );
1347
1348 # Fail gracefully
1349 if ( ! isset($nt) ) {
1350 # wfDebugDieBacktrace();
1351 wfProfileOut( $fname );
1352 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1353 }
1354
1355 $ns = $nt->getNamespace();
1356 $dbkey = $nt->getDBkey();
1357 if ( $nt->isExternal() ) {
1358 $u = $nt->getFullURL();
1359 $link = $nt->getPrefixedURL();
1360 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
1361 $style = $this->getExternalLinkAttributes( $link, $text, 'extiw' );
1362
1363 $inside = '';
1364 if ( '' != $trail ) {
1365 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
1366 $inside = $m[1];
1367 $trail = $m[2];
1368 }
1369 }
1370 # Assume $this->postParseLinkColour(). This prevents
1371 # interwiki links from being parsed as external links.
1372 global $wgInterwikiLinkHolders;
1373 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
1374 $nr = array_push($wgInterwikiLinkHolders, $t);
1375 $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
1376 } elseif ( 0 == $ns && "" == $dbkey ) {
1377 # A self-link with a fragment; skip existence check.
1378 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1379 } elseif ( ( NS_SPECIAL == $ns ) || ( NS_IMAGE == $ns ) ) {
1380 # These are always shown as existing, currently.
1381 # Special pages don't exist in the database; images may
1382 # occasionally be present when there is no description
1383 # page per se, so we always shown them.
1384 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1385 } elseif ( $this->postParseLinkColour ) {
1386 wfProfileIn( $fname.'-postparse' );
1387 # Insert a placeholder, and we'll work out the existence checks
1388 # in a big lump later.
1389 $inside = '';
1390 if ( '' != $trail ) {
1391 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1392 $inside = $m[1];
1393 $trail = $m[2];
1394 }
1395 }
1396
1397 # These get picked up by Parser::replaceLinkHolders()
1398 $nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() );
1399 $wgLinkHolders['dbkeys'][] = $dbkey;
1400 $wgLinkHolders['queries'][] = $query;
1401 $wgLinkHolders['texts'][] = $prefix.$text.$inside;
1402 $wgLinkHolders['titles'][] =& $nt;
1403
1404 $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
1405 wfProfileOut( $fname.'-postparse' );
1406 } else {
1407 wfProfileIn( $fname.'-immediate' );
1408 # Work out link colour immediately
1409 $aid = $nt->getArticleID() ;
1410 if ( 0 == $aid ) {
1411 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
1412 } else {
1413 $threshold = $wgUser->getOption('stubthreshold') ;
1414 if ( $threshold > 0 ) {
1415 $dbr =& wfGetDB( DB_SLAVE );
1416 $s = $dbr->selectRow( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace',
1417 'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ;
1418 if ( $s !== false ) {
1419 $size = $s->x;
1420 if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) {
1421 $size = $threshold*2 ; # Really big
1422 }
1423 } else {
1424 $size = $threshold*2 ; # Really big
1425 }
1426 } else {
1427 $size = 1 ;
1428 }
1429 if ( $size < $threshold ) {
1430 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
1431 } else {
1432 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1433 }
1434 }
1435 wfProfileOut( $fname.'-immediate' );
1436 }
1437 wfProfileOut( $fname );
1438 return $retVal;
1439 }
1440
1441 /**
1442 * Pass a title object, not a title string
1443 */
1444 function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
1445 global $wgOut, $wgTitle, $wgInputEncoding;
1446
1447 $fname = 'Skin::makeKnownLinkObj';
1448 wfProfileIn( $fname );
1449
1450 if ( !is_object( $nt ) ) {
1451 wfProfileIn( $fname );
1452 return $text;
1453 }
1454
1455 $u = $nt->escapeLocalURL( $query );
1456 if ( '' != $nt->getFragment() ) {
1457 if( $nt->getPrefixedDbkey() == '' ) {
1458 $u = '';
1459 if ( '' == $text ) {
1460 $text = htmlspecialchars( $nt->getFragment() );
1461 }
1462 }
1463 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT, $wgInputEncoding ) );
1464 $replacearray = array(
1465 '%3A' => ':',
1466 '%' => '.'
1467 );
1468 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
1469 }
1470 if ( '' == $text ) {
1471 $text = htmlspecialchars( $nt->getPrefixedText() );
1472 }
1473 $style = $this->getInternalLinkAttributesObj( $nt, $text );
1474
1475 $inside = '';
1476 if ( '' != $trail ) {
1477 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1478 $inside = $m[1];
1479 $trail = $m[2];
1480 }
1481 }
1482 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
1483 wfProfileOut( $fname );
1484 return $r;
1485 }
1486
1487 /**
1488 * Pass a title object, not a title string
1489 */
1490 function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1491 # Fail gracefully
1492 if ( ! isset($nt) ) {
1493 # wfDebugDieBacktrace();
1494 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1495 }
1496
1497 $fname = 'Skin::makeBrokenLinkObj';
1498 wfProfileIn( $fname );
1499
1500 if ( '' == $query ) {
1501 $q = 'action=edit';
1502 } else {
1503 $q = 'action=edit&'.$query;
1504 }
1505 $u = $nt->escapeLocalURL( $q );
1506
1507 if ( '' == $text ) {
1508 $text = htmlspecialchars( $nt->getPrefixedText() );
1509 }
1510 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
1511
1512 $inside = '';
1513 if ( '' != $trail ) {
1514 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1515 $inside = $m[1];
1516 $trail = $m[2];
1517 }
1518 }
1519 if ( $this->mOptions['highlightbroken'] ) {
1520 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1521 } else {
1522 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
1523 }
1524
1525 wfProfileOut( $fname );
1526 return $s;
1527 }
1528
1529 /**
1530 * Pass a title object, not a title string
1531 */
1532 function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1533 $link = $nt->getPrefixedURL();
1534
1535 $u = $nt->escapeLocalURL( $query );
1536
1537 if ( '' == $text ) {
1538 $text = htmlspecialchars( $nt->getPrefixedText() );
1539 }
1540 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
1541
1542 $inside = '';
1543 if ( '' != $trail ) {
1544 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1545 $inside = $m[1];
1546 $trail = $m[2];
1547 }
1548 }
1549 if ( $this->mOptions['highlightbroken'] ) {
1550 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1551 } else {
1552 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
1553 }
1554 return $s;
1555 }
1556
1557 function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1558 $u = $nt->escapeLocalURL( $query );
1559 if ( '' == $text ) {
1560 $text = htmlspecialchars( $nt->getPrefixedText() );
1561 }
1562 $inside = '';
1563 if ( '' != $trail ) {
1564 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1565 $inside = $m[1];
1566 $trail = $m[2];
1567 }
1568 }
1569 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
1570 }
1571
1572 /* these are used extensively in SkinPHPTal, but also some other places */
1573 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1574 $title = Title::makeTitle( NS_SPECIAL, $name );
1575 $this->checkTitle($title, $name);
1576 return $title->getLocalURL( $urlaction );
1577 }
1578 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
1579 $title = Title::newFromText( $name );
1580 $title = $title->getTalkPage();
1581 $this->checkTitle($title, $name);
1582 return $title->getLocalURL( $urlaction );
1583 }
1584 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
1585 $title = Title::newFromText( $name );
1586 $title= $title->getSubjectPage();
1587 $this->checkTitle($title, $name);
1588 return $title->getLocalURL( $urlaction );
1589 }
1590 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1591 $title = Title::newFromText( wfMsgForContent($name) );
1592 $this->checkTitle($title, $name);
1593 return $title->getLocalURL( $urlaction );
1594 }
1595 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1596 $title = Title::newFromText( $name );
1597 $this->checkTitle($title, $name);
1598 return $title->getLocalURL( $urlaction );
1599 }
1600
1601 # If url string starts with http, consider as external URL, else
1602 # internal
1603 /*static*/ function makeInternalOrExternalUrl( $name ) {
1604 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1605 return $name;
1606 } else {
1607 return $this->makeUrl( $name );
1608 }
1609 }
1610
1611 # this can be passed the NS number as defined in Language.php
1612 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=0 ) {
1613 $title = Title::makeTitleSafe( $namespace, $name );
1614 $this->checkTitle($title, $name);
1615 return $title->getLocalURL( $urlaction );
1616 }
1617
1618 /* these return an array with the 'href' and boolean 'exists' */
1619 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1620 $title = Title::newFromText( $name );
1621 $this->checkTitle($title, $name);
1622 return array(
1623 'href' => $title->getLocalURL( $urlaction ),
1624 'exists' => $title->getArticleID() != 0?true:false
1625 );
1626 }
1627 /*static*/ function makeTalkUrlDetails ( $name, $urlaction='' ) {
1628 $title = Title::newFromText( $name );
1629 $title = $title->getTalkPage();
1630 $this->checkTitle($title, $name);
1631 return array(
1632 'href' => $title->getLocalURL( $urlaction ),
1633 'exists' => $title->getArticleID() != 0?true:false
1634 );
1635 }
1636 /*static*/ function makeArticleUrlDetails ( $name, $urlaction='' ) {
1637 $title = Title::newFromText( $name );
1638 $title= $title->getSubjectPage();
1639 $this->checkTitle($title, $name);
1640 return array(
1641 'href' => $title->getLocalURL( $urlaction ),
1642 'exists' => $title->getArticleID() != 0?true:false
1643 );
1644 }
1645 /*static*/ function makeI18nUrlDetails ( $name, $urlaction='' ) {
1646 $title = Title::newFromText( wfMsgForContent($name) );
1647 $this->checkTitle($title, $name);
1648 return array(
1649 'href' => $title->getLocalURL( $urlaction ),
1650 'exists' => $title->getArticleID() != 0?true:false
1651 );
1652 }
1653
1654 # make sure we have some title to operate on
1655 /*static*/ function checkTitle ( &$title, &$name ) {
1656 if(!is_object($title)) {
1657 $title = Title::newFromText( $name );
1658 if(!is_object($title)) {
1659 $title = Title::newFromText( '--error: link target missing--' );
1660 }
1661 }
1662 }
1663
1664 function fnamePart( $url ) {
1665 $basename = strrchr( $url, '/' );
1666 if ( false === $basename ) {
1667 $basename = $url;
1668 } else {
1669 $basename = substr( $basename, 1 );
1670 }
1671 return htmlspecialchars( $basename );
1672 }
1673
1674 function makeImage( $url, $alt = '' ) {
1675 global $wgOut;
1676 if ( '' == $alt ) {
1677 $alt = $this->fnamePart( $url );
1678 }
1679 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
1680 return $s;
1681 }
1682
1683 function makeImageLink( $name, $url, $alt = '' ) {
1684 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1685 return $this->makeImageLinkObj( $nt, $alt );
1686 }
1687
1688 function makeImageLinkObj( $nt, $alt = '' ) {
1689 global $wgContLang, $wgUseImageResize;
1690 $img = Image::newFromTitle( $nt );
1691 $url = $img->getViewURL();
1692
1693 $align = '';
1694 $prefix = $postfix = '';
1695
1696 # Check if the alt text is of the form "options|alt text"
1697 # Options are:
1698 # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
1699 # * left no resizing, just left align. label is used for alt= only
1700 # * right same, but right aligned
1701 # * none same, but not aligned
1702 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
1703 # * center center the image
1704 # * framed Keep original image size, no magnify-button.
1705
1706 $part = explode( '|', $alt);
1707
1708 $mwThumb =& MagicWord::get( MAG_IMG_THUMBNAIL );
1709 $mwLeft =& MagicWord::get( MAG_IMG_LEFT );
1710 $mwRight =& MagicWord::get( MAG_IMG_RIGHT );
1711 $mwNone =& MagicWord::get( MAG_IMG_NONE );
1712 $mwWidth =& MagicWord::get( MAG_IMG_WIDTH );
1713 $mwCenter =& MagicWord::get( MAG_IMG_CENTER );
1714 $mwFramed =& MagicWord::get( MAG_IMG_FRAMED );
1715 $alt = '';
1716
1717 $height = $framed = $thumb = false;
1718 $manual_thumb = "" ;
1719
1720 foreach( $part as $key => $val ) {
1721 $val_parts = explode ( "=" , $val , 2 ) ;
1722 $left_part = array_shift ( $val_parts ) ;
1723 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
1724 $thumb=true;
1725 } elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
1726 # use manually specified thumbnail
1727 $thumb=true;
1728 $manual_thumb = array_shift ( $val_parts ) ;
1729 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
1730 # remember to set an alignment, don't render immediately
1731 $align = 'right';
1732 } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
1733 # remember to set an alignment, don't render immediately
1734 $align = 'left';
1735 } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
1736 # remember to set an alignment, don't render immediately
1737 $align = 'center';
1738 } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
1739 # remember to set an alignment, don't render immediately
1740 $align = 'none';
1741 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
1742 # $match is the image width in pixels
1743 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
1744 $width = intval( $m[1] );
1745 $height = intval( $m[2] );
1746 } else {
1747 $width = intval($match);
1748 }
1749 } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
1750 $framed=true;
1751 } else {
1752 $alt = $val;
1753 }
1754 }
1755 if ( 'center' == $align )
1756 {
1757 $prefix = '<div class="center">';
1758 $postfix = '</div>';
1759 $align = 'none';
1760 }
1761
1762 if ( $thumb || $framed ) {
1763
1764 # Create a thumbnail. Alignment depends on language
1765 # writing direction, # right aligned for left-to-right-
1766 # languages ("Western languages"), left-aligned
1767 # for right-to-left-languages ("Semitic languages")
1768 #
1769 # If thumbnail width has not been provided, it is set
1770 # here to 180 pixels
1771 if ( $align == '' ) {
1772 $align = $wgContLang->isRTL() ? 'left' : 'right';
1773 }
1774 if ( ! isset($width) ) {
1775 $width = 180;
1776 }
1777 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
1778
1779 } elseif ( isset($width) ) {
1780
1781 # Create a resized image, without the additional thumbnail
1782 # features
1783
1784 if ( ( ! $height === false )
1785 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
1786 $width = $img->getWidth() * $height / $img->getHeight();
1787 }
1788 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
1789 }
1790
1791 $alt = preg_replace( '/<[^>]*>/', '', $alt );
1792 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1793 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1794
1795 $u = $nt->escapeLocalURL();
1796 if ( $url == '' ) {
1797 $s = wfMsg( 'missingimage', $img->getName() );
1798 $s .= "<br>{$alt}<br>{$url}<br>\n";
1799 } else {
1800 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
1801 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
1802 }
1803 if ( '' != $align ) {
1804 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
1805 }
1806 return str_replace("\n", ' ',$prefix.$s.$postfix);
1807 }
1808
1809 /**
1810 * Make HTML for a thumbnail including image, border and caption
1811 * $img is an Image object
1812 */
1813 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
1814 global $wgStylePath, $wgContLang;
1815 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
1816 $url = $img->getViewURL();
1817
1818 #$label = htmlspecialchars( $label );
1819 $alt = preg_replace( '/<[^>]*>/', '', $label);
1820 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1821 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1822
1823 $width = $height = 0;
1824 if ( $img->exists() )
1825 {
1826 $width = $img->getWidth();
1827 $height = $img->getHeight();
1828 }
1829 if ( 0 == $width || 0 == $height )
1830 {
1831 $width = $height = 200;
1832 }
1833 if ( $boxwidth == 0 )
1834 {
1835 $boxwidth = 200;
1836 }
1837 if ( $framed )
1838 {
1839 // Use image dimensions, don't scale
1840 $boxwidth = $width;
1841 $oboxwidth = $boxwidth + 2;
1842 $boxheight = $height;
1843 $thumbUrl = $url;
1844 } else {
1845 $h = intval( $height/($width/$boxwidth) );
1846 $oboxwidth = $boxwidth + 2;
1847 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
1848 {
1849 $boxwidth *= $boxheight/$h;
1850 } else {
1851 $boxheight = $h;
1852 }
1853 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
1854 }
1855
1856 if ( $manual_thumb != '' ) # Use manually specified thumbnail
1857 {
1858 $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb ); #new Title ( $manual_thumb ) ;
1859 $manual_img = Image::newFromTitle( $manual_title );
1860 $thumbUrl = $manual_img->getViewURL();
1861 if ( $manual_img->exists() )
1862 {
1863 $width = $manual_img->getWidth();
1864 $height = $manual_img->getHeight();
1865 $boxwidth = $width ;
1866 $boxheight = $height ;
1867 $oboxwidth = $boxwidth + 2 ;
1868 }
1869 }
1870
1871 $u = $img->getEscapeLocalURL();
1872
1873 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
1874 $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
1875 $textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
1876
1877 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
1878 if ( $thumbUrl == '' ) {
1879 $s .= wfMsg( 'missingimage', $img->getName() );
1880 $zoomicon = '';
1881 } else {
1882 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
1883 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
1884 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
1885 'longdesc="'.$u.'" /></a>';
1886 if ( $framed ) {
1887 $zoomicon="";
1888 } else {
1889 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
1890 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
1891 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
1892 'width="15" height="11" alt="'.$more.'" /></a></div>';
1893 }
1894 }
1895 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
1896 return str_replace("\n", ' ', $s);
1897 }
1898
1899 function makeMediaLink( $name, $url, $alt = '' ) {
1900 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1901 return $this->makeMediaLinkObj( $nt, $alt );
1902 }
1903
1904 function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {
1905 if ( ! isset( $nt ) )
1906 {
1907 ### HOTFIX. Instead of breaking, return empty string.
1908 $s = $alt;
1909 } else {
1910 $name = $nt->getDBKey();
1911 $img = Image::newFromTitle( $nt );
1912 $url = $img->getURL();
1913 # $nourl can be set by the parser
1914 # this is a hack to mask absolute URLs, so the parser doesn't
1915 # linkify them (it is currently not context-aware)
1916 # 2004-10-25
1917 if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
1918 if ( empty( $alt ) ) {
1919 $alt = preg_replace( '/\.(.+?)^/', '', $name );
1920 }
1921 $u = htmlspecialchars( $url );
1922 $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
1923 }
1924 return $s;
1925 }
1926
1927 function specialLink( $name, $key = '' ) {
1928 global $wgContLang;
1929
1930 if ( '' == $key ) { $key = strtolower( $name ); }
1931 $pn = $wgContLang->ucfirst( $name );
1932 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1933 wfMsg( $key ) );
1934 }
1935
1936 function makeExternalLink( $url, $text, $escape = true ) {
1937 $style = $this->getExternalLinkAttributes( $url, $text );
1938 $url = htmlspecialchars( $url );
1939 if( $escape ) {
1940 $text = htmlspecialchars( $text );
1941 }
1942 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
1943 }
1944
1945 /**
1946 * This function is called by all recent changes variants, by the page history,
1947 * and by the user contributions list. It is responsible for formatting edit
1948 * comments. It escapes any HTML in the comment, but adds some CSS to format
1949 * auto-generated comments (from section editing) and formats [[wikilinks]].
1950 *
1951 * The &$title parameter must be a title OBJECT. It is used to generate a
1952 * direct link to the section in the autocomment.
1953 * @author Erik Moeller <moeller@scireview.de>
1954 *
1955 * Note: there's not always a title to pass to this function.
1956 * Since you can't set a default parameter for a reference, I've turned it
1957 * temporarily to a value pass. Should be adjusted further. --brion
1958 */
1959 function formatComment($comment, $title = NULL) {
1960 $fname = 'Skin::formatComment';
1961 wfProfileIn( $fname );
1962
1963 global $wgContLang;
1964 $comment = htmlspecialchars( $comment );
1965
1966 # The pattern for autogen comments is / * foo * /, which makes for
1967 # some nasty regex.
1968 # We look for all comments, match any text before and after the comment,
1969 # add a separator where needed and format the comment itself with CSS
1970 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
1971 $pre=$match[1];
1972 $auto=$match[2];
1973 $post=$match[3];
1974 $link='';
1975 if($title) {
1976 $section=$auto;
1977
1978 # This is hackish but should work in most cases.
1979 $section=str_replace('[[','',$section);
1980 $section=str_replace(']]','',$section);
1981 $title->mFragment=$section;
1982 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
1983 }
1984 $sep='-';
1985 $auto=$link.$auto;
1986 if($pre) { $auto = $sep.' '.$auto; }
1987 if($post) { $auto .= ' '.$sep; }
1988 $auto='<span class="autocomment">'.$auto.'</span>';
1989 $comment=$pre.$auto.$post;
1990 }
1991
1992 # format regular and media links - all other wiki formatting
1993 # is ignored
1994 $medians = $wgContLang->getNsText(Namespace::getMedia()).':';
1995 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
1996 # Handle link renaming [[foo|text]] will show link as "text"
1997 if( "" != $match[3] ) {
1998 $text = $match[3];
1999 } else {
2000 $text = $match[1];
2001 }
2002 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
2003 # Media link; trail not supported.
2004 $linkRegexp = '/\[\[(.*?)\]\]/';
2005 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
2006 } else {
2007 # Other kind of link
2008 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
2009 $trail = $submatch[1];
2010 } else {
2011 $trail = "";
2012 }
2013 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
2014 if ($match[1][0] == ':')
2015 $match[1] = substr($match[1], 1);
2016 $thelink = $this->makeLink( $match[1], $text, "", $trail );
2017 }
2018 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
2019 }
2020 wfProfileOut( $fname );
2021 return $comment;
2022 }
2023
2024 function tocIndent($level) {
2025 return str_repeat( '<div class="tocindent">'."\n", $level>0 ? $level : 0 );
2026 }
2027
2028 function tocUnindent($level) {
2029 return str_repeat( "</div>\n", $level>0 ? $level : 0 );
2030 }
2031
2032 /**
2033 * parameter level defines if we are on an indentation level
2034 */
2035 function tocLine( $anchor, $tocline, $level ) {
2036 $link = '<a href="#'.$anchor.'">'.$tocline.'</a><br />';
2037 if($level) {
2038 return $link."\n";
2039 } else {
2040 return '<div class="tocline">'.$link."</div>\n";
2041 }
2042
2043 }
2044
2045 function tocTable($toc) {
2046 # note to CSS fanatics: putting this in a div does not work -- div won't auto-expand
2047 # try min-width & co when somebody gets a chance
2048 $hideline = ' <script type="text/javascript">showTocToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '")</script>';
2049 return
2050 '<table border="0" id="toc"><tr id="toctitle"><td align="center">'."\n".
2051 '<b>'.wfMsgForContent('toc').'</b>' .
2052 $hideline .
2053 '</td></tr><tr id="tocinside"><td>'."\n".
2054 $toc."</td></tr></table>\n";
2055 }
2056
2057 /**
2058 * These two do not check for permissions: check $wgTitle->userCanEdit
2059 * before calling them
2060 */
2061 function editSectionScriptForOther( $title, $section, $head ) {
2062 $ttl = Title::newFromText( $title );
2063 $url = $ttl->escapeLocalURL( 'action=edit&section='.$section );
2064 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2065 }
2066
2067 function editSectionScript( $nt, $section, $head ) {
2068 global $wgRequest;
2069 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2070 return $head;
2071 }
2072 $url = $nt->escapeLocalURL( 'action=edit&section='.$section );
2073 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2074 }
2075
2076 function editSectionLinkForOther( $title, $section ) {
2077 global $wgRequest;
2078 global $wgContLang;
2079
2080 $title = Title::newFromText($title);
2081 $editurl = '&section='.$section;
2082 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2083
2084 if( $wgContLang->isRTL() ) {
2085 $farside = 'left';
2086 $nearside = 'right';
2087 } else {
2088 $farside = 'right';
2089 $nearside = 'left';
2090 }
2091 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2092
2093 }
2094
2095 function editSectionLink( $nt, $section ) {
2096 global $wgRequest;
2097 global $wgContLang;
2098
2099 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2100 # Section edit links would be out of sync on an old page.
2101 # But, if we're diffing to the current page, they'll be
2102 # correct.
2103 return '';
2104 }
2105
2106 $editurl = '&section='.$section;
2107 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2108
2109 if( $wgContLang->isRTL() ) {
2110 $farside = 'left';
2111 $nearside = 'right';
2112 } else {
2113 $farside = 'right';
2114 $nearside = 'left';
2115 }
2116 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2117
2118 }
2119
2120 /**
2121 * @access public
2122 */
2123 function suppressUrlExpansion() {
2124 return false;
2125 }
2126 }
2127
2128 }
2129 ?>