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