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