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