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