* (bug 1010) fix broken Commons image link on Classic & Cologne Blue
[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 $dbr->freeResult( $res );
1409 } else {
1410 $size = $threshold*2 ; # Really big
1411 }
1412 } else {
1413 $size = 1 ;
1414 }
1415 if ( $size < $threshold ) {
1416 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
1417 } else {
1418 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1419 }
1420 }
1421 wfProfileOut( $fname.'-immediate' );
1422 }
1423 wfProfileOut( $fname );
1424 return $retVal;
1425 }
1426
1427 /**
1428 * Pass a title object, not a title string
1429 */
1430 function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
1431 global $wgOut, $wgTitle, $wgInputEncoding;
1432
1433 $fname = 'Skin::makeKnownLinkObj';
1434 wfProfileIn( $fname );
1435
1436 if ( !is_object( $nt ) ) {
1437 wfProfileIn( $fname );
1438 return $text;
1439 }
1440
1441 $u = $nt->escapeLocalURL( $query );
1442 if ( '' != $nt->getFragment() ) {
1443 if( $nt->getPrefixedDbkey() == '' ) {
1444 $u = '';
1445 if ( '' == $text ) {
1446 $text = htmlspecialchars( $nt->getFragment() );
1447 }
1448 }
1449 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT, $wgInputEncoding ) );
1450 $replacearray = array(
1451 '%3A' => ':',
1452 '%' => '.'
1453 );
1454 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
1455 }
1456 if ( '' == $text ) {
1457 $text = htmlspecialchars( $nt->getPrefixedText() );
1458 }
1459 $style = $this->getInternalLinkAttributesObj( $nt, $text );
1460
1461 $inside = '';
1462 if ( '' != $trail ) {
1463 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1464 $inside = $m[1];
1465 $trail = $m[2];
1466 }
1467 }
1468 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
1469 wfProfileOut( $fname );
1470 return $r;
1471 }
1472
1473 /**
1474 * Pass a title object, not a title string
1475 */
1476 function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1477 # Fail gracefully
1478 if ( ! isset($nt) ) {
1479 # wfDebugDieBacktrace();
1480 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1481 }
1482
1483 $fname = 'Skin::makeBrokenLinkObj';
1484 wfProfileIn( $fname );
1485
1486 if ( '' == $query ) {
1487 $q = 'action=edit';
1488 } else {
1489 $q = 'action=edit&'.$query;
1490 }
1491 $u = $nt->escapeLocalURL( $q );
1492
1493 if ( '' == $text ) {
1494 $text = htmlspecialchars( $nt->getPrefixedText() );
1495 }
1496 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
1497
1498 $inside = '';
1499 if ( '' != $trail ) {
1500 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1501 $inside = $m[1];
1502 $trail = $m[2];
1503 }
1504 }
1505 if ( $this->mOptions['highlightbroken'] ) {
1506 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1507 } else {
1508 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
1509 }
1510
1511 wfProfileOut( $fname );
1512 return $s;
1513 }
1514
1515 /**
1516 * Pass a title object, not a title string
1517 */
1518 function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1519 $link = $nt->getPrefixedURL();
1520
1521 $u = $nt->escapeLocalURL( $query );
1522
1523 if ( '' == $text ) {
1524 $text = htmlspecialchars( $nt->getPrefixedText() );
1525 }
1526 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
1527
1528 $inside = '';
1529 if ( '' != $trail ) {
1530 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1531 $inside = $m[1];
1532 $trail = $m[2];
1533 }
1534 }
1535 if ( $this->mOptions['highlightbroken'] ) {
1536 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1537 } else {
1538 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
1539 }
1540 return $s;
1541 }
1542
1543 function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1544 $u = $nt->escapeLocalURL( $query );
1545 if ( '' == $text ) {
1546 $text = htmlspecialchars( $nt->getPrefixedText() );
1547 }
1548 $inside = '';
1549 if ( '' != $trail ) {
1550 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1551 $inside = $m[1];
1552 $trail = $m[2];
1553 }
1554 }
1555 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
1556 }
1557
1558 /* these are used extensively in SkinPHPTal, but also some other places */
1559 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1560 $title = Title::makeTitle( NS_SPECIAL, $name );
1561 $this->checkTitle($title, $name);
1562 return $title->getLocalURL( $urlaction );
1563 }
1564 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
1565 $title = Title::newFromText( $name );
1566 $title = $title->getTalkPage();
1567 $this->checkTitle($title, $name);
1568 return $title->getLocalURL( $urlaction );
1569 }
1570 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
1571 $title = Title::newFromText( $name );
1572 $title= $title->getSubjectPage();
1573 $this->checkTitle($title, $name);
1574 return $title->getLocalURL( $urlaction );
1575 }
1576 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1577 $title = Title::newFromText( wfMsgForContent($name) );
1578 $this->checkTitle($title, $name);
1579 return $title->getLocalURL( $urlaction );
1580 }
1581 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1582 $title = Title::newFromText( $name );
1583 $this->checkTitle($title, $name);
1584 return $title->getLocalURL( $urlaction );
1585 }
1586
1587 # If url string starts with http, consider as external URL, else
1588 # internal
1589 /*static*/ function makeInternalOrExternalUrl( $name ) {
1590 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1591 return $name;
1592 } else {
1593 return $this->makeUrl( $name );
1594 }
1595 }
1596
1597 # this can be passed the NS number as defined in Language.php
1598 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=0 ) {
1599 $title = Title::makeTitleSafe( $namespace, $name );
1600 $this->checkTitle($title, $name);
1601 return $title->getLocalURL( $urlaction );
1602 }
1603
1604 /* these return an array with the 'href' and boolean 'exists' */
1605 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1606 $title = Title::newFromText( $name );
1607 $this->checkTitle($title, $name);
1608 return array(
1609 'href' => $title->getLocalURL( $urlaction ),
1610 'exists' => $title->getArticleID() != 0?true:false
1611 );
1612 }
1613 /*static*/ function makeTalkUrlDetails ( $name, $urlaction='' ) {
1614 $title = Title::newFromText( $name );
1615 $title = $title->getTalkPage();
1616 $this->checkTitle($title, $name);
1617 return array(
1618 'href' => $title->getLocalURL( $urlaction ),
1619 'exists' => $title->getArticleID() != 0?true:false
1620 );
1621 }
1622 /*static*/ function makeArticleUrlDetails ( $name, $urlaction='' ) {
1623 $title = Title::newFromText( $name );
1624 $title= $title->getSubjectPage();
1625 $this->checkTitle($title, $name);
1626 return array(
1627 'href' => $title->getLocalURL( $urlaction ),
1628 'exists' => $title->getArticleID() != 0?true:false
1629 );
1630 }
1631 /*static*/ function makeI18nUrlDetails ( $name, $urlaction='' ) {
1632 $title = Title::newFromText( wfMsgForContent($name) );
1633 $this->checkTitle($title, $name);
1634 return array(
1635 'href' => $title->getLocalURL( $urlaction ),
1636 'exists' => $title->getArticleID() != 0?true:false
1637 );
1638 }
1639
1640 # make sure we have some title to operate on
1641 /*static*/ function checkTitle ( &$title, &$name ) {
1642 if(!is_object($title)) {
1643 $title = Title::newFromText( $name );
1644 if(!is_object($title)) {
1645 $title = Title::newFromText( '--error: link target missing--' );
1646 }
1647 }
1648 }
1649
1650 function fnamePart( $url ) {
1651 $basename = strrchr( $url, '/' );
1652 if ( false === $basename ) {
1653 $basename = $url;
1654 } else {
1655 $basename = substr( $basename, 1 );
1656 }
1657 return htmlspecialchars( $basename );
1658 }
1659
1660 function makeImage( $url, $alt = '' ) {
1661 global $wgOut;
1662 if ( '' == $alt ) {
1663 $alt = $this->fnamePart( $url );
1664 }
1665 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
1666 return $s;
1667 }
1668
1669 function makeImageLink( $name, $url, $alt = '' ) {
1670 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1671 return $this->makeImageLinkObj( $nt, $alt );
1672 }
1673
1674 function makeImageLinkObj( $nt, $alt = '' ) {
1675 global $wgContLang, $wgUseImageResize;
1676 $img = Image::newFromTitle( $nt );
1677 $url = $img->getViewURL();
1678
1679 $align = '';
1680 $prefix = $postfix = '';
1681
1682 # Check if the alt text is of the form "options|alt text"
1683 # Options are:
1684 # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
1685 # * left no resizing, just left align. label is used for alt= only
1686 # * right same, but right aligned
1687 # * none same, but not aligned
1688 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
1689 # * center center the image
1690 # * framed Keep original image size, no magnify-button.
1691
1692 $part = explode( '|', $alt);
1693
1694 $mwThumb =& MagicWord::get( MAG_IMG_THUMBNAIL );
1695 $mwLeft =& MagicWord::get( MAG_IMG_LEFT );
1696 $mwRight =& MagicWord::get( MAG_IMG_RIGHT );
1697 $mwNone =& MagicWord::get( MAG_IMG_NONE );
1698 $mwWidth =& MagicWord::get( MAG_IMG_WIDTH );
1699 $mwCenter =& MagicWord::get( MAG_IMG_CENTER );
1700 $mwFramed =& MagicWord::get( MAG_IMG_FRAMED );
1701 $alt = '';
1702
1703 $height = $framed = $thumb = false;
1704 $manual_thumb = "" ;
1705
1706 foreach( $part as $key => $val ) {
1707 $val_parts = explode ( "=" , $val , 2 ) ;
1708 $left_part = array_shift ( $val_parts ) ;
1709 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
1710 $thumb=true;
1711 } elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
1712 # use manually specified thumbnail
1713 $thumb=true;
1714 $manual_thumb = array_shift ( $val_parts ) ;
1715 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
1716 # remember to set an alignment, don't render immediately
1717 $align = 'right';
1718 } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
1719 # remember to set an alignment, don't render immediately
1720 $align = 'left';
1721 } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
1722 # remember to set an alignment, don't render immediately
1723 $align = 'center';
1724 } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
1725 # remember to set an alignment, don't render immediately
1726 $align = 'none';
1727 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
1728 # $match is the image width in pixels
1729 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
1730 $width = intval( $m[1] );
1731 $height = intval( $m[2] );
1732 } else {
1733 $width = intval($match);
1734 }
1735 } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
1736 $framed=true;
1737 } else {
1738 $alt = $val;
1739 }
1740 }
1741 if ( 'center' == $align )
1742 {
1743 $prefix = '<div class="center">';
1744 $postfix = '</div>';
1745 $align = 'none';
1746 }
1747
1748 if ( $thumb || $framed ) {
1749
1750 # Create a thumbnail. Alignment depends on language
1751 # writing direction, # right aligned for left-to-right-
1752 # languages ("Western languages"), left-aligned
1753 # for right-to-left-languages ("Semitic languages")
1754 #
1755 # If thumbnail width has not been provided, it is set
1756 # here to 180 pixels
1757 if ( $align == '' ) {
1758 $align = $wgContLang->isRTL() ? 'left' : 'right';
1759 }
1760 if ( ! isset($width) ) {
1761 $width = 180;
1762 }
1763 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
1764
1765 } elseif ( isset($width) ) {
1766
1767 # Create a resized image, without the additional thumbnail
1768 # features
1769
1770 if ( ( ! $height === false )
1771 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
1772 $width = $img->getWidth() * $height / $img->getHeight();
1773 }
1774 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
1775 }
1776
1777 $alt = preg_replace( '/<[^>]*>/', '', $alt );
1778 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1779 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1780
1781 $u = $nt->escapeLocalURL();
1782 if ( $url == '' ) {
1783 $s = wfMsg( 'missingimage', $img->getName() );
1784 $s .= "<br>{$alt}<br>{$url}<br>\n";
1785 } else {
1786 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
1787 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
1788 }
1789 if ( '' != $align ) {
1790 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
1791 }
1792 return str_replace("\n", ' ',$prefix.$s.$postfix);
1793 }
1794
1795 /**
1796 * Make HTML for a thumbnail including image, border and caption
1797 * $img is an Image object
1798 */
1799 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
1800 global $wgStylePath, $wgContLang;
1801 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
1802 $url = $img->getViewURL();
1803
1804 #$label = htmlspecialchars( $label );
1805 $alt = preg_replace( '/<[^>]*>/', '', $label);
1806 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1807 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1808
1809 $width = $height = 0;
1810 if ( $img->exists() )
1811 {
1812 $width = $img->getWidth();
1813 $height = $img->getHeight();
1814 }
1815 if ( 0 == $width || 0 == $height )
1816 {
1817 $width = $height = 200;
1818 }
1819 if ( $boxwidth == 0 )
1820 {
1821 $boxwidth = 200;
1822 }
1823 if ( $framed )
1824 {
1825 // Use image dimensions, don't scale
1826 $boxwidth = $width;
1827 $oboxwidth = $boxwidth + 2;
1828 $boxheight = $height;
1829 $thumbUrl = $url;
1830 } else {
1831 $h = intval( $height/($width/$boxwidth) );
1832 $oboxwidth = $boxwidth + 2;
1833 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
1834 {
1835 $boxwidth *= $boxheight/$h;
1836 } else {
1837 $boxheight = $h;
1838 }
1839 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
1840 }
1841
1842 if ( $manual_thumb != '' ) # Use manually specified thumbnail
1843 {
1844 $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb ); #new Title ( $manual_thumb ) ;
1845 $manual_img = Image::newFromTitle( $manual_title );
1846 $thumbUrl = $manual_img->getViewURL();
1847 if ( $manual_img->exists() )
1848 {
1849 $width = $manual_img->getWidth();
1850 $height = $manual_img->getHeight();
1851 $boxwidth = $width ;
1852 $boxheight = $height ;
1853 $oboxwidth = $boxwidth + 2 ;
1854 }
1855 }
1856
1857 $u = $img->getEscapeLocalURL();
1858
1859 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
1860 $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
1861 $textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
1862
1863 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
1864 if ( $thumbUrl == '' ) {
1865 $s .= wfMsg( 'missingimage', $img->getName() );
1866 $zoomicon = '';
1867 } else {
1868 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
1869 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
1870 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
1871 'longdesc="'.$u.'" /></a>';
1872 if ( $framed ) {
1873 $zoomicon="";
1874 } else {
1875 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
1876 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
1877 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
1878 'width="15" height="11" alt="'.$more.'" /></a></div>';
1879 }
1880 }
1881 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
1882 return str_replace("\n", ' ', $s);
1883 }
1884
1885 function makeMediaLink( $name, $url, $alt = '' ) {
1886 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1887 return $this->makeMediaLinkObj( $nt, $alt );
1888 }
1889
1890 function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {
1891 if ( ! isset( $nt ) )
1892 {
1893 ### HOTFIX. Instead of breaking, return empty string.
1894 $s = $alt;
1895 } else {
1896 $name = $nt->getDBKey();
1897 $img = Image::newFromTitle( $nt );
1898 $url = $img->getURL();
1899 # $nourl can be set by the parser
1900 # this is a hack to mask absolute URLs, so the parser doesn't
1901 # linkify them (it is currently not context-aware)
1902 # 2004-10-25
1903 if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
1904 if ( empty( $alt ) ) {
1905 $alt = preg_replace( '/\.(.+?)^/', '', $name );
1906 }
1907 $u = htmlspecialchars( $url );
1908 $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
1909 }
1910 return $s;
1911 }
1912
1913 function specialLink( $name, $key = '' ) {
1914 global $wgContLang;
1915
1916 if ( '' == $key ) { $key = strtolower( $name ); }
1917 $pn = $wgContLang->ucfirst( $name );
1918 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1919 wfMsg( $key ) );
1920 }
1921
1922 function makeExternalLink( $url, $text, $escape = true ) {
1923 $style = $this->getExternalLinkAttributes( $url, $text );
1924 $url = htmlspecialchars( $url );
1925 if( $escape ) {
1926 $text = htmlspecialchars( $text );
1927 }
1928 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
1929 }
1930
1931
1932 /**
1933 * This function is called by all recent changes variants, by the page history,
1934 * and by the user contributions list. It is responsible for formatting edit
1935 * comments. It escapes any HTML in the comment, but adds some CSS to format
1936 * auto-generated comments (from section editing) and formats [[wikilinks]].
1937 *
1938 * The &$title parameter must be a title OBJECT. It is used to generate a
1939 * direct link to the section in the autocomment.
1940 * @author Erik Moeller <moeller@scireview.de>
1941 *
1942 * Note: there's not always a title to pass to this function.
1943 * Since you can't set a default parameter for a reference, I've turned it
1944 * temporarily to a value pass. Should be adjusted further. --brion
1945 */
1946 function formatComment($comment, $title = NULL) {
1947 $fname = 'Skin::formatComment';
1948 wfProfileIn( $fname );
1949
1950 global $wgContLang;
1951 $comment = htmlspecialchars( $comment );
1952
1953 # The pattern for autogen comments is / * foo * /, which makes for
1954 # some nasty regex.
1955 # We look for all comments, match any text before and after the comment,
1956 # add a separator where needed and format the comment itself with CSS
1957 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
1958 $pre=$match[1];
1959 $auto=$match[2];
1960 $post=$match[3];
1961 $link='';
1962 if($title) {
1963 $section=$auto;
1964
1965 # This is hackish but should work in most cases.
1966 $section=str_replace('[[','',$section);
1967 $section=str_replace(']]','',$section);
1968 $title->mFragment=$section;
1969 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
1970 }
1971 $sep='-';
1972 $auto=$link.$auto;
1973 if($pre) { $auto = $sep.' '.$auto; }
1974 if($post) { $auto .= ' '.$sep; }
1975 $auto='<span class="autocomment">'.$auto.'</span>';
1976 $comment=$pre.$auto.$post;
1977 }
1978
1979 # format regular and media links - all other wiki formatting
1980 # is ignored
1981 $medians = $wgContLang->getNsText(Namespace::getMedia()).':';
1982 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
1983 # Handle link renaming [[foo|text]] will show link as "text"
1984 if( "" != $match[3] ) {
1985 $text = $match[3];
1986 } else {
1987 $text = $match[1];
1988 }
1989 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
1990 # Media link; trail not supported.
1991 $linkRegexp = '/\[\[(.*?)\]\]/';
1992 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
1993 } else {
1994 # Other kind of link
1995 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
1996 $trail = $submatch[1];
1997 } else {
1998 $trail = "";
1999 }
2000 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
2001 if ($match[1][0] == ':')
2002 $match[1] = substr($match[1], 1);
2003 $thelink = $this->makeLink( $match[1], $text, "", $trail );
2004 }
2005 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
2006 }
2007 wfProfileOut( $fname );
2008 return $comment;
2009 }
2010
2011 function tocIndent($level) {
2012 return str_repeat( '<div class="tocindent">'."\n", $level>0 ? $level : 0 );
2013 }
2014
2015 function tocUnindent($level) {
2016 return str_repeat( "</div>\n", $level>0 ? $level : 0 );
2017 }
2018
2019 /**
2020 * parameter level defines if we are on an indentation level
2021 */
2022 function tocLine( $anchor, $tocline, $level ) {
2023 $link = '<a href="#'.$anchor.'">'.$tocline.'</a><br />';
2024 if($level) {
2025 return $link."\n";
2026 } else {
2027 return '<div class="tocline">'.$link."</div>\n";
2028 }
2029
2030 }
2031
2032 function tocTable($toc) {
2033 # note to CSS fanatics: putting this in a div does not work -- div won't auto-expand
2034 # try min-width & co when somebody gets a chance
2035 $hideline = ' <script type="text/javascript">showTocToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '")</script>';
2036 return
2037 '<table border="0" id="toc"><tr id="toctitle"><td align="center">'."\n".
2038 '<b>'.wfMsgForContent('toc').'</b>' .
2039 $hideline .
2040 '</td></tr><tr id="tocinside"><td>'."\n".
2041 $toc."</td></tr></table>\n";
2042 }
2043
2044 /**
2045 * These two do not check for permissions: check $wgTitle->userCanEdit
2046 * before calling them
2047 */
2048 function editSectionScriptForOther( $title, $section, $head ) {
2049 $ttl = Title::newFromText( $title );
2050 $url = $ttl->escapeLocalURL( 'action=edit&section='.$section );
2051 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2052 }
2053
2054 function editSectionScript( $nt, $section, $head ) {
2055 global $wgRequest;
2056 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2057 return $head;
2058 }
2059 $url = $nt->escapeLocalURL( 'action=edit&section='.$section );
2060 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2061 }
2062
2063 function editSectionLinkForOther( $title, $section ) {
2064 global $wgRequest;
2065 global $wgContLang;
2066
2067 $title = Title::newFromText($title);
2068 $editurl = '&section='.$section;
2069 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2070
2071 if( $wgContLang->isRTL() ) {
2072 $farside = 'left';
2073 $nearside = 'right';
2074 } else {
2075 $farside = 'right';
2076 $nearside = 'left';
2077 }
2078 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2079
2080 }
2081
2082 function editSectionLink( $nt, $section ) {
2083 global $wgRequest;
2084 global $wgContLang;
2085
2086 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2087 # Section edit links would be out of sync on an old page.
2088 # But, if we're diffing to the current page, they'll be
2089 # correct.
2090 return '';
2091 }
2092
2093 $editurl = '&section='.$section;
2094 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2095
2096 if( $wgContLang->isRTL() ) {
2097 $farside = 'left';
2098 $nearside = 'right';
2099 } else {
2100 $farside = 'right';
2101 $nearside = 'left';
2102 }
2103 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2104
2105 }
2106
2107 /**
2108 * @access public
2109 */
2110 function suppressUrlExpansion() {
2111 return false;
2112 }
2113 }
2114
2115 }
2116 ?>