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