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