a30d198c105a05f17e7176c17f0ba92aac36fd8b
[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 ( NS_IMAGE == $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->getViewURL();
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 = 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 {
1783 $s = wfMsg( 'missingimage', $img->getName() );
1784 $s .= "<br>{$alt}<br>{$url}<br>\n";
1785 } else {
1786 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
1787 '<img src="'.$url.'" alt="'.$alt.'" /></a>';
1788 }
1789 if ( '' != $align ) {
1790 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
1791 }
1792 return str_replace("\n", ' ',$prefix.$s.$postfix);
1793 }
1794
1795 /**
1796 * Make HTML for a thumbnail including image, border and caption
1797 * $img is an Image object
1798 */
1799 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
1800 global $wgStylePath, $wgContLang;
1801 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
1802 $url = $img->getViewURL();
1803
1804 #$label = htmlspecialchars( $label );
1805 $alt = preg_replace( '/<[^>]*>/', '', $label);
1806 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1807 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1808
1809 $width = $height = 0;
1810 if ( $img->exists() )
1811 {
1812 $width = $img->getWidth();
1813 $height = $img->getHeight();
1814 }
1815 if ( 0 == $width || 0 == $height )
1816 {
1817 $width = $height = 200;
1818 }
1819 if ( $boxwidth == 0 )
1820 {
1821 $boxwidth = 200;
1822 }
1823 if ( $framed )
1824 {
1825 // Use image dimensions, don't scale
1826 $boxwidth = $width;
1827 $oboxwidth = $boxwidth + 2;
1828 $boxheight = $height;
1829 $thumbUrl = $url;
1830 } else {
1831 $h = intval( $height/($width/$boxwidth) );
1832 $oboxwidth = $boxwidth + 2;
1833 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
1834 {
1835 $boxwidth *= $boxheight/$h;
1836 } else {
1837 $boxheight = $h;
1838 }
1839 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
1840 }
1841
1842 if ( $manual_thumb != '' ) # Use manually specified thumbnail
1843 {
1844 $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb ); #new Title ( $manual_thumb ) ;
1845 $manual_img = Image::newFromTitle( $manual_title );
1846 $thumbUrl = $manual_img->getViewURL();
1847 if ( $manual_img->exists() )
1848 {
1849 $width = $manual_img->getWidth();
1850 $height = $manual_img->getHeight();
1851 $boxwidth = $width ;
1852 $boxheight = $height ;
1853 $oboxwidth = $boxwidth + 2 ;
1854 }
1855 }
1856
1857 $u = $img->getEscapeLocalURL();
1858
1859 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
1860 $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
1861 $textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
1862
1863 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
1864 if ( $thumbUrl == '' ) {
1865 $s .= wfMsg( 'missingimage', $img->getName() );
1866 $zoomicon = '';
1867 } else {
1868 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
1869 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
1870 'width="'.$boxwidth.'" height="'.$boxheight.'" /></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( Namespace::getMedia(), $name );
1886 return $this->makeMediaLinkObj( $nt, $alt );
1887 }
1888
1889 function makeMediaLinkObj( $nt, $alt = '' ) {
1890 if ( ! isset( $nt ) )
1891 {
1892 ### HOTFIX. Instead of breaking, return empty string.
1893 $s = $alt;
1894 } else {
1895 $name = $nt->getDBKey();
1896 $url = Image::wfImageUrl( $name );
1897 if ( empty( $alt ) ) {
1898 $alt = preg_replace( '/\.(.+?)^/', '', $name );
1899 }
1900
1901 $u = htmlspecialchars( $url );
1902 $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
1903 }
1904 return $s;
1905 }
1906
1907 function specialLink( $name, $key = '' ) {
1908 global $wgContLang;
1909
1910 if ( '' == $key ) { $key = strtolower( $name ); }
1911 $pn = $wgContLang->ucfirst( $name );
1912 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1913 wfMsg( $key ) );
1914 }
1915
1916 function makeExternalLink( $url, $text, $escape = true ) {
1917 $style = $this->getExternalLinkAttributes( $url, $text );
1918 $url = htmlspecialchars( $url );
1919 if( $escape ) {
1920 $text = htmlspecialchars( $text );
1921 }
1922 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
1923 }
1924
1925 # Called by history lists and recent changes
1926 #
1927
1928 # Returns text for the start of the tabular part of RC
1929 function beginRecentChangesList() {
1930 $this->rc_cache = array() ;
1931 $this->rcMoveIndex = 0;
1932 $this->rcCacheIndex = 0 ;
1933 $this->lastdate = '';
1934 $this->rclistOpen = false;
1935 return '';
1936 }
1937
1938 function beginImageHistoryList() {
1939 $s = "\n<h2>" . wfMsg( 'imghistory' ) . "</h2>\n" .
1940 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
1941 return $s;
1942 }
1943
1944 /**
1945 * Returns text for the end of RC
1946 * If enhanced RC is in use, returns pretty much all the text
1947 */
1948 function endRecentChangesList() {
1949 $s = $this->recentChangesBlock() ;
1950 if( $this->rclistOpen ) {
1951 $s .= "</ul>\n";
1952 }
1953 return $s;
1954 }
1955
1956 /**
1957 * Enhanced RC ungrouped line
1958 */
1959 function recentChangesBlockLine ( $rcObj ) {
1960 global $wgStylePath, $wgContLang ;
1961
1962 # Get rc_xxxx variables
1963 extract( $rcObj->mAttribs ) ;
1964 $curIdEq = 'curid='.$rc_cur_id;
1965
1966 # Spacer image
1967 $r = '' ;
1968
1969 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" border="0" />' ;
1970 $r .= '<tt>' ;
1971
1972 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
1973 $r .= '&nbsp;&nbsp;';
1974 } else {
1975 # M & N (minor & new)
1976 $M = wfMsg( 'minoreditletter' );
1977 $N = wfMsg( 'newpageletter' );
1978
1979 if ( $rc_type == RC_NEW ) {
1980 $r .= $N ;
1981 } else {
1982 $r .= '&nbsp;' ;
1983 }
1984 if ( $rc_minor ) {
1985 $r .= $M ;
1986 } else {
1987 $r .= '&nbsp;' ;
1988 }
1989 }
1990
1991 # Timestamp
1992 $r .= ' '.$rcObj->timestamp.' ' ;
1993 $r .= '</tt>' ;
1994
1995 # Article link
1996 $link = $rcObj->link ;
1997 if ( $rcObj->watched ) $link = '<strong>'.$link.'</strong>' ;
1998 $r .= $link ;
1999
2000 # Diff
2001 $r .= ' (' ;
2002 $r .= $rcObj->difflink ;
2003 $r .= '; ' ;
2004
2005 # Hist
2006 $r .= $this->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
2007
2008 # User/talk
2009 $r .= ') . . '.$rcObj->userlink ;
2010 $r .= $rcObj->usertalklink ;
2011
2012 # Comment
2013 if ( $rc_comment != '' && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
2014 $rc_comment=$this->formatComment($rc_comment, $rcObj->getTitle());
2015 $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' );
2016 }
2017
2018 $r .= "<br />\n" ;
2019 return $r ;
2020 }
2021
2022 /**
2023 * Enhanced RC group
2024 */
2025 function recentChangesBlockGroup ( $block ) {
2026 global $wgStylePath, $wgContLang ;
2027
2028 $r = '' ;
2029 $M = wfMsg( 'minoreditletter' );
2030 $N = wfMsg( 'newpageletter' );
2031
2032 # Collate list of users
2033 $isnew = false ;
2034 $userlinks = array () ;
2035 foreach ( $block AS $rcObj ) {
2036 $oldid = $rcObj->mAttribs['rc_last_oldid'];
2037 if ( $rcObj->mAttribs['rc_new'] ) $isnew = true ;
2038 $u = $rcObj->userlink ;
2039 if ( !isset ( $userlinks[$u] ) ) $userlinks[$u] = 0 ;
2040 $userlinks[$u]++ ;
2041 }
2042
2043 # Sort the list and convert to text
2044 krsort ( $userlinks ) ;
2045 asort ( $userlinks ) ;
2046 $users = array () ;
2047 foreach ( $userlinks as $userlink => $count) {
2048 $text = $userlink ;
2049 if ( $count > 1 ) $text .= " ({$count}&times;)" ;
2050 array_push ( $users , $text ) ;
2051 }
2052 $users = ' <font size="-1">['.implode('; ',$users).']</font>' ;
2053
2054 # Arrow
2055 $rci = 'RCI'.$this->rcCacheIndex ;
2056 $rcl = 'RCL'.$this->rcCacheIndex ;
2057 $rcm = 'RCM'.$this->rcCacheIndex ;
2058 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ;
2059 $arrowdir = $wgContLang->isRTL() ? 'l' : 'r';
2060 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" /></a></span>' ;
2061 $tl .= '<span id="'.$rcl.'" style="display:none"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_d.png" width="12" height="12" /></a></span>' ;
2062 $r .= $tl ;
2063
2064 # Main line
2065 # M/N
2066 $r .= '<tt>' ;
2067 if ( $isnew ) $r .= $N ;
2068 else $r .= '&nbsp;' ;
2069 $r .= '&nbsp;' ; # Minor
2070
2071 # Timestamp
2072 $r .= ' '.$block[0]->timestamp.' ' ;
2073 $r .= '</tt>' ;
2074
2075 # Article link
2076 $link = $block[0]->link ;
2077 if ( $block[0]->watched ) $link = '<strong>'.$link.'</strong>' ;
2078 $r .= $link ;
2079
2080 $curIdEq = 'curid=' . $block[0]->mAttribs['rc_cur_id'];
2081 if ( $block[0]->mAttribs['rc_type'] != RC_LOG ) {
2082 # Changes
2083 $r .= ' ('.count($block).' ' ;
2084 if ( $isnew ) $r .= wfMsg('changes');
2085 else $r .= $this->makeKnownLinkObj( $block[0]->getTitle() , wfMsg('changes') ,
2086 $curIdEq.'&diff=0&oldid='.$oldid ) ;
2087 $r .= '; ' ;
2088
2089 # History
2090 $r .= $this->makeKnownLinkObj( $block[0]->getTitle(), wfMsg( 'history' ), $curIdEq.'&action=history' );
2091 $r .= ')' ;
2092 }
2093
2094 $r .= $users ;
2095 $r .= "<br />\n" ;
2096
2097 # Sub-entries
2098 $r .= '<div id="'.$rci.'" style="display:none">' ;
2099 foreach ( $block AS $rcObj ) {
2100 # Get rc_xxxx variables
2101 extract( $rcObj->mAttribs );
2102
2103 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" />';
2104 $r .= '<tt>&nbsp; &nbsp; &nbsp; &nbsp;' ;
2105 if ( $rc_new ) $r .= $N ;
2106 else $r .= '&nbsp;' ;
2107 if ( $rc_minor ) $r .= $M ;
2108 else $r .= '&nbsp;' ;
2109 $r .= '</tt>' ;
2110
2111 $o = '' ;
2112 if ( $rc_last_oldid != 0 ) {
2113 $o = 'oldid='.$rc_last_oldid ;
2114 }
2115 if ( $rc_type == RC_LOG ) {
2116 $link = $rcObj->timestamp ;
2117 } else {
2118 $link = $this->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp , "{$curIdEq}&$o" ) ;
2119 }
2120 $link = '<tt>'.$link.'</tt>' ;
2121
2122 $r .= $link ;
2123 $r .= ' (' ;
2124 $r .= $rcObj->curlink ;
2125 $r .= '; ' ;
2126 $r .= $rcObj->lastlink ;
2127 $r .= ') . . '.$rcObj->userlink ;
2128 $r .= $rcObj->usertalklink ;
2129 if ( $rc_comment != '' ) {
2130 $rc_comment=$this->formatComment($rc_comment, $rcObj->getTitle());
2131 $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' ) ;
2132 }
2133 $r .= "<br />\n" ;
2134 }
2135 $r .= "</div>\n" ;
2136
2137 $this->rcCacheIndex++ ;
2138 return $r ;
2139 }
2140
2141 /**
2142 * If enhanced RC is in use, this function takes the previously cached
2143 * RC lines, arranges them, and outputs the HTML
2144 */
2145 function recentChangesBlock () {
2146 global $wgStylePath ;
2147 if ( count ( $this->rc_cache ) == 0 ) return '' ;
2148 $blockOut = '';
2149 foreach ( $this->rc_cache AS $secureName => $block ) {
2150 if ( count ( $block ) < 2 ) {
2151 $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ;
2152 } else {
2153 $blockOut .= $this->recentChangesBlockGroup ( $block ) ;
2154 }
2155 }
2156
2157 return '<div>'.$blockOut.'</div>' ;
2158 }
2159
2160 /**
2161 * Called in a loop over all displayed RC entries
2162 * Either returns the line, or caches it for later use
2163 */
2164 function recentChangesLine( &$rc, $watched = false ) {
2165 global $wgUser ;
2166 $usenew = $wgUser->getOption( 'usenewrc' );
2167 if ( $usenew )
2168 $line = $this->recentChangesLineNew ( $rc, $watched ) ;
2169 else
2170 $line = $this->recentChangesLineOld ( $rc, $watched ) ;
2171 return $line ;
2172 }
2173
2174 function recentChangesLineOld( &$rc, $watched = false ) {
2175 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds, $wgUseRCPatrol, $wgOnlySysopsCanPatrol;
2176
2177 # Extract DB fields into local scope
2178 extract( $rc->mAttribs );
2179 $curIdEq = 'curid=' . $rc_cur_id;
2180
2181 # Make date header if necessary
2182 $date = $wgContLang->date( $rc_timestamp, true);
2183 $uidate = $wgLang->date( $rc_timestamp, true);
2184 $s = '';
2185 if ( $date != $this->lastdate ) {
2186 if ( '' != $this->lastdate ) { $s .= "</ul>\n"; }
2187 $s .= "<h4>{$uidate}</h4>\n<ul class='special'>";
2188 $this->lastdate = $date;
2189 $this->rclistOpen = true;
2190 }
2191
2192 # If this edit has not yet been patrolled, make it stick out
2193 $s .= ( ! $wgUseRCPatrol || $rc_patrolled ) ? '<li> ' : '<li class="not_patrolled"> ';
2194
2195 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2196 # Diff
2197 $s .= '(' . wfMsg( 'diff' ) . ') (';
2198 # Hist
2199 $s .= $this->makeKnownLinkObj( $rc->getMovedToTitle(), wfMsg( 'hist' ), 'action=history' ) .
2200 ') . . ';
2201
2202 # "[[x]] moved to [[y]]"
2203 $msg = ( $rc_type == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
2204 $s .= wfMsg( $msg, $this->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
2205 $this->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
2206 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
2207 # Log updates, etc
2208 $logtype = $matches[1];
2209 $logname = LogPage::logName( $logtype );
2210 $s .= '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
2211 } else {
2212 # Diff link
2213 if ( $rc_type == RC_NEW || $rc_type == RC_LOG ) {
2214 $diffLink = wfMsg( 'diff' );
2215 } else {
2216 if ( $wgUseRCPatrol && $rc_patrolled == 0 && $wgUser->getID() != 0 &&
2217 ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) )
2218 $rcidparam = "&rcid={$rc_id}";
2219 else
2220 $rcidparam = "";
2221 $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'diff' ),
2222 "{$curIdEq}&diff={$rc_this_oldid}&oldid={$rc_last_oldid}{$rcidparam}",
2223 '', '', ' tabindex="'.$rc->counter.'"');
2224 }
2225 $s .= '('.$diffLink.') (';
2226
2227 # History link
2228 $s .= $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
2229 $s .= ') . . ';
2230
2231 # M and N (minor and new)
2232 if ( $rc_minor ) { $s .= ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>'; }
2233 if ( $rc_type == RC_NEW ) { $s .= '<span class="newpage">'.wfMsg( "newpageletter" ).'</span>'; }
2234
2235 # Article link
2236 # If it's a new article, there is no diff link, but if it hasn't been
2237 # patrolled yet, we need to give users a way to do so
2238 if ( $wgUseRCPatrol && $rc_type == RC_NEW && $rc_patrolled == 0 &&
2239 $wgUser->getID() != 0 && ( $wgUser->isSysop() || !$wgOnlySysopsCanPatrol ) )
2240 $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
2241 else
2242 $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '' );
2243
2244 if ( $watched ) {
2245 $articleLink = '<strong>'.$articleLink.'</strong>';
2246 }
2247 $s .= ' '.$articleLink;
2248
2249 }
2250
2251 # Timestamp
2252 $s .= '; ' . $wgLang->time( $rc_timestamp, true, $wgRCSeconds ) . ' . . ';
2253
2254 # User link (or contributions for unregistered users)
2255 if ( 0 == $rc_user ) {
2256 $userLink = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
2257 $rc_user_text, 'target=' . $rc_user_text );
2258 } else {
2259 $userLink = $this->makeLink( $wgContLang->getNsText( NS_USER ) . ':'.$rc_user_text, $rc_user_text );
2260 }
2261 $s .= $userLink;
2262
2263 # User talk link
2264 $talkname=$wgContLang->getNsText(NS_TALK); # use the shorter name
2265 global $wgDisableAnonTalk;
2266 if( 0 == $rc_user && $wgDisableAnonTalk ) {
2267 $userTalkLink = '';
2268 } else {
2269 $utns=$wgContLang->getNsText(NS_USER_TALK);
2270 $userTalkLink= $this->makeLink($utns . ':'.$rc_user_text, $talkname );
2271 }
2272 # Block link
2273 $blockLink='';
2274 if ( ( 0 == $rc_user ) && $wgUser->isSysop() ) {
2275 $blockLink = $this->makeKnownLink( $wgContLang->specialPage(
2276 'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text );
2277
2278 }
2279 if($blockLink) {
2280 if($userTalkLink) $userTalkLink .= ' | ';
2281 $userTalkLink .= $blockLink;
2282 }
2283 if($userTalkLink) $s.=' ('.$userTalkLink.')';
2284
2285 # Add comment
2286 if ( '' != $rc_comment && '*' != $rc_comment && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
2287 $rc_comment=$this->formatComment($rc_comment,$rc->getTitle());
2288 $s .= $wgContLang->emphasize(' (' . $rc_comment . ')');
2289 }
2290 $s .= "</li>\n";
2291
2292 return $s;
2293 }
2294
2295 function recentChangesLineNew( &$baseRC, $watched = false ) {
2296 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds;
2297
2298 # Create a specialised object
2299 $rc = RCCacheEntry::newFromParent( $baseRC ) ;
2300
2301 # Extract fields from DB into the function scope (rc_xxxx variables)
2302 extract( $rc->mAttribs );
2303 $curIdEq = 'curid=' . $rc_cur_id;
2304
2305 # If it's a new day, add the headline and flush the cache
2306 $date = $wgContLang->date( $rc_timestamp, true);
2307 $uidate = $wgLang->date( $rc_timestamp, true);
2308 $ret = '';
2309 if ( $date != $this->lastdate ) {
2310 # Process current cache
2311 $ret = $this->recentChangesBlock () ;
2312 $this->rc_cache = array() ;
2313 $ret .= "<h4>{$uidate}</h4>\n";
2314 $this->lastdate = $date;
2315 }
2316
2317 # Make article link
2318 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2319 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
2320 $clink = wfMsg( $msg, $this->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
2321 $this->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
2322 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
2323 # Log updates, etc
2324 $logtype = $matches[1];
2325 $logname = LogPage::logName( $logtype );
2326 $clink = '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
2327 } else {
2328 $clink = $this->makeKnownLinkObj( $rc->getTitle(), '' ) ;
2329 }
2330
2331 $time = $wgContLang->time( $rc_timestamp, true, $wgRCSeconds );
2332 $rc->watched = $watched ;
2333 $rc->link = $clink ;
2334 $rc->timestamp = $time;
2335
2336 # Make "cur" and "diff" links
2337 if ( ( $rc_type == RC_NEW && $rc_this_oldid == 0 ) || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2338 $curLink = wfMsg( 'cur' );
2339 $diffLink = wfMsg( 'diff' );
2340 } else {
2341 $query = $curIdEq.'&diff=0&oldid='.$rc_this_oldid;
2342 $aprops = ' tabindex="'.$baseRC->counter.'"';
2343 $curLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'cur' ), $query, '' ,'' , $aprops );
2344 $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'diff'), $query, '' ,'' , $aprops );
2345 }
2346
2347 # Make "last" link
2348 $titleObj = $rc->getTitle();
2349 if ( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2350 $lastLink = wfMsg( 'last' );
2351 } else {
2352 $lastLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'last' ),
2353 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid );
2354 }
2355
2356 # Make user link (or user contributions for unregistered users)
2357 if ( $rc_user == 0 ) {
2358 $userLink = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
2359 $rc_user_text, 'target=' . $rc_user_text );
2360 } else {
2361 $userLink = $this->makeLink( $wgContLang->getNsText(
2362 Namespace::getUser() ) . ':'.$rc_user_text, $rc_user_text );
2363 }
2364
2365 $rc->userlink = $userLink;
2366 $rc->lastlink = $lastLink;
2367 $rc->curlink = $curLink;
2368 $rc->difflink = $diffLink;
2369
2370 # Make user talk link
2371 $utns=$wgContLang->getNsText(NS_USER_TALK);
2372 $talkname=$wgContLang->getNsText(NS_TALK); # use the shorter name
2373 $userTalkLink= $this->makeLink($utns . ':'.$rc_user_text, $talkname );
2374
2375 global $wgDisableAnonTalk;
2376 if ( ( 0 == $rc_user ) && $wgUser->isSysop() ) {
2377 $blockLink = $this->makeKnownLink( $wgContLang->specialPage(
2378 'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text );
2379 if( $wgDisableAnonTalk )
2380 $rc->usertalklink = ' ('.$blockLink.')';
2381 else
2382 $rc->usertalklink = ' ('.$userTalkLink.' | '.$blockLink.')';
2383 } else {
2384 if( $wgDisableAnonTalk && ($rc_user == 0) )
2385 $rc->usertalklink = '';
2386 else
2387 $rc->usertalklink = ' ('.$userTalkLink.')';
2388 }
2389
2390 # Put accumulated information into the cache, for later display
2391 # Page moves go on their own line
2392 $title = $rc->getTitle();
2393 $secureName = $title->getPrefixedDBkey();
2394 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2395 # Use an @ character to prevent collision with page names
2396 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
2397 } else {
2398 if ( !isset ( $this->rc_cache[$secureName] ) ) $this->rc_cache[$secureName] = array() ;
2399 array_push ( $this->rc_cache[$secureName] , $rc ) ;
2400 }
2401 return $ret;
2402 }
2403
2404 function endImageHistoryList() {
2405 $s = "</ul>\n";
2406 return $s;
2407 }
2408
2409 /**
2410 * This function is called by all recent changes variants, by the page history,
2411 * and by the user contributions list. It is responsible for formatting edit
2412 * comments. It escapes any HTML in the comment, but adds some CSS to format
2413 * auto-generated comments (from section editing) and formats [[wikilinks]].
2414 *
2415 * The &$title parameter must be a title OBJECT. It is used to generate a
2416 * direct link to the section in the autocomment.
2417 * @author Erik Moeller <moeller@scireview.de>
2418 *
2419 * Note: there's not always a title to pass to this function.
2420 * Since you can't set a default parameter for a reference, I've turned it
2421 * temporarily to a value pass. Should be adjusted further. --brion
2422 */
2423 function formatComment($comment, $title = NULL) {
2424 global $wgContLang;
2425 $comment = htmlspecialchars( $comment );
2426
2427 # The pattern for autogen comments is / * foo * /, which makes for
2428 # some nasty regex.
2429 # We look for all comments, match any text before and after the comment,
2430 # add a separator where needed and format the comment itself with CSS
2431 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
2432 $pre=$match[1];
2433 $auto=$match[2];
2434 $post=$match[3];
2435 $link='';
2436 if($title) {
2437 $section=$auto;
2438
2439 # This is hackish but should work in most cases.
2440 $section=str_replace('[[','',$section);
2441 $section=str_replace(']]','',$section);
2442 $title->mFragment=$section;
2443 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
2444 }
2445 $sep='-';
2446 $auto=$link.$auto;
2447 if($pre) { $auto = $sep.' '.$auto; }
2448 if($post) { $auto .= ' '.$sep; }
2449 $auto='<span class="autocomment">'.$auto.'</span>';
2450 $comment=$pre.$auto.$post;
2451 }
2452
2453 # format regular and media links - all other wiki formatting
2454 # is ignored
2455 $medians = $wgContLang->getNsText(Namespace::getMedia()).':';
2456 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
2457 # Handle link renaming [[foo|text]] will show link as "text"
2458 if( "" != $match[3] ) {
2459 $text = $match[3];
2460 } else {
2461 $text = $match[1];
2462 }
2463 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
2464 # Media link; trail not supported.
2465 $linkRegexp = '/\[\[(.*?)\]\]/';
2466 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
2467 } else {
2468 # Other kind of link
2469 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
2470 $trail = $submatch[1];
2471 } else {
2472 $trail = "";
2473 }
2474 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
2475 if ($match[1][0] == ':')
2476 $match[1] = substr($match[1], 1);
2477 $thelink = $this->makeLink( $match[1], $text, "", $trail );
2478 }
2479 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
2480 }
2481 return $comment;
2482 }
2483
2484 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
2485 global $wgUser, $wgLang, $wgContLang, $wgTitle;
2486
2487 $datetime = $wgLang->timeanddate( $timestamp, true );
2488 $del = wfMsg( 'deleteimg' );
2489 $delall = wfMsg( 'deleteimgcompletely' );
2490 $cur = wfMsg( 'cur' );
2491
2492 if ( $iscur ) {
2493 $url = Image::wfImageUrl( $img );
2494 $rlink = $cur;
2495 if ( $wgUser->isSysop() ) {
2496 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
2497 '&action=delete' );
2498 $style = $this->getInternalLinkAttributes( $link, $delall );
2499
2500 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
2501 } else {
2502 $dlink = $del;
2503 }
2504 } else {
2505 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
2506 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
2507 $rlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
2508 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
2509 urlencode( $img ) );
2510 $dlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
2511 $del, 'action=delete&oldimage=' . urlencode( $img ) );
2512 } else {
2513 # Having live active links for non-logged in users
2514 # means that bots and spiders crawling our site can
2515 # inadvertently change content. Baaaad idea.
2516 $rlink = wfMsg( 'revertimg' );
2517 $dlink = $del;
2518 }
2519 }
2520 if ( 0 == $user ) {
2521 $userlink = $usertext;
2522 } else {
2523 $userlink = $this->makeLink( $wgContLang->getNsText( Namespace::getUser() ) .
2524 ':'.$usertext, $usertext );
2525 }
2526 $nbytes = wfMsg( 'nbytes', $size );
2527 $style = $this->getInternalLinkAttributes( $url, $datetime );
2528
2529 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
2530 . " . . {$userlink} ({$nbytes})";
2531
2532 if ( '' != $description && '*' != $description ) {
2533 $sk=$wgUser->getSkin();
2534 $s .= $wgContLang->emphasize(' (' . $sk->formatComment($description,$wgTitle) . ')');
2535 }
2536 $s .= "</li>\n";
2537 return $s;
2538 }
2539
2540 function tocIndent($level) {
2541 return str_repeat( '<div class="tocindent">'."\n", $level>0 ? $level : 0 );
2542 }
2543
2544 function tocUnindent($level) {
2545 return str_repeat( "</div>\n", $level>0 ? $level : 0 );
2546 }
2547
2548 /**
2549 * parameter level defines if we are on an indentation level
2550 */
2551 function tocLine( $anchor, $tocline, $level ) {
2552 $link = '<a href="#'.$anchor.'">'.$tocline.'</a><br />';
2553 if($level) {
2554 return $link."\n";
2555 } else {
2556 return '<div class="tocline">'.$link."</div>\n";
2557 }
2558
2559 }
2560
2561 function tocTable($toc) {
2562 # note to CSS fanatics: putting this in a div does not work -- div won't auto-expand
2563 # try min-width & co when somebody gets a chance
2564 $hideline = ' <script type="text/javascript">showTocToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '")</script>';
2565 return
2566 '<table border="0" id="toc"><tr id="toctitle"><td align="center">'."\n".
2567 '<b>'.wfMsg('toc').'</b>' .
2568 $hideline .
2569 '</td></tr><tr id="tocinside"><td>'."\n".
2570 $toc."</td></tr></table>\n";
2571 }
2572
2573 /**
2574 * These two do not check for permissions: check $wgTitle->userCanEdit
2575 * before calling them
2576 */
2577 function editSectionScriptForOther( $title, $section, $head ) {
2578 $ttl = Title::newFromText( $title );
2579 $url = $ttl->escapeLocalURL( 'action=edit&section='.$section );
2580 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2581 }
2582
2583 function editSectionScript( $section, $head ) {
2584 global $wgTitle, $wgRequest;
2585 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2586 return $head;
2587 }
2588 $url = $wgTitle->escapeLocalURL( 'action=edit&section='.$section );
2589 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2590 }
2591
2592 function editSectionLinkForOther( $title, $section ) {
2593 global $wgRequest;
2594 global $wgUser, $wgContLang;
2595
2596 $title = Title::newFromText($title);
2597 $editurl = '&section='.$section;
2598 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2599
2600 if( $wgContLang->isRTL() ) {
2601 $farside = 'left';
2602 $nearside = 'right';
2603 } else {
2604 $farside = 'right';
2605 $nearside = 'left';
2606 }
2607 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2608
2609 }
2610
2611 function editSectionLink( $section ) {
2612 global $wgRequest;
2613 global $wgTitle, $wgUser, $wgContLang;
2614
2615 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2616 # Section edit links would be out of sync on an old page.
2617 # But, if we're diffing to the current page, they'll be
2618 # correct.
2619 return '';
2620 }
2621
2622 $editurl = '&section='.$section;
2623 $url = $this->makeKnownLink($wgTitle->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2624
2625 if( $wgContLang->isRTL() ) {
2626 $farside = 'left';
2627 $nearside = 'right';
2628 } else {
2629 $farside = 'right';
2630 $nearside = 'left';
2631 }
2632 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2633
2634 }
2635
2636 /**
2637 * This function is called by EditPage.php and shows a bulletin board style
2638 * toolbar for common editing functions. It can be disabled in the user
2639 * preferences.
2640 * The necessary JavaScript code can be found in style/wikibits.js.
2641 */
2642 function getEditToolbar() {
2643 global $wgStylePath, $wgLang, $wgMimeType;
2644
2645 /**
2646 * toolarray an array of arrays which each include the filename of
2647 * the button image (without path), the opening tag, the closing tag,
2648 * and optionally a sample text that is inserted between the two when no
2649 * selection is highlighted.
2650 * The tip text is shown when the user moves the mouse over the button.
2651 *
2652 * Already here are accesskeys (key), which are not used yet until someone
2653 * can figure out a way to make them work in IE. However, we should make
2654 * sure these keys are not defined on the edit page.
2655 */
2656 $toolarray=array(
2657 array( 'image'=>'button_bold.png',
2658 'open' => "\'\'\'",
2659 'close' => "\'\'\'",
2660 'sample'=> wfMsg('bold_sample'),
2661 'tip' => wfMsg('bold_tip'),
2662 'key' => 'B'
2663 ),
2664 array( 'image'=>'button_italic.png',
2665 'open' => "\'\'",
2666 'close' => "\'\'",
2667 'sample'=> wfMsg('italic_sample'),
2668 'tip' => wfMsg('italic_tip'),
2669 'key' => 'I'
2670 ),
2671 array( 'image'=>'button_link.png',
2672 'open' => '[[',
2673 'close' => ']]',
2674 'sample'=> wfMsg('link_sample'),
2675 'tip' => wfMsg('link_tip'),
2676 'key' => 'L'
2677 ),
2678 array( 'image'=>'button_extlink.png',
2679 'open' => '[',
2680 'close' => ']',
2681 'sample'=> wfMsg('extlink_sample'),
2682 'tip' => wfMsg('extlink_tip'),
2683 'key' => 'X'
2684 ),
2685 array( 'image'=>'button_headline.png',
2686 'open' => "\\n== ",
2687 'close' => " ==\\n",
2688 'sample'=> wfMsg('headline_sample'),
2689 'tip' => wfMsg('headline_tip'),
2690 'key' => 'H'
2691 ),
2692 array( 'image'=>'button_image.png',
2693 'open' => '[['.$wgLang->getNsText(NS_IMAGE).":",
2694 'close' => ']]',
2695 'sample'=> wfMsg('image_sample'),
2696 'tip' => wfMsg('image_tip'),
2697 'key' => 'D'
2698 ),
2699 array( 'image' => 'button_media.png',
2700 'open' => '[['.$wgLang->getNsText(NS_MEDIA).':',
2701 'close' => ']]',
2702 'sample'=> wfMsg('media_sample'),
2703 'tip' => wfMsg('media_tip'),
2704 'key' => 'M'
2705 ),
2706 array( 'image' => 'button_math.png',
2707 'open' => "\\<math\\>",
2708 'close' => "\\</math\\>",
2709 'sample'=> wfMsg('math_sample'),
2710 'tip' => wfMsg('math_tip'),
2711 'key' => 'C'
2712 ),
2713 array( 'image' => 'button_nowiki.png',
2714 'open' => "\\<nowiki\\>",
2715 'close' => "\\</nowiki\\>",
2716 'sample'=> wfMsg('nowiki_sample'),
2717 'tip' => wfMsg('nowiki_tip'),
2718 'key' => 'N'
2719 ),
2720 array( 'image' => 'button_sig.png',
2721 'open' => '--~~~~',
2722 'close' => '',
2723 'sample'=> '',
2724 'tip' => wfMsg('sig_tip'),
2725 'key' => 'Y'
2726 ),
2727 array( 'image' => 'button_hr.png',
2728 'open' => "\\n----\\n",
2729 'close' => '',
2730 'sample'=> '',
2731 'tip' => wfMsg('hr_tip'),
2732 'key' => 'R'
2733 )
2734 );
2735 $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
2736
2737 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
2738 foreach($toolarray as $tool) {
2739
2740 $image=$wgStylePath.'/common/images/'.$tool['image'];
2741 $open=$tool['open'];
2742 $close=$tool['close'];
2743 $sample = addslashes( $tool['sample'] );
2744
2745 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2746 // Older browsers show a "speedtip" type message only for ALT.
2747 // Ideally these should be different, realistically they
2748 // probably don't need to be.
2749 $tip = addslashes( $tool['tip'] );
2750
2751 #$key = $tool["key"];
2752
2753 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
2754 }
2755
2756 $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
2757 $toolbar.="document.writeln(\"</div>\");\n";
2758
2759 $toolbar.="/*]]>*/\n</script>";
2760 return $toolbar;
2761 }
2762
2763 /**
2764 * @access public
2765 */
2766 function suppressUrlExpansion() {
2767 return false;
2768 }
2769 }
2770
2771 }
2772 ?>