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