* remove PHP5 warning; PHPTAL no longer needed for MonoBook
[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->getCategorieBrowser();
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->makeKnownLink($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 function specialPagesList() {
903 global $wgUser, $wgOut, $wgContLang, $wgServer, $wgRedirectScript;
904 require_once('SpecialPage.php');
905 $a = array();
906 $pages = SpecialPage::getPages();
907
908 foreach ( $pages[''] as $name => $page ) {
909 $a[$name] = $page->getDescription();
910 }
911 if ( $wgUser->isSysop() )
912 {
913 foreach ( $pages['sysop'] as $name => $page ) {
914 $a[$name] = $page->getDescription();
915 }
916 }
917 if ( $wgUser->isDeveloper() )
918 {
919 foreach ( $pages['developer'] as $name => $page ) {
920 $a[$name] = $page->getDescription() ;
921 }
922 }
923 $go = wfMsg( 'go' );
924 $sp = wfMsg( 'specialpages' );
925 $spp = $wgContLang->specialPage( 'Specialpages' );
926
927 $s = '<form id="specialpages" method="get" class="inline" ' .
928 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
929 $s .= "<select name=\"wpDropdown\">\n";
930 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
931
932 foreach ( $a as $name => $desc ) {
933 $p = $wgContLang->specialPage( $name );
934 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
935 }
936 $s .= "</select>\n";
937 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
938 $s .= "</form>\n";
939 return $s;
940 }
941
942 function mainPageLink() {
943 $mp = wfMsgForContent( 'mainpage' );
944 $mptxt = wfMsg( 'mainpage');
945 $s = $this->makeKnownLink( $mp, $mptxt );
946 return $s;
947 }
948
949 function copyrightLink() {
950 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
951 wfMsg( 'copyrightpagename' ) );
952 return $s;
953 }
954
955 function aboutLink() {
956 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
957 wfMsg( 'aboutsite' ) );
958 return $s;
959 }
960
961
962 function disclaimerLink() {
963 $disclaimers = wfMsg( 'disclaimers' );
964 if ($disclaimers == '-') {
965 return "";
966 } else {
967 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
968 $disclaimers );
969 }
970 }
971
972 function editThisPage() {
973 global $wgOut, $wgTitle, $wgRequest;
974
975 $oldid = $wgRequest->getVal( 'oldid' );
976 $diff = $wgRequest->getVal( 'diff' );
977 $redirect = $wgRequest->getVal( 'redirect' );
978
979 if ( ! $wgOut->isArticleRelated() ) {
980 $s = wfMsg( 'protectedpage' );
981 } else {
982 $n = $wgTitle->getPrefixedText();
983 if ( $wgTitle->userCanEdit() ) {
984 $t = wfMsg( 'editthispage' );
985 } else {
986 #$t = wfMsg( "protectedpage" );
987 $t = wfMsg( 'viewsource' );
988 }
989 $oid = $red = '';
990
991 if ( !is_null( $redirect ) ) { $red = "&redirect={$redirect}"; }
992 if ( $oldid && ! isset( $diff ) ) {
993 $oid = '&oldid='.$oldid;
994 }
995 $s = $this->makeKnownLink( $n, $t, "action=edit{$oid}{$red}" );
996 }
997 return $s;
998 }
999
1000 function deleteThisPage() {
1001 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1002
1003 $diff = $wgRequest->getVal( 'diff' );
1004 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1005 $n = $wgTitle->getPrefixedText();
1006 $t = wfMsg( 'deletethispage' );
1007
1008 $s = $this->makeKnownLink( $n, $t, 'action=delete' );
1009 } else {
1010 $s = '';
1011 }
1012 return $s;
1013 }
1014
1015 function protectThisPage() {
1016 global $wgUser, $wgOut, $wgTitle, $wgRequest;
1017
1018 $diff = $wgRequest->getVal( 'diff' );
1019 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1020 $n = $wgTitle->getPrefixedText();
1021
1022 if ( $wgTitle->isProtected() ) {
1023 $t = wfMsg( 'unprotectthispage' );
1024 $q = 'action=unprotect';
1025 } else {
1026 $t = wfMsg( 'protectthispage' );
1027 $q = 'action=protect';
1028 }
1029 $s = $this->makeKnownLink( $n, $t, $q );
1030 } else {
1031 $s = '';
1032 }
1033 return $s;
1034 }
1035
1036 function watchThisPage() {
1037 global $wgUser, $wgOut, $wgTitle;
1038
1039 if ( $wgOut->isArticleRelated() ) {
1040 $n = $wgTitle->getPrefixedText();
1041
1042 if ( $wgTitle->userIsWatching() ) {
1043 $t = wfMsg( 'unwatchthispage' );
1044 $q = 'action=unwatch';
1045 } else {
1046 $t = wfMsg( 'watchthispage' );
1047 $q = 'action=watch';
1048 }
1049 $s = $this->makeKnownLink( $n, $t, $q );
1050 } else {
1051 $s = wfMsg( 'notanarticle' );
1052 }
1053 return $s;
1054 }
1055
1056 function moveThisPage() {
1057 global $wgTitle, $wgContLang;
1058
1059 if ( $wgTitle->userCanEdit() ) {
1060 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Movepage' ),
1061 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1062 } // no message if page is protected - would be redundant
1063 return $s;
1064 }
1065
1066 function historyLink() {
1067 global $wgTitle;
1068
1069 $s = $this->makeKnownLink( $wgTitle->getPrefixedText(),
1070 wfMsg( 'history' ), 'action=history' );
1071 return $s;
1072 }
1073
1074 function whatLinksHere() {
1075 global $wgTitle, $wgContLang;
1076
1077 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Whatlinkshere' ),
1078 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1079 return $s;
1080 }
1081
1082 function userContribsLink() {
1083 global $wgTitle, $wgContLang;
1084
1085 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
1086 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1087 return $s;
1088 }
1089
1090 function emailUserLink() {
1091 global $wgTitle, $wgContLang;
1092
1093 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Emailuser' ),
1094 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1095 return $s;
1096 }
1097
1098 function watchPageLinksLink() {
1099 global $wgOut, $wgTitle, $wgContLang;
1100
1101 if ( ! $wgOut->isArticleRelated() ) {
1102 $s = '(' . wfMsg( 'notanarticle' ) . ')';
1103 } else {
1104 $s = $this->makeKnownLink( $wgContLang->specialPage(
1105 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1106 'target=' . $wgTitle->getPrefixedURL() );
1107 }
1108 return $s;
1109 }
1110
1111 function otherLanguages() {
1112 global $wgOut, $wgContLang, $wgTitle, $wgUseNewInterlanguage;
1113
1114 $a = $wgOut->getLanguageLinks();
1115 if ( 0 == count( $a ) ) {
1116 if ( !$wgUseNewInterlanguage ) return '';
1117 $ns = $wgContLang->getNsIndex ( $wgTitle->getNamespace () ) ;
1118 if ( $ns != 0 AND $ns != 1 ) return '' ;
1119 $pn = 'Intl' ;
1120 $x = 'mode=addlink&xt='.$wgTitle->getDBkey() ;
1121 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1122 wfMsg( 'intl' ) , $x );
1123 }
1124
1125 if ( !$wgUseNewInterlanguage ) {
1126 $s = wfMsg( 'otherlanguages' ) . ': ';
1127 } else {
1128 global $wgContLanguageCode ;
1129 $x = 'mode=zoom&xt='.$wgTitle->getDBkey() ;
1130 $x .= '&xl='.$wgContLanguageCode ;
1131 $s = $this->makeKnownLink( $wgContLang->specialPage( 'Intl' ),
1132 wfMsg( 'otherlanguages' ) , $x ) . ': ' ;
1133 }
1134
1135 $s = wfMsg( 'otherlanguages' ) . ': ';
1136 $first = true;
1137 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1138 foreach( $a as $l ) {
1139 if ( ! $first ) { $s .= ' | '; }
1140 $first = false;
1141
1142 $nt = Title::newFromText( $l );
1143 $url = $nt->getFullURL();
1144 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1145
1146 if ( '' == $text ) { $text = $l; }
1147 $style = $this->getExternalLinkAttributes( $l, $text );
1148 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1149 }
1150 if($wgContLang->isRTL()) $s .= '</span>';
1151 return $s;
1152 }
1153
1154 function bugReportsLink() {
1155 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1156 wfMsg( 'bugreports' ) );
1157 return $s;
1158 }
1159
1160 function dateLink() {
1161 global $wgLinkCache;
1162 $t1 = Title::newFromText( gmdate( 'F j' ) );
1163 $t2 = Title::newFromText( gmdate( 'Y' ) );
1164
1165 $wgLinkCache->suspend();
1166 $id = $t1->getArticleID();
1167 $wgLinkCache->resume();
1168
1169 if ( 0 == $id ) {
1170 $s = $this->makeBrokenLink( $t1->getText() );
1171 } else {
1172 $s = $this->makeKnownLink( $t1->getText() );
1173 }
1174 $s .= ', ';
1175
1176 $wgLinkCache->suspend();
1177 $id = $t2->getArticleID();
1178 $wgLinkCache->resume();
1179
1180 if ( 0 == $id ) {
1181 $s .= $this->makeBrokenLink( $t2->getText() );
1182 } else {
1183 $s .= $this->makeKnownLink( $t2->getText() );
1184 }
1185 return $s;
1186 }
1187
1188 function talkLink() {
1189 global $wgContLang, $wgTitle, $wgLinkCache;
1190
1191 $tns = $wgTitle->getNamespace();
1192 if ( -1 == $tns ) { return ''; }
1193
1194 $pn = $wgTitle->getText();
1195 $tp = wfMsg( 'talkpage' );
1196 if ( Namespace::isTalk( $tns ) ) {
1197 $lns = Namespace::getSubject( $tns );
1198 switch($tns) {
1199 case 1:
1200 $text = wfMsg('articlepage');
1201 break;
1202 case 3:
1203 $text = wfMsg('userpage');
1204 break;
1205 case 5:
1206 $text = wfMsg('wikipediapage');
1207 break;
1208 case 7:
1209 $text = wfMsg('imagepage');
1210 break;
1211 default:
1212 $text= wfMsg('articlepage');
1213 }
1214 } else {
1215
1216 $lns = Namespace::getTalk( $tns );
1217 $text=$tp;
1218 }
1219 $n = $wgContLang->getNsText( $lns );
1220 if ( '' == $n ) { $link = $pn; }
1221 else { $link = $n.':'.$pn; }
1222
1223 $wgLinkCache->suspend();
1224 $s = $this->makeLink( $link, $text );
1225 $wgLinkCache->resume();
1226
1227 return $s;
1228 }
1229
1230 function commentLink() {
1231 global $wgContLang, $wgTitle, $wgLinkCache;
1232
1233 $tns = $wgTitle->getNamespace();
1234 if ( -1 == $tns ) { return ''; }
1235
1236 $lns = ( Namespace::isTalk( $tns ) ) ? $tns : Namespace::getTalk( $tns );
1237
1238 # assert Namespace::isTalk( $lns )
1239
1240 $n = $wgContLang->getNsText( $lns );
1241 $pn = $wgTitle->getText();
1242
1243 $link = $n.':'.$pn;
1244
1245 $wgLinkCache->suspend();
1246 $s = $this->makeKnownLink($link, wfMsg('postcomment'), 'action=edit&section=new');
1247 $wgLinkCache->resume();
1248
1249 return $s;
1250 }
1251
1252 /**
1253 * After all the page content is transformed into HTML, it makes
1254 * a final pass through here for things like table backgrounds.
1255 * @todo probably deprecated [AV]
1256 */
1257 function transformContent( $text ) {
1258 return $text;
1259 }
1260
1261 /**
1262 * Note: This function MUST call getArticleID() on the link,
1263 * otherwise the cache won't get updated properly. See LINKCACHE.DOC.
1264 */
1265 function makeLink( $title, $text = '', $query = '', $trail = '' ) {
1266 wfProfileIn( 'Skin::makeLink' );
1267 $nt = Title::newFromText( $title );
1268 if ($nt) {
1269 $result = $this->makeLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1270 } else {
1271 wfDebug( 'Invalid title passed to Skin::makeLink(): "'.$title."\"\n" );
1272 $result = $text == "" ? $title : $text;
1273 }
1274
1275 wfProfileOut( 'Skin::makeLink' );
1276 return $result;
1277 }
1278
1279 function makeKnownLink( $title, $text = '', $query = '', $trail = '', $prefix = '',$aprops = '') {
1280 $nt = Title::newFromText( $title );
1281 if ($nt) {
1282 return $this->makeKnownLinkObj( Title::newFromText( $title ), $text, $query, $trail, $prefix , $aprops );
1283 } else {
1284 wfDebug( 'Invalid title passed to Skin::makeKnownLink(): "'.$title."\"\n" );
1285 return $text == '' ? $title : $text;
1286 }
1287 }
1288
1289 function makeBrokenLink( $title, $text = '', $query = '', $trail = '' ) {
1290 $nt = Title::newFromText( $title );
1291 if ($nt) {
1292 return $this->makeBrokenLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1293 } else {
1294 wfDebug( 'Invalid title passed to Skin::makeBrokenLink(): "'.$title."\"\n" );
1295 return $text == '' ? $title : $text;
1296 }
1297 }
1298
1299 function makeStubLink( $title, $text = '', $query = '', $trail = '' ) {
1300 $nt = Title::newFromText( $title );
1301 if ($nt) {
1302 return $this->makeStubLinkObj( Title::newFromText( $title ), $text, $query, $trail );
1303 } else {
1304 wfDebug( 'Invalid title passed to Skin::makeStubLink(): "'.$title."\"\n" );
1305 return $text == '' ? $title : $text;
1306 }
1307 }
1308
1309 /**
1310 * Pass a title object, not a title string
1311 */
1312 function makeLinkObj( &$nt, $text= '', $query = '', $trail = '', $prefix = '' ) {
1313 global $wgOut, $wgUser, $wgLinkHolders;
1314 $fname = 'Skin::makeLinkObj';
1315
1316 # Fail gracefully
1317 if ( ! isset($nt) ) {
1318 # wfDebugDieBacktrace();
1319 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1320 }
1321
1322 if ( $nt->isExternal() ) {
1323 $u = $nt->getFullURL();
1324 $link = $nt->getPrefixedURL();
1325 if ( '' == $text ) { $text = $nt->getPrefixedText(); }
1326 $style = $this->getExternalLinkAttributes( $link, $text, 'extiw' );
1327
1328 $inside = '';
1329 if ( '' != $trail ) {
1330 if ( preg_match( '/^([a-z]+)(.*)$$/sD', $trail, $m ) ) {
1331 $inside = $m[1];
1332 $trail = $m[2];
1333 }
1334 }
1335 # Assume $this->postParseLinkColour(). This prevents
1336 # interwiki links from being parsed as external links.
1337 global $wgInterwikiLinkHolders;
1338 $t = "<a href=\"{$u}\"{$style}>{$text}{$inside}</a>";
1339 $nr = array_push($wgInterwikiLinkHolders, $t);
1340 $retVal = '<!--IWLINK '. ($nr-1) ."-->{$trail}";
1341 } elseif ( 0 == $nt->getNamespace() && "" == $nt->getText() ) {
1342 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1343 } elseif ( ( -1 == $nt->getNamespace() ) ||
1344 ( NS_IMAGE == $nt->getNamespace() ) ) {
1345 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1346 } else {
1347 if ( $this->postParseLinkColour() ) {
1348 $inside = '';
1349 if ( '' != $trail ) {
1350 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1351 $inside = $m[1];
1352 $trail = $m[2];
1353 }
1354 }
1355
1356 # Allows wiki to bypass using linkcache, see OutputPage::parseLinkHolders()
1357 $nr = array_push( $wgLinkHolders['namespaces'], $nt->getNamespace() );
1358 $wgLinkHolders['dbkeys'][] = $nt->getDBkey();
1359 $wgLinkHolders['queries'][] = $query;
1360 $wgLinkHolders['texts'][] = $prefix.$text.$inside;
1361 $wgLinkHolders['titles'][] = $nt;
1362
1363 $retVal = '<!--LINK '. ($nr-1) ."-->{$trail}";
1364 } else {
1365 # Work out link colour immediately
1366 $aid = $nt->getArticleID() ;
1367 if ( 0 == $aid ) {
1368 $retVal = $this->makeBrokenLinkObj( $nt, $text, $query, $trail, $prefix );
1369 } else {
1370 $threshold = $wgUser->getOption('stubthreshold') ;
1371 if ( $threshold > 0 ) {
1372 $dbr =& wfGetDB( DB_SLAVE );
1373 $s = $dbr->selectRow( 'cur', array( 'LENGTH(cur_text) AS x', 'cur_namespace',
1374 'cur_is_redirect' ), array( 'cur_id' => $aid ), $fname ) ;
1375 if ( $s !== false ) {
1376 $size = $s->x;
1377 if ( $s->cur_is_redirect OR $s->cur_namespace != 0 ) {
1378 $size = $threshold*2 ; # Really big
1379 }
1380 $dbr->freeResult( $res );
1381 } else {
1382 $size = $threshold*2 ; # Really big
1383 }
1384 } else {
1385 $size = 1 ;
1386 }
1387 if ( $size < $threshold ) {
1388 $retVal = $this->makeStubLinkObj( $nt, $text, $query, $trail, $prefix );
1389 } else {
1390 $retVal = $this->makeKnownLinkObj( $nt, $text, $query, $trail, $prefix );
1391 }
1392 }
1393 }
1394 }
1395 return $retVal;
1396 }
1397
1398 /**
1399 * Pass a title object, not a title string
1400 */
1401 function makeKnownLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' , $aprops = '' ) {
1402 global $wgOut, $wgTitle, $wgInputEncoding;
1403
1404 $fname = 'Skin::makeKnownLinkObj';
1405 wfProfileIn( $fname );
1406
1407 if ( !is_object( $nt ) ) {
1408 return $text;
1409 }
1410 $link = $nt->getPrefixedURL();
1411 # if ( '' != $section && substr($section,0,1) != "#" ) {
1412 # $section = ''
1413
1414 if ( '' == $link ) {
1415 $u = '';
1416 if ( '' == $text ) {
1417 $text = htmlspecialchars( $nt->getFragment() );
1418 }
1419 } else {
1420 $u = $nt->escapeLocalURL( $query );
1421 }
1422 if ( '' != $nt->getFragment() ) {
1423 $anchor = urlencode( do_html_entity_decode( str_replace(' ', '_', $nt->getFragment()), ENT_COMPAT, $wgInputEncoding ) );
1424 $replacearray = array(
1425 '%3A' => ':',
1426 '%' => '.'
1427 );
1428 $u .= '#' . str_replace(array_keys($replacearray),array_values($replacearray),$anchor);
1429 }
1430 if ( '' == $text ) {
1431 $text = htmlspecialchars( $nt->getPrefixedText() );
1432 }
1433 $style = $this->getInternalLinkAttributesObj( $nt, $text );
1434
1435 $inside = '';
1436 if ( '' != $trail ) {
1437 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1438 $inside = $m[1];
1439 $trail = $m[2];
1440 }
1441 }
1442 $r = "<a href=\"{$u}\"{$style}{$aprops}>{$prefix}{$text}{$inside}</a>{$trail}";
1443 wfProfileOut( $fname );
1444 return $r;
1445 }
1446
1447 /**
1448 * Pass a title object, not a title string
1449 */
1450 function makeBrokenLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1451 global $wgOut, $wgUser;
1452
1453 # Fail gracefully
1454 if ( ! isset($nt) ) {
1455 # wfDebugDieBacktrace();
1456 return "<!-- ERROR -->{$prefix}{$text}{$trail}";
1457 }
1458
1459 $fname = 'Skin::makeBrokenLinkObj';
1460 wfProfileIn( $fname );
1461
1462 if ( '' == $query ) {
1463 $q = 'action=edit';
1464 } else {
1465 $q = 'action=edit&'.$query;
1466 }
1467 $u = $nt->escapeLocalURL( $q );
1468
1469 if ( '' == $text ) {
1470 $text = htmlspecialchars( $nt->getPrefixedText() );
1471 }
1472 $style = $this->getInternalLinkAttributesObj( $nt, $text, "yes" );
1473
1474 $inside = '';
1475 if ( '' != $trail ) {
1476 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1477 $inside = $m[1];
1478 $trail = $m[2];
1479 }
1480 }
1481 if ( $wgUser->getOption( 'highlightbroken' ) ) {
1482 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1483 } else {
1484 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>?</a>{$trail}";
1485 }
1486
1487 wfProfileOut( $fname );
1488 return $s;
1489 }
1490
1491 /**
1492 * Pass a title object, not a title string
1493 */
1494 function makeStubLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1495 global $wgOut, $wgUser;
1496
1497 $link = $nt->getPrefixedURL();
1498
1499 $u = $nt->escapeLocalURL( $query );
1500
1501 if ( '' == $text ) {
1502 $text = htmlspecialchars( $nt->getPrefixedText() );
1503 }
1504 $style = $this->getInternalLinkAttributesObj( $nt, $text, 'stub' );
1505
1506 $inside = '';
1507 if ( '' != $trail ) {
1508 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1509 $inside = $m[1];
1510 $trail = $m[2];
1511 }
1512 }
1513 if ( $wgUser->getOption( 'highlightbroken' ) ) {
1514 $s = "<a href=\"{$u}\"{$style}>{$prefix}{$text}{$inside}</a>{$trail}";
1515 } else {
1516 $s = "{$prefix}{$text}{$inside}<a href=\"{$u}\"{$style}>!</a>{$trail}";
1517 }
1518 return $s;
1519 }
1520
1521 function makeSelfLinkObj( &$nt, $text = '', $query = '', $trail = '', $prefix = '' ) {
1522 $u = $nt->escapeLocalURL( $query );
1523 if ( '' == $text ) {
1524 $text = htmlspecialchars( $nt->getPrefixedText() );
1525 }
1526 $inside = '';
1527 if ( '' != $trail ) {
1528 if ( preg_match( $this->linktrail, $trail, $m ) ) {
1529 $inside = $m[1];
1530 $trail = $m[2];
1531 }
1532 }
1533 return "<strong>{$prefix}{$text}{$inside}</strong>{$trail}";
1534 }
1535
1536 /* these are used extensively in SkinPHPTal, but also some other places */
1537 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1538 $title = Title::makeTitle( NS_SPECIAL, $name );
1539 $this->checkTitle($title, $name);
1540 return $title->getLocalURL( $urlaction );
1541 }
1542 /*static*/ function makeTalkUrl ( $name, $urlaction='' ) {
1543 $title = Title::newFromText( $name );
1544 $title = $title->getTalkPage();
1545 $this->checkTitle($title, $name);
1546 return $title->getLocalURL( $urlaction );
1547 }
1548 /*static*/ function makeArticleUrl ( $name, $urlaction='' ) {
1549 $title = Title::newFromText( $name );
1550 $title= $title->getSubjectPage();
1551 $this->checkTitle($title, $name);
1552 return $title->getLocalURL( $urlaction );
1553 }
1554 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1555 $title = Title::newFromText( wfMsgForContent($name) );
1556 $this->checkTitle($title, $name);
1557 return $title->getLocalURL( $urlaction );
1558 }
1559 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1560 $title = Title::newFromText( $name );
1561 $this->checkTitle($title, $name);
1562 return $title->getLocalURL( $urlaction );
1563 }
1564
1565 # If url string starts with http, consider as external URL, else
1566 # internal
1567 /*static*/ function makeInternalOrExternalUrl( $name ) {
1568 if ( strncmp( $name, 'http', 4 ) == 0 ) {
1569 return $name;
1570 } else {
1571 return $this->makeUrl( $name );
1572 }
1573 }
1574
1575 # this can be passed the NS number as defined in Language.php
1576 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=0 ) {
1577 $title = Title::makeTitleSafe( $namespace, $name );
1578 $this->checkTitle($title, $name);
1579 return $title->getLocalURL( $urlaction );
1580 }
1581
1582 /* these return an array with the 'href' and boolean 'exists' */
1583 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1584 $title = Title::newFromText( $name );
1585 $this->checkTitle($title, $name);
1586 return array(
1587 'href' => $title->getLocalURL( $urlaction ),
1588 'exists' => $title->getArticleID() != 0?true:false
1589 );
1590 }
1591 /*static*/ function makeTalkUrlDetails ( $name, $urlaction='' ) {
1592 $title = Title::newFromText( $name );
1593 $title = $title->getTalkPage();
1594 $this->checkTitle($title, $name);
1595 return array(
1596 'href' => $title->getLocalURL( $urlaction ),
1597 'exists' => $title->getArticleID() != 0?true:false
1598 );
1599 }
1600 /*static*/ function makeArticleUrlDetails ( $name, $urlaction='' ) {
1601 $title = Title::newFromText( $name );
1602 $title= $title->getSubjectPage();
1603 $this->checkTitle($title, $name);
1604 return array(
1605 'href' => $title->getLocalURL( $urlaction ),
1606 'exists' => $title->getArticleID() != 0?true:false
1607 );
1608 }
1609 /*static*/ function makeI18nUrlDetails ( $name, $urlaction='' ) {
1610 $title = Title::newFromText( wfMsgForContent($name) );
1611 $this->checkTitle($title, $name);
1612 return array(
1613 'href' => $title->getLocalURL( $urlaction ),
1614 'exists' => $title->getArticleID() != 0?true:false
1615 );
1616 }
1617
1618 # make sure we have some title to operate on
1619 /*static*/ function checkTitle ( &$title, &$name ) {
1620 if(!is_object($title)) {
1621 $title = Title::newFromText( $name );
1622 if(!is_object($title)) {
1623 $title = Title::newFromText( '--error: link target missing--' );
1624 }
1625 }
1626 }
1627
1628 function fnamePart( $url ) {
1629 $basename = strrchr( $url, '/' );
1630 if ( false === $basename ) {
1631 $basename = $url;
1632 } else {
1633 $basename = substr( $basename, 1 );
1634 }
1635 return htmlspecialchars( $basename );
1636 }
1637
1638 function makeImage( $url, $alt = '' ) {
1639 global $wgOut;
1640 if ( '' == $alt ) {
1641 $alt = $this->fnamePart( $url );
1642 }
1643 $s = '<img src="'.$url.'" alt="'.$alt.'" />';
1644 return $s;
1645 }
1646
1647 function makeImageLink( $name, $url, $alt = '' ) {
1648 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1649 return $this->makeImageLinkObj( $nt, $alt );
1650 }
1651
1652 function makeImageLinkObj( $nt, $alt = '' ) {
1653 global $wgContLang, $wgUseImageResize;
1654 $img = Image::newFromTitle( $nt );
1655 $url = $img->getViewURL();
1656
1657 $align = '';
1658 $prefix = $postfix = '';
1659
1660 # Check if the alt text is of the form "options|alt text"
1661 # Options are:
1662 # * thumbnail make a thumbnail with enlarge-icon and caption, alignment depends on lang
1663 # * left no resizing, just left align. label is used for alt= only
1664 # * right same, but right aligned
1665 # * none same, but not aligned
1666 # * ___px scale to ___ pixels width, no aligning. e.g. use in taxobox
1667 # * center center the image
1668 # * framed Keep original image size, no magnify-button.
1669
1670 $part = explode( '|', $alt);
1671
1672 $mwThumb =& MagicWord::get( MAG_IMG_THUMBNAIL );
1673 $mwLeft =& MagicWord::get( MAG_IMG_LEFT );
1674 $mwRight =& MagicWord::get( MAG_IMG_RIGHT );
1675 $mwNone =& MagicWord::get( MAG_IMG_NONE );
1676 $mwWidth =& MagicWord::get( MAG_IMG_WIDTH );
1677 $mwCenter =& MagicWord::get( MAG_IMG_CENTER );
1678 $mwFramed =& MagicWord::get( MAG_IMG_FRAMED );
1679 $alt = '';
1680
1681 $height = $framed = $thumb = false;
1682 $manual_thumb = "" ;
1683
1684 foreach( $part as $key => $val ) {
1685 $val_parts = explode ( "=" , $val , 2 ) ;
1686 $left_part = array_shift ( $val_parts ) ;
1687 if ( $wgUseImageResize && ! is_null( $mwThumb->matchVariableStartToEnd($val) ) ) {
1688 $thumb=true;
1689 } elseif ( $wgUseImageResize && count ( $val_parts ) == 1 && ! is_null( $mwThumb->matchVariableStartToEnd($left_part) ) ) {
1690 # use manually specified thumbnail
1691 $thumb=true;
1692 $manual_thumb = array_shift ( $val_parts ) ;
1693 } elseif ( ! is_null( $mwRight->matchVariableStartToEnd($val) ) ) {
1694 # remember to set an alignment, don't render immediately
1695 $align = 'right';
1696 } elseif ( ! is_null( $mwLeft->matchVariableStartToEnd($val) ) ) {
1697 # remember to set an alignment, don't render immediately
1698 $align = 'left';
1699 } elseif ( ! is_null( $mwCenter->matchVariableStartToEnd($val) ) ) {
1700 # remember to set an alignment, don't render immediately
1701 $align = 'center';
1702 } elseif ( ! is_null( $mwNone->matchVariableStartToEnd($val) ) ) {
1703 # remember to set an alignment, don't render immediately
1704 $align = 'none';
1705 } elseif ( $wgUseImageResize && ! is_null( $match = $mwWidth->matchVariableStartToEnd($val) ) ) {
1706 # $match is the image width in pixels
1707 if ( preg_match( '/^([0-9]*)x([0-9]*)$/', $match, $m ) ) {
1708 $width = intval( $m[1] );
1709 $height = intval( $m[2] );
1710 } else {
1711 $width = intval($match);
1712 }
1713 } elseif ( ! is_null( $mwFramed->matchVariableStartToEnd($val) ) ) {
1714 $framed=true;
1715 } else {
1716 $alt = $val;
1717 }
1718 }
1719 if ( 'center' == $align )
1720 {
1721 $prefix = '<div class="center">';
1722 $postfix = '</div>';
1723 $align = 'none';
1724 }
1725
1726 if ( $thumb || $framed ) {
1727
1728 # Create a thumbnail. Alignment depends on language
1729 # writing direction, # right aligned for left-to-right-
1730 # languages ("Western languages"), left-aligned
1731 # for right-to-left-languages ("Semitic languages")
1732 #
1733 # If thumbnail width has not been provided, it is set
1734 # here to 180 pixels
1735 if ( $align == '' ) {
1736 $align = $wgContLang->isRTL() ? 'left' : 'right';
1737 }
1738 if ( ! isset($width) ) {
1739 $width = 180;
1740 }
1741 return $prefix.$this->makeThumbLinkObj( $img, $alt, $align, $width, $height, $framed, $manual_thumb ).$postfix;
1742
1743 } elseif ( isset($width) ) {
1744
1745 # Create a resized image, without the additional thumbnail
1746 # features
1747
1748 if ( ( ! $height === false )
1749 && ( $img->getHeight() * $width / $img->getWidth() > $height ) ) {
1750 $width = $img->getWidth() * $height / $img->getHeight();
1751 }
1752 if ( '' == $manual_thumb ) $url = $img->createThumb( $width );
1753 }
1754
1755 $alt = preg_replace( '/<[^>]*>/', '', $alt );
1756 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1757 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1758
1759 $u = $nt->escapeLocalURL();
1760 if ( $url == '' ) {
1761 $s = wfMsg( 'missingimage', $img->getName() );
1762 $s .= "<br>{$alt}<br>{$url}<br>\n";
1763 } else {
1764 $s = '<a href="'.$u.'" class="image" title="'.$alt.'">' .
1765 '<img src="'.$url.'" alt="'.$alt.'" longdesc="'.$u.'" /></a>';
1766 }
1767 if ( '' != $align ) {
1768 $s = "<div class=\"float{$align}\"><span>{$s}</span></div>";
1769 }
1770 return str_replace("\n", ' ',$prefix.$s.$postfix);
1771 }
1772
1773 /**
1774 * Make HTML for a thumbnail including image, border and caption
1775 * $img is an Image object
1776 */
1777 function makeThumbLinkObj( $img, $label = '', $align = 'right', $boxwidth = 180, $boxheight=false, $framed=false , $manual_thumb = "" ) {
1778 global $wgStylePath, $wgContLang;
1779 # $image = Title::makeTitleSafe( NS_IMAGE, $name );
1780 $url = $img->getViewURL();
1781
1782 #$label = htmlspecialchars( $label );
1783 $alt = preg_replace( '/<[^>]*>/', '', $label);
1784 $alt = preg_replace('/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', '&amp;', $alt);
1785 $alt = str_replace( array('<', '>', '"'), array('&lt;', '&gt;', '&quot;'), $alt );
1786
1787 $width = $height = 0;
1788 if ( $img->exists() )
1789 {
1790 $width = $img->getWidth();
1791 $height = $img->getHeight();
1792 }
1793 if ( 0 == $width || 0 == $height )
1794 {
1795 $width = $height = 200;
1796 }
1797 if ( $boxwidth == 0 )
1798 {
1799 $boxwidth = 200;
1800 }
1801 if ( $framed )
1802 {
1803 // Use image dimensions, don't scale
1804 $boxwidth = $width;
1805 $oboxwidth = $boxwidth + 2;
1806 $boxheight = $height;
1807 $thumbUrl = $url;
1808 } else {
1809 $h = intval( $height/($width/$boxwidth) );
1810 $oboxwidth = $boxwidth + 2;
1811 if ( ( ! $boxheight === false ) && ( $h > $boxheight ) )
1812 {
1813 $boxwidth *= $boxheight/$h;
1814 } else {
1815 $boxheight = $h;
1816 }
1817 if ( '' == $manual_thumb ) $thumbUrl = $img->createThumb( $boxwidth );
1818 }
1819
1820 if ( $manual_thumb != '' ) # Use manually specified thumbnail
1821 {
1822 $manual_title = Title::makeTitleSafe( NS_IMAGE, $manual_thumb ); #new Title ( $manual_thumb ) ;
1823 $manual_img = Image::newFromTitle( $manual_title );
1824 $thumbUrl = $manual_img->getViewURL();
1825 if ( $manual_img->exists() )
1826 {
1827 $width = $manual_img->getWidth();
1828 $height = $manual_img->getHeight();
1829 $boxwidth = $width ;
1830 $boxheight = $height ;
1831 $oboxwidth = $boxwidth + 2 ;
1832 }
1833 }
1834
1835 $u = $img->getEscapeLocalURL();
1836
1837 $more = htmlspecialchars( wfMsg( 'thumbnail-more' ) );
1838 $magnifyalign = $wgContLang->isRTL() ? 'left' : 'right';
1839 $textalign = $wgContLang->isRTL() ? ' style="text-align:right"' : '';
1840
1841 $s = "<div class=\"thumb t{$align}\"><div style=\"width:{$oboxwidth}px;\">";
1842 if ( $thumbUrl == '' ) {
1843 $s .= wfMsg( 'missingimage', $img->getName() );
1844 $zoomicon = '';
1845 } else {
1846 $s .= '<a href="'.$u.'" class="internal" title="'.$alt.'">'.
1847 '<img src="'.$thumbUrl.'" alt="'.$alt.'" ' .
1848 'width="'.$boxwidth.'" height="'.$boxheight.'" ' .
1849 'longdesc="'.$u.'" /></a>';
1850 if ( $framed ) {
1851 $zoomicon="";
1852 } else {
1853 $zoomicon = '<div class="magnify" style="float:'.$magnifyalign.'">'.
1854 '<a href="'.$u.'" class="internal" title="'.$more.'">'.
1855 '<img src="'.$wgStylePath.'/common/images/magnify-clip.png" ' .
1856 'width="15" height="11" alt="'.$more.'" /></a></div>';
1857 }
1858 }
1859 $s .= ' <div class="thumbcaption" '.$textalign.'>'.$zoomicon.$label."</div></div></div>";
1860 return str_replace("\n", ' ', $s);
1861 }
1862
1863 function makeMediaLink( $name, $url, $alt = '' ) {
1864 $nt = Title::makeTitleSafe( NS_IMAGE, $name );
1865 return $this->makeMediaLinkObj( $nt, $alt );
1866 }
1867
1868 function makeMediaLinkObj( $nt, $alt = '', $nourl=false ) {
1869 if ( ! isset( $nt ) )
1870 {
1871 ### HOTFIX. Instead of breaking, return empty string.
1872 $s = $alt;
1873 } else {
1874 $name = $nt->getDBKey();
1875 $img = Image::newFromTitle( $nt );
1876 $url = $img->getURL();
1877 # $nourl can be set by the parser
1878 # this is a hack to mask absolute URLs, so the parser doesn't
1879 # linkify them (it is currently not context-aware)
1880 # 2004-10-25
1881 if ($nourl) { $url=str_replace("http://","http-noparse://",$url) ; }
1882 if ( empty( $alt ) ) {
1883 $alt = preg_replace( '/\.(.+?)^/', '', $name );
1884 }
1885 $u = htmlspecialchars( $url );
1886 $s = "<a href=\"{$u}\" class='internal' title=\"{$alt}\">{$alt}</a>";
1887 }
1888 return $s;
1889 }
1890
1891 function specialLink( $name, $key = '' ) {
1892 global $wgContLang;
1893
1894 if ( '' == $key ) { $key = strtolower( $name ); }
1895 $pn = $wgContLang->ucfirst( $name );
1896 return $this->makeKnownLink( $wgContLang->specialPage( $pn ),
1897 wfMsg( $key ) );
1898 }
1899
1900 function makeExternalLink( $url, $text, $escape = true ) {
1901 $style = $this->getExternalLinkAttributes( $url, $text );
1902 $url = htmlspecialchars( $url );
1903 if( $escape ) {
1904 $text = htmlspecialchars( $text );
1905 }
1906 return '<a href="'.$url.'"'.$style.'>'.$text.'</a>';
1907 }
1908
1909 # Called by history lists and recent changes
1910 #
1911
1912 # Returns text for the start of the tabular part of RC
1913 function beginRecentChangesList() {
1914 $this->rc_cache = array() ;
1915 $this->rcMoveIndex = 0;
1916 $this->rcCacheIndex = 0 ;
1917 $this->lastdate = '';
1918 $this->rclistOpen = false;
1919 return '';
1920 }
1921
1922 function beginImageHistoryList() {
1923 $s = "\n<h2>" . wfMsg( 'imghistory' ) . "</h2>\n" .
1924 "<p>" . wfMsg( 'imghistlegend' ) . "</p>\n".'<ul class="special">';
1925 return $s;
1926 }
1927
1928 /**
1929 * Returns text for the end of RC
1930 * If enhanced RC is in use, returns pretty much all the text
1931 */
1932 function endRecentChangesList() {
1933 $s = $this->recentChangesBlock() ;
1934 if( $this->rclistOpen ) {
1935 $s .= "</ul>\n";
1936 }
1937 return $s;
1938 }
1939
1940 /**
1941 * Enhanced RC ungrouped line
1942 */
1943 function recentChangesBlockLine ( $rcObj ) {
1944 global $wgStylePath, $wgContLang ;
1945
1946 # Get rc_xxxx variables
1947 extract( $rcObj->mAttribs ) ;
1948 $curIdEq = 'curid='.$rc_cur_id;
1949
1950 # Spacer image
1951 $r = '' ;
1952
1953 $r .= '<img src="'.$wgStylePath.'/common/images/Arr_.png" width="12" height="12" border="0" />' ;
1954 $r .= '<tt>' ;
1955
1956 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
1957 $r .= '&nbsp;&nbsp;';
1958 } else {
1959 # M, N and !
1960 $M = wfMsg( 'minoreditletter' );
1961 $N = wfMsg( 'newpageletter' );
1962
1963 if ( $rc_type == RC_NEW ) {
1964 $r .= $N ;
1965 } else {
1966 $r .= '&nbsp;' ;
1967 }
1968 if ( $rc_minor ) {
1969 $r .= $M ;
1970 } else {
1971 $r .= '&nbsp;' ;
1972 }
1973 if ( $rcObj->unpatrolled ) {
1974 $r .= '!';
1975 } else {
1976 $r .= '&nbsp;';
1977 }
1978 }
1979
1980 # Timestamp
1981 $r .= ' '.$rcObj->timestamp.' ' ;
1982 $r .= '</tt>' ;
1983
1984 # Article link
1985 $link = $rcObj->link ;
1986 if ( $rcObj->watched ) $link = '<strong>'.$link.'</strong>' ;
1987 $r .= $link ;
1988
1989 # Diff
1990 $r .= ' (' ;
1991 $r .= $rcObj->difflink ;
1992 $r .= '; ' ;
1993
1994 # Hist
1995 $r .= $this->makeKnownLinkObj( $rcObj->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
1996
1997 # User/talk
1998 $r .= ') . . '.$rcObj->userlink ;
1999 $r .= $rcObj->usertalklink ;
2000
2001 # Comment
2002 if ( $rc_comment != '' && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
2003 $rc_comment=$this->formatComment($rc_comment, $rcObj->getTitle());
2004 $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' );
2005 }
2006
2007 $r .= "<br />\n" ;
2008 return $r ;
2009 }
2010
2011 /**
2012 * Enhanced RC group
2013 */
2014 function recentChangesBlockGroup ( $block ) {
2015 global $wgStylePath, $wgContLang ;
2016
2017 $r = '' ;
2018 $M = wfMsg( 'minoreditletter' );
2019 $N = wfMsg( 'newpageletter' );
2020
2021 # Collate list of users
2022 $isnew = false ;
2023 $unpatrolled = false;
2024 $userlinks = array () ;
2025 foreach ( $block AS $rcObj ) {
2026 $oldid = $rcObj->mAttribs['rc_last_oldid'];
2027 if ( $rcObj->mAttribs['rc_new'] ) {
2028 $isnew = true ;
2029 }
2030 $u = $rcObj->userlink ;
2031 if ( !isset ( $userlinks[$u] ) ) {
2032 $userlinks[$u] = 0 ;
2033 }
2034 if ( $rcObj->unpatrolled ) {
2035 $unpatrolled = true;
2036 }
2037 $userlinks[$u]++ ;
2038 }
2039
2040 # Sort the list and convert to text
2041 krsort ( $userlinks ) ;
2042 asort ( $userlinks ) ;
2043 $users = array () ;
2044 foreach ( $userlinks as $userlink => $count) {
2045 $text = $userlink ;
2046 if ( $count > 1 ) $text .= " ({$count}&times;)" ;
2047 array_push ( $users , $text ) ;
2048 }
2049 $users = ' <font size="-1">['.implode('; ',$users).']</font>' ;
2050
2051 # Arrow
2052 $rci = 'RCI'.$this->rcCacheIndex ;
2053 $rcl = 'RCL'.$this->rcCacheIndex ;
2054 $rcm = 'RCM'.$this->rcCacheIndex ;
2055 $toggleLink = "javascript:toggleVisibility('$rci','$rcm','$rcl')" ;
2056 $arrowdir = $wgContLang->isRTL() ? 'l' : 'r';
2057 $tl = '<span id="'.$rcm.'"><a href="'.$toggleLink.'"><img src="'.$wgStylePath.'/common/images/Arr_'.$arrowdir.'.png" width="12" height="12" alt="+" /></a></span>' ;
2058 $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>' ;
2059 $r .= $tl ;
2060
2061 # Main line
2062 # M/N
2063 $r .= '<tt>' ;
2064 if ( $isnew ) $r .= $N ;
2065 else $r .= '&nbsp;' ;
2066 $r .= '&nbsp;' ; # Minor
2067 if ( $unpatrolled ) {
2068 $r .= "!";
2069 } else {
2070 $r .= "&nbsp;";
2071 }
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 ) {
2108 $r .= $N ;
2109 } else {
2110 $r .= '&nbsp;' ;
2111 }
2112
2113 if ( $rc_minor ) {
2114 $r .= $M ;
2115 } else {
2116 $r .= '&nbsp;' ;
2117 }
2118
2119 if ( $rcObj->unpatrolled ) {
2120 $r .= "!";
2121 } else {
2122 $r .= "&nbsp;";
2123 }
2124
2125 $r .= '&nbsp;</tt>' ;
2126
2127 $o = '' ;
2128 if ( $rc_last_oldid != 0 ) {
2129 $o = 'oldid='.$rc_last_oldid ;
2130 }
2131 if ( $rc_type == RC_LOG ) {
2132 $link = $rcObj->timestamp ;
2133 } else {
2134 $link = $this->makeKnownLinkObj( $rcObj->getTitle(), $rcObj->timestamp , "{$curIdEq}&$o" ) ;
2135 }
2136 $link = '<tt>'.$link.'</tt>' ;
2137
2138 $r .= $link ;
2139 $r .= ' (' ;
2140 $r .= $rcObj->curlink ;
2141 $r .= '; ' ;
2142 $r .= $rcObj->lastlink ;
2143 $r .= ') . . '.$rcObj->userlink ;
2144 $r .= $rcObj->usertalklink ;
2145 if ( $rc_comment != '' ) {
2146 $rc_comment=$this->formatComment($rc_comment, $rcObj->getTitle());
2147 $r .= $wgContLang->emphasize( ' ('.$rc_comment.')' ) ;
2148 }
2149 $r .= "<br />\n" ;
2150 }
2151 $r .= "</div>\n" ;
2152
2153 $this->rcCacheIndex++ ;
2154 return $r ;
2155 }
2156
2157 /**
2158 * If enhanced RC is in use, this function takes the previously cached
2159 * RC lines, arranges them, and outputs the HTML
2160 */
2161 function recentChangesBlock () {
2162 global $wgStylePath ;
2163 if ( count ( $this->rc_cache ) == 0 ) return '' ;
2164 $blockOut = '';
2165 foreach ( $this->rc_cache AS $secureName => $block ) {
2166 if ( count ( $block ) < 2 ) {
2167 $blockOut .= $this->recentChangesBlockLine ( array_shift ( $block ) ) ;
2168 } else {
2169 $blockOut .= $this->recentChangesBlockGroup ( $block ) ;
2170 }
2171 }
2172
2173 return '<div>'.$blockOut.'</div>' ;
2174 }
2175
2176 /**
2177 * Called in a loop over all displayed RC entries
2178 * Either returns the line, or caches it for later use
2179 */
2180 function recentChangesLine( &$rc, $watched = false ) {
2181 global $wgUser ;
2182 $usenew = $wgUser->getOption( 'usenewrc' );
2183 if ( $usenew )
2184 $line = $this->recentChangesLineNew ( $rc, $watched ) ;
2185 else
2186 $line = $this->recentChangesLineOld ( $rc, $watched ) ;
2187 return $line ;
2188 }
2189
2190 function recentChangesLineOld( &$rc, $watched = false ) {
2191 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds, $wgUseRCPatrol, $wgOnlySysopsCanPatrol;
2192
2193 # Extract DB fields into local scope
2194 extract( $rc->mAttribs );
2195 $curIdEq = 'curid=' . $rc_cur_id;
2196
2197 # Should patrol-related stuff be shown?
2198 $unpatrolled = $wgUseRCPatrol && $wgUser->getID() != 0 &&
2199 ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') ) && $rc_patrolled == 0;
2200
2201 # Make date header if necessary
2202 $date = $wgContLang->date( $rc_timestamp, true);
2203 $uidate = $wgLang->date( $rc_timestamp, true);
2204 $s = '';
2205 if ( $date != $this->lastdate ) {
2206 if ( '' != $this->lastdate ) { $s .= "</ul>\n"; }
2207 $s .= "<h4>{$uidate}</h4>\n<ul class=\"special\">";
2208 $this->lastdate = $date;
2209 $this->rclistOpen = true;
2210 }
2211
2212 $s .= '<li>';
2213
2214 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2215 # Diff
2216 $s .= '(' . wfMsg( 'diff' ) . ') (';
2217 # Hist
2218 $s .= $this->makeKnownLinkObj( $rc->getMovedToTitle(), wfMsg( 'hist' ), 'action=history' ) .
2219 ') . . ';
2220
2221 # "[[x]] moved to [[y]]"
2222 $msg = ( $rc_type == RC_MOVE ) ? '1movedto2' : '1movedto2_redir';
2223 $s .= wfMsg( $msg, $this->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
2224 $this->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
2225 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
2226 # Log updates, etc
2227 $logtype = $matches[1];
2228 $logname = LogPage::logName( $logtype );
2229 $s .= '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
2230 } else {
2231 # Diff link
2232 if ( $rc_type == RC_NEW || $rc_type == RC_LOG ) {
2233 $diffLink = wfMsg( 'diff' );
2234 } else {
2235 if ( $unpatrolled )
2236 $rcidparam = "&rcid={$rc_id}";
2237 else
2238 $rcidparam = "";
2239 $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'diff' ),
2240 "{$curIdEq}&diff={$rc_this_oldid}&oldid={$rc_last_oldid}{$rcidparam}",
2241 '', '', ' tabindex="'.$rc->counter.'"');
2242 }
2243 $s .= '('.$diffLink.') (';
2244
2245 # History link
2246 $s .= $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'hist' ), $curIdEq.'&action=history' );
2247 $s .= ') . . ';
2248
2249 # M, N and ! (minor, new and unpatrolled)
2250 if ( $rc_minor ) { $s .= ' <span class="minor">'.wfMsg( "minoreditletter" ).'</span>'; }
2251 if ( $rc_type == RC_NEW ) { $s .= '<span class="newpage">'.wfMsg( "newpageletter" ).'</span>'; }
2252 if ( !$rc_patrolled ) { $s .= ' <span class="unpatrolled">!</span>'; }
2253
2254 # Article link
2255 # If it's a new article, there is no diff link, but if it hasn't been
2256 # patrolled yet, we need to give users a way to do so
2257 if ( $unpatrolled && $rc_type == RC_NEW )
2258 $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
2259 else
2260 $articleLink = $this->makeKnownLinkObj( $rc->getTitle(), '' );
2261
2262 if ( $watched ) {
2263 $articleLink = '<strong>'.$articleLink.'</strong>';
2264 }
2265 $s .= ' '.$articleLink;
2266
2267 }
2268
2269 # Timestamp
2270 $s .= '; ' . $wgLang->time( $rc_timestamp, true, $wgRCSeconds ) . ' . . ';
2271
2272 # User link (or contributions for unregistered users)
2273 if ( 0 == $rc_user ) {
2274 $userLink = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
2275 $rc_user_text, 'target=' . $rc_user_text );
2276 } else {
2277 $userLink = $this->makeLink( $wgContLang->getNsText( NS_USER ) . ':'.$rc_user_text, $rc_user_text );
2278 }
2279 $s .= $userLink;
2280
2281 # User talk link
2282 $talkname=$wgContLang->getNsText(NS_TALK); # use the shorter name
2283 global $wgDisableAnonTalk;
2284 if( 0 == $rc_user && $wgDisableAnonTalk ) {
2285 $userTalkLink = '';
2286 } else {
2287 $utns=$wgContLang->getNsText(NS_USER_TALK);
2288 $userTalkLink= $this->makeLink($utns . ':'.$rc_user_text, $talkname );
2289 }
2290 # Block link
2291 $blockLink='';
2292 if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
2293 $blockLink = $this->makeKnownLink( $wgContLang->specialPage(
2294 'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text );
2295
2296 }
2297 if($blockLink) {
2298 if($userTalkLink) $userTalkLink .= ' | ';
2299 $userTalkLink .= $blockLink;
2300 }
2301 if($userTalkLink) $s.=' ('.$userTalkLink.')';
2302
2303 # Add comment
2304 if ( '' != $rc_comment && '*' != $rc_comment && $rc_type != RC_MOVE && $rc_type != RC_MOVE_OVER_REDIRECT ) {
2305 $rc_comment=$this->formatComment($rc_comment,$rc->getTitle());
2306 $s .= $wgContLang->emphasize(' (' . $rc_comment . ')');
2307 }
2308 $s .= "</li>\n";
2309
2310 return $s;
2311 }
2312
2313 function recentChangesLineNew( &$baseRC, $watched = false ) {
2314 global $wgTitle, $wgLang, $wgContLang, $wgUser, $wgRCSeconds;
2315 global $wgUseRCPatrol, $wgOnlySysopsCanPatrol;
2316
2317 # Create a specialised object
2318 $rc = RCCacheEntry::newFromParent( $baseRC ) ;
2319
2320 # Extract fields from DB into the function scope (rc_xxxx variables)
2321 extract( $rc->mAttribs );
2322 $curIdEq = 'curid=' . $rc_cur_id;
2323
2324 # If it's a new day, add the headline and flush the cache
2325 $date = $wgContLang->date( $rc_timestamp, true);
2326 $uidate = $wgLang->date( $rc_timestamp, true);
2327 $ret = '';
2328 if ( $date != $this->lastdate ) {
2329 # Process current cache
2330 $ret = $this->recentChangesBlock () ;
2331 $this->rc_cache = array() ;
2332 $ret .= "<h4>{$uidate}</h4>\n";
2333 $this->lastdate = $date;
2334 }
2335
2336 # Should patrol-related stuff be shown?
2337 if ( $wgUseRCPatrol && $wgUser->getID() != 0 &&
2338 ( !$wgOnlySysopsCanPatrol || $wgUser->isAllowed('patrol') )) {
2339 $rc->unpatrolled = !$rc_patrolled;
2340 } else {
2341 $rc->unpatrolled = false;
2342 }
2343
2344 # Make article link
2345 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2346 $msg = ( $rc_type == RC_MOVE ) ? "1movedto2" : "1movedto2_redir";
2347 $clink = wfMsg( $msg, $this->makeKnownLinkObj( $rc->getTitle(), '', 'redirect=no' ),
2348 $this->makeKnownLinkObj( $rc->getMovedToTitle(), '' ) );
2349 } elseif( $rc_namespace == NS_SPECIAL && preg_match( '!^Log/(.*)$!', $rc_title, $matches ) ) {
2350 # Log updates, etc
2351 $logtype = $matches[1];
2352 $logname = LogPage::logName( $logtype );
2353 $clink = '(' . $this->makeKnownLinkObj( $rc->getTitle(), $logname ) . ')';
2354 } elseif ( $rc->unpatrolled && $rc_type == RC_NEW ) {
2355 # Unpatrolled new page, give rc_id in query
2356 $clink = $this->makeKnownLinkObj( $rc->getTitle(), '', "rcid={$rc_id}" );
2357 } else {
2358 $clink = $this->makeKnownLinkObj( $rc->getTitle(), '' ) ;
2359 }
2360
2361 $time = $wgContLang->time( $rc_timestamp, true, $wgRCSeconds );
2362 $rc->watched = $watched ;
2363 $rc->link = $clink ;
2364 $rc->timestamp = $time;
2365
2366 # Make "cur" and "diff" links
2367 if ( ( $rc_type == RC_NEW && $rc_this_oldid == 0 ) || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2368 $curLink = wfMsg( 'cur' );
2369 $diffLink = wfMsg( 'diff' );
2370 } else {
2371 $query = $curIdEq.'&diff=0&oldid='.$rc_this_oldid;
2372 $aprops = ' tabindex="'.$baseRC->counter.'"';
2373 $curLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'cur' ), $query, '' ,'' , $aprops );
2374 $diffLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'diff'), $query, '' ,'' , $aprops );
2375 }
2376
2377 # Make "last" link
2378 $titleObj = $rc->getTitle();
2379 if ( $rc->unpatrolled ) {
2380 $rcIdQuery = "&rcid={$rc_id}";
2381 } else {
2382 $rcIdQuery = '';
2383 }
2384 if ( $rc_last_oldid == 0 || $rc_type == RC_LOG || $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2385 $lastLink = wfMsg( 'last' );
2386 } else {
2387 $lastLink = $this->makeKnownLinkObj( $rc->getTitle(), wfMsg( 'last' ),
2388 $curIdEq.'&diff='.$rc_this_oldid.'&oldid='.$rc_last_oldid . $rcIdQuery );
2389 }
2390
2391 # Make user link (or user contributions for unregistered users)
2392 if ( $rc_user == 0 ) {
2393 $userLink = $this->makeKnownLink( $wgContLang->specialPage( 'Contributions' ),
2394 $rc_user_text, 'target=' . $rc_user_text );
2395 } else {
2396 $userLink = $this->makeLink( $wgContLang->getNsText(
2397 Namespace::getUser() ) . ':'.$rc_user_text, $rc_user_text );
2398 }
2399
2400 $rc->userlink = $userLink;
2401 $rc->lastlink = $lastLink;
2402 $rc->curlink = $curLink;
2403 $rc->difflink = $diffLink;
2404
2405 # Make user talk link
2406 $utns=$wgContLang->getNsText(NS_USER_TALK);
2407 $talkname=$wgContLang->getNsText(NS_TALK); # use the shorter name
2408 $userTalkLink= $this->makeLink($utns . ':'.$rc_user_text, $talkname );
2409
2410 global $wgDisableAnonTalk;
2411 if ( ( 0 == $rc_user ) && $wgUser->isAllowed('block') ) {
2412 $blockLink = $this->makeKnownLink( $wgContLang->specialPage(
2413 'Blockip' ), wfMsg( 'blocklink' ), 'ip='.$rc_user_text );
2414 if( $wgDisableAnonTalk )
2415 $rc->usertalklink = ' ('.$blockLink.')';
2416 else
2417 $rc->usertalklink = ' ('.$userTalkLink.' | '.$blockLink.')';
2418 } else {
2419 if( $wgDisableAnonTalk && ($rc_user == 0) )
2420 $rc->usertalklink = '';
2421 else
2422 $rc->usertalklink = ' ('.$userTalkLink.')';
2423 }
2424
2425 # Put accumulated information into the cache, for later display
2426 # Page moves go on their own line
2427 $title = $rc->getTitle();
2428 $secureName = $title->getPrefixedDBkey();
2429 if ( $rc_type == RC_MOVE || $rc_type == RC_MOVE_OVER_REDIRECT ) {
2430 # Use an @ character to prevent collision with page names
2431 $this->rc_cache['@@' . ($this->rcMoveIndex++)] = array($rc);
2432 } else {
2433 if ( !isset ( $this->rc_cache[$secureName] ) ) $this->rc_cache[$secureName] = array() ;
2434 array_push ( $this->rc_cache[$secureName] , $rc ) ;
2435 }
2436 return $ret;
2437 }
2438
2439 function endImageHistoryList() {
2440 $s = "</ul>\n";
2441 return $s;
2442 }
2443
2444 /**
2445 * This function is called by all recent changes variants, by the page history,
2446 * and by the user contributions list. It is responsible for formatting edit
2447 * comments. It escapes any HTML in the comment, but adds some CSS to format
2448 * auto-generated comments (from section editing) and formats [[wikilinks]].
2449 *
2450 * The &$title parameter must be a title OBJECT. It is used to generate a
2451 * direct link to the section in the autocomment.
2452 * @author Erik Moeller <moeller@scireview.de>
2453 *
2454 * Note: there's not always a title to pass to this function.
2455 * Since you can't set a default parameter for a reference, I've turned it
2456 * temporarily to a value pass. Should be adjusted further. --brion
2457 */
2458 function formatComment($comment, $title = NULL) {
2459 global $wgContLang;
2460 $comment = htmlspecialchars( $comment );
2461
2462 # The pattern for autogen comments is / * foo * /, which makes for
2463 # some nasty regex.
2464 # We look for all comments, match any text before and after the comment,
2465 # add a separator where needed and format the comment itself with CSS
2466 while (preg_match('/(.*)\/\*\s*(.*?)\s*\*\/(.*)/', $comment,$match)) {
2467 $pre=$match[1];
2468 $auto=$match[2];
2469 $post=$match[3];
2470 $link='';
2471 if($title) {
2472 $section=$auto;
2473
2474 # This is hackish but should work in most cases.
2475 $section=str_replace('[[','',$section);
2476 $section=str_replace(']]','',$section);
2477 $title->mFragment=$section;
2478 $link=$this->makeKnownLinkObj($title,wfMsg('sectionlink'));
2479 }
2480 $sep='-';
2481 $auto=$link.$auto;
2482 if($pre) { $auto = $sep.' '.$auto; }
2483 if($post) { $auto .= ' '.$sep; }
2484 $auto='<span class="autocomment">'.$auto.'</span>';
2485 $comment=$pre.$auto.$post;
2486 }
2487
2488 # format regular and media links - all other wiki formatting
2489 # is ignored
2490 $medians = $wgContLang->getNsText(Namespace::getMedia()).':';
2491 while(preg_match('/\[\[(.*?)(\|(.*?))*\]\](.*)$/',$comment,$match)) {
2492 # Handle link renaming [[foo|text]] will show link as "text"
2493 if( "" != $match[3] ) {
2494 $text = $match[3];
2495 } else {
2496 $text = $match[1];
2497 }
2498 if( preg_match( '/^' . $medians . '(.*)$/i', $match[1], $submatch ) ) {
2499 # Media link; trail not supported.
2500 $linkRegexp = '/\[\[(.*?)\]\]/';
2501 $thelink = $this->makeMediaLink( $submatch[1], "", $text );
2502 } else {
2503 # Other kind of link
2504 if( preg_match( wfMsgForContent( "linktrail" ), $match[4], $submatch ) ) {
2505 $trail = $submatch[1];
2506 } else {
2507 $trail = "";
2508 }
2509 $linkRegexp = '/\[\[(.*?)\]\]' . preg_quote( $trail, '/' ) . '/';
2510 if ($match[1][0] == ':')
2511 $match[1] = substr($match[1], 1);
2512 $thelink = $this->makeLink( $match[1], $text, "", $trail );
2513 }
2514 $comment = preg_replace( $linkRegexp, $thelink, $comment, 1 );
2515 }
2516 return $comment;
2517 }
2518
2519 function imageHistoryLine( $iscur, $timestamp, $img, $user, $usertext, $size, $description ) {
2520 global $wgUser, $wgLang, $wgContLang, $wgTitle;
2521
2522 $datetime = $wgLang->timeanddate( $timestamp, true );
2523 $del = wfMsg( 'deleteimg' );
2524 $delall = wfMsg( 'deleteimgcompletely' );
2525 $cur = wfMsg( 'cur' );
2526
2527 if ( $iscur ) {
2528 $url = Image::wfImageUrl( $img );
2529 $rlink = $cur;
2530 if ( $wgUser->isAllowed('delete') ) {
2531 $link = $wgTitle->escapeLocalURL( 'image=' . $wgTitle->getPartialURL() .
2532 '&action=delete' );
2533 $style = $this->getInternalLinkAttributes( $link, $delall );
2534
2535 $dlink = '<a href="'.$link.'"'.$style.'>'.$delall.'</a>';
2536 } else {
2537 $dlink = $del;
2538 }
2539 } else {
2540 $url = htmlspecialchars( wfImageArchiveUrl( $img ) );
2541 if( $wgUser->getID() != 0 && $wgTitle->userCanEdit() ) {
2542 $rlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
2543 wfMsg( 'revertimg' ), 'action=revert&oldimage=' .
2544 urlencode( $img ) );
2545 $dlink = $this->makeKnownLink( $wgTitle->getPrefixedText(),
2546 $del, 'action=delete&oldimage=' . urlencode( $img ) );
2547 } else {
2548 # Having live active links for non-logged in users
2549 # means that bots and spiders crawling our site can
2550 # inadvertently change content. Baaaad idea.
2551 $rlink = wfMsg( 'revertimg' );
2552 $dlink = $del;
2553 }
2554 }
2555 if ( 0 == $user ) {
2556 $userlink = $usertext;
2557 } else {
2558 $userlink = $this->makeLink( $wgContLang->getNsText( Namespace::getUser() ) .
2559 ':'.$usertext, $usertext );
2560 }
2561 $nbytes = wfMsg( 'nbytes', $size );
2562 $style = $this->getInternalLinkAttributes( $url, $datetime );
2563
2564 $s = "<li> ({$dlink}) ({$rlink}) <a href=\"{$url}\"{$style}>{$datetime}</a>"
2565 . " . . {$userlink} ({$nbytes})";
2566
2567 if ( '' != $description && '*' != $description ) {
2568 $sk=$wgUser->getSkin();
2569 $s .= $wgContLang->emphasize(' (' . $sk->formatComment($description,$wgTitle) . ')');
2570 }
2571 $s .= "</li>\n";
2572 return $s;
2573 }
2574
2575 function tocIndent($level) {
2576 return str_repeat( '<div class="tocindent">'."\n", $level>0 ? $level : 0 );
2577 }
2578
2579 function tocUnindent($level) {
2580 return str_repeat( "</div>\n", $level>0 ? $level : 0 );
2581 }
2582
2583 /**
2584 * parameter level defines if we are on an indentation level
2585 */
2586 function tocLine( $anchor, $tocline, $level ) {
2587 $link = '<a href="#'.$anchor.'">'.$tocline.'</a><br />';
2588 if($level) {
2589 return $link."\n";
2590 } else {
2591 return '<div class="tocline">'.$link."</div>\n";
2592 }
2593
2594 }
2595
2596 function tocTable($toc) {
2597 # note to CSS fanatics: putting this in a div does not work -- div won't auto-expand
2598 # try min-width & co when somebody gets a chance
2599 $hideline = ' <script type="text/javascript">showTocToggle("' . addslashes( wfMsg('showtoc') ) . '","' . addslashes( wfMsg('hidetoc') ) . '")</script>';
2600 return
2601 '<table border="0" id="toc"><tr id="toctitle"><td align="center">'."\n".
2602 '<b>'.wfMsgForContent('toc').'</b>' .
2603 $hideline .
2604 '</td></tr><tr id="tocinside"><td>'."\n".
2605 $toc."</td></tr></table>\n";
2606 }
2607
2608 /**
2609 * These two do not check for permissions: check $wgTitle->userCanEdit
2610 * before calling them
2611 */
2612 function editSectionScriptForOther( $title, $section, $head ) {
2613 $ttl = Title::newFromText( $title );
2614 $url = $ttl->escapeLocalURL( 'action=edit&section='.$section );
2615 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2616 }
2617
2618 function editSectionScript( $nt, $section, $head ) {
2619 global $wgRequest;
2620 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2621 return $head;
2622 }
2623 $url = $nt->escapeLocalURL( 'action=edit&section='.$section );
2624 return '<span oncontextmenu=\'document.location="'.$url.'";return false;\'>'.$head.'</span>';
2625 }
2626
2627 function editSectionLinkForOther( $title, $section ) {
2628 global $wgRequest;
2629 global $wgContLang;
2630
2631 $title = Title::newFromText($title);
2632 $editurl = '&section='.$section;
2633 $url = $this->makeKnownLink($title->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2634
2635 if( $wgContLang->isRTL() ) {
2636 $farside = 'left';
2637 $nearside = 'right';
2638 } else {
2639 $farside = 'right';
2640 $nearside = 'left';
2641 }
2642 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2643
2644 }
2645
2646 function editSectionLink( $nt, $section ) {
2647 global $wgRequest;
2648 global $wgContLang;
2649
2650 if( $wgRequest->getInt( 'oldid' ) && ( $wgRequest->getVal( 'diff' ) != '0' ) ) {
2651 # Section edit links would be out of sync on an old page.
2652 # But, if we're diffing to the current page, they'll be
2653 # correct.
2654 return '';
2655 }
2656
2657 $editurl = '&section='.$section;
2658 $url = $this->makeKnownLink($nt->getPrefixedText(),wfMsg('editsection'),'action=edit'.$editurl);
2659
2660 if( $wgContLang->isRTL() ) {
2661 $farside = 'left';
2662 $nearside = 'right';
2663 } else {
2664 $farside = 'right';
2665 $nearside = 'left';
2666 }
2667 return "<div class=\"editsection\" style=\"float:$farside;margin-$nearside:5px;\">[".$url."]</div>";
2668
2669 }
2670
2671 /**
2672 * This function is called by EditPage.php and shows a bulletin board style
2673 * toolbar for common editing functions. It can be disabled in the user
2674 * preferences.
2675 * The necessary JavaScript code can be found in style/wikibits.js.
2676 */
2677 function getEditToolbar() {
2678 global $wgStylePath, $wgLang, $wgMimeType;
2679
2680 /**
2681 * toolarray an array of arrays which each include the filename of
2682 * the button image (without path), the opening tag, the closing tag,
2683 * and optionally a sample text that is inserted between the two when no
2684 * selection is highlighted.
2685 * The tip text is shown when the user moves the mouse over the button.
2686 *
2687 * Already here are accesskeys (key), which are not used yet until someone
2688 * can figure out a way to make them work in IE. However, we should make
2689 * sure these keys are not defined on the edit page.
2690 */
2691 $toolarray=array(
2692 array( 'image'=>'button_bold.png',
2693 'open' => "\'\'\'",
2694 'close' => "\'\'\'",
2695 'sample'=> wfMsg('bold_sample'),
2696 'tip' => wfMsg('bold_tip'),
2697 'key' => 'B'
2698 ),
2699 array( 'image'=>'button_italic.png',
2700 'open' => "\'\'",
2701 'close' => "\'\'",
2702 'sample'=> wfMsg('italic_sample'),
2703 'tip' => wfMsg('italic_tip'),
2704 'key' => 'I'
2705 ),
2706 array( 'image'=>'button_link.png',
2707 'open' => '[[',
2708 'close' => ']]',
2709 'sample'=> wfMsg('link_sample'),
2710 'tip' => wfMsg('link_tip'),
2711 'key' => 'L'
2712 ),
2713 array( 'image'=>'button_extlink.png',
2714 'open' => '[',
2715 'close' => ']',
2716 'sample'=> wfMsg('extlink_sample'),
2717 'tip' => wfMsg('extlink_tip'),
2718 'key' => 'X'
2719 ),
2720 array( 'image'=>'button_headline.png',
2721 'open' => "\\n== ",
2722 'close' => " ==\\n",
2723 'sample'=> wfMsg('headline_sample'),
2724 'tip' => wfMsg('headline_tip'),
2725 'key' => 'H'
2726 ),
2727 array( 'image'=>'button_image.png',
2728 'open' => '[['.$wgLang->getNsText(NS_IMAGE).":",
2729 'close' => ']]',
2730 'sample'=> wfMsg('image_sample'),
2731 'tip' => wfMsg('image_tip'),
2732 'key' => 'D'
2733 ),
2734 array( 'image' => 'button_media.png',
2735 'open' => '[['.$wgLang->getNsText(NS_MEDIA).':',
2736 'close' => ']]',
2737 'sample'=> wfMsg('media_sample'),
2738 'tip' => wfMsg('media_tip'),
2739 'key' => 'M'
2740 ),
2741 array( 'image' => 'button_math.png',
2742 'open' => "\\<math\\>",
2743 'close' => "\\</math\\>",
2744 'sample'=> wfMsg('math_sample'),
2745 'tip' => wfMsg('math_tip'),
2746 'key' => 'C'
2747 ),
2748 array( 'image' => 'button_nowiki.png',
2749 'open' => "\\<nowiki\\>",
2750 'close' => "\\</nowiki\\>",
2751 'sample'=> wfMsg('nowiki_sample'),
2752 'tip' => wfMsg('nowiki_tip'),
2753 'key' => 'N'
2754 ),
2755 array( 'image' => 'button_sig.png',
2756 'open' => '--~~~~',
2757 'close' => '',
2758 'sample'=> '',
2759 'tip' => wfMsg('sig_tip'),
2760 'key' => 'Y'
2761 ),
2762 array( 'image' => 'button_hr.png',
2763 'open' => "\\n----\\n",
2764 'close' => '',
2765 'sample'=> '',
2766 'tip' => wfMsg('hr_tip'),
2767 'key' => 'R'
2768 )
2769 );
2770 $toolbar ="<script type='text/javascript'>\n/*<![CDATA[*/\n";
2771
2772 $toolbar.="document.writeln(\"<div id='toolbar'>\");\n";
2773 foreach($toolarray as $tool) {
2774
2775 $image=$wgStylePath.'/common/images/'.$tool['image'];
2776 $open=$tool['open'];
2777 $close=$tool['close'];
2778 $sample = addslashes( $tool['sample'] );
2779
2780 // Note that we use the tip both for the ALT tag and the TITLE tag of the image.
2781 // Older browsers show a "speedtip" type message only for ALT.
2782 // Ideally these should be different, realistically they
2783 // probably don't need to be.
2784 $tip = addslashes( $tool['tip'] );
2785
2786 #$key = $tool["key"];
2787
2788 $toolbar.="addButton('$image','$tip','$open','$close','$sample');\n";
2789 }
2790
2791 $toolbar.="addInfobox('" . addslashes( wfMsg( "infobox" ) ) . "','" . addslashes(wfMsg("infobox_alert")) . "');\n";
2792 $toolbar.="document.writeln(\"</div>\");\n";
2793
2794 $toolbar.="/*]]>*/\n</script>";
2795 return $toolbar;
2796 }
2797
2798 /**
2799 * @access public
2800 */
2801 function suppressUrlExpansion() {
2802 return false;
2803 }
2804 }
2805
2806 }
2807 ?>