restore old order of replaceInternal/replaceExternal, mask absolute URLs
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2
3 /**
4 *
5 * @package MediaWiki
6 */
7
8 /**
9 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
10 */
11 if( defined( "MEDIAWIKI" ) ) {
12
13 # See skin.doc
14 require_once( 'Image.php' );
15
16 # These are the INTERNAL names, which get mapped directly to class names and
17 # file names in ./skins/. For display purposes, the Language class has
18 # internationalized names
19 #
20 /*
21 $wgValidSkinNames = array(
22 'standard' => 'Standard',
23 'nostalgia' => 'Nostalgia',
24 'cologneblue' => 'CologneBlue'
25 );
26 if( $wgUsePHPTal ) {
27 #$wgValidSkinNames[] = 'PHPTal';
28 #$wgValidSkinNames['davinci'] = 'DaVinci';
29 #$wgValidSkinNames['mono'] = 'Mono';
30 #$wgValidSkinNames['monobookminimal'] = 'MonoBookMinimal';
31 $wgValidSkinNames['monobook'] = 'MonoBook';
32 $wgValidSkinNames['myskin'] = 'MySkin';
33 $wgValidSkinNames['chick'] = 'Chick';
34 }
35 */
36
37 # Get a list of all skins available in /skins/
38 # Build using the regular expression '^(.*).php$'
39 # Array keys are all lower case, array value keep the case used by filename
40 #
41
42 $skinDir = dir($IP.'/skins');
43
44 # while code from www.php.net
45 while (false !== ($file = $skinDir->read())) {
46 if(preg_match('/^(.*).php$/',$file, $matches)) {
47 $aSkin = $matches[1];
48 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
49 }
50 }
51 $skinDir->close();
52 unset($matches);
53
54 require_once( 'RecentChange.php' );
55
56 global $wgLinkHolders;
57 $wgLinkHolders = array(
58 'namespaces' => array(),
59 'dbkeys' => array(),
60 'queries' => array(),
61 'texts' => array(),
62 'titles' => array()
63 );
64 global $wgInterwikiLinkHolders;
65 $wgInterwikiLinkHolders = array();
66
67 /**
68 * @todo document
69 * @package MediaWiki
70 */
71 class RCCacheEntry extends RecentChange
72 {
73 var $secureName, $link;
74 var $curlink , $difflink, $lastlink , $usertalklink , $versionlink ;
75 var $userlink, $timestamp, $watched;
76
77 function newFromParent( $rc )
78 {
79 $rc2 = new RCCacheEntry;
80 $rc2->mAttribs = $rc->mAttribs;
81 $rc2->mExtra = $rc->mExtra;
82 return $rc2;
83 }
84 } ;
85
86
87 /**
88 * The main skin class that provide methods and properties for all other skins
89 * including PHPTal skins.
90 * This base class is also the "Standard" skin.
91 * @package MediaWiki
92 */
93 class Skin {
94 /**#@+
95 * @access private
96 */
97 var $lastdate, $lastline;
98 var $linktrail ; # linktrail regexp
99 var $rc_cache ; # Cache for Enhanced Recent Changes
100 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
101 var $rcMoveIndex;
102 var $postParseLinkColour = false;
103 /**#@-*/
104
105 function Skin() {
106 $this->linktrail = wfMsg('linktrail');
107 }
108
109 function getSkinNames() {
110 global $wgValidSkinNames;
111 return $wgValidSkinNames;
112 }
113
114 function getStylesheet() {
115 return 'common/wikistandard.css';
116 }
117
118 function getSkinName() {
119 return 'standard';
120 }
121
122 /**
123 * Get/set accessor for delayed link colouring
124 */
125 function postParseLinkColour( $setting = NULL ) {
126 return wfSetVar( $this->postParseLinkColour, $setting );
127 }
128
129 function qbSetting() {
130 global $wgOut, $wgUser;
131
132 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
133 $q = $wgUser->getOption( 'quickbar' );
134 if ( '' == $q ) { $q = 0; }
135 return $q;
136 }
137
138 function initPage( &$out ) {
139 $fname = 'Skin::initPage';
140 wfProfileIn( $fname );
141
142 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => '/favicon.ico' ) );
143
144 $this->addMetadataLinks($out);
145
146 wfProfileOut( $fname );
147 }
148
149 function addMetadataLinks( &$out ) {
150 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf, $wgRdfMimeType, $action;
151 global $wgRightsPage, $wgRightsUrl;
152
153 if( $out->isArticleRelated() ) {
154 # note: buggy CC software only reads first "meta" link
155 if( $wgEnableCreativeCommonsRdf ) {
156 $out->addMetadataLink( array(
157 'title' => 'Creative Commons',
158 'type' => 'application/rdf+xml',
159 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
160 }
161 if( $wgEnableDublinCoreRdf ) {
162 $out->addMetadataLink( array(
163 'title' => 'Dublin Core',
164 'type' => 'application/rdf+xml',
165 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
166 }
167 }
168 $copyright = '';
169 if( $wgRightsPage ) {
170 $copy = Title::newFromText( $wgRightsPage );
171 if( $copy ) {
172 $copyright = $copy->getLocalURL();
173 }
174 }
175 if( !$copyright && $wgRightsUrl ) {
176 $copyright = $wgRightsUrl;
177 }
178 if( $copyright ) {
179 $out->addLink( array(
180 'rel' => 'copyright',
181 'href' => $copyright ) );
182 }
183 }
184
185 function outputPage( &$out ) {
186 global $wgDebugComments;
187
188 wfProfileIn( 'Skin::outputPage' );
189 $this->initPage( $out );
190 $out->out( $out->headElement() );
191
192 $out->out( "\n<body" );
193 $ops = $this->getBodyOptions();
194 foreach ( $ops as $name => $val ) {
195 $out->out( " $name='$val'" );
196 }
197 $out->out( ">\n" );
198 if ( $wgDebugComments ) {
199 $out->out( "<!-- Wiki debugging output:\n" .
200 $out->mDebugtext . "-->\n" );
201 }
202 $out->out( $this->beforeContent() );
203
204 $out->out( $out->mBodytext . "\n" );
205
206 $out->out( $this->afterContent() );
207
208 wfProfileClose();
209 $out->out( $out->reportTime() );
210
211 $out->out( "\n</body></html>" );
212 }
213
214 function getHeadScripts() {
215 global $wgStylePath, $wgUser, $wgContLang, $wgAllowUserJs;
216 $r = "<script type=\"text/javascript\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
217 if( $wgAllowUserJs && $wgUser->getID() != 0 ) { # logged in
218 $userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
219 $userjs = htmlspecialchars($this->makeUrl($userpage.'/'.$this->getSkinName().'.js', 'action=raw&ctype=text/javascript'));
220 $r .= '<script type="text/javascript" src="'.$userjs."\"></script>\n";
221 }
222 return $r;
223 }
224
225 # get the user/site-specific stylesheet, SkinPHPTal called from RawPage.php (settings are cached that way)
226 function getUserStylesheet() {
227 global $wgOut, $wgStylePath, $wgContLang, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
228 $sheet = $this->getStylesheet();
229 $action = $wgRequest->getText('action');
230 $s = "@import \"$wgStylePath/$sheet\";\n";
231 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
232 if( $wgAllowUserCss && $wgUser->getID() != 0 ) { # logged in
233 if($wgTitle->isCssSubpage() and $action == 'submit' and $wgTitle->userCanEditCssJsSubpage()) {
234 $s .= $wgRequest->getText('wpTextbox1');
235 } else {
236 $userpage = $wgContLang->getNsText( Namespace::getUser() ) . ":" . $wgUser->getName();
237 $s.= '@import "'.$this->makeUrl($userpage.'/'.$this->getSkinName().'.css', 'action=raw&ctype=text/css').'";'."\n";
238 }
239 }
240 $s .= $this->doGetUserStyles();
241 return $s."\n";
242 }
243
244 /**
245 * placeholder, returns generated js in monobook
246 */
247 function getUserJs() { return; }
248
249 /**
250 * Return html code that include User stylesheets
251 */
252 function getUserStyles() {
253 global $wgOut, $wgStylePath, $wgLang;
254 $s = "<style type='text/css'>\n";
255 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
256 $s .= $this->getUserStylesheet();
257 $s .= "/*]]>*/ /* */\n";
258 $s .= "</style>\n";
259 return $s;
260 }
261
262 /**
263 * Some styles that are set by user through the user settings interface.
264 */
265 function doGetUserStyles() {
266 global $wgUser, $wgContLang;
267
268 $csspage = $wgContLang->getNsText( NS_MEDIAWIKI ) . ':' . $this->getSkinName() . '.css';
269 $s = '@import "'.$this->makeUrl($csspage, 'action=raw&ctype=text/css')."\";\n";
270
271 if ( 1 == $wgUser->getOption( 'underline' ) ) {
272 # Don't override browser settings
273 } else {
274 # CHECK MERGE @@@
275 # Force no underline
276 $s .= "a { text-decoration: none; }\n";
277 }
278 if ( 1 == $wgUser->getOption( 'highlightbroken' ) ) {
279 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
280 }
281 if ( 1 == $wgUser->getOption( 'justify' ) ) {
282 $s .= "#article { text-align: justify; }\n";
283 }
284 return $s;
285 }
286
287 function getBodyOptions() {
288 global $wgUser, $wgTitle, $wgNamespaceBackgrounds, $wgOut, $wgRequest;
289
290 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
291
292 if ( 0 != $wgTitle->getNamespace() ) {
293 $a = array( 'bgcolor' => '#ffffec' );
294 }
295 else $a = array( 'bgcolor' => '#FFFFFF' );
296 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
297 (!$wgTitle->isProtected() || $wgUser->isAllowed('protect')) ) {
298 $t = wfMsg( 'editthispage' );
299 $oid = $red = '';
300 if ( !empty($redirect) && $redirect == 'no' ) {
301 $red = "&redirect={$redirect}";
302 }
303 if ( !empty($oldid) && ! isset( $diff ) ) {
304 $oid = "&oldid=" . IntVal( $oldid );
305 }
306 $s = $wgTitle->getFullURL( "action=edit{$oid}{$red}" );
307 $s = 'document.location = "' .$s .'";';
308 $a += array ('ondblclick' => $s);
309
310 }
311 $a['onload'] = $wgOut->getOnloadHandler();
312 return $a;
313 }
314
315 function getExternalLinkAttributes( $link, $text, $class='' ) {
316 global $wgUser, $wgOut, $wgContLang;
317
318 $same = ($link == $text);
319 $link = urldecode( $link );
320 $link = $wgContLang->checkTitleEncoding( $link );
321 $link = str_replace( '_', ' ', $link );
322 $link = htmlspecialchars( $link );
323
324 $r = ($class != '') ? " class='$class'" : " class='external'";
325
326 if ( !$same && $wgUser->getOption( 'hover' ) ) {
327 $r .= " title=\"{$link}\"";
328 }
329 return $r;
330 }
331
332 function getInternalLinkAttributes( $link, $text, $broken = false ) {
333 global $wgUser, $wgOut;
334
335 $link = urldecode( $link );
336 $link = str_replace( '_', ' ', $link );
337 $link = htmlspecialchars( $link );
338
339 if ( $broken == 'stub' ) {
340 $r = ' class="stub"';
341 } else if ( $broken == 'yes' ) {
342 $r = ' class="new"';
343 } else {
344 $r = '';
345 }
346
347 if ( 1 == $wgUser->getOption( 'hover' ) ) {
348 $r .= " title=\"{$link}\"";
349 }
350 return $r;
351 }
352
353 /**
354 * @param bool $broken
355 */
356 function getInternalLinkAttributesObj( &$nt, $text, $broken = false ) {
357 global $wgUser, $wgOut;
358
359 if ( $broken == 'stub' ) {
360 $r = ' class="stub"';
361 } else if ( $broken == 'yes' ) {
362 $r = ' class="new"';
363 } else {
364 $r = '';
365 }
366
367 if ( 1 == $wgUser->getOption( 'hover' ) ) {
368 $r .= ' title="' . $nt->getEscapedText() . '"';
369 }
370 return $r;
371 }
372
373 /**
374 * URL to the logo
375 */
376 function getLogo() {
377 global $wgLogo;
378 return $wgLogo;
379 }
380
381 /**
382 * This will be called immediately after the <body> tag. Split into
383 * two functions to make it easier to subclass.
384 */
385 function beforeContent() {
386 global $wgUser, $wgOut;
387
388 return $this->doBeforeContent();
389 }
390
391 function doBeforeContent() {
392 global $wgUser, $wgOut, $wgTitle, $wgContLang, $wgSiteNotice;
393 $fname = 'Skin::doBeforeContent';
394 wfProfileIn( $fname );
395
396 $s = '';
397 $qb = $this->qbSetting();
398
399 if( $langlinks = $this->otherLanguages() ) {
400 $rows = 2;
401 $borderhack = '';
402 } else {
403 $rows = 1;
404 $langlinks = false;
405 $borderhack = 'class="top"';
406 }
407
408 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
409 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
410
411 $shove = ($qb != 0);
412 $left = ($qb == 1 || $qb == 3);
413 if($wgContLang->isRTL()) $left = !$left;
414
415 if ( !$shove ) {
416 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
417 $this->logoText() . '</td>';
418 } elseif( $left ) {
419 $s .= $this->getQuickbarCompensator( $rows );
420 }
421 $l = $wgContLang->isRTL() ? 'right' : 'left';
422 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
423
424 $s .= $this->topLinks() ;
425 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
426
427 $r = $wgContLang->isRTL() ? "left" : "right";
428 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
429 $s .= $this->nameAndLogin();
430 $s .= "\n<br />" . $this->searchForm() . "</td>";
431
432 if ( $langlinks ) {
433 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
434 }
435
436 if ( $shove && !$left ) { # Right
437 $s .= $this->getQuickbarCompensator( $rows );
438 }
439 $s .= "</tr>\n</table>\n</div>\n";
440 $s .= "\n<div id='article'>\n";
441
442 if( $wgSiteNotice ) {
443 $s .= "\n<div id='siteNotice'>$wgSiteNotice</div>\n";
444 }
445 $s .= $this->pageTitle();
446 $s .= $this->pageSubtitle() ;
447 $s .= $this->getCategories();
448 wfProfileOut( $fname );
449 return $s;
450 }
451
452
453 function getCategoryLinks () {
454 global $wgOut, $wgTitle, $wgUser, $wgParser;
455 global $wgUseCategoryMagic, $wgUseCategoryBrowser, $wgLang;
456
457 if( !$wgUseCategoryMagic ) return '' ;
458 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
459
460 # Taken out so that they will be displayed in previews -- TS
461 #if( !$wgOut->isArticle() ) return '';
462
463 $t = implode ( ' | ' , $wgOut->mCategoryLinks ) ;
464 $s = $this->makeKnownLink( 'Special:Categories',
465 wfMsg( 'categories' ), 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
466 . ': ' . $t;
467
468 # optional 'dmoz-like' category browser. Will be shown under the list
469 # of categories an article belong to
470 if($wgUseCategoryBrowser) {
471 $s .= '<br/><hr/>';
472
473 # get a big array of the parents tree
474 $parenttree = $wgTitle->getCategorieBrowser();
475
476 # Render the array as a serie of links
477 function walkThrough ($tree) {
478 global $wgUser;
479 $sk = $wgUser->getSkin();
480 $return = '';
481 foreach($tree as $element => $parent) {
482 if(empty($parent)) {
483 # element start a new list
484 $return .= '<br />';
485 } else {
486 # grab the others elements
487 $return .= walkThrough($parent);
488 }
489 # add our current element to the list
490 $eltitle = Title::NewFromText($element);
491 # FIXME : should be makeLink() [AV]
492 $return .= $sk->makeKnownLink($element, $eltitle->getText()).' &gt; ';
493 }
494 return $return;
495 }
496
497 $s .= walkThrough($parenttree);
498 }
499
500 return $s;
501 }
502
503 function getCategories() {
504 $catlinks=$this->getCategoryLinks();
505 if(!empty($catlinks)) {
506 return "<p class='catlinks'>{$catlinks}</p>";
507 }
508 }
509
510 function getQuickbarCompensator( $rows = 1 ) {
511 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
512 }
513
514 # This gets called immediately before the </body> tag.
515 #
516 function afterContent() {
517 global $wgUser, $wgOut, $wgServer;
518 global $wgTitle, $wgLang;
519
520 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
521 return $printfooter . $this->doAfterContent();
522 }
523
524 function printSource() {
525 global $wgTitle;
526 $url = htmlspecialchars( $wgTitle->getFullURL() );
527 return wfMsg( "retrievedfrom", "<a href=\"$url\">$url</a>" );
528 }
529
530 function printFooter() {
531 return "<p>" . $this->printSource() .
532 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
533 }
534
535 function doAfterContent() {
536 # overloaded by derived classes
537 }
538
539 function pageTitleLinks() {
540 global $wgOut, $wgTitle, $wgUser, $wgContLang, $wgUseApproval, $wgRequest;
541
542 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
543 $action = $wgRequest->getText( 'action' );
544
545 $s = $this->printableLink();
546 $disclaimer = $this->disclaimerLink(); # may be empty
547 if( $disclaimer ) {
548 $s .= ' | ' . $disclaimer;
549 }
550
551 if ( $wgOut->isArticleRelated() ) {
552 if ( $wgTitle->getNamespace() == Namespace::getImage() ) {
553 $name = $wgTitle->getDBkey();
554 $link = htmlspecialchars( Image::wfImageUrl( $name ) );
555 $style = $this->getInternalLinkAttributes( $link, $name );
556 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
557 }
558 # This will show the "Approve" link if $wgUseApproval=true;
559 if ( isset ( $wgUseApproval ) && $wgUseApproval )
560 {
561 $t = $wgTitle->getDBkey();
562 $name = 'Approve this article' ;
563 $link = "http://test.wikipedia.org/w/magnus/wiki.phtml?title={$t}&action=submit&doit=1" ;
564 #htmlspecialchars( wfImageUrl( $name ) );
565 $style = $this->getExternalLinkAttributes( $link, $name );
566 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>" ;
567 }
568 }
569 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
570 $s .= ' | ' . $this->makeKnownLink( $wgTitle->getPrefixedText(),
571 wfMsg( 'currentrev' ) );
572 }
573
574 if ( $wgUser->getNewtalk() ) {
575 # do not show "You have new messages" text when we are viewing our
576 # own talk page
577
578 if(!(strcmp($wgTitle->getText(),$wgUser->getName()) == 0 &&
579 $wgTitle->getNamespace()==Namespace::getTalk(Namespace::getUser()))) {
580 $n =$wgUser->getName();
581 $tl = $this->makeKnownLink( $wgContLang->getNsText(
582 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
583 wfMsg('newmessageslink') );
584 $s.= ' | <strong>'. wfMsg( 'newmessages', $tl ) . '</strong>';
585 # disable caching
586 $wgOut->setSquidMaxage(0);
587 $wgOut->enableClientCache(false);
588 }
589 }
590
591 $undelete = $this->getUndeleteLink();
592 if( !empty( $undelete ) ) {
593 $s .= ' | '.$undelete;
594 }
595 return $s;
596 }
597
598 function getUndeleteLink() {
599 global $wgUser, $wgTitle, $wgContLang, $action;
600 if( $wgUser->isAllowed('rollback') &&
601 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
602 ($n = $wgTitle->isDeleted() ) ) {
603 return wfMsg( 'thisisdeleted',
604 $this->makeKnownLink(
605 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
606 wfMsg( 'restorelink', $n ) ) );
607 }
608 return '';
609 }
610
611 function printableLink() {
612 global $wgOut, $wgFeedClasses, $wgRequest;
613
614 $baseurl = $_SERVER['REQUEST_URI'];
615 if( strpos( '?', $baseurl ) == false ) {
616 $baseurl .= '?';
617 } else {
618 $baseurl .= '&';
619 }
620 $baseurl = htmlspecialchars( $baseurl );
621 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
622
623 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
624 if( $wgOut->isSyndicated() ) {
625 foreach( $wgFeedClasses as $format => $class ) {
626 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
627 $s .= " | <a href=\"$feedurl\">{$format}</a>";
628 }
629 }
630 return $s;
631 }
632
633 function pageTitle() {
634 global $wgOut, $wgTitle, $wgUser;
635
636 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
637 if($wgUser->getOption( 'editsectiononrightclick' ) && $wgTitle->userCanEdit()) { $s=$this->editSectionScript($wgTitle, 0,$s);}
638 return $s;
639 }
640
641 function pageSubtitle() {
642 global $wgOut;
643
644 $sub = $wgOut->getSubtitle();
645 if ( '' == $sub ) {
646 global $wgExtraSubtitle;
647 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
648 }
649 $subpages = $this->subPageSubtitle();
650 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
651 $s = "<p class='subtitle'>{$sub}</p>\n";
652 return $s;
653 }
654
655 function subPageSubtitle() {
656 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
657 $subpages = '';
658 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
659 $ptext=$wgTitle->getPrefixedText();
660 if(preg_match('/\//',$ptext)) {
661 $links = explode('/',$ptext);
662 $c = 0;
663 $growinglink = '';
664 foreach($links as $link) {
665 $c++;
666 if ($c<count($links)) {
667 $growinglink .= $link;
668 $getlink = $this->makeLink( $growinglink, $link );
669 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
670 if ($c>1) {
671 $subpages .= ' | ';
672 } else {
673 $subpages .= '&lt; ';
674 }
675 $subpages .= $getlink;
676 $growinglink .= '/';
677 }
678 }
679 }
680 }
681 return $subpages;
682 }
683
684 function nameAndLogin() {
685 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader, $wgIP;
686
687 $li = $wgContLang->specialPage( 'Userlogin' );
688 $lo = $wgContLang->specialPage( 'Userlogout' );
689
690 $s = '';
691 if ( 0 == $wgUser->getID() ) {
692 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
693 $n = $wgIP;
694
695 $tl = $this->makeKnownLink( $wgContLang->getNsText(
696 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
697 $wgContLang->getNsText( Namespace::getTalk( 0 ) ) );
698
699 $s .= $n . ' ('.$tl.')';
700 } else {
701 $s .= wfMsg('notloggedin');
702 }
703
704 $rt = $wgTitle->getPrefixedURL();
705 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
706 $q = '';
707 } else { $q = "returnto={$rt}"; }
708
709 $s .= "\n<br />" . $this->makeKnownLink( $li,
710 wfMsg( 'login' ), $q );
711 } else {
712 $n = $wgUser->getName();
713 $rt = $wgTitle->getPrefixedURL();
714 $tl = $this->makeKnownLink( $wgContLang->getNsText(
715 Namespace::getTalk( Namespace::getUser() ) ) . ":{$n}",
716 $wgContLang->getNsText( Namespace::getTalk( 0 ) ) );
717
718 $tl = " ({$tl})";
719
720 $s .= $this->makeKnownLink( $wgContLang->getNsText(
721 Namespace::getUser() ) . ":{$n}", $n ) . "{$tl}<br />" .
722 $this->makeKnownLink( $lo, wfMsg( 'logout' ),
723 "returnto={$rt}" ) . ' | ' .
724 $this->specialLink( 'preferences' );
725 }
726 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
727 wfMsg( 'help' ) );
728
729 return $s;
730 }
731
732 function getSearchLink() {
733 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
734 return $searchPage->getLocalURL();
735 }
736
737 function escapeSearchLink() {
738 return htmlspecialchars( $this->getSearchLink() );
739 }
740
741 function searchForm() {
742 global $wgRequest;
743 $search = $wgRequest->getText( 'search' );
744
745 $s = '<form name="search" class="inline" method="post" action="'
746 . $this->escapeSearchLink() . "\">\n"
747 . '<input type="text" name="search" size="19" value="'
748 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
749 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
750 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
751
752 return $s;
753 }
754
755 function topLinks() {
756 global $wgOut;
757 $sep = " |\n";
758
759 $s = $this->mainPageLink() . $sep
760 . $this->specialLink( 'recentchanges' );
761
762 if ( $wgOut->isArticleRelated() ) {
763 $s .= $sep . $this->editThisPage()
764 . $sep . $this->historyLink();
765 }
766 # Many people don't like this dropdown box
767 #$s .= $sep . $this->specialPagesList();
768
769 return $s;
770 }
771
772 function bottomLinks() {
773 global $wgOut, $wgUser, $wgTitle;
774 $sep = " |\n";
775
776 $s = '';
777 if ( $wgOut->isArticleRelated() ) {
778 $s .= '<strong>' . $this->editThisPage() . '</strong>';
779 if ( 0 != $wgUser->getID() ) {
780 $s .= $sep . $this->watchThisPage();
781 }
782 $s .= $sep . $this->talkLink()
783 . $sep . $this->historyLink()
784 . $sep . $this->whatLinksHere()
785 . $sep . $this->watchPageLinksLink();
786
787 if ( $wgTitle->getNamespace() == Namespace::getUser()
788 || $wgTitle->getNamespace() == Namespace::getTalk(Namespace::getUser()) )
789
790 {
791 $id=User::idFromName($wgTitle->getText());
792 $ip=User::isIP($wgTitle->getText());
793
794 if($id || $ip) { # both anons and non-anons have contri list
795 $s .= $sep . $this->userContribsLink();
796 }
797 if ( 0 != $wgUser->getID() ) { # show only to signed in users
798 if($id) { # can only email non-anons
799 $s .= $sep . $this->emailUserLink();
800 }
801 }
802 }
803 if ( $wgTitle->getArticleId() ) {
804 $s .= "\n<br />";
805 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
806 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
807 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
808 }
809 $s .= "<br />\n" . $this->otherLanguages();
810 }
811 return $s;
812 }
813
814 function pageStats() {
815 global $wgOut, $wgLang, $wgArticle, $wgRequest;
816 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax;
817
818 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
819 if ( ! $wgOut->isArticle() ) { return ''; }
820 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
821 if ( 0 == $wgArticle->getID() ) { return ''; }
822
823 $s = '';
824 if ( !$wgDisableCounters ) {
825 $count = $wgLang->formatNum( $wgArticle->getCount() );
826 if ( $count ) {
827 $s = wfMsg( 'viewcount', $count );
828 }
829 }
830
831 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
832 require_once("Credits.php");
833 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
834 } else {
835 $s .= $this->lastModified();
836 }
837
838 return $s . ' ' . $this->getCopyright();
839 }
840
841 function getCopyright() {
842 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
843
844
845 $oldid = $wgRequest->getVal( 'oldid' );
846 $diff = $wgRequest->getVal( 'diff' );
847
848 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
849 $msg = 'history_copyright';
850 } else {
851 $msg = 'copyright';
852 }
853
854 $out = '';
855 if( $wgRightsPage ) {
856 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
857 } elseif( $wgRightsUrl ) {
858 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
859 } else {
860 # Give up now
861 return $out;
862 }
863 $out .= wfMsgForContent( $msg, $link );
864 return $out;
865 }
866
867 function getCopyrightIcon() {
868 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRightsIcon;
869 $out = '';
870 if( $wgRightsIcon ) {
871 $icon = htmlspecialchars( $wgRightsIcon );
872 if( $wgRightsUrl ) {
873 $url = htmlspecialchars( $wgRightsUrl );
874 $out .= '<a href="'.$url.'">';
875 }
876 $text = htmlspecialchars( $wgRightsText );
877 $out .= "<img src=\"$icon\" alt='$text' />";
878 if( $wgRightsUrl ) {
879 $out .= '</a>';
880 }
881 }
882 return $out;
883 }
884
885 function getPoweredBy() {
886 global $wgStylePath;
887 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
888 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
889 return $img;
890 }
891
892 function lastModified() {
893 global $wgLang, $wgArticle;
894
895 $timestamp = $wgArticle->getTimestamp();
896 if ( $timestamp ) {
897 $d = $wgLang->timeanddate( $wgArticle->getTimestamp(), true );
898 $s = ' ' . wfMsg( 'lastmodified', $d );
899 } else {
900 $s = '';
901 }
902 return $s;
903 }
904
905 function logoText( $align = '' ) {
906 if ( '' != $align ) { $a = " align='{$align}'"; }
907 else { $a = ''; }
908
909 $mp = wfMsg( 'mainpage' );
910 $titleObj = Title::newFromText( $mp );
911 if ( is_object( $titleObj ) ) {
912 $url = $titleObj->escapeLocalURL();
913 } else {
914 $url = '';
915 }
916
917 $logourl = $this->getLogo();
918 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
919 return $s;
920 }
921
922 function specialPagesList() {
923 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript;
924 require_once('SpecialPage.php');
925 $a = array();
926 $pages = SpecialPage::getPages();
927
928 foreach ( $pages[''] as $name => $page ) {
929 $a[$name] = $page->getDescription();
930 }
931 if ( $wgUser->isSysop() )
932 {
933 foreach ( $pages['sysop'] as $name => $page ) {
934 $a[$name] = $page->getDescription();
935 }
936 }
937 if ( $wgUser->isDeveloper() )
938 {
939 foreach ( $pages['developer'] as $name => $page ) {
940 $a[$name] = $page->getDescription() ;
941 }
942 }
943 $go = wfMsg( 'go' );
944 $sp = wfMsg( 'specialpages' );
945 $spp = $wgContLang->specialPage( 'Specialpages' );
946
947 $s = '<form id="specialpages" method="get" class="inline" ' .
948 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
949 $s .= "<select name=\"wpDropdown\">\n";
950 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
951
952 foreach ( $a as $name => $desc ) {
953 $p = $wgContLang->specialPage( $name );
954 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
955 }
956 $s .= "</select>\n";
957 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
958 $s .= "</form>\n";
959 return $s;
960 }
961
962 function mainPageLink() {
963 $mp = wfMsgForContent( 'mainpage' );
964 $mptxt = wfMsg( 'mainpage');
965 $s = $this->makeKnownLink( $mp, $mptxt );
966 return $s;
967 }
968
969 function copyrightLink() {
970 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
971 wfMsg( 'copyrightpagename' ) );
972 return $s;
973 }
974
975 function aboutLink() {
976 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
977 wfMsg( 'aboutsite' ) );
978 return $s;
979 }
980
981
982 function disclaimerLink() {
983 $disclaimers = wfMsg( 'disclaimers' );
984 if ($disclaimers == '-') {
985 return "";
986 } else {
987 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
988 $disclaimers );
989 }
990 }
991
992 function editThisPage() {
993 global $wgOut, $wgTitle, $wgRequest;
994
995 $oldid = $wgRequest->getVal( 'oldid' );
996 $diff = $wgRequest->getVal( 'diff' );
997 $redirect = $wgRequest->getVal( 'redirect' );
998
999 if ( ! $wgOut->isArticleRelated() ) {
1000 $s = wfMsg( 'protectedpage' );
1001 } else {
1002 $n = $wgTitle->getPrefixedText();
1003 if ( $wgTitle->userCanEdit() ) {
1004 $t = wfMsg( 'editthispage' );
1005 } else {
1006 #$t = wfMsg( "protectedpage" );
1007 $t = wfMsg( 'viewsource' );
1008 }
1009 $oid = $red = '';
1010
1011 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
1012 if ( $oldid && ! isset( $diff ) ) {
1013 $oid = '&oldid='.$oldid;
1014 }
1015 $s = $this->makeKnownLink( $n, $t, "action=edit{$oid}{$red}" );
1016 }
1017 return $s;
1018 }
1019
1020 function deleteThisPage() {
1021 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1022
1023 $diff = $wgRequest->getVal( 'diff' );
1024 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1025 $n = $wgTitle->getPrefixedText();
1026 $t = wfMsg( 'deletethispage' );
1027
1028 $s = $this->makeKnownLink( $n, $t, 'action=delete' );
1029 } else {
1030 $s = '';
1031 }
1032 return $s;
1033 }
1034
1035 function protectThisPage() {
1036 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1037
1038 $diff = $wgRequest->getVal( 'diff' );
1039 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1040 $n = $wgTitle->getPrefixedText();
1041
1042 if ( $wgTitle->isProtected() ) {
1043 $t = wfMsg( 'unprotectthispage' );
1044 $q = 'action=unprotect';
1045 } else {
1046 $t = wfMsg( 'protectthispage' );
1047 $q = 'action=protect';
1048 }
1049 $s = $this->makeKnownLink( $n, $t, $q );
1050 } else {
1051 $s = '';
1052 }
1053 return $s;
1054 }
1055
1056 function watchThisPage() {
1057 global $wgUser, $wgOut, $wgTitle;
1058
1059 if ( $wgOut->isArticleRelated() ) {
1060 $n = $wgTitle->getPrefixedText();
1061
1062 if ( $wgTitle->userIsWatching() ) {
1063 $t = wfMsg( 'unwatchthispage' );
1064 $q = 'action=unwatch';
1065 } else {
1066 $t = wfMsg( 'watchthispage' );
1067 $q = 'action=watch';
1068 }
1069 $s = $this->makeKnownLink( $n, $t, $q );
1070 } else {
1071 $s = wfMsg( 'notanarticle' );
1072 }
1073 return $s;
1074 }
1075
1076 function moveThisPage() {
1077 global $wgTitle, $wgContLang;
1078
1079 if ( $wgTitle->userCanEdit() ) {
1080 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Movepage' ),
1081 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1082 } // no message if page is protected - would be redundant
1083 return $s;
1084 }
1085
1086 function historyLink() {
1087 global $wgTitle;
1088
1089 $s = $this->makeKnownLink( $wgTitle->getPrefixedText(),
1090 wfMsg( 'history' ), 'action=history' );
1091 return $s;
1092 }
1093
1094 function whatLinksHere() {
1095 global $wgTitle, $wgContLang;
1096
1097 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Whatlinkshere' ),
1098 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1099 return $s;
1100 }
1101
1102 function userContribsLink() {
1103 global $wgTitle, $wgContLang;
1104
1105 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
1106 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1107 return $s;
1108 }
1109
1110 function emailUserLink() {
1111 global $wgTitle, $wgContLang;
1112
1113 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Emailuser' ),
1114 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1115 return $s;
1116 }
1117
1118 function watchPageLinksLink() {
1119 global $wgOut, $wgTitle, $wgContLang;
1120
1121 if ( ! $wgOut->isArticleRelated() ) {
1122 $s = '(' . wfMsg( 'notanarticle' ) . ')';
1123 } else {
1124 $s = $this->makeKnownLink( $wgContLang->specialPage(
1125 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1126 'target=' . $wgTitle->getPrefixedURL() );
1127 }
1128 return $s;
1129 }
1130
1131 function otherLanguages() {
1132 global $wgOut, $wgContLang, $wgTitle, $wgUseNewInterlanguage;
1133
1134 $a = $wgOut->getLanguageLinks();
1135 if ( 0 == count( $a ) ) {
1136 if ( !$wgUseNewInterlanguage ) return '';
1137 $ns = $wgContLang->getNsIndex ( $wgTitle->getNamespace () ) ;
1138 if ( $ns != 0 AND $ns != 1 ) return '' ;
1139 $pn = 'Intl' ;
1140 $x = 'mode=addlink&xt='.$wgTitle->getDBkey() ;
1141 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1142 wfMsg( 'intl' ) , $x );
1143 }
1144
1145 if ( !$wgUseNewInterlanguage ) {
1146 $s = wfMsg( 'otherlanguages' ) . ': ';
1147 } else {
1148 global $wgContLanguageCode ;
1149 $x = 'mode=zoom&xt='.$wgTitle->getDBkey() ;
1150 $x .= '&xl='.$wgContLanguageCode ;
1151 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Intl' ),
1152 wfMsg( 'otherlanguages' ) , $x ) . ': ' ;
1153 }
1154
1155 $s = wfMsg( 'otherlanguages' ) . ': ';
1156 $first = true;
1157 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1158 foreach( $a as $l ) {
1159 if ( ! $first ) { $s .= ' | '; }
1160 $first = false;
1161
1162 $nt = Title::newFromText( $l );
1163 $url = $nt->getFullURL();
1164 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1165
1166 if ( '' == $text ) { $text = $l; }
1167 $style = $this->getExternalLinkAttributes( $l, $text );
1168 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1169 }
1170 if($wgContLang->isRTL()) $s .= '</span>';
1171 return $s;
1172 }
1173
1174 function bugReportsLink() {
1175 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1176 wfMsg( 'bugreports' ) );
1177 return $s;
1178 }
1179
1180 function dateLink() {
1181 global $wgLinkCache;
1182 $t1 = Title::newFromText( gmdate( 'F j' ) );
1183 $t2 = Title::newFromText( gmdate( 'Y' ) );
1184
1185 $wgLinkCache->suspend();
1186 $id = $t1->getArticleID();
1187 $wgLinkCache->resume();
1188
1189 if ( 0 == $id ) {
1190 $s = $this->makeBrokenLink( $t1->getText() );
1191 } else {
1192 $s = $this->makeKnownLink( $t1->getText() );
1193 }
1194 $s .= ', ';
1195
1196 $wgLinkCache->suspend();
1197 $id = $t2->getArticleID();
1198 $wgLinkCache->resume();
1199
1200 if ( 0 == $id ) {
1201 $s .= $this->makeBrokenLink( $t2->getText() );
1202 } else {
1203 $s .= $this->makeKnownLink( $t2->getText() );
1204 }
1205 return $s;
1206 }
1207
1208 function talkLink() {
1209 global $wgContLang, $wgTitle, $wgLinkCache;
1210
1211 $tns = $wgTitle->getNamespace();
1212 if ( -1 == $tns ) { return ''; }
1213
1214 $pn = $wgTitle->getText();
1215 $tp = wfMsg( 'talkpage' );
1216 if ( Namespace::isTalk( $tns ) ) {
1217 $lns = Namespace::getSubject( $tns );
1218 switch($tns) {
1219 case 1:
1220 $text = wfMsg('articlepage');
1221 break;
1222 case 3:
1223 $text = wfMsg('userpage');
1224 break;
1225 case 5:
1226 $text = wfMsg('wikipediapage');
1227 break;
1228 case 7:
1229 $text = wfMsg('imagepage');
1230 break;
1231 default:
1232 $text= wfMsg('articlepage');
1233 }
1234 } else {
1235
1236 $lns = Namespace::getTalk( $tns );
1237 $text=$tp;
1238 }
1239 $n = $wgContLang->getNsText( $lns );
1240 if ( '' == $n ) { $link = $pn; }
1241 else { $link = $n.':'.$pn; }
1242
1243 $wgLinkCache->suspend();
1244 $s = $this->makeLink( $link, $text );
1245 $wgLinkCache->resume();
1246
1247 return $s;
1248 }
1249
1250 function commentLink() {
1251 global $wgContLang, $wgTitle, $wgLinkCache;
1252
1253 $tns = $wgTitle->getNamespace();
1254 if ( -1 == $tns ) { return ''; }
1255
1256 $lns = ( Namespace::isTalk( $tns ) ) ? $tns : Namespace::getTalk( $tns );
1257
1258 # assert Namespace::isTalk( $lns )
1259
1260 $n = $wgContLang->getNsText( $lns );
1261 $pn = $wgTitle->getText();
1262
1263 $link = $n.':'.$pn;
1264
1265 $wgLinkCache->suspend();
1266 $s = $this->makeKnownLink($link, wfMsg('postcomment'), 'action=edit&section=new');
1267 $wgLinkCache->resume();
1268
1269 return $s;
1270 }
1271
1272 /**
1273 * After all the page content is transformed into HTML, it makes
1274 * a final pass through here for things like table backgrounds.
1275 * @todo probably deprecated [AV]
1276 */
1277 function transformContent( $text ) {
1278 return $text;
1279 }
1280
1281 /**
1282 * Note: This function MUST call getArticleID() on the link,
1283 * otherwise the cache won't get updated properly. See LINKCACHE.DOC.
1284 */
1285 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
1286 wfProfileIn( 'Skin::makeLink' );
1287 $nt = Title::newFromText( $title );
1288 if ($nt) {
1289 $result = $this->makeLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1290 } else {
1291 wfDebug( 'Invalid title passed to Skin::makeLink(): "'.$title."\"\n" );
1292 $result = $text == "" ? $title : $text;
1293 }
1294
1295 wfProfileOut( 'Skin::makeLink' );
1296 return $result;
1297 }
1298
1299 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
1300 $nt = Title::newFromText( $title );
1301 if ($nt) {
1302 return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
1303 } else {
1304 wfDebug( 'Invalid title passed to Skin::makeKnownLink(): "'.$title."\"\n" );
1305 return $text == '' ? $title : $text;
1306 }
1307 }
1308
1309 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1310 $nt = Title::newFromText( $title );
1311 if ($nt) {
1312 return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1313 } else {
1314 wfDebug( 'Invalid title passed to Skin::makeBrokenLink(): "'.$title."\"\n" );
1315 return $text == '' ? $title : $text;
1316 }
1317 }
1318
1319 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
1320 $nt = Title::newFromText( $title );
1321 if ($nt) {
1322 return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1323 } else {
1324 wfDebug( 'Invalid title passed to Skin::makeStubLink(): "'.$title."\"\n" );
1325 return $text == '' ? $title : $text;
1326 }
1327 }
1328
1329 /**
1330 * Pass a title object, not a title string
1331 */
1332 function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
1333 global $wgOut, $wgUser, $wgLinkHolders;
1334 $fname = 'Skin::makeLinkObj';
1335
1336 # Fail gracefully
1337 if ( ! isset($nt) ) {
1338 # wfDebugDieBacktrace();
1339 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1340 }
1341
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 == $nt->getNamespace() && "" == $nt->getText() ) {
1362 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1363 } elseif ( ( -1 == $nt->getNamespace() ) ||
1364 ( NS_IMAGE == $nt->getNamespace() ) ) {
1365 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1366 } else {
1367 if ( $this->postParseLinkColour() ) {
1368 $inside = '';
1369 if ( '' != $trail ) {
1370 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1371 $inside = $m[1];
1372 $trail = $m[2];
1373 }
1374 }
1375
1376 # Allows wiki to bypass using linkcache, see OutputPage::parseLinkHolders()
1377 $nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() );
1378 $wgLinkHolders['dbkeys'][] = $nt->getDBkey();
1379 $wgLinkHolders['queries'][] = $query;
1380 $wgLinkHolders['texts'][] = $prefix.$text.$inside;
1381 $wgLinkHolders['titles'][] = $nt;
1382
1383 $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
1384 } else {
1385 # Work out link colour immediately
1386 $aid = $nt->getArticleID() ;
1387 if ( 0 == $aid ) {
1388 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
1389 } else {
1390 $threshold = $wgUser->getOption('stubthreshold') ;
1391 if ( $threshold > 0 ) {
1392 $dbr =& wfGetDB( DB_SLAVE );
1393 $s = $dbr->selectRow( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace',
1394 'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ;
1395 if ( $s !== false ) {
1396 $size = $s->x;
1397 if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) {
1398 $size = $threshold*2 ; # Really big
1399 }
1400 $dbr->freeResult( $res );
1401 } else {
1402 $size = $threshold*2 ; # Really big
1403 }
1404 } else {
1405 $size = 1 ;
1406 }
1407 if ( $size < $threshold ) {
1408 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
1409 } else {
1410 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1411 }
1412 }
1413 }
1414 }
1415 return $retVal;
1416 }
1417
1418 /**
1419 * Pass a title object, not a title string
1420 */
1421 function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
1422 global $wgOut, $wgTitle, $wgInputEncoding;
1423
1424 $fname = 'Skin::makeKnownLinkObj';
1425 wfProfileIn( $fname );
1426
1427 if ( !is_object( $nt ) ) {
1428 return $text;
1429 }
1430 $link = $nt->getPrefixedURL();
1431 # if ( '' != $section && substr($section,0,1) != "#" ) {
1432 # $section = ''
1433
1434 if ( '' == $link ) {
1435 $u = '';
1436 if ( '' == $text ) {
1437 $text = htmlspecialchars( $nt->getFragment() );
1438 }
1439 } else {
1440 $u = $nt->escapeLocalURL( $query );
1441 }
1442 if ( '' != $nt->getFragment() ) {
1443 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT, $wgInputEncoding ) );
1444 $replacearray = array(
1445 '%3A' => ':',
1446 '%' => '.'
1447 );
1448 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
1449 }
1450 if ( '' == $text ) {
1451 $text = htmlspecialchars( $nt->getPrefixedText() );
1452 }
1453 $style = $this->getInternalLinkAttributesObj( $nt, $text );
1454
1455 $inside = '';
1456 if ( '' != $trail ) {
1457 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1458 $inside = $m[1];
1459 $trail = $m[2];
1460 }
1461 }
1462 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
1463 wfProfileOut( $fname );
1464 return $r;
1465 }
1466
1467 /**
1468 * Pass a title object, not a title string
1469 */
1470 function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1471 global $wgOut, $wgUser;
1472
1473 # Fail gracefully
1474 if ( ! isset($nt) ) {
1475 # wfDebugDieBacktrace();
1476 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1477 }
1478
1479 $fname = 'Skin::makeBrokenLinkObj';
1480 wfProfileIn( $fname );
1481
1482 if ( '' == $query ) {
1483 $q = 'action=edit';
1484 } else {
1485 $q = 'action=edit&'.$query;
1486 }
1487 $u = $nt->escapeLocalURL( $q );
1488
1489 if ( '' == $text ) {
1490 $text = htmlspecialchars( $nt->getPrefixedText() );
1491 }
1492 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
1493
1494 $inside = '';
1495 if ( '' != $trail ) {
1496 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1497 $inside = $m[1];
1498 $trail = $m[2];
1499 }
1500 }
1501 if ( $wgUser->getOption( 'highlightbroken' ) ) {
1502 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1503 } else {
1504 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
1505 }
1506
1507 wfProfileOut( $fname );
1508 return $s;
1509 }
1510
1511 /**
1512 * Pass a title object, not a title string
1513 */
1514 function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1515 global $wgOut, $wgUser;
1516
1517 $link = $nt->getPrefixedURL();
1518
1519 $u = $nt->escapeLocalURL( $query );
1520
1521 if ( '' == $text ) {
1522 $text = htmlspecialchars( $nt->getPrefixedText() );
1523 }
1524 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
1525
1526 $inside = '';
1527 if ( '' != $trail ) {
1528 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1529 $inside = $m[1];
1530 $trail = $m[2];
1531 }
1532 }
1533 if ( $wgUser->getOption( 'highlightbroken' ) ) {
1534 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1535 } else {
1536 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
1537 }
1538 return $s;
1539 }
1540
1541 function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1542 $u = $nt->escapeLocalURL( $query );
1543 if ( '' == $text ) {
1544 $text = htmlspecialchars( $nt->getPrefixedText() );
1545 }
1546 $inside = '';
1547 if ( '' != $trail ) {
1548 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1549 $inside = $m[1];
1550 $trail = $m[2];
1551 }
1552 }
1553 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
1554 }
1555
1556 /* these are used extensively in SkinPHPTal, but also some other places */
1557 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1558 $title = Title::makeTitle( NS_SPECIAL, $name );
1559 $this->checkTitle($title, $name);
1560 return $title->getLocalURL( $urlaction );
1561 }
1562 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
1563 $title = Title::newFromText( $name );
1564 $title = $title->getTalkPage();
1565 $this->checkTitle($title, $name);
1566 return $title->getLocalURL( $urlaction );
1567 }
1568 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
1569 $title = Title::newFromText( $name );
1570 $title= $title->getSubjectPage();
1571 $this->checkTitle($title, $name);
1572 return $title->getLocalURL( $urlaction );
1573 }
1574 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1575 $title = Title::newFromText( wfMsgForContent($name) );
1576 $this->checkTitle($title, $name);
1577 return $title->getLocalURL( $urlaction );
1578 }
1579 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1580 $title = Title::newFromText( $name );
1581 $this->checkTitle($title, $name);
1582 return $title->getLocalURL( $urlaction );
1583 }
1584
1585 # If url string starts with http, consider as external URL, else
1586 # internal
1587 /*static*/ function makeInternalOrExternalUrl( $name ) {
1588 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1589 return $name;
1590 } else {
1591 return $this->makeUrl( $name );
1592 }
1593 }
1594
1595 # this can be passed the NS number as defined in Language.php
1596 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=0 ) {
1597 $title = Title::makeTitleSafe( $namespace, $name );
1598 $this->checkTitle($title, $name);
1599 return $title->getLocalURL( $urlaction );
1600 }
1601
1602 /* these return an array with the 'href' and boolean 'exists' */
1603 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1604 $title = Title::newFromText( $name );
1605 $this->checkTitle($title, $name);
1606 return array(
1607 'href' => $title->getLocalURL( $urlaction ),
1608 'exists' => $title->getArticleID() != 0?true:false
1609 );
1610 }
1611 /*static*/ function makeTalkUrlDetails ( $name, $urlaction='' ) {
1612 $title = Title::newFromText( $name );
1613 $title = $title->getTalkPage();
1614 $this->checkTitle($title, $name);
1615 return array(
1616 'href' => $title->getLocalURL( $urlaction ),
1617 'exists' => $title->getArticleID() != 0?true:false
1618 );
1619 }
1620 /*static*/ function makeArticleUrlDetails ( $name, $urlaction='' ) {
1621 $title = Title::newFromText( $name );
1622 $title= $title->getSubjectPage();
1623 $this->checkTitle($title, $name);
1624 return array(
1625 'href' => $title->getLocalURL( $urlaction ),
1626 'exists' => $title->getArticleID() != 0?true:false
1627 );
1628 }
1629 /*static*/ function makeI18nUrlDetails ( $name, $urlaction='' ) {
1630 $title = Title::newFromText( wfMsgForContent($name) );
1631 $this->checkTitle($title, $name);
1632 return array(
1633 'href' => $title->getLocalURL( $urlaction ),
1634 'exists' => $title->getArticleID() != 0?true:false
1635 );
1636 }
1637
1638 # make sure we have some title to operate on
1639 /*static*/ function checkTitle ( &$title, &$name ) {
1640 if(!is_object($title)) {
1641 $title = Title::newFromText( $name );
1642 if(!is_object($title)) {
1643 $title = Title::newFromText( '--error: link target missing--' );
1644 }
1645 }
1646 }
1647
1648 function fnamePart( $url ) {
1649 $basename = strrchr( $url, '/' );
1650 if ( false === $basename ) {
1651 $basename = $url;
1652 } else {
1653 $basename = substr( $basename, 1 );
1654 }
1655 return htmlspecialchars( $basename );
1656 }
1657
1658 function makeImage( $url, $alt = '' ) {
1659 global $wgOut;
1660 if ( '' == $alt ) {
1661 $alt = $this->fnamePart( $url );
1662 }
1663 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
1664 return $s;
1665 }
1666
1667 function makeImageLink( $name, $url, $alt = '' ) {
1668 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1669 return $this->makeImageLinkObj( $nt, $alt );
1670 }
1671
1672 function makeImageLinkObj( $nt, $alt = '' ) {
1673 global $wgContLang, $wgUseImageResize;
1674 $img = Image::newFromTitle( $nt );
1675 $url = $img->getViewURL();
1676
1677 $align = '';
1678 $prefix = $postfix = '';
1679
1680 # Check if the alt text is of the form "options|alt text"
1681 # Options are:
1682 # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
1683 # * left no resizing, just left align. label is used for alt= only
1684 # * right same, but right aligned
1685 # * none same, but not aligned
1686 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
1687 # * center center the image
1688 # * framed Keep original image size, no magnify-button.
1689
1690 $part = explode( '|', $alt);
1691
1692 $mwThumb =& MagicWord::get( MAG_IMG_THUMBNAIL );
1693 $mwLeft =& MagicWord::get( MAG_IMG_LEFT );
1694 $mwRight =& MagicWord::get( MAG_IMG_RIGHT );
1695 $mwNone =& MagicWord::get( MAG_IMG_NONE );
1696 $mwWidth =& MagicWord::get( MAG_IMG_WIDTH );
1697 $mwCenter =& MagicWord::get( MAG_IMG_CENTER );
1698 $mwFramed =& MagicWord::get( MAG_IMG_FRAMED );
1699 $alt = $part[count($part)-1];
1700
1701 $height = $framed = $thumb = false;
1702 $manual_thumb = "" ;
1703
1704 foreach( $part as $key => $val ) {
1705 $val_parts = explode ( "=" , $val , 2 ) ;
1706 $left_part = array_shift ( $val_parts ) ;
1707 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
1708 $thumb=true;
1709 } elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
1710 # use manually specified thumbnail
1711 $thumb=true;
1712 $manual_thumb = array_shift ( $val_parts ) ;
1713 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
1714 # remember to set an alignment, don't render immediately
1715 $align = 'right';
1716 } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
1717 # remember to set an alignment, don't render immediately
1718 $align = 'left';
1719 } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
1720 # remember to set an alignment, don't render immediately
1721 $align = 'center';
1722 } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
1723 # remember to set an alignment, don't render immediately
1724 $align = 'none';
1725 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
1726 # $match is the image width in pixels
1727 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
1728 $width = intval( $m[1] );
1729 $height = intval( $m[2] );
1730 } else {
1731 $width = intval($match);
1732 }
1733 } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
1734 $framed=true;
1735 }
1736 }
1737 if ( 'center' == $align )
1738 {
1739 $prefix = '<div class="center">';
1740 $postfix = '</div>';
1741 $align = 'none';
1742 }
1743
1744 if ( $thumb || $framed ) {
1745
1746 # Create a thumbnail. Alignment depends on language
1747 # writing direction, # right aligned for left-to-right-
1748 # languages ("Western languages"), left-aligned
1749 # for right-to-left-languages ("Semitic languages")
1750 #
1751 # If thumbnail width has not been provided, it is set
1752 # here to 180 pixels
1753 if ( $align == '' ) {
1754 $align = $wgContLang->isRTL() ? 'left' : 'right';
1755 }
1756 if ( ! isset($width) ) {
1757 $width = 180;
1758 }
1759 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
1760
1761 } elseif ( isset($width) ) {
1762
1763 # Create a resized image, without the additional thumbnail
1764 # features
1765
1766 if ( ( ! $height === false )
1767 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
1768 $width = $img->getWidth() * $height / $img->getHeight();
1769 }
1770 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
1771 }
1772
1773 if ( empty( $alt ) ) {
1774 $alt = preg_replace( '/\.(.+?)^/', '', $img->getName() );
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 $uf = $nt->escapeFullURL();
1782 if ( $url == '' )
1783 {
1784 $s = wfMsg( 'missingimage', $img->getName() );
1785 $s .= "<br>{$alt}<br>{$url}<br>\n";
1786 } else {
1787 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
1788 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$uf.'" /></a>';
1789 }
1790 if ( '' != $align ) {
1791 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
1792 }
1793 return str_replace("\n", ' ',$prefix.$s.$postfix);
1794 }
1795
1796 /**
1797 * Make HTML for a thumbnail including image, border and caption
1798 * $img is an Image object
1799 */
1800 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
1801 global $wgStylePath, $wgContLang;
1802 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
1803 $url = $img->getViewURL();
1804
1805 #$label = htmlspecialchars( $label );
1806 $alt = preg_replace( '/<[^>]*>/', '', $label);
1807 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1808 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1809
1810 $width = $height = 0;
1811 if ( $img->exists() )
1812 {
1813 $width = $img->getWidth();
1814 $height = $img->getHeight();
1815 }
1816 if ( 0 == $width || 0 == $height )
1817 {
1818 $width = $height = 200;
1819 }
1820 if ( $boxwidth == 0 )
1821 {
1822 $boxwidth = 200;
1823 }
1824 if ( $framed )
1825 {
1826 // Use image dimensions, don't scale
1827 $boxwidth = $width;
1828 $oboxwidth = $boxwidth + 2;
1829 $boxheight = $height;
1830 $thumbUrl = $url;
1831 } else {
1832 $h = intval( $height/($width/$boxwidth) );
1833 $oboxwidth = $boxwidth + 2;
1834 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
1835 {
1836 $boxwidth *= $boxheight/$h;
1837 } else {
1838 $boxheight = $h;
1839 }
1840 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
1841 }
1842
1843 if ( $manual_thumb != '' ) # Use manually specified thumbnail
1844 {
1845 $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb ); #new Title ( $manual_thumb ) ;
1846 $manual_img = Image::newFromTitle( $manual_title );
1847 $thumbUrl = $manual_img->getViewURL();
1848 if ( $manual_img->exists() )
1849 {
1850 $width = $manual_img->getWidth();
1851 $height = $manual_img->getHeight();
1852 $boxwidth = $width ;
1853 $boxheight = $height ;
1854 $oboxwidth = $boxwidth + 2 ;
1855 }
1856 }
1857
1858 $u = $img->getEscapeLocalURL();
1859 $uf = $img->getEscapeFullURL();
1860
1861 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
1862 $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
1863 $textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
1864
1865 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
1866 if ( $thumbUrl == '' ) {
1867 $s .= wfMsg( 'missingimage', $img->getName() );
1868 $zoomicon = '';
1869 } else {
1870 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
1871 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
1872 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
1873 'longdesc="'.$uf.'" /></a>';
1874 if ( $framed ) {
1875 $zoomicon="";
1876 } else {
1877 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
1878 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
1879 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
1880 'width="15" height="11" alt="'.$more.'" /></a></div>';
1881 }
1882 }
1883 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
1884 return str_replace("\n", ' ', $s);
1885 }
1886
1887 function makeMediaLink( $name, $url, $alt = '' ) {
1888 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1889 return $this->makeMediaLinkObj( $nt, $alt );
1890 }
1891
1892 function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {
1893 if ( ! isset( $nt ) )
1894 {
1895 ### HOTFIX. Instead of breaking, return empty string.
1896 $s = $alt;
1897 } else {
1898 $name = $nt->getDBKey();
1899 $img = Image::newFromTitle( $nt );
1900 $url = $img->getURL();
1901 # $nourl can be set by the parser
1902 # this is a hack to mask absolute URLs, so the parser doesn't
1903 # linkify them (it is currently not context-aware)
1904 # 2004-10-25
1905 if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
1906 if ( empty( $alt ) ) {
1907 $alt = preg_replace( '/\.(.+?)^/', '', $name );
1908 }
1909 $u = htmlspecialchars( $url );
1910 $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
1911 }
1912 return $s;
1913 }
1914
1915 function specialLink( $name, $key = '' ) {
1916 global $wgContLang;
1917
1918 if ( '' == $key ) { $key = strtolower( $name ); }
1919 $pn = $wgContLang->ucfirst( $name );
1920 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1921 wfMsg( $key ) );
1922 }
1923
1924 function makeExternalLink( $url, $text, $escape = true ) {
1925 $style = $this->getExternalLinkAttributes( $url, $text );
1926 $url = htmlspecialchars( $url );
1927 if( $escape ) {
1928 $text = htmlspecialchars( $text );
1929 }
1930 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
1931 }
1932
1933 # Called by history lists and recent changes
1934 #
1935
1936 # Returns text for the start of the tabular part of RC
1937 function beginRecentChangesList() {
1938 $this->rc_cache = array() ;
1939 $this->rcMoveIndex = 0;
1940 $this->rcCacheIndex = 0 ;
1941 $this->lastdate = '';
1942 $this->rclistOpen = false;
1943 return '';
1944 }
1945
1946 function beginImageHistoryList() {
1947 $s = "\n<h2>" . wfMsg( 'imghistory' ) . "</h2>\n" .
1948 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
1949 return $s;
1950 }
1951
1952 /**
1953 * Returns text for the end of RC
1954 * If enhanced RC is in use, returns pretty much all the text
1955 */
1956 function endRecentChangesList() {
1957 $s = $this->recentChangesBlock() ;
1958 if( $this->rclistOpen ) {
1959 $s .= "</ul>\n";
1960 }
1961 return $s;
1962 }
1963
1964 /**
1965 * Enhanced RC ungrouped line
1966 */
1967 function recentChangesBlockLine ( $rcObj ) {
1968 global $wgStylePath, $wgContLang ;
1969
1970 # Get rc_xxxx variables
1971 extract( $rcObj->mAttribs ) ;
1972 $curIdEq = 'curid='.$rc_cur_id;
1973
1974 # Spacer image
1975 $r = '' ;
1976
1977 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" border="0" />' ;
1978 $r .= '<tt>' ;
1979
1980 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
1981 $r .= '&nbsp;&nbsp;';
1982 } else {
1983 # M & N (minor & new)
1984 $M = wfMsg( 'minoreditletter' );
1985 $N = wfMsg( 'newpageletter' );
1986
1987 if ( $rc_type == RC_NEW ) {
1988 $r .= $N ;
1989 } else {
1990 $r .= '&nbsp;' ;
1991 }
1992 if ( $rc_minor ) {
1993 $r .= $M ;
1994 } else {
1995 $r .= '&nbsp;' ;
1996 }
1997 }
1998
1999 # Timestamp
2000 $r .= ' '.$rcObj->timestamp.' ' ;
2001 $r .= '</tt>' ;
2002
2003 # Article link
2004 $link = $rcObj->link ;
2005 if ( $rcObj->watched ) $link = '<strong>'.$link.'</strong>' ;
2006 $r .= $link ;
2007
2008 # Diff
2009 $r .= ' (' ;
2010 $r .= $rcObj->difflink ;
2011 $r .= '; ' ;
2012
2013 # Hist
2014 $r .= $this->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
2015
2016 # User/talk
2017 $r .= ') . . '.$rcObj->userlink ;
2018 $r .= $rcObj->usertalklink ;
2019
2020 # Comment
2021 if ( $rc_comment != '' && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
2022 $rc_comment=$this->formatComment($rc_comment, $rcObj->getTitle());
2023 $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' );
2024 }
2025
2026 $r .= "<br />\n" ;
2027 return $r ;
2028 }
2029
2030 /**
2031 * Enhanced RC group
2032 */
2033 function recentChangesBlockGroup ( $block ) {
2034 global $wgStylePath, $wgContLang ;
2035
2036 $r = '' ;
2037 $M = wfMsg( 'minoreditletter' );
2038 $N = wfMsg( 'newpageletter' );
2039
2040 # Collate list of users
2041 $isnew = false ;
2042 $userlinks = array () ;
2043 foreach ( $block AS $rcObj ) {
2044 $oldid = $rcObj->mAttribs['rc_last_oldid'];
2045 if ( $rcObj->mAttribs['rc_new'] ) $isnew = true ;
2046 $u = $rcObj->userlink ;
2047 if ( !isset ( $userlinks[$u] ) ) $userlinks[$u] = 0 ;
2048 $userlinks[$u]++ ;
2049 }
2050
2051 # Sort the list and convert to text
2052 krsort ( $userlinks ) ;
2053 asort ( $userlinks ) ;
2054 $users = array () ;
2055 foreach ( $userlinks as $userlink => $count) {
2056 $text = $userlink ;
2057 if ( $count > 1 ) $text .= " ({$count}&times;)" ;
2058 array_push ( $users , $text ) ;
2059 }
2060 $users = ' <font size="-1">['.implode('; ',$users).']</font>' ;
2061
2062 # Arrow
2063 $rci = 'RCI'.$this->rcCacheIndex ;
2064 $rcl = 'RCL'.$this->rcCacheIndex ;
2065 $rcm = 'RCM'.$this->rcCacheIndex ;
2066 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ;
2067 $arrowdir = $wgContLang->isRTL() ? 'l' : 'r';
2068 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" /></a></span>' ;
2069 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_d.png" width="12" height="12" /></a></span>' ;
2070 $r .= $tl ;
2071
2072 # Main line
2073 # M/N
2074 $r .= '<tt>' ;
2075 if ( $isnew ) $r .= $N ;
2076 else $r .= '&nbsp;' ;
2077 $r .= '&nbsp;' ; # Minor
2078
2079 # Timestamp
2080 $r .= ' '.$block[0]->timestamp.' ' ;
2081 $r .= '</tt>' ;
2082
2083 # Article link
2084 $link = $block[0]->link ;
2085 if ( $block[0]->watched ) $link = '<strong>'.$link.'</strong>' ;
2086 $r .= $link ;
2087
2088 $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id'];
2089 if ( $block[0]->mAttribs['rc_type'] != RC_LOG ) {
2090 # Changes
2091 $r .= ' ('.count($block).' ' ;
2092 if ( $isnew ) $r .= wfMsg('changes');
2093 else $r .= $this->makeKnownLinkObj( $block[0]->getTitle() , wfMsg('changes') ,
2094 $curIdEq.'&diff=0&oldid='.$oldid ) ;
2095 $r .= '; ' ;
2096
2097 # History
2098 $r .= $this->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' );
2099 $r .= ')' ;
2100 }
2101
2102 $r .= $users ;
2103 $r .= "<br />\n" ;
2104
2105 # Sub-entries
2106 $r .= '<div id="'.$rci.'" style="display:none">' ;
2107 foreach ( $block AS $rcObj ) {
2108 # Get rc_xxxx variables
2109 extract( $rcObj->mAttribs );
2110
2111 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" />';
2112 $r .= '<tt>&nbsp; &nbsp; &nbsp; &nbsp;' ;
2113 if ( $rc_new ) $r .= $N ;
2114 else $r .= '&nbsp;' ;
2115 if ( $rc_minor ) $r .= $M ;
2116 else $r .= '&nbsp;' ;
2117 $r .= '</tt>' ;
2118
2119 $o = '' ;
2120 if ( $rc_last_oldid != 0 ) {
2121 $o = 'oldid='.$rc_last_oldid ;
2122 }
2123 if ( $rc_type == RC_LOG ) {
2124 $link = $rcObj->timestamp ;
2125 } else {
2126 $link = $this->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp , "{$curIdEq}&$o" ) ;
2127 }
2128 $link = '<tt>'.$link.'</tt>' ;
2129
2130 $r .= $link ;
2131 $r .= ' (' ;
2132 $r .= $rcObj->curlink ;
2133 $r .= '; ' ;
2134 $r .= $rcObj->lastlink ;
2135 $r .= ') . . '.$rcObj->userlink ;
2136 $r .= $rcObj->usertalklink ;
2137 if ( $rc_comment != '' ) {
2138 $rc_comment=$this->formatComment($rc_comment, $rcObj->getTitle());
2139 $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' ) ;
2140 }
2141 $r .= "<br />\n" ;
2142 }
2143 $r .= "</div>\n" ;
2144
2145 $this->rcCacheIndex++ ;
2146 return $r ;
2147 }
2148
2149 /**
2150 * If enhanced RC is in use, this function takes the previously cached
2151 * RC lines, arranges them, and outputs the HTML
2152 */
2153 function recentChangesBlock () {
2154 global $wgStylePath ;
2155 if ( count ( $this->rc_cache ) == 0 ) return '' ;
2156 $blockOut = '';
2157 foreach ( $this->rc_cache AS $secureName => $block ) {
2158 if ( count ( $block ) < 2 ) {
2159 $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ;
2160 } else {
2161 $blockOut .= $this->recentChangesBlockGroup ( $block ) ;
2162 }
2163 }
2164
2165 return '<div>'.$blockOut.'</div>' ;
2166 }
2167
2168 /**
2169 * Called in a loop over all displayed RC entries
2170 * Either returns the line, or caches it for later use
2171 */
2172 function recentChangesLine( &$rc, $watched = false ) {
2173 global $wgUser ;
2174 $usenew = $wgUser->getOption( 'usenewrc' );
2175 if ( $usenew )
2176 $line = $this->recentChangesLineNew ( $rc, $watched ) ;
2177 else
2178 $line = $this->recentChangesLineOld ( $rc, $watched ) ;
2179 return $line ;
2180 }
2181
2182 function recentChangesLineOld( &$rc, $watched = false ) {
2183 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds, $wgUseRCPatrol, $wgOnlySysopsCanPatrol;
2184
2185 # Extract DB fields into local scope
2186 extract( $rc->mAttribs );
2187 $curIdEq = 'curid=' . $rc_cur_id;
2188
2189 # Make date header if necessary
2190 $date = $wgContLang->date( $rc_timestamp, true);
2191 $uidate = $wgLang->date( $rc_timestamp, true);
2192 $s = '';
2193 if ( $date != $this->lastdate ) {
2194 if ( '' != $this->lastdate ) { $s .= "</ul>\n"; }
2195 $s .= "<h4>{$uidate}</h4>\n<ul class=\"special\">";
2196 $this->lastdate = $date;
2197 $this->rclistOpen = true;
2198 }
2199
2200 # If this edit has not yet been patrolled, make it stick out
2201 if ( !$wgUseRCPatrol || $rc_patrolled ) {
2202 $s .= '<table border="0"><tr><td><li>';
2203 } else {
2204 $s .= '<table border="0" width="96%"><tr><td class="not_patrolled"><li>';
2205 }
2206
2207 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2208 # Diff
2209 $s .= '(' . wfMsg( 'diff' ) . ') (';
2210 # Hist
2211 $s .= $this->makeKnownLinkObj( $rc->getMovedToTitle(), wfMsg( 'hist' ), 'action=history' ) .
2212 ') . . ';
2213
2214 # "[[x]] moved to [[y]]"
2215 $msg = ( $rc_type == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
2216 $s .= wfMsg( $msg, $this->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
2217 $this->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
2218 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
2219 # Log updates, etc
2220 $logtype = $matches[1];
2221 $logname = LogPage::logName( $logtype );
2222 $s .= '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
2223 } else {
2224 # Diff link
2225 if ( $rc_type == RC_NEW || $rc_type == RC_LOG ) {
2226 $diffLink = wfMsg( 'diff' );
2227 } else {
2228 if ( $wgUseRCPatrol && $rc_patrolled == 0 && $wgUser->getID() != 0 &&
2229 ( $wgUser->isAllowed('protect') || !$wgOnlySysopsCanPatrol ) )
2230 $rcidparam = "&rcid={$rc_id}";
2231 else
2232 $rcidparam = "";
2233 $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'diff' ),
2234 "{$curIdEq}&diff={$rc_this_oldid}&oldid={$rc_last_oldid}{$rcidparam}",
2235 '', '', ' tabindex="'.$rc->counter.'"');
2236 }
2237 $s .= '('.$diffLink.') (';
2238
2239 # History link
2240 $s .= $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
2241 $s .= ') . . ';
2242
2243 # M and N (minor and new)
2244 if ( $rc_minor ) { $s .= ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>'; }
2245 if ( $rc_type == RC_NEW ) { $s .= '<span class="newpage">'.wfMsg( "newpageletter" ).'</span>'; }
2246
2247 # Article link
2248 # If it's a new article, there is no diff link, but if it hasn't been
2249 # patrolled yet, we need to give users a way to do so
2250 if ( $wgUseRCPatrol && $rc_type == RC_NEW && $rc_patrolled == 0 &&
2251 $wgUser->getID() != 0 && ( $wgUser->isAllowed('patrol') || !$wgOnlySysopsCanPatrol ) )
2252 $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
2253 else
2254 $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '' );
2255
2256 if ( $watched ) {
2257 $articleLink = '<strong>'.$articleLink.'</strong>';
2258 }
2259 $s .= ' '.$articleLink;
2260
2261 }
2262
2263 # Timestamp
2264 $s .= '; ' . $wgLang->time( $rc_timestamp, true, $wgRCSeconds ) . ' . . ';
2265
2266 # User link (or contributions for unregistered users)
2267 if ( 0 == $rc_user ) {
2268 $userLink = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
2269 $rc_user_text, 'target=' . $rc_user_text );
2270 } else {
2271 $userLink = $this->makeLink( $wgContLang->getNsText( NS_USER ) . ':'.$rc_user_text, $rc_user_text );
2272 }
2273 $s .= $userLink;
2274
2275 # User talk link
2276 $talkname=$wgContLang->getNsText(NS_TALK); # use the shorter name
2277 global $wgDisableAnonTalk;
2278 if( 0 == $rc_user && $wgDisableAnonTalk ) {
2279 $userTalkLink = '';
2280 } else {
2281 $utns=$wgContLang->getNsText(NS_USER_TALK);
2282 $userTalkLink= $this->makeLink($utns . ':'.$rc_user_text, $talkname );
2283 }
2284 # Block link
2285 $blockLink='';
2286 if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
2287 $blockLink = $this->makeKnownLink( $wgContLang->specialPage(
2288 'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text );
2289
2290 }
2291 if($blockLink) {
2292 if($userTalkLink) $userTalkLink .= ' | ';
2293 $userTalkLink .= $blockLink;
2294 }
2295 if($userTalkLink) $s.=' ('.$userTalkLink.')';
2296
2297 # Add comment
2298 if ( '' != $rc_comment && '*' != $rc_comment && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
2299 $rc_comment=$this->formatComment($rc_comment,$rc->getTitle());
2300 $s .= $wgContLang->emphasize(' (' . $rc_comment . ')');
2301 }
2302 $s .= "</li></td></tr></table>\n";
2303
2304 return $s;
2305 }
2306
2307 function recentChangesLineNew( &$baseRC, $watched = false ) {
2308 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds;
2309
2310 # Create a specialised object
2311 $rc = RCCacheEntry::newFromParent( $baseRC ) ;
2312
2313 # Extract fields from DB into the function scope (rc_xxxx variables)
2314 extract( $rc->mAttribs );
2315 $curIdEq = 'curid=' . $rc_cur_id;
2316
2317 # If it's a new day, add the headline and flush the cache
2318 $date = $wgContLang->date( $rc_timestamp, true);
2319 $uidate = $wgLang->date( $rc_timestamp, true);
2320 $ret = '';
2321 if ( $date != $this->lastdate ) {
2322 # Process current cache
2323 $ret = $this->recentChangesBlock () ;
2324 $this->rc_cache = array() ;
2325 $ret .= "<h4>{$uidate}</h4>\n";
2326 $this->lastdate = $date;
2327 }
2328
2329 # Make article link
2330 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2331 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
2332 $clink = wfMsg( $msg, $this->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
2333 $this->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
2334 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
2335 # Log updates, etc
2336 $logtype = $matches[1];
2337 $logname = LogPage::logName( $logtype );
2338 $clink = '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
2339 } else {
2340 $clink = $this->makeKnownLinkObj( $rc->getTitle(), '' ) ;
2341 }
2342
2343 $time = $wgContLang->time( $rc_timestamp, true, $wgRCSeconds );
2344 $rc->watched = $watched ;
2345 $rc->link = $clink ;
2346 $rc->timestamp = $time;
2347
2348 # Make "cur" and "diff" links
2349 if ( ( $rc_type == RC_NEW && $rc_this_oldid == 0 ) || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2350 $curLink = wfMsg( 'cur' );
2351 $diffLink = wfMsg( 'diff' );
2352 } else {
2353 $query = $curIdEq.'&diff=0&oldid='.$rc_this_oldid;
2354 $aprops = ' tabindex="'.$baseRC->counter.'"';
2355 $curLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'cur' ), $query, '' ,'' , $aprops );
2356 $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'diff'), $query, '' ,'' , $aprops );
2357 }
2358
2359 # Make "last" link
2360 $titleObj = $rc->getTitle();
2361 if ( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2362 $lastLink = wfMsg( 'last' );
2363 } else {
2364 $lastLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'last' ),
2365 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid );
2366 }
2367
2368 # Make user link (or user contributions for unregistered users)
2369 if ( $rc_user == 0 ) {
2370 $userLink = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
2371 $rc_user_text, 'target=' . $rc_user_text );
2372 } else {
2373 $userLink = $this->makeLink( $wgContLang->getNsText(
2374 Namespace::getUser() ) . ':'.$rc_user_text, $rc_user_text );
2375 }
2376
2377 $rc->userlink = $userLink;
2378 $rc->lastlink = $lastLink;
2379 $rc->curlink = $curLink;
2380 $rc->difflink = $diffLink;
2381
2382 # Make user talk link
2383 $utns=$wgContLang->getNsText(NS_USER_TALK);
2384 $talkname=$wgContLang->getNsText(NS_TALK); # use the shorter name
2385 $userTalkLink= $this->makeLink($utns . ':'.$rc_user_text, $talkname );
2386
2387 global $wgDisableAnonTalk;
2388 if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
2389 $blockLink = $this->makeKnownLink( $wgContLang->specialPage(
2390 'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text );
2391 if( $wgDisableAnonTalk )
2392 $rc->usertalklink = ' ('.$blockLink.')';
2393 else
2394 $rc->usertalklink = ' ('.$userTalkLink.' | '.$blockLink.')';
2395 } else {
2396 if( $wgDisableAnonTalk && ($rc_user == 0) )
2397 $rc->usertalklink = '';
2398 else
2399 $rc->usertalklink = ' ('.$userTalkLink.')';
2400 }
2401
2402 # Put accumulated information into the cache, for later display
2403 # Page moves go on their own line
2404 $title = $rc->getTitle();
2405 $secureName = $title->getPrefixedDBkey();
2406 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2407 # Use an @ character to prevent collision with page names
2408 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
2409 } else {
2410 if ( !isset ( $this->rc_cache[$secureName] ) ) $this->rc_cache[$secureName] = array() ;
2411 array_push ( $this->rc_cache[$secureName] , $rc ) ;
2412 }
2413 return $ret;
2414 }
2415
2416 function endImageHistoryList() {
2417 $s = "</ul>\n";
2418 return $s;
2419 }
2420
2421 /**
2422 * This function is called by all recent changes variants, by the page history,
2423 * and by the user contributions list. It is responsible for formatting edit
2424 * comments. It escapes any HTML in the comment, but adds some CSS to format
2425 * auto-generated comments (from section editing) and formats [[wikilinks]].
2426 *
2427 * The &$title parameter must be a title OBJECT. It is used to generate a
2428 * direct link to the section in the autocomment.
2429 * @author Erik Moeller <moeller@scireview.de>
2430 *
2431 * Note: there's not always a title to pass to this function.
2432 * Since you can't set a default parameter for a reference, I've turned it
2433 * temporarily to a value pass. Should be adjusted further. --brion
2434 */
2435 function formatComment($comment, $title = NULL) {
2436 global $wgContLang;
2437 $comment = htmlspecialchars( $comment );
2438
2439 # The pattern for autogen comments is / * foo * /, which makes for
2440 # some nasty regex.
2441 # We look for all comments, match any text before and after the comment,
2442 # add a separator where needed and format the comment itself with CSS
2443 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
2444 $pre=$match[1];
2445 $auto=$match[2];
2446 $post=$match[3];
2447 $link='';
2448 if($title) {
2449 $section=$auto;
2450
2451 # This is hackish but should work in most cases.
2452 $section=str_replace('[[','',$section);
2453 $section=str_replace(']]','',$section);
2454 $title->mFragment=$section;
2455 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
2456 }
2457 $sep='-';
2458 $auto=$link.$auto;
2459 if($pre) { $auto = $sep.' '.$auto; }
2460 if($post) { $auto .= ' '.$sep; }
2461 $auto='<span class="autocomment">'.$auto.'</span>';
2462 $comment=$pre.$auto.$post;
2463 }
2464
2465 # format regular and media links - all other wiki formatting
2466 # is ignored
2467 $medians = $wgContLang->getNsText(Namespace::getMedia()).':';
2468 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
2469 # Handle link renaming [[foo|text]] will show link as "text"
2470 if( "" != $match[3] ) {
2471 $text = $match[3];
2472 } else {
2473 $text = $match[1];
2474 }
2475 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
2476 # Media link; trail not supported.
2477 $linkRegexp = '/\[\[(.*?)\]\]/';
2478 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
2479 } else {
2480 # Other kind of link
2481 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
2482 $trail = $submatch[1];
2483 } else {
2484 $trail = "";
2485 }
2486 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
2487 if ($match[1][0] == ':')
2488 $match[1] = substr($match[1], 1);
2489 $thelink = $this->makeLink( $match[1], $text, "", $trail );
2490 }
2491 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
2492 }
2493 return $comment;
2494 }
2495
2496 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
2497 global $wgUser, $wgLang, $wgContLang, $wgTitle;
2498
2499 $datetime = $wgLang->timeanddate( $timestamp, true );
2500 $del = wfMsg( 'deleteimg' );
2501 $delall = wfMsg( 'deleteimgcompletely' );
2502 $cur = wfMsg( 'cur' );
2503
2504 if ( $iscur ) {
2505 $url = Image::wfImageUrl( $img );
2506 $rlink = $cur;
2507 if ( $wgUser->isAllowed('delete') ) {
2508 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
2509 '&action=delete' );
2510 $style = $this->getInternalLinkAttributes( $link, $delall );
2511
2512 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
2513 } else {
2514 $dlink = $del;
2515 }
2516 } else {
2517 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
2518 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
2519 $rlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
2520 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
2521 urlencode( $img ) );
2522 $dlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
2523 $del, 'action=delete&oldimage=' . urlencode( $img ) );
2524 } else {
2525 # Having live active links for non-logged in users
2526 # means that bots and spiders crawling our site can
2527 # inadvertently change content. Baaaad idea.
2528 $rlink = wfMsg( 'revertimg' );
2529 $dlink = $del;
2530 }
2531 }
2532 if ( 0 == $user ) {
2533 $userlink = $usertext;
2534 } else {
2535 $userlink = $this->makeLink( $wgContLang->getNsText( Namespace::getUser() ) .
2536 ':'.$usertext, $usertext );
2537 }
2538 $nbytes = wfMsg( 'nbytes', $size );
2539 $style = $this->getInternalLinkAttributes( $url, $datetime );
2540
2541 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
2542 . " . . {$userlink} ({$nbytes})";
2543
2544 if ( '' != $description && '*' != $description ) {
2545 $sk=$wgUser->getSkin();
2546 $s .= $wgContLang->emphasize(' (' . $sk->formatComment($description,$wgTitle) . ')');
2547 }
2548 $s .= "</li>\n";
2549 return $s;
2550 }
2551
2552 function tocIndent($level) {
2553 return str_repeat( '<div class="tocindent">'."\n", $level>0 ? $level : 0 );
2554 }
2555
2556 function tocUnindent($level) {
2557 return str_repeat( "</div>\n", $level>0 ? $level : 0 );
2558 }
2559
2560 /**
2561 * parameter level defines if we are on an indentation level
2562 */
2563 function tocLine( $anchor, $tocline, $level ) {
2564 $link = '<a href="#'.$anchor.'">'.$tocline.'</a><br />';
2565 if($level) {
2566 return $link."\n";
2567 } else {
2568 return '<div class="tocline">'.$link."</div>\n";
2569 }
2570
2571 }
2572
2573 function tocTable($toc) {
2574 # note to CSS fanatics: putting this in a div does not work -- div won't auto-expand
2575 # try min-width & co when somebody gets a chance
2576 $hideline = ' <script type="text/javascript">showTocToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '")</script>';
2577 return
2578 '<table border="0" id="toc"><tr id="toctitle"><td align="center">'."\n".
2579 '<b>'.wfMsgForContent('toc').'</b>' .
2580 $hideline .
2581 '</td></tr><tr id="tocinside"><td>'."\n".
2582 $toc."</td></tr></table>\n";
2583 }
2584
2585 /**
2586 * These two do not check for permissions: check $wgTitle->userCanEdit
2587 * before calling them
2588 */
2589 function editSectionScriptForOther( $title, $section, $head ) {
2590 $ttl = Title::newFromText( $title );
2591 $url = $ttl->escapeLocalURL( 'action=edit&section='.$section );
2592 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2593 }
2594
2595 function editSectionScript( $nt, $section, $head ) {
2596 global $wgRequest;
2597 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2598 return $head;
2599 }
2600 $url = $nt->escapeLocalURL( 'action=edit&section='.$section );
2601 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2602 }
2603
2604 function editSectionLinkForOther( $title, $section ) {
2605 global $wgRequest;
2606 global $wgContLang;
2607
2608 $title = Title::newFromText($title);
2609 $editurl = '&section='.$section;
2610 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2611
2612 if( $wgContLang->isRTL() ) {
2613 $farside = 'left';
2614 $nearside = 'right';
2615 } else {
2616 $farside = 'right';
2617 $nearside = 'left';
2618 }
2619 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2620
2621 }
2622
2623 function editSectionLink( $nt, $section ) {
2624 global $wgRequest;
2625 global $wgContLang;
2626
2627 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2628 # Section edit links would be out of sync on an old page.
2629 # But, if we're diffing to the current page, they'll be
2630 # correct.
2631 return '';
2632 }
2633
2634 $editurl = '&section='.$section;
2635 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2636
2637 if( $wgContLang->isRTL() ) {
2638 $farside = 'left';
2639 $nearside = 'right';
2640 } else {
2641 $farside = 'right';
2642 $nearside = 'left';
2643 }
2644 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2645
2646 }
2647
2648 /**
2649 * This function is called by EditPage.php and shows a bulletin board style
2650 * toolbar for common editing functions. It can be disabled in the user
2651 * preferences.
2652 * The necessary JavaScript code can be found in style/wikibits.js.
2653 */
2654 function getEditToolbar() {
2655 global $wgStylePath, $wgLang, $wgMimeType;
2656
2657 /**
2658 * toolarray an array of arrays which each include the filename of
2659 * the button image (without path), the opening tag, the closing tag,
2660 * and optionally a sample text that is inserted between the two when no
2661 * selection is highlighted.
2662 * The tip text is shown when the user moves the mouse over the button.
2663 *
2664 * Already here are accesskeys (key), which are not used yet until someone
2665 * can figure out a way to make them work in IE. However, we should make
2666 * sure these keys are not defined on the edit page.
2667 */
2668 $toolarray=array(
2669 array( 'image'=>'button_bold.png',
2670 'open' => "\'\'\'",
2671 'close' => "\'\'\'",
2672 'sample'=> wfMsg('bold_sample'),
2673 'tip' => wfMsg('bold_tip'),
2674 'key' => 'B'
2675 ),
2676 array( 'image'=>'button_italic.png',
2677 'open' => "\'\'",
2678 'close' => "\'\'",
2679 'sample'=> wfMsg('italic_sample'),
2680 'tip' => wfMsg('italic_tip'),
2681 'key' => 'I'
2682 ),
2683 array( 'image'=>'button_link.png',
2684 'open' => '[[',
2685 'close' => ']]',
2686 'sample'=> wfMsg('link_sample'),
2687 'tip' => wfMsg('link_tip'),
2688 'key' => 'L'
2689 ),
2690 array( 'image'=>'button_extlink.png',
2691 'open' => '[',
2692 'close' => ']',
2693 'sample'=> wfMsg('extlink_sample'),
2694 'tip' => wfMsg('extlink_tip'),
2695 'key' => 'X'
2696 ),
2697 array( 'image'=>'button_headline.png',
2698 'open' => "\\n== ",
2699 'close' => " ==\\n",
2700 'sample'=> wfMsg('headline_sample'),
2701 'tip' => wfMsg('headline_tip'),
2702 'key' => 'H'
2703 ),
2704 array( 'image'=>'button_image.png',
2705 'open' => '[['.$wgLang->getNsText(NS_IMAGE).":",
2706 'close' => ']]',
2707 'sample'=> wfMsg('image_sample'),
2708 'tip' => wfMsg('image_tip'),
2709 'key' => 'D'
2710 ),
2711 array( 'image' => 'button_media.png',
2712 'open' => '[['.$wgLang->getNsText(NS_MEDIA).':',
2713 'close' => ']]',
2714 'sample'=> wfMsg('media_sample'),
2715 'tip' => wfMsg('media_tip'),
2716 'key' => 'M'
2717 ),
2718 array( 'image' => 'button_math.png',
2719 'open' => "\\<math\\>",
2720 'close' => "\\</math\\>",
2721 'sample'=> wfMsg('math_sample'),
2722 'tip' => wfMsg('math_tip'),
2723 'key' => 'C'
2724 ),
2725 array( 'image' => 'button_nowiki.png',
2726 'open' => "\\<nowiki\\>",
2727 'close' => "\\</nowiki\\>",
2728 'sample'=> wfMsg('nowiki_sample'),
2729 'tip' => wfMsg('nowiki_tip'),
2730 'key' => 'N'
2731 ),
2732 array( 'image' => 'button_sig.png',
2733 'open' => '--~~~~',
2734 'close' => '',
2735 'sample'=> '',
2736 'tip' => wfMsg('sig_tip'),
2737 'key' => 'Y'
2738 ),
2739 array( 'image' => 'button_hr.png',
2740 'open' => "\\n----\\n",
2741 'close' => '',
2742 'sample'=> '',
2743 'tip' => wfMsg('hr_tip'),
2744 'key' => 'R'
2745 )
2746 );
2747 $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
2748
2749 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
2750 foreach($toolarray as $tool) {
2751
2752 $image=$wgStylePath.'/common/images/'.$tool['image'];
2753 $open=$tool['open'];
2754 $close=$tool['close'];
2755 $sample = addslashes( $tool['sample'] );
2756
2757 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2758 // Older browsers show a "speedtip" type message only for ALT.
2759 // Ideally these should be different, realistically they
2760 // probably don't need to be.
2761 $tip = addslashes( $tool['tip'] );
2762
2763 #$key = $tool["key"];
2764
2765 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
2766 }
2767
2768 $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
2769 $toolbar.="document.writeln(\"</div>\");\n";
2770
2771 $toolbar.="/*]]>*/\n</script>";
2772 return $toolbar;
2773 }
2774
2775 /**
2776 * @access public
2777 */
2778 function suppressUrlExpansion() {
2779 return false;
2780 }
2781 }
2782
2783 }
2784 ?>