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