* (bug 1018) Some pages fail with stub threshold enabled
[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 $image = new Image( $wgTitle->getDBkey() );
538 if( $image->exists() ) {
539 $link = htmlspecialchars( $image->getURL() );
540 $style = $this->getInternalLinkAttributes( $link, $name );
541 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
542 }
543 }
544 # This will show the "Approve" link if $wgUseApproval=true;
545 if ( isset ( $wgUseApproval ) && $wgUseApproval )
546 {
547 $t = $wgTitle->getDBkey();
548 $name = 'Approve this article' ;
549 $link = "http://test.wikipedia.org/w/magnus/wiki.phtml?title={$t}&action=submit&doit=1" ;
550 #htmlspecialchars( wfImageUrl( $name ) );
551 $style = $this->getExternalLinkAttributes( $link, $name );
552 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>" ;
553 }
554 }
555 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
556 $s .= ' | ' . $this->makeKnownLink( $wgTitle->getPrefixedText(),
557 wfMsg( 'currentrev' ) );
558 }
559
560 if ( $wgUser->getNewtalk() ) {
561 # do not show "You have new messages" text when we are viewing our
562 # own talk page
563
564 if(!(strcmp($wgTitle->getText(),$wgUser->getName()) == 0 &&
565 $wgTitle->getNamespace()==Namespace::getTalk(Namespace::getUser()))) {
566 $n =$wgUser->getName();
567 $tl = $this->makeKnownLink( $wgContLang->getNsText(
568 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
569 wfMsg('newmessageslink') );
570 $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
571 # disable caching
572 $wgOut->setSquidMaxage(0);
573 $wgOut->enableClientCache(false);
574 }
575 }
576
577 $undelete = $this->getUndeleteLink();
578 if( !empty( $undelete ) ) {
579 $s .= ' | '.$undelete;
580 }
581 return $s;
582 }
583
584 function getUndeleteLink() {
585 global $wgUser, $wgTitle, $wgContLang, $action;
586 if( $wgUser->isAllowed('rollback') &&
587 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
588 ($n = $wgTitle->isDeleted() ) ) {
589 return wfMsg( 'thisisdeleted',
590 $this->makeKnownLink(
591 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
592 wfMsg( 'restorelink', $n ) ) );
593 }
594 return '';
595 }
596
597 function printableLink() {
598 global $wgOut, $wgFeedClasses, $wgRequest;
599
600 $baseurl = $_SERVER['REQUEST_URI'];
601 if( strpos( '?', $baseurl ) == false ) {
602 $baseurl .= '?';
603 } else {
604 $baseurl .= '&';
605 }
606 $baseurl = htmlspecialchars( $baseurl );
607 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
608
609 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
610 if( $wgOut->isSyndicated() ) {
611 foreach( $wgFeedClasses as $format => $class ) {
612 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
613 $s .= " | <a href=\"$feedurl\">{$format}</a>";
614 }
615 }
616 return $s;
617 }
618
619 function pageTitle() {
620 global $wgOut, $wgTitle, $wgUser;
621
622 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
623 if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);}
624 return $s;
625 }
626
627 function pageSubtitle() {
628 global $wgOut;
629
630 $sub = $wgOut->getSubtitle();
631 if ( '' == $sub ) {
632 global $wgExtraSubtitle;
633 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
634 }
635 $subpages = $this->subPageSubtitle();
636 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
637 $s = "<p class='subtitle'>{$sub}</p>\n";
638 return $s;
639 }
640
641 function subPageSubtitle() {
642 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
643 $subpages = '';
644 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
645 $ptext=$wgTitle->getPrefixedText();
646 if(preg_match('/\//',$ptext)) {
647 $links = explode('/',$ptext);
648 $c = 0;
649 $growinglink = '';
650 foreach($links as $link) {
651 $c++;
652 if ($c<count($links)) {
653 $growinglink .= $link;
654 $getlink = $this->makeLink( $growinglink, $link );
655 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
656 if ($c>1) {
657 $subpages .= ' | ';
658 } else {
659 $subpages .= '&lt; ';
660 }
661 $subpages .= $getlink;
662 $growinglink .= '/';
663 }
664 }
665 }
666 }
667 return $subpages;
668 }
669
670 function nameAndLogin() {
671 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
672
673 $li = $wgContLang->specialPage( 'Userlogin' );
674 $lo = $wgContLang->specialPage( 'Userlogout' );
675
676 $s = '';
677 if ( 0 == $wgUser->getID() ) {
678 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
679 $n = $wgIP;
680
681 $tl = $this->makeKnownLink( $wgContLang->getNsText(
682 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
683 $wgContLang->getNsText( Namespace::getTalk( 0 ) ) );
684
685 $s .= $n . ' ('.$tl.')';
686 } else {
687 $s .= wfMsg('notloggedin');
688 }
689
690 $rt = $wgTitle->getPrefixedURL();
691 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
692 $q = '';
693 } else { $q = "returnto={$rt}"; }
694
695 $s .= "\n<br />" . $this->makeKnownLink( $li,
696 wfMsg( 'login' ), $q );
697 } else {
698 $n = $wgUser->getName();
699 $rt = $wgTitle->getPrefixedURL();
700 $tl = $this->makeKnownLink( $wgContLang->getNsText(
701 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
702 $wgContLang->getNsText( Namespace::getTalk( 0 ) ) );
703
704 $tl = " ({$tl})";
705
706 $s .= $this->makeKnownLink( $wgContLang->getNsText(
707 Namespace::getUser() ) . ":{$n}", $n ) . "{$tl}<br />" .
708 $this->makeKnownLink( $lo, wfMsg( 'logout' ),
709 "returnto={$rt}" ) . ' | ' .
710 $this->specialLink( 'preferences' );
711 }
712 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
713 wfMsg( 'help' ) );
714
715 return $s;
716 }
717
718 function getSearchLink() {
719 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
720 return $searchPage->getLocalURL();
721 }
722
723 function escapeSearchLink() {
724 return htmlspecialchars( $this->getSearchLink() );
725 }
726
727 function searchForm() {
728 global $wgRequest;
729 $search = $wgRequest->getText( 'search' );
730
731 $s = '<form name="search" class="inline" method="post" action="'
732 . $this->escapeSearchLink() . "\">\n"
733 . '<input type="text" name="search" size="19" value="'
734 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
735 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
736 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
737
738 return $s;
739 }
740
741 function topLinks() {
742 global $wgOut;
743 $sep = " |\n";
744
745 $s = $this->mainPageLink() . $sep
746 . $this->specialLink( 'recentchanges' );
747
748 if ( $wgOut->isArticleRelated() ) {
749 $s .= $sep . $this->editThisPage()
750 . $sep . $this->historyLink();
751 }
752 # Many people don't like this dropdown box
753 #$s .= $sep . $this->specialPagesList();
754
755 return $s;
756 }
757
758 function bottomLinks() {
759 global $wgOut, $wgUser, $wgTitle;
760 $sep = " |\n";
761
762 $s = '';
763 if ( $wgOut->isArticleRelated() ) {
764 $s .= '<strong>' . $this->editThisPage() . '</strong>';
765 if ( 0 != $wgUser->getID() ) {
766 $s .= $sep . $this->watchThisPage();
767 }
768 $s .= $sep . $this->talkLink()
769 . $sep . $this->historyLink()
770 . $sep . $this->whatLinksHere()
771 . $sep . $this->watchPageLinksLink();
772
773 if ( $wgTitle->getNamespace() == Namespace::getUser()
774 || $wgTitle->getNamespace() == Namespace::getTalk(Namespace::getUser()) )
775
776 {
777 $id=User::idFromName($wgTitle->getText());
778 $ip=User::isIP($wgTitle->getText());
779
780 if($id || $ip) { # both anons and non-anons have contri list
781 $s .= $sep . $this->userContribsLink();
782 }
783 if( $this->showEmailUser( $id ) ) {
784 $s .= $sep . $this->emailUserLink();
785 }
786 }
787 if ( $wgTitle->getArticleId() ) {
788 $s .= "\n<br />";
789 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
790 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
791 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
792 }
793 $s .= "<br />\n" . $this->otherLanguages();
794 }
795 return $s;
796 }
797
798 function pageStats() {
799 global $wgOut, $wgLang, $wgArticle, $wgRequest;
800 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax;
801
802 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
803 if ( ! $wgOut->isArticle() ) { return ''; }
804 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
805 if ( 0 == $wgArticle->getID() ) { return ''; }
806
807 $s = '';
808 if ( !$wgDisableCounters ) {
809 $count = $wgLang->formatNum( $wgArticle->getCount() );
810 if ( $count ) {
811 $s = wfMsg( 'viewcount', $count );
812 }
813 }
814
815 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
816 require_once("Credits.php");
817 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
818 } else {
819 $s .= $this->lastModified();
820 }
821
822 return $s . ' ' . $this->getCopyright();
823 }
824
825 function getCopyright() {
826 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
827
828
829 $oldid = $wgRequest->getVal( 'oldid' );
830 $diff = $wgRequest->getVal( 'diff' );
831
832 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
833 $msg = 'history_copyright';
834 } else {
835 $msg = 'copyright';
836 }
837
838 $out = '';
839 if( $wgRightsPage ) {
840 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
841 } elseif( $wgRightsUrl ) {
842 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
843 } else {
844 # Give up now
845 return $out;
846 }
847 $out .= wfMsgForContent( $msg, $link );
848 return $out;
849 }
850
851 function getCopyrightIcon() {
852 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon;
853 $out = '';
854 if( $wgRightsIcon ) {
855 $icon = htmlspecialchars( $wgRightsIcon );
856 if( $wgRightsUrl ) {
857 $url = htmlspecialchars( $wgRightsUrl );
858 $out .= '<a href="'.$url.'">';
859 }
860 $text = htmlspecialchars( $wgRightsText );
861 $out .= "<img src=\"$icon\" alt='$text' />";
862 if( $wgRightsUrl ) {
863 $out .= '</a>';
864 }
865 }
866 return $out;
867 }
868
869 function getPoweredBy() {
870 global $wgStylePath;
871 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
872 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
873 return $img;
874 }
875
876 function lastModified() {
877 global $wgLang, $wgArticle;
878
879 $timestamp = $wgArticle->getTimestamp();
880 if ( $timestamp ) {
881 $d = $wgLang->timeanddate( $wgArticle->getTimestamp(), true );
882 $s = ' ' . wfMsg( 'lastmodified', $d );
883 } else {
884 $s = '';
885 }
886 return $s;
887 }
888
889 function logoText( $align = '' ) {
890 if ( '' != $align ) { $a = " align='{$align}'"; }
891 else { $a = ''; }
892
893 $mp = wfMsg( 'mainpage' );
894 $titleObj = Title::newFromText( $mp );
895 if ( is_object( $titleObj ) ) {
896 $url = $titleObj->escapeLocalURL();
897 } else {
898 $url = '';
899 }
900
901 $logourl = $this->getLogo();
902 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
903 return $s;
904 }
905
906 /**
907 * show a drop-down box of special pages
908 * @TODO crash bug913. Need to be rewrote completly.
909 */
910 function specialPagesList() {
911 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript;
912 require_once('SpecialPage.php');
913 $a = array();
914 $pages = SpecialPage::getPages();
915
916 foreach ( $pages[''] as $name => $page ) {
917 $a[$name] = $page->getDescription();
918 }
919 if ( $wgUser->isSysop() )
920 {
921 foreach ( $pages['sysop'] as $name => $page ) {
922 $a[$name] = $page->getDescription();
923 }
924 }
925 if ( $wgUser->isDeveloper() )
926 {
927 foreach ( $pages['developer'] as $name => $page ) {
928 $a[$name] = $page->getDescription() ;
929 }
930 }
931 $go = wfMsg( 'go' );
932 $sp = wfMsg( 'specialpages' );
933 $spp = $wgContLang->specialPage( 'Specialpages' );
934
935 $s = '<form id="specialpages" method="get" class="inline" ' .
936 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
937 $s .= "<select name=\"wpDropdown\">\n";
938 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
939
940 foreach ( $a as $name => $desc ) {
941 $p = $wgContLang->specialPage( $name );
942 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
943 }
944 $s .= "</select>\n";
945 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
946 $s .= "</form>\n";
947 return $s;
948 }
949
950 function mainPageLink() {
951 $mp = wfMsgForContent( 'mainpage' );
952 $mptxt = wfMsg( 'mainpage');
953 $s = $this->makeKnownLink( $mp, $mptxt );
954 return $s;
955 }
956
957 function copyrightLink() {
958 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
959 wfMsg( 'copyrightpagename' ) );
960 return $s;
961 }
962
963 function aboutLink() {
964 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
965 wfMsg( 'aboutsite' ) );
966 return $s;
967 }
968
969
970 function disclaimerLink() {
971 $disclaimers = wfMsg( 'disclaimers' );
972 if ($disclaimers == '-') {
973 return "";
974 } else {
975 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
976 $disclaimers );
977 }
978 }
979
980 function editThisPage() {
981 global $wgOut, $wgTitle, $wgRequest;
982
983 $oldid = $wgRequest->getVal( 'oldid' );
984 $diff = $wgRequest->getVal( 'diff' );
985 $redirect = $wgRequest->getVal( 'redirect' );
986
987 if ( ! $wgOut->isArticleRelated() ) {
988 $s = wfMsg( 'protectedpage' );
989 } else {
990 $n = $wgTitle->getPrefixedText();
991 if ( $wgTitle->userCanEdit() ) {
992 $t = wfMsg( 'editthispage' );
993 } else {
994 #$t = wfMsg( "protectedpage" );
995 $t = wfMsg( 'viewsource' );
996 }
997 $oid = $red = '';
998
999 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
1000 if ( $oldid && ! isset( $diff ) ) {
1001 $oid = '&oldid='.$oldid;
1002 }
1003 $s = $this->makeKnownLink( $n, $t, "action=edit{$oid}{$red}" );
1004 }
1005 return $s;
1006 }
1007
1008 function deleteThisPage() {
1009 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1010
1011 $diff = $wgRequest->getVal( 'diff' );
1012 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1013 $n = $wgTitle->getPrefixedText();
1014 $t = wfMsg( 'deletethispage' );
1015
1016 $s = $this->makeKnownLink( $n, $t, 'action=delete' );
1017 } else {
1018 $s = '';
1019 }
1020 return $s;
1021 }
1022
1023 function protectThisPage() {
1024 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1025
1026 $diff = $wgRequest->getVal( 'diff' );
1027 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1028 $n = $wgTitle->getPrefixedText();
1029
1030 if ( $wgTitle->isProtected() ) {
1031 $t = wfMsg( 'unprotectthispage' );
1032 $q = 'action=unprotect';
1033 } else {
1034 $t = wfMsg( 'protectthispage' );
1035 $q = 'action=protect';
1036 }
1037 $s = $this->makeKnownLink( $n, $t, $q );
1038 } else {
1039 $s = '';
1040 }
1041 return $s;
1042 }
1043
1044 function watchThisPage() {
1045 global $wgUser, $wgOut, $wgTitle;
1046
1047 if ( $wgOut->isArticleRelated() ) {
1048 $n = $wgTitle->getPrefixedText();
1049
1050 if ( $wgTitle->userIsWatching() ) {
1051 $t = wfMsg( 'unwatchthispage' );
1052 $q = 'action=unwatch';
1053 } else {
1054 $t = wfMsg( 'watchthispage' );
1055 $q = 'action=watch';
1056 }
1057 $s = $this->makeKnownLink( $n, $t, $q );
1058 } else {
1059 $s = wfMsg( 'notanarticle' );
1060 }
1061 return $s;
1062 }
1063
1064 function moveThisPage() {
1065 global $wgTitle, $wgContLang;
1066
1067 if ( $wgTitle->userCanMove() ) {
1068 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Movepage' ),
1069 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1070 } // no message if page is protected - would be redundant
1071 return $s;
1072 }
1073
1074 function historyLink() {
1075 global $wgTitle;
1076
1077 $s = $this->makeKnownLink( $wgTitle->getPrefixedText(),
1078 wfMsg( 'history' ), 'action=history' );
1079 return $s;
1080 }
1081
1082 function whatLinksHere() {
1083 global $wgTitle, $wgContLang;
1084
1085 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Whatlinkshere' ),
1086 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1087 return $s;
1088 }
1089
1090 function userContribsLink() {
1091 global $wgTitle, $wgContLang;
1092
1093 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
1094 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1095 return $s;
1096 }
1097
1098 function showEmailUser( $id ) {
1099 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1100 return $wgEnableEmail &&
1101 $wgEnableUserEmail &&
1102 0 != $wgUser->getID() && # show only to signed in users
1103 0 != $id; # can only email non-anons
1104 }
1105
1106 function emailUserLink() {
1107 global $wgTitle, $wgContLang;
1108
1109 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Emailuser' ),
1110 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1111 return $s;
1112 }
1113
1114 function watchPageLinksLink() {
1115 global $wgOut, $wgTitle, $wgContLang;
1116
1117 if ( ! $wgOut->isArticleRelated() ) {
1118 $s = '(' . wfMsg( 'notanarticle' ) . ')';
1119 } else {
1120 $s = $this->makeKnownLink( $wgContLang->specialPage(
1121 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1122 'target=' . $wgTitle->getPrefixedURL() );
1123 }
1124 return $s;
1125 }
1126
1127 function otherLanguages() {
1128 global $wgOut, $wgContLang, $wgTitle, $wgUseNewInterlanguage;
1129
1130 $a = $wgOut->getLanguageLinks();
1131 if ( 0 == count( $a ) ) {
1132 if ( !$wgUseNewInterlanguage ) return '';
1133 $ns = $wgContLang->getNsIndex ( $wgTitle->getNamespace () ) ;
1134 if ( $ns != 0 AND $ns != 1 ) return '' ;
1135 $pn = 'Intl' ;
1136 $x = 'mode=addlink&xt='.$wgTitle->getDBkey() ;
1137 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1138 wfMsg( 'intl' ) , $x );
1139 }
1140
1141 if ( !$wgUseNewInterlanguage ) {
1142 $s = wfMsg( 'otherlanguages' ) . ': ';
1143 } else {
1144 global $wgContLanguageCode ;
1145 $x = 'mode=zoom&xt='.$wgTitle->getDBkey() ;
1146 $x .= '&xl='.$wgContLanguageCode ;
1147 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Intl' ),
1148 wfMsg( 'otherlanguages' ) , $x ) . ': ' ;
1149 }
1150
1151 $s = wfMsg( 'otherlanguages' ) . ': ';
1152 $first = true;
1153 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1154 foreach( $a as $l ) {
1155 if ( ! $first ) { $s .= ' | '; }
1156 $first = false;
1157
1158 $nt = Title::newFromText( $l );
1159 $url = $nt->getFullURL();
1160 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1161
1162 if ( '' == $text ) { $text = $l; }
1163 $style = $this->getExternalLinkAttributes( $l, $text );
1164 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1165 }
1166 if($wgContLang->isRTL()) $s .= '</span>';
1167 return $s;
1168 }
1169
1170 function bugReportsLink() {
1171 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1172 wfMsg( 'bugreports' ) );
1173 return $s;
1174 }
1175
1176 function dateLink() {
1177 global $wgLinkCache;
1178 $t1 = Title::newFromText( gmdate( 'F j' ) );
1179 $t2 = Title::newFromText( gmdate( 'Y' ) );
1180
1181 $wgLinkCache->suspend();
1182 $id = $t1->getArticleID();
1183 $wgLinkCache->resume();
1184
1185 if ( 0 == $id ) {
1186 $s = $this->makeBrokenLink( $t1->getText() );
1187 } else {
1188 $s = $this->makeKnownLink( $t1->getText() );
1189 }
1190 $s .= ', ';
1191
1192 $wgLinkCache->suspend();
1193 $id = $t2->getArticleID();
1194 $wgLinkCache->resume();
1195
1196 if ( 0 == $id ) {
1197 $s .= $this->makeBrokenLink( $t2->getText() );
1198 } else {
1199 $s .= $this->makeKnownLink( $t2->getText() );
1200 }
1201 return $s;
1202 }
1203
1204 function talkLink() {
1205 global $wgContLang, $wgTitle, $wgLinkCache;
1206
1207 $tns = $wgTitle->getNamespace();
1208 if ( -1 == $tns ) { return ''; }
1209
1210 $pn = $wgTitle->getText();
1211 $tp = wfMsg( 'talkpage' );
1212 if ( Namespace::isTalk( $tns ) ) {
1213 $lns = Namespace::getSubject( $tns );
1214 switch($tns) {
1215 case 1:
1216 $text = wfMsg('articlepage');
1217 break;
1218 case 3:
1219 $text = wfMsg('userpage');
1220 break;
1221 case 5:
1222 $text = wfMsg('wikipediapage');
1223 break;
1224 case 7:
1225 $text = wfMsg('imagepage');
1226 break;
1227 default:
1228 $text= wfMsg('articlepage');
1229 }
1230 } else {
1231
1232 $lns = Namespace::getTalk( $tns );
1233 $text=$tp;
1234 }
1235 $n = $wgContLang->getNsText( $lns );
1236 if ( '' == $n ) { $link = $pn; }
1237 else { $link = $n.':'.$pn; }
1238
1239 $wgLinkCache->suspend();
1240 $s = $this->makeLink( $link, $text );
1241 $wgLinkCache->resume();
1242
1243 return $s;
1244 }
1245
1246 function commentLink() {
1247 global $wgContLang, $wgTitle, $wgLinkCache;
1248
1249 $tns = $wgTitle->getNamespace();
1250 if ( -1 == $tns ) { return ''; }
1251
1252 $lns = ( Namespace::isTalk( $tns ) ) ? $tns : Namespace::getTalk( $tns );
1253
1254 # assert Namespace::isTalk( $lns )
1255
1256 $n = $wgContLang->getNsText( $lns );
1257 $pn = $wgTitle->getText();
1258
1259 $link = $n.':'.$pn;
1260
1261 $wgLinkCache->suspend();
1262 $s = $this->makeKnownLink($link, wfMsg('postcomment'), 'action=edit&section=new');
1263 $wgLinkCache->resume();
1264
1265 return $s;
1266 }
1267
1268 /**
1269 * After all the page content is transformed into HTML, it makes
1270 * a final pass through here for things like table backgrounds.
1271 * @todo probably deprecated [AV]
1272 */
1273 function transformContent( $text ) {
1274 return $text;
1275 }
1276
1277 /**
1278 * Note: This function MUST call getArticleID() on the link,
1279 * otherwise the cache won't get updated properly. See LINKCACHE.DOC.
1280 */
1281 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
1282 wfProfileIn( 'Skin::makeLink' );
1283 $nt = Title::newFromText( $title );
1284 if ($nt) {
1285 $result = $this->makeLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1286 } else {
1287 wfDebug( 'Invalid title passed to Skin::makeLink(): "'.$title."\"\n" );
1288 $result = $text == "" ? $title : $text;
1289 }
1290
1291 wfProfileOut( 'Skin::makeLink' );
1292 return $result;
1293 }
1294
1295 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
1296 $nt = Title::newFromText( $title );
1297 if ($nt) {
1298 return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
1299 } else {
1300 wfDebug( 'Invalid title passed to Skin::makeKnownLink(): "'.$title."\"\n" );
1301 return $text == '' ? $title : $text;
1302 }
1303 }
1304
1305 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1306 $nt = Title::newFromText( $title );
1307 if ($nt) {
1308 return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1309 } else {
1310 wfDebug( 'Invalid title passed to Skin::makeBrokenLink(): "'.$title."\"\n" );
1311 return $text == '' ? $title : $text;
1312 }
1313 }
1314
1315 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
1316 $nt = Title::newFromText( $title );
1317 if ($nt) {
1318 return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1319 } else {
1320 wfDebug( 'Invalid title passed to Skin::makeStubLink(): "'.$title."\"\n" );
1321 return $text == '' ? $title : $text;
1322 }
1323 }
1324
1325 /**
1326 * Pass a title object, not a title string
1327 */
1328 function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
1329 global $wgOut, $wgUser, $wgLinkHolders;
1330 $fname = 'Skin::makeLinkObj';
1331 wfProfileIn( $fname );
1332
1333 # Fail gracefully
1334 if ( ! isset($nt) ) {
1335 # wfDebugDieBacktrace();
1336 wfProfileOut( $fname );
1337 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1338 }
1339
1340 $ns = $nt->getNamespace();
1341 $dbkey = $nt->getDBkey();
1342 if ( $nt->isExternal() ) {
1343 $u = $nt->getFullURL();
1344 $link = $nt->getPrefixedURL();
1345 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
1346 $style = $this->getExternalLinkAttributes( $link, $text, 'extiw' );
1347
1348 $inside = '';
1349 if ( '' != $trail ) {
1350 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
1351 $inside = $m[1];
1352 $trail = $m[2];
1353 }
1354 }
1355 # Assume $this->postParseLinkColour(). This prevents
1356 # interwiki links from being parsed as external links.
1357 global $wgInterwikiLinkHolders;
1358 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
1359 $nr = array_push($wgInterwikiLinkHolders, $t);
1360 $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
1361 } elseif ( 0 == $ns && "" == $dbkey ) {
1362 # A self-link with a fragment; skip existence check.
1363 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1364 } elseif ( ( NS_SPECIAL == $ns ) || ( NS_IMAGE == $ns ) ) {
1365 # These are always shown as existing, currently.
1366 # Special pages don't exist in the database; images may
1367 # occasionally be present when there is no description
1368 # page per se, so we always shown them.
1369 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1370 } elseif ( $this->postParseLinkColour ) {
1371 wfProfileIn( $fname.'-postparse' );
1372 # Insert a placeholder, and we'll work out the existence checks
1373 # in a big lump later.
1374 $inside = '';
1375 if ( '' != $trail ) {
1376 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1377 $inside = $m[1];
1378 $trail = $m[2];
1379 }
1380 }
1381
1382 # These get picked up by Parser::replaceLinkHolders()
1383 $nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() );
1384 $wgLinkHolders['dbkeys'][] = $dbkey;
1385 $wgLinkHolders['queries'][] = $query;
1386 $wgLinkHolders['texts'][] = $prefix.$text.$inside;
1387 $wgLinkHolders['titles'][] =& $nt;
1388
1389 $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
1390 wfProfileOut( $fname.'-postparse' );
1391 } else {
1392 wfProfileIn( $fname.'-immediate' );
1393 # Work out link colour immediately
1394 $aid = $nt->getArticleID() ;
1395 if ( 0 == $aid ) {
1396 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
1397 } else {
1398 $threshold = $wgUser->getOption('stubthreshold') ;
1399 if ( $threshold > 0 ) {
1400 $dbr =& wfGetDB( DB_SLAVE );
1401 $s = $dbr->selectRow( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace',
1402 'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ;
1403 if ( $s !== false ) {
1404 $size = $s->x;
1405 if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) {
1406 $size = $threshold*2 ; # Really big
1407 }
1408 } else {
1409 $size = $threshold*2 ; # Really big
1410 }
1411 } else {
1412 $size = 1 ;
1413 }
1414 if ( $size < $threshold ) {
1415 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
1416 } else {
1417 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1418 }
1419 }
1420 wfProfileOut( $fname.'-immediate' );
1421 }
1422 wfProfileOut( $fname );
1423 return $retVal;
1424 }
1425
1426 /**
1427 * Pass a title object, not a title string
1428 */
1429 function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
1430 global $wgOut, $wgTitle, $wgInputEncoding;
1431
1432 $fname = 'Skin::makeKnownLinkObj';
1433 wfProfileIn( $fname );
1434
1435 if ( !is_object( $nt ) ) {
1436 wfProfileIn( $fname );
1437 return $text;
1438 }
1439
1440 $u = $nt->escapeLocalURL( $query );
1441 if ( '' != $nt->getFragment() ) {
1442 if( $nt->getPrefixedDbkey() == '' ) {
1443 $u = '';
1444 if ( '' == $text ) {
1445 $text = htmlspecialchars( $nt->getFragment() );
1446 }
1447 }
1448 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT, $wgInputEncoding ) );
1449 $replacearray = array(
1450 '%3A' => ':',
1451 '%' => '.'
1452 );
1453 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
1454 }
1455 if ( '' == $text ) {
1456 $text = htmlspecialchars( $nt->getPrefixedText() );
1457 }
1458 $style = $this->getInternalLinkAttributesObj( $nt, $text );
1459
1460 $inside = '';
1461 if ( '' != $trail ) {
1462 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1463 $inside = $m[1];
1464 $trail = $m[2];
1465 }
1466 }
1467 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
1468 wfProfileOut( $fname );
1469 return $r;
1470 }
1471
1472 /**
1473 * Pass a title object, not a title string
1474 */
1475 function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1476 # Fail gracefully
1477 if ( ! isset($nt) ) {
1478 # wfDebugDieBacktrace();
1479 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1480 }
1481
1482 $fname = 'Skin::makeBrokenLinkObj';
1483 wfProfileIn( $fname );
1484
1485 if ( '' == $query ) {
1486 $q = 'action=edit';
1487 } else {
1488 $q = 'action=edit&'.$query;
1489 }
1490 $u = $nt->escapeLocalURL( $q );
1491
1492 if ( '' == $text ) {
1493 $text = htmlspecialchars( $nt->getPrefixedText() );
1494 }
1495 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
1496
1497 $inside = '';
1498 if ( '' != $trail ) {
1499 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1500 $inside = $m[1];
1501 $trail = $m[2];
1502 }
1503 }
1504 if ( $this->mOptions['highlightbroken'] ) {
1505 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1506 } else {
1507 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
1508 }
1509
1510 wfProfileOut( $fname );
1511 return $s;
1512 }
1513
1514 /**
1515 * Pass a title object, not a title string
1516 */
1517 function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1518 $link = $nt->getPrefixedURL();
1519
1520 $u = $nt->escapeLocalURL( $query );
1521
1522 if ( '' == $text ) {
1523 $text = htmlspecialchars( $nt->getPrefixedText() );
1524 }
1525 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
1526
1527 $inside = '';
1528 if ( '' != $trail ) {
1529 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1530 $inside = $m[1];
1531 $trail = $m[2];
1532 }
1533 }
1534 if ( $this->mOptions['highlightbroken'] ) {
1535 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1536 } else {
1537 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
1538 }
1539 return $s;
1540 }
1541
1542 function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1543 $u = $nt->escapeLocalURL( $query );
1544 if ( '' == $text ) {
1545 $text = htmlspecialchars( $nt->getPrefixedText() );
1546 }
1547 $inside = '';
1548 if ( '' != $trail ) {
1549 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1550 $inside = $m[1];
1551 $trail = $m[2];
1552 }
1553 }
1554 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
1555 }
1556
1557 /* these are used extensively in SkinPHPTal, but also some other places */
1558 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1559 $title = Title::makeTitle( NS_SPECIAL, $name );
1560 $this->checkTitle($title, $name);
1561 return $title->getLocalURL( $urlaction );
1562 }
1563 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
1564 $title = Title::newFromText( $name );
1565 $title = $title->getTalkPage();
1566 $this->checkTitle($title, $name);
1567 return $title->getLocalURL( $urlaction );
1568 }
1569 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
1570 $title = Title::newFromText( $name );
1571 $title= $title->getSubjectPage();
1572 $this->checkTitle($title, $name);
1573 return $title->getLocalURL( $urlaction );
1574 }
1575 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1576 $title = Title::newFromText( wfMsgForContent($name) );
1577 $this->checkTitle($title, $name);
1578 return $title->getLocalURL( $urlaction );
1579 }
1580 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1581 $title = Title::newFromText( $name );
1582 $this->checkTitle($title, $name);
1583 return $title->getLocalURL( $urlaction );
1584 }
1585
1586 # If url string starts with http, consider as external URL, else
1587 # internal
1588 /*static*/ function makeInternalOrExternalUrl( $name ) {
1589 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1590 return $name;
1591 } else {
1592 return $this->makeUrl( $name );
1593 }
1594 }
1595
1596 # this can be passed the NS number as defined in Language.php
1597 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=0 ) {
1598 $title = Title::makeTitleSafe( $namespace, $name );
1599 $this->checkTitle($title, $name);
1600 return $title->getLocalURL( $urlaction );
1601 }
1602
1603 /* these return an array with the 'href' and boolean 'exists' */
1604 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1605 $title = Title::newFromText( $name );
1606 $this->checkTitle($title, $name);
1607 return array(
1608 'href' => $title->getLocalURL( $urlaction ),
1609 'exists' => $title->getArticleID() != 0?true:false
1610 );
1611 }
1612 /*static*/ function makeTalkUrlDetails ( $name, $urlaction='' ) {
1613 $title = Title::newFromText( $name );
1614 $title = $title->getTalkPage();
1615 $this->checkTitle($title, $name);
1616 return array(
1617 'href' => $title->getLocalURL( $urlaction ),
1618 'exists' => $title->getArticleID() != 0?true:false
1619 );
1620 }
1621 /*static*/ function makeArticleUrlDetails ( $name, $urlaction='' ) {
1622 $title = Title::newFromText( $name );
1623 $title= $title->getSubjectPage();
1624 $this->checkTitle($title, $name);
1625 return array(
1626 'href' => $title->getLocalURL( $urlaction ),
1627 'exists' => $title->getArticleID() != 0?true:false
1628 );
1629 }
1630 /*static*/ function makeI18nUrlDetails ( $name, $urlaction='' ) {
1631 $title = Title::newFromText( wfMsgForContent($name) );
1632 $this->checkTitle($title, $name);
1633 return array(
1634 'href' => $title->getLocalURL( $urlaction ),
1635 'exists' => $title->getArticleID() != 0?true:false
1636 );
1637 }
1638
1639 # make sure we have some title to operate on
1640 /*static*/ function checkTitle ( &$title, &$name ) {
1641 if(!is_object($title)) {
1642 $title = Title::newFromText( $name );
1643 if(!is_object($title)) {
1644 $title = Title::newFromText( '--error: link target missing--' );
1645 }
1646 }
1647 }
1648
1649 function fnamePart( $url ) {
1650 $basename = strrchr( $url, '/' );
1651 if ( false === $basename ) {
1652 $basename = $url;
1653 } else {
1654 $basename = substr( $basename, 1 );
1655 }
1656 return htmlspecialchars( $basename );
1657 }
1658
1659 function makeImage( $url, $alt = '' ) {
1660 global $wgOut;
1661 if ( '' == $alt ) {
1662 $alt = $this->fnamePart( $url );
1663 }
1664 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
1665 return $s;
1666 }
1667
1668 function makeImageLink( $name, $url, $alt = '' ) {
1669 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1670 return $this->makeImageLinkObj( $nt, $alt );
1671 }
1672
1673 function makeImageLinkObj( $nt, $alt = '' ) {
1674 global $wgContLang, $wgUseImageResize;
1675 $img = Image::newFromTitle( $nt );
1676 $url = $img->getViewURL();
1677
1678 $align = '';
1679 $prefix = $postfix = '';
1680
1681 # Check if the alt text is of the form "options|alt text"
1682 # Options are:
1683 # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
1684 # * left no resizing, just left align. label is used for alt= only
1685 # * right same, but right aligned
1686 # * none same, but not aligned
1687 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
1688 # * center center the image
1689 # * framed Keep original image size, no magnify-button.
1690
1691 $part = explode( '|', $alt);
1692
1693 $mwThumb =& MagicWord::get( MAG_IMG_THUMBNAIL );
1694 $mwLeft =& MagicWord::get( MAG_IMG_LEFT );
1695 $mwRight =& MagicWord::get( MAG_IMG_RIGHT );
1696 $mwNone =& MagicWord::get( MAG_IMG_NONE );
1697 $mwWidth =& MagicWord::get( MAG_IMG_WIDTH );
1698 $mwCenter =& MagicWord::get( MAG_IMG_CENTER );
1699 $mwFramed =& MagicWord::get( MAG_IMG_FRAMED );
1700 $alt = '';
1701
1702 $height = $framed = $thumb = false;
1703 $manual_thumb = "" ;
1704
1705 foreach( $part as $key => $val ) {
1706 $val_parts = explode ( "=" , $val , 2 ) ;
1707 $left_part = array_shift ( $val_parts ) ;
1708 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
1709 $thumb=true;
1710 } elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
1711 # use manually specified thumbnail
1712 $thumb=true;
1713 $manual_thumb = array_shift ( $val_parts ) ;
1714 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
1715 # remember to set an alignment, don't render immediately
1716 $align = 'right';
1717 } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
1718 # remember to set an alignment, don't render immediately
1719 $align = 'left';
1720 } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
1721 # remember to set an alignment, don't render immediately
1722 $align = 'center';
1723 } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
1724 # remember to set an alignment, don't render immediately
1725 $align = 'none';
1726 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
1727 # $match is the image width in pixels
1728 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
1729 $width = intval( $m[1] );
1730 $height = intval( $m[2] );
1731 } else {
1732 $width = intval($match);
1733 }
1734 } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
1735 $framed=true;
1736 } else {
1737 $alt = $val;
1738 }
1739 }
1740 if ( 'center' == $align )
1741 {
1742 $prefix = '<div class="center">';
1743 $postfix = '</div>';
1744 $align = 'none';
1745 }
1746
1747 if ( $thumb || $framed ) {
1748
1749 # Create a thumbnail. Alignment depends on language
1750 # writing direction, # right aligned for left-to-right-
1751 # languages ("Western languages"), left-aligned
1752 # for right-to-left-languages ("Semitic languages")
1753 #
1754 # If thumbnail width has not been provided, it is set
1755 # here to 180 pixels
1756 if ( $align == '' ) {
1757 $align = $wgContLang->isRTL() ? 'left' : 'right';
1758 }
1759 if ( ! isset($width) ) {
1760 $width = 180;
1761 }
1762 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
1763
1764 } elseif ( isset($width) ) {
1765
1766 # Create a resized image, without the additional thumbnail
1767 # features
1768
1769 if ( ( ! $height === false )
1770 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
1771 $width = $img->getWidth() * $height / $img->getHeight();
1772 }
1773 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
1774 }
1775
1776 $alt = preg_replace( '/<[^>]*>/', '', $alt );
1777 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1778 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1779
1780 $u = $nt->escapeLocalURL();
1781 if ( $url == '' ) {
1782 $s = wfMsg( 'missingimage', $img->getName() );
1783 $s .= "<br>{$alt}<br>{$url}<br>\n";
1784 } else {
1785 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
1786 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
1787 }
1788 if ( '' != $align ) {
1789 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
1790 }
1791 return str_replace("\n", ' ',$prefix.$s.$postfix);
1792 }
1793
1794 /**
1795 * Make HTML for a thumbnail including image, border and caption
1796 * $img is an Image object
1797 */
1798 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
1799 global $wgStylePath, $wgContLang;
1800 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
1801 $url = $img->getViewURL();
1802
1803 #$label = htmlspecialchars( $label );
1804 $alt = preg_replace( '/<[^>]*>/', '', $label);
1805 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1806 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1807
1808 $width = $height = 0;
1809 if ( $img->exists() )
1810 {
1811 $width = $img->getWidth();
1812 $height = $img->getHeight();
1813 }
1814 if ( 0 == $width || 0 == $height )
1815 {
1816 $width = $height = 200;
1817 }
1818 if ( $boxwidth == 0 )
1819 {
1820 $boxwidth = 200;
1821 }
1822 if ( $framed )
1823 {
1824 // Use image dimensions, don't scale
1825 $boxwidth = $width;
1826 $oboxwidth = $boxwidth + 2;
1827 $boxheight = $height;
1828 $thumbUrl = $url;
1829 } else {
1830 $h = intval( $height/($width/$boxwidth) );
1831 $oboxwidth = $boxwidth + 2;
1832 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
1833 {
1834 $boxwidth *= $boxheight/$h;
1835 } else {
1836 $boxheight = $h;
1837 }
1838 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
1839 }
1840
1841 if ( $manual_thumb != '' ) # Use manually specified thumbnail
1842 {
1843 $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb ); #new Title ( $manual_thumb ) ;
1844 $manual_img = Image::newFromTitle( $manual_title );
1845 $thumbUrl = $manual_img->getViewURL();
1846 if ( $manual_img->exists() )
1847 {
1848 $width = $manual_img->getWidth();
1849 $height = $manual_img->getHeight();
1850 $boxwidth = $width ;
1851 $boxheight = $height ;
1852 $oboxwidth = $boxwidth + 2 ;
1853 }
1854 }
1855
1856 $u = $img->getEscapeLocalURL();
1857
1858 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
1859 $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
1860 $textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
1861
1862 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
1863 if ( $thumbUrl == '' ) {
1864 $s .= wfMsg( 'missingimage', $img->getName() );
1865 $zoomicon = '';
1866 } else {
1867 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
1868 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
1869 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
1870 'longdesc="'.$u.'" /></a>';
1871 if ( $framed ) {
1872 $zoomicon="";
1873 } else {
1874 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
1875 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
1876 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
1877 'width="15" height="11" alt="'.$more.'" /></a></div>';
1878 }
1879 }
1880 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
1881 return str_replace("\n", ' ', $s);
1882 }
1883
1884 function makeMediaLink( $name, $url, $alt = '' ) {
1885 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1886 return $this->makeMediaLinkObj( $nt, $alt );
1887 }
1888
1889 function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {
1890 if ( ! isset( $nt ) )
1891 {
1892 ### HOTFIX. Instead of breaking, return empty string.
1893 $s = $alt;
1894 } else {
1895 $name = $nt->getDBKey();
1896 $img = Image::newFromTitle( $nt );
1897 $url = $img->getURL();
1898 # $nourl can be set by the parser
1899 # this is a hack to mask absolute URLs, so the parser doesn't
1900 # linkify them (it is currently not context-aware)
1901 # 2004-10-25
1902 if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
1903 if ( empty( $alt ) ) {
1904 $alt = preg_replace( '/\.(.+?)^/', '', $name );
1905 }
1906 $u = htmlspecialchars( $url );
1907 $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
1908 }
1909 return $s;
1910 }
1911
1912 function specialLink( $name, $key = '' ) {
1913 global $wgContLang;
1914
1915 if ( '' == $key ) { $key = strtolower( $name ); }
1916 $pn = $wgContLang->ucfirst( $name );
1917 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1918 wfMsg( $key ) );
1919 }
1920
1921 function makeExternalLink( $url, $text, $escape = true ) {
1922 $style = $this->getExternalLinkAttributes( $url, $text );
1923 $url = htmlspecialchars( $url );
1924 if( $escape ) {
1925 $text = htmlspecialchars( $text );
1926 }
1927 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
1928 }
1929
1930
1931 /**
1932 * This function is called by all recent changes variants, by the page history,
1933 * and by the user contributions list. It is responsible for formatting edit
1934 * comments. It escapes any HTML in the comment, but adds some CSS to format
1935 * auto-generated comments (from section editing) and formats [[wikilinks]].
1936 *
1937 * The &$title parameter must be a title OBJECT. It is used to generate a
1938 * direct link to the section in the autocomment.
1939 * @author Erik Moeller <moeller@scireview.de>
1940 *
1941 * Note: there's not always a title to pass to this function.
1942 * Since you can't set a default parameter for a reference, I've turned it
1943 * temporarily to a value pass. Should be adjusted further. --brion
1944 */
1945 function formatComment($comment, $title = NULL) {
1946 $fname = 'Skin::formatComment';
1947 wfProfileIn( $fname );
1948
1949 global $wgContLang;
1950 $comment = htmlspecialchars( $comment );
1951
1952 # The pattern for autogen comments is / * foo * /, which makes for
1953 # some nasty regex.
1954 # We look for all comments, match any text before and after the comment,
1955 # add a separator where needed and format the comment itself with CSS
1956 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
1957 $pre=$match[1];
1958 $auto=$match[2];
1959 $post=$match[3];
1960 $link='';
1961 if($title) {
1962 $section=$auto;
1963
1964 # This is hackish but should work in most cases.
1965 $section=str_replace('[[','',$section);
1966 $section=str_replace(']]','',$section);
1967 $title->mFragment=$section;
1968 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
1969 }
1970 $sep='-';
1971 $auto=$link.$auto;
1972 if($pre) { $auto = $sep.' '.$auto; }
1973 if($post) { $auto .= ' '.$sep; }
1974 $auto='<span class="autocomment">'.$auto.'</span>';
1975 $comment=$pre.$auto.$post;
1976 }
1977
1978 # format regular and media links - all other wiki formatting
1979 # is ignored
1980 $medians = $wgContLang->getNsText(Namespace::getMedia()).':';
1981 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
1982 # Handle link renaming [[foo|text]] will show link as "text"
1983 if( "" != $match[3] ) {
1984 $text = $match[3];
1985 } else {
1986 $text = $match[1];
1987 }
1988 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1989 # Media link; trail not supported.
1990 $linkRegexp = '/\[\[(.*?)\]\]/';
1991 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
1992 } else {
1993 # Other kind of link
1994 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
1995 $trail = $submatch[1];
1996 } else {
1997 $trail = "";
1998 }
1999 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
2000 if ($match[1][0] == ':')
2001 $match[1] = substr($match[1], 1);
2002 $thelink = $this->makeLink( $match[1], $text, "", $trail );
2003 }
2004 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
2005 }
2006 wfProfileOut( $fname );
2007 return $comment;
2008 }
2009
2010 function tocIndent($level) {
2011 return str_repeat( '<div class="tocindent">'."\n", $level>0 ? $level : 0 );
2012 }
2013
2014 function tocUnindent($level) {
2015 return str_repeat( "</div>\n", $level>0 ? $level : 0 );
2016 }
2017
2018 /**
2019 * parameter level defines if we are on an indentation level
2020 */
2021 function tocLine( $anchor, $tocline, $level ) {
2022 $link = '<a href="#'.$anchor.'">'.$tocline.'</a><br />';
2023 if($level) {
2024 return $link."\n";
2025 } else {
2026 return '<div class="tocline">'.$link."</div>\n";
2027 }
2028
2029 }
2030
2031 function tocTable($toc) {
2032 # note to CSS fanatics: putting this in a div does not work -- div won't auto-expand
2033 # try min-width & co when somebody gets a chance
2034 $hideline = ' <script type="text/javascript">showTocToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '")</script>';
2035 return
2036 '<table border="0" id="toc"><tr id="toctitle"><td align="center">'."\n".
2037 '<b>'.wfMsgForContent('toc').'</b>' .
2038 $hideline .
2039 '</td></tr><tr id="tocinside"><td>'."\n".
2040 $toc."</td></tr></table>\n";
2041 }
2042
2043 /**
2044 * These two do not check for permissions: check $wgTitle->userCanEdit
2045 * before calling them
2046 */
2047 function editSectionScriptForOther( $title, $section, $head ) {
2048 $ttl = Title::newFromText( $title );
2049 $url = $ttl->escapeLocalURL( 'action=edit&section='.$section );
2050 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2051 }
2052
2053 function editSectionScript( $nt, $section, $head ) {
2054 global $wgRequest;
2055 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2056 return $head;
2057 }
2058 $url = $nt->escapeLocalURL( 'action=edit&section='.$section );
2059 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2060 }
2061
2062 function editSectionLinkForOther( $title, $section ) {
2063 global $wgRequest;
2064 global $wgContLang;
2065
2066 $title = Title::newFromText($title);
2067 $editurl = '&section='.$section;
2068 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2069
2070 if( $wgContLang->isRTL() ) {
2071 $farside = 'left';
2072 $nearside = 'right';
2073 } else {
2074 $farside = 'right';
2075 $nearside = 'left';
2076 }
2077 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2078
2079 }
2080
2081 function editSectionLink( $nt, $section ) {
2082 global $wgRequest;
2083 global $wgContLang;
2084
2085 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2086 # Section edit links would be out of sync on an old page.
2087 # But, if we're diffing to the current page, they'll be
2088 # correct.
2089 return '';
2090 }
2091
2092 $editurl = '&section='.$section;
2093 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2094
2095 if( $wgContLang->isRTL() ) {
2096 $farside = 'left';
2097 $nearside = 'right';
2098 } else {
2099 $farside = 'right';
2100 $nearside = 'left';
2101 }
2102 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2103
2104 }
2105
2106 /**
2107 * @access public
2108 */
2109 function suppressUrlExpansion() {
2110 return false;
2111 }
2112 }
2113
2114 }
2115 ?>