call JS onload hooks at the end of the html body in all skins
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4
5 /**
6 *
7 * @package MediaWiki
8 * @subpackage Skins
9 */
10
11 # See skin.txt
12
13 /**
14 * The main skin class that provide methods and properties for all other skins.
15 * This base class is also the "Standard" skin.
16 * @package MediaWiki
17 */
18 class Skin extends Linker {
19 /**#@+
20 * @private
21 */
22 var $lastdate, $lastline;
23 var $rc_cache ; # Cache for Enhanced Recent Changes
24 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
25 var $rcMoveIndex;
26 /**#@-*/
27
28 /** Constructor, call parent constructor */
29 function Skin() { parent::Linker(); }
30
31 /**
32 * Fetch the set of available skins.
33 * @return array of strings
34 * @static
35 */
36 static function &getSkinNames() {
37 global $wgValidSkinNames;
38 static $skinsInitialised = false;
39 if ( !$skinsInitialised ) {
40 # Get a list of available skins
41 # Build using the regular expression '^(.*).php$'
42 # Array keys are all lower case, array value keep the case used by filename
43 #
44 wfProfileIn( __METHOD__ . '-init' );
45 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
47
48 # while code from www.php.net
49 while (false !== ($file = $skinDir->read())) {
50 // Skip non-PHP files, hidden files, and '.dep' includes
51 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
52 $aSkin = $matches[1];
53 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
54 }
55 }
56 $skinDir->close();
57 $skinsInitialised = true;
58 wfProfileOut( __METHOD__ . '-init' );
59 }
60 return $wgValidSkinNames;
61 }
62
63 /**
64 * Normalize a skin preference value to a form that can be loaded.
65 * If a skin can't be found, it will fall back to the configured
66 * default (or the old 'Classic' skin if that's broken).
67 * @param string $key
68 * @return string
69 * @static
70 */
71 static function normalizeKey( $key ) {
72 global $wgDefaultSkin;
73 $skinNames = Skin::getSkinNames();
74
75 if( $key == '' ) {
76 // Don't return the default immediately;
77 // in a misconfiguration we need to fall back.
78 $key = $wgDefaultSkin;
79 }
80
81 if( isset( $skinNames[$key] ) ) {
82 return $key;
83 }
84
85 // Older versions of the software used a numeric setting
86 // in the user preferences.
87 $fallback = array(
88 0 => $wgDefaultSkin,
89 1 => 'nostalgia',
90 2 => 'cologneblue' );
91
92 if( isset( $fallback[$key] ) ){
93 $key = $fallback[$key];
94 }
95
96 if( isset( $skinNames[$key] ) ) {
97 return $key;
98 } else {
99 // The old built-in skin
100 return 'standard';
101 }
102 }
103
104 /**
105 * Factory method for loading a skin of a given type
106 * @param string $key 'monobook', 'standard', etc
107 * @return Skin
108 * @static
109 */
110 static function &newFromKey( $key ) {
111 global $wgStyleDirectory;
112
113 $key = Skin::normalizeKey( $key );
114
115 $skinNames = Skin::getSkinNames();
116 $skinName = $skinNames[$key];
117
118 # Grab the skin class and initialise it.
119 wfSuppressWarnings();
120 // Preload base classes to work around APC/PHP5 bug
121 include_once( "{$wgStyleDirectory}/{$skinName}.deps.php" );
122 wfRestoreWarnings();
123 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
124
125 # Check if we got if not failback to default skin
126 $className = 'Skin'.$skinName;
127 if( !class_exists( $className ) ) {
128 # DO NOT die if the class isn't found. This breaks maintenance
129 # scripts and can cause a user account to be unrecoverable
130 # except by SQL manipulation if a previously valid skin name
131 # is no longer valid.
132 wfDebug( "Skin class does not exist: $className\n" );
133 $className = 'SkinStandard';
134 require_once( "{$wgStyleDirectory}/Standard.php" );
135 }
136 $skin = new $className;
137 return $skin;
138 }
139
140 /** @return string path to the skin stylesheet */
141 function getStylesheet() {
142 return 'common/wikistandard.css?1';
143 }
144
145 /** @return string skin name */
146 function getSkinName() {
147 return 'standard';
148 }
149
150 function qbSetting() {
151 global $wgOut, $wgUser;
152
153 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
154 $q = $wgUser->getOption( 'quickbar' );
155 if ( '' == $q ) { $q = 0; }
156 return $q;
157 }
158
159 function initPage( &$out ) {
160 global $wgFavicon;
161
162 $fname = 'Skin::initPage';
163 wfProfileIn( $fname );
164
165 if( false !== $wgFavicon ) {
166 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
167 }
168
169 $this->addMetadataLinks($out);
170
171 $this->mRevisionId = $out->mRevisionId;
172
173 $this->preloadExistence();
174
175 wfProfileOut( $fname );
176 }
177
178 /**
179 * Preload the existence of three commonly-requested pages in a single query
180 */
181 function preloadExistence() {
182 global $wgUser, $wgTitle;
183
184 if ( $wgTitle->isTalkPage() ) {
185 $otherTab = $wgTitle->getSubjectPage();
186 } else {
187 $otherTab = $wgTitle->getTalkPage();
188 }
189 $lb = new LinkBatch( array(
190 $wgUser->getUserPage(),
191 $wgUser->getTalkPage(),
192 $otherTab
193 ));
194 $lb->execute();
195 }
196
197 function addMetadataLinks( &$out ) {
198 global $wgTitle, $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
199 global $wgRightsPage, $wgRightsUrl;
200
201 if( $out->isArticleRelated() ) {
202 # note: buggy CC software only reads first "meta" link
203 if( $wgEnableCreativeCommonsRdf ) {
204 $out->addMetadataLink( array(
205 'title' => 'Creative Commons',
206 'type' => 'application/rdf+xml',
207 'href' => $wgTitle->getLocalURL( 'action=creativecommons') ) );
208 }
209 if( $wgEnableDublinCoreRdf ) {
210 $out->addMetadataLink( array(
211 'title' => 'Dublin Core',
212 'type' => 'application/rdf+xml',
213 'href' => $wgTitle->getLocalURL( 'action=dublincore' ) ) );
214 }
215 }
216 $copyright = '';
217 if( $wgRightsPage ) {
218 $copy = Title::newFromText( $wgRightsPage );
219 if( $copy ) {
220 $copyright = $copy->getLocalURL();
221 }
222 }
223 if( !$copyright && $wgRightsUrl ) {
224 $copyright = $wgRightsUrl;
225 }
226 if( $copyright ) {
227 $out->addLink( array(
228 'rel' => 'copyright',
229 'href' => $copyright ) );
230 }
231 }
232
233 function outputPage( &$out ) {
234 global $wgDebugComments;
235
236 wfProfileIn( 'Skin::outputPage' );
237 $this->initPage( $out );
238
239 $out->out( $out->headElement() );
240
241 $out->out( "\n<body" );
242 $ops = $this->getBodyOptions();
243 foreach ( $ops as $name => $val ) {
244 $out->out( " $name='$val'" );
245 }
246 $out->out( ">\n" );
247 if ( $wgDebugComments ) {
248 $out->out( "<!-- Wiki debugging output:\n" .
249 $out->mDebugtext . "-->\n" );
250 }
251
252 $out->out( $this->beforeContent() );
253
254 $out->out( $out->mBodytext . "\n" );
255
256 $out->out( $this->afterContent() );
257
258 $out->out( $this->bottomScripts() );
259
260 $out->out( $out->reportTime() );
261
262 $out->out( "\n</body></html>" );
263 }
264
265 /*static*/ function makeGlobalVariablesScript( $data ) {
266 $r = '<script type= "' . $data['jsmimetype'] . '">
267 var skin = "' . Xml::escapeJsString( $data['skinname'] ) . '";
268 var stylepath = "' . Xml::escapeJsString( $data['stylepath'] ) . '";
269
270 var wgArticlePath = "' . Xml::escapeJsString( $data['articlepath'] ) . '";
271 var wgScriptPath = "' . Xml::escapeJsString( $data['scriptpath'] ) . '";
272 var wgServer = "' . Xml::escapeJsString( $data['serverurl'] ) . '";
273
274 var wgCanonicalNamespace = "' . Xml::escapeJsString( $data['nscanonical'] ) . '";
275 var wgPageName = "' . Xml::escapeJsString( $data['titleprefixeddbkey'] ) . '";
276 var wgTitle = "' . Xml::escapeJsString( $data['titletext'] ) . '";
277 var wgArticleId = ' . (int)$data['articleid'] . ';
278
279 var wgUserName = ' . ( $data['username'] == NULL ? 'null' : ( '"' . Xml::escapeJsString( $data['username'] ) . '"' ) ) . ';
280 var wgUserLanguage = "' . Xml::escapeJsString( $data['userlang'] ) . '";
281 var wgContentLanguage = "' . Xml::escapeJsString( $data['lang'] ) . '";
282 </script>
283 ';
284
285 return $r;
286 }
287
288 function getHeadScripts() {
289 global $wgStylePath, $wgUser, $wgAllowUserJs, $wgJsMimeType;
290 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
291 global $wgTitle, $wgCanonicalNamespaceNames;
292
293 $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
294 if ( $nsname === NULL ) $nsname = $wgTitle->getNsText();
295
296 $vars = array(
297 'jsmimetype' => $wgJsMimeType,
298 'skinname' => $this->getSkinName(),
299 'stylepath' => $wgStylePath,
300 'articlepath' => $wgArticlePath,
301 'scriptpath' => $wgScriptPath,
302 'serverurl' => $wgServer,
303 'nscanonical' => $nsname,
304 'titleprefixeddbkey' => $wgTitle->getPrefixedDBKey(),
305 'titletext' => $wgTitle->getText(),
306 'articleid' => $wgTitle->getArticleId(),
307 'username' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
308 'userlang' => $wgLang->getCode(),
309 'lang' => $wgContLang->getCode(),
310 );
311
312 $r = Skin::makeGlobalVariablesScript( $vars );
313
314 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js\"></script>\n";
315 if( $wgAllowUserJs && $wgUser->isLoggedIn() ) {
316 $userpage = $wgUser->getUserPage();
317 $userjs = htmlspecialchars( $this->makeUrl(
318 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
319 'action=raw&ctype='.$wgJsMimeType));
320 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
321 }
322 return $r;
323 }
324
325 /**
326 * To make it harder for someone to slip a user a fake
327 * user-JavaScript or user-CSS preview, a random token
328 * is associated with the login session. If it's not
329 * passed back with the preview request, we won't render
330 * the code.
331 *
332 * @param string $action
333 * @return bool
334 * @private
335 */
336 function userCanPreview( $action ) {
337 global $wgTitle, $wgRequest, $wgUser;
338
339 if( $action != 'submit' )
340 return false;
341 if( !$wgRequest->wasPosted() )
342 return false;
343 if( !$wgTitle->userCanEditCssJsSubpage() )
344 return false;
345 return $wgUser->matchEditToken(
346 $wgRequest->getVal( 'wpEditToken' ) );
347 }
348
349 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
350 function getUserStylesheet() {
351 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage;
352 $sheet = $this->getStylesheet();
353 $action = $wgRequest->getText('action');
354 $s = "@import \"$wgStylePath/$sheet\";\n";
355 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css\";\n";
356
357 $query = "action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
358 $s .= '@import "' . $this->makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
359 '@import "'.$this->makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
360
361 $s .= $this->doGetUserStyles();
362 return $s."\n";
363 }
364
365 /**
366 * placeholder, returns generated js in monobook
367 */
368 function getUserJs() { return; }
369
370 /**
371 * Return html code that include User stylesheets
372 */
373 function getUserStyles() {
374 $s = "<style type='text/css'>\n";
375 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
376 $s .= $this->getUserStylesheet();
377 $s .= "/*]]>*/ /* */\n";
378 $s .= "</style>\n";
379 return $s;
380 }
381
382 /**
383 * Some styles that are set by user through the user settings interface.
384 */
385 function doGetUserStyles() {
386 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
387
388 $s = '';
389
390 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
391 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
392 $s .= $wgRequest->getText('wpTextbox1');
393 } else {
394 $userpage = $wgUser->getUserPage();
395 $s.= '@import "'.$this->makeUrl(
396 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
397 'action=raw&ctype=text/css').'";'."\n";
398 }
399 }
400
401 return $s . $this->reallyDoGetUserStyles();
402 }
403
404 function reallyDoGetUserStyles() {
405 global $wgUser;
406 $s = '';
407 if (($undopt = $wgUser->getOption("underline")) != 2) {
408 $underline = $undopt ? 'underline' : 'none';
409 $s .= "a { text-decoration: $underline; }\n";
410 }
411 if( $wgUser->getOption( 'highlightbroken' ) ) {
412 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
413 } else {
414 $s .= <<<END
415 a.new, #quickbar a.new,
416 a.stub, #quickbar a.stub {
417 color: inherit;
418 text-decoration: inherit;
419 }
420 a.new:after, #quickbar a.new:after {
421 content: "?";
422 color: #CC2200;
423 text-decoration: $underline;
424 }
425 a.stub:after, #quickbar a.stub:after {
426 content: "!";
427 color: #772233;
428 text-decoration: $underline;
429 }
430 END;
431 }
432 if( $wgUser->getOption( 'justify' ) ) {
433 $s .= "#article, #bodyContent { text-align: justify; }\n";
434 }
435 if( !$wgUser->getOption( 'showtoc' ) ) {
436 $s .= "#toc { display: none; }\n";
437 }
438 if( !$wgUser->getOption( 'editsection' ) ) {
439 $s .= ".editsection { display: none; }\n";
440 }
441 return $s;
442 }
443
444 function getBodyOptions() {
445 global $wgUser, $wgTitle, $wgOut, $wgRequest;
446
447 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
448
449 if ( 0 != $wgTitle->getNamespace() ) {
450 $a = array( 'bgcolor' => '#ffffec' );
451 }
452 else $a = array( 'bgcolor' => '#FFFFFF' );
453 if($wgOut->isArticle() && $wgUser->getOption('editondblclick') &&
454 $wgTitle->userCanEdit() ) {
455 $t = wfMsg( 'editthispage' );
456 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
457 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
458 $a += array ('ondblclick' => $s);
459
460 }
461 $a['onload'] = $wgOut->getOnloadHandler();
462 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
463 if( $a['onload'] != '' ) {
464 $a['onload'] .= ';';
465 }
466 $a['onload'] .= 'setupRightClickEdit()';
467 }
468 return $a;
469 }
470
471 /**
472 * URL to the logo
473 */
474 function getLogo() {
475 global $wgLogo;
476 return $wgLogo;
477 }
478
479 /**
480 * This will be called immediately after the <body> tag. Split into
481 * two functions to make it easier to subclass.
482 */
483 function beforeContent() {
484 return $this->doBeforeContent();
485 }
486
487 function doBeforeContent() {
488 global $wgContLang;
489 $fname = 'Skin::doBeforeContent';
490 wfProfileIn( $fname );
491
492 $s = '';
493 $qb = $this->qbSetting();
494
495 if( $langlinks = $this->otherLanguages() ) {
496 $rows = 2;
497 $borderhack = '';
498 } else {
499 $rows = 1;
500 $langlinks = false;
501 $borderhack = 'class="top"';
502 }
503
504 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
505 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
506
507 $shove = ($qb != 0);
508 $left = ($qb == 1 || $qb == 3);
509 if($wgContLang->isRTL()) $left = !$left;
510
511 if ( !$shove ) {
512 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
513 $this->logoText() . '</td>';
514 } elseif( $left ) {
515 $s .= $this->getQuickbarCompensator( $rows );
516 }
517 $l = $wgContLang->isRTL() ? 'right' : 'left';
518 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
519
520 $s .= $this->topLinks() ;
521 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
522
523 $r = $wgContLang->isRTL() ? "left" : "right";
524 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
525 $s .= $this->nameAndLogin();
526 $s .= "\n<br />" . $this->searchForm() . "</td>";
527
528 if ( $langlinks ) {
529 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
530 }
531
532 if ( $shove && !$left ) { # Right
533 $s .= $this->getQuickbarCompensator( $rows );
534 }
535 $s .= "</tr>\n</table>\n</div>\n";
536 $s .= "\n<div id='article'>\n";
537
538 $notice = wfGetSiteNotice();
539 if( $notice ) {
540 $s .= "\n<div id='siteNotice'>$notice</div>\n";
541 }
542 $s .= $this->pageTitle();
543 $s .= $this->pageSubtitle() ;
544 $s .= $this->getCategories();
545 wfProfileOut( $fname );
546 return $s;
547 }
548
549
550 function getCategoryLinks () {
551 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
552 global $wgContLang;
553
554 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
555
556 # Separator
557 $sep = wfMsgHtml( 'catseparator' );
558
559 // Use Unicode bidi embedding override characters,
560 // to make sure links don't smash each other up in ugly ways.
561 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
562 $embed = "<span dir='$dir'>";
563 $pop = '</span>';
564 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop;
565
566 $msg = wfMsgExt('categories', array('parsemag', 'escape'), count( $wgOut->mCategoryLinks ));
567 $s = $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Categories' ),
568 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
569 . ': ' . $t;
570
571 # optional 'dmoz-like' category browser. Will be shown under the list
572 # of categories an article belong to
573 if($wgUseCategoryBrowser) {
574 $s .= '<br /><hr />';
575
576 # get a big array of the parents tree
577 $parenttree = $wgTitle->getParentCategoryTree();
578 # Skin object passed by reference cause it can not be
579 # accessed under the method subfunction drawCategoryBrowser
580 $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
581 # Clean out bogus first entry and sort them
582 unset($tempout[0]);
583 asort($tempout);
584 # Output one per line
585 $s .= implode("<br />\n", $tempout);
586 }
587
588 return $s;
589 }
590
591 /** Render the array as a serie of links.
592 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
593 * @param &skin Object: skin passed by reference
594 * @return String separated by &gt;, terminate with "\n"
595 */
596 function drawCategoryBrowser($tree, &$skin) {
597 $return = '';
598 foreach ($tree as $element => $parent) {
599 if (empty($parent)) {
600 # element start a new list
601 $return .= "\n";
602 } else {
603 # grab the others elements
604 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
605 }
606 # add our current element to the list
607 $eltitle = Title::NewFromText($element);
608 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
609 }
610 return $return;
611 }
612
613 function getCategories() {
614 $catlinks=$this->getCategoryLinks();
615 if(!empty($catlinks)) {
616 return "<p class='catlinks'>{$catlinks}</p>";
617 }
618 }
619
620 function getQuickbarCompensator( $rows = 1 ) {
621 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
622 }
623
624 /**
625 * This gets called shortly before the \</body\> tag.
626 * @return String HTML to be put before \</body\>
627 */
628 function afterContent() {
629 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
630 return $printfooter . $this->doAfterContent();
631 }
632
633 /**
634 * This gets called shortly before the \</body\> tag.
635 * @return String HTML-wrapped JS code to be put before \</body\>
636 */
637 function bottomScripts() {
638 global $wgJsMimeType;
639 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
640 }
641
642 /** @return string Retrievied from HTML text */
643 function printSource() {
644 global $wgTitle;
645 $url = htmlspecialchars( $wgTitle->getFullURL() );
646 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
647 }
648
649 function printFooter() {
650 return "<p>" . $this->printSource() .
651 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
652 }
653
654 /** overloaded by derived classes */
655 function doAfterContent() { }
656
657 function pageTitleLinks() {
658 global $wgOut, $wgTitle, $wgUser, $wgRequest;
659
660 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
661 $action = $wgRequest->getText( 'action' );
662
663 $s = $this->printableLink();
664 $disclaimer = $this->disclaimerLink(); # may be empty
665 if( $disclaimer ) {
666 $s .= ' | ' . $disclaimer;
667 }
668 $privacy = $this->privacyLink(); # may be empty too
669 if( $privacy ) {
670 $s .= ' | ' . $privacy;
671 }
672
673 if ( $wgOut->isArticleRelated() ) {
674 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
675 $name = $wgTitle->getDBkey();
676 $image = new Image( $wgTitle );
677 if( $image->exists() ) {
678 $link = htmlspecialchars( $image->getURL() );
679 $style = $this->getInternalLinkAttributes( $link, $name );
680 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
681 }
682 }
683 }
684 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
685 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
686 wfMsg( 'currentrev' ) );
687 }
688
689 if ( $wgUser->getNewtalk() ) {
690 # do not show "You have new messages" text when we are viewing our
691 # own talk page
692 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
693 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
694 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
695 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
696 # disable caching
697 $wgOut->setSquidMaxage(0);
698 $wgOut->enableClientCache(false);
699 }
700 }
701
702 $undelete = $this->getUndeleteLink();
703 if( !empty( $undelete ) ) {
704 $s .= ' | '.$undelete;
705 }
706 return $s;
707 }
708
709 function getUndeleteLink() {
710 global $wgUser, $wgTitle, $wgContLang, $action;
711 if( $wgUser->isAllowed( 'deletedhistory' ) &&
712 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
713 ($n = $wgTitle->isDeleted() ) )
714 {
715 if ( $wgUser->isAllowed( 'delete' ) ) {
716 $msg = 'thisisdeleted';
717 } else {
718 $msg = 'viewdeleted';
719 }
720 return wfMsg( $msg,
721 $this->makeKnownLink(
722 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
723 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
724 }
725 return '';
726 }
727
728 function printableLink() {
729 global $wgOut, $wgFeedClasses, $wgRequest;
730
731 $baseurl = $_SERVER['REQUEST_URI'];
732 if( strpos( '?', $baseurl ) == false ) {
733 $baseurl .= '?';
734 } else {
735 $baseurl .= '&';
736 }
737 $baseurl = htmlspecialchars( $baseurl );
738 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
739
740 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
741 if( $wgOut->isSyndicated() ) {
742 foreach( $wgFeedClasses as $format => $class ) {
743 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
744 $s .= " | <a href=\"$feedurl\">{$format}</a>";
745 }
746 }
747 return $s;
748 }
749
750 function pageTitle() {
751 global $wgOut;
752 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
753 return $s;
754 }
755
756 function pageSubtitle() {
757 global $wgOut;
758
759 $sub = $wgOut->getSubtitle();
760 if ( '' == $sub ) {
761 global $wgExtraSubtitle;
762 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
763 }
764 $subpages = $this->subPageSubtitle();
765 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
766 $s = "<p class='subtitle'>{$sub}</p>\n";
767 return $s;
768 }
769
770 function subPageSubtitle() {
771 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
772 $subpages = '';
773 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
774 $ptext=$wgTitle->getPrefixedText();
775 if(preg_match('/\//',$ptext)) {
776 $links = explode('/',$ptext);
777 $c = 0;
778 $growinglink = '';
779 foreach($links as $link) {
780 $c++;
781 if ($c<count($links)) {
782 $growinglink .= $link;
783 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
784 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
785 if ($c>1) {
786 $subpages .= ' | ';
787 } else {
788 $subpages .= '&lt; ';
789 }
790 $subpages .= $getlink;
791 $growinglink .= '/';
792 }
793 }
794 }
795 }
796 return $subpages;
797 }
798
799 function nameAndLogin() {
800 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
801
802 $li = $wgContLang->specialPage( 'Userlogin' );
803 $lo = $wgContLang->specialPage( 'Userlogout' );
804
805 $s = '';
806 if ( $wgUser->isAnon() ) {
807 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
808 $n = wfGetIP();
809
810 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
811 $wgLang->getNsText( NS_TALK ) );
812
813 $s .= $n . ' ('.$tl.')';
814 } else {
815 $s .= wfMsg('notloggedin');
816 }
817
818 $rt = $wgTitle->getPrefixedURL();
819 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
820 $q = '';
821 } else { $q = "returnto={$rt}"; }
822
823 $s .= "\n<br />" . $this->makeKnownLinkObj(
824 Title::makeTitle( NS_SPECIAL, 'Userlogin' ),
825 wfMsg( 'login' ), $q );
826 } else {
827 $n = $wgUser->getName();
828 $rt = $wgTitle->getPrefixedURL();
829 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
830 $wgLang->getNsText( NS_TALK ) );
831
832 $tl = " ({$tl})";
833
834 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
835 $n ) . "{$tl}<br />" .
836 $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogout' ), wfMsg( 'logout' ),
837 "returnto={$rt}" ) . ' | ' .
838 $this->specialLink( 'preferences' );
839 }
840 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
841 wfMsg( 'help' ) );
842
843 return $s;
844 }
845
846 function getSearchLink() {
847 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
848 return $searchPage->getLocalURL();
849 }
850
851 function escapeSearchLink() {
852 return htmlspecialchars( $this->getSearchLink() );
853 }
854
855 function searchForm() {
856 global $wgRequest;
857 $search = $wgRequest->getText( 'search' );
858
859 $s = '<form name="search" class="inline" method="post" action="'
860 . $this->escapeSearchLink() . "\">\n"
861 . '<input type="text" name="search" size="19" value="'
862 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
863 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
864 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
865
866 return $s;
867 }
868
869 function topLinks() {
870 global $wgOut;
871 $sep = " |\n";
872
873 $s = $this->mainPageLink() . $sep
874 . $this->specialLink( 'recentchanges' );
875
876 if ( $wgOut->isArticleRelated() ) {
877 $s .= $sep . $this->editThisPage()
878 . $sep . $this->historyLink();
879 }
880 # Many people don't like this dropdown box
881 #$s .= $sep . $this->specialPagesList();
882
883 /* show links to different language variants */
884 global $wgDisableLangConversion, $wgContLang, $wgTitle;
885 $variants = $wgContLang->getVariants();
886 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
887 foreach( $variants as $code ) {
888 $varname = $wgContLang->getVariantname( $code );
889 if( $varname == 'disable' )
890 continue;
891 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
892 }
893 }
894
895 return $s;
896 }
897
898 function bottomLinks() {
899 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
900 $sep = " |\n";
901
902 $s = '';
903 if ( $wgOut->isArticleRelated() ) {
904 $s .= '<strong>' . $this->editThisPage() . '</strong>';
905 if ( $wgUser->isLoggedIn() ) {
906 $s .= $sep . $this->watchThisPage();
907 }
908 $s .= $sep . $this->talkLink()
909 . $sep . $this->historyLink()
910 . $sep . $this->whatLinksHere()
911 . $sep . $this->watchPageLinksLink();
912
913 if ($wgUseTrackbacks)
914 $s .= $sep . $this->trackbackLink();
915
916 if ( $wgTitle->getNamespace() == NS_USER
917 || $wgTitle->getNamespace() == NS_USER_TALK )
918
919 {
920 $id=User::idFromName($wgTitle->getText());
921 $ip=User::isIP($wgTitle->getText());
922
923 if($id || $ip) { # both anons and non-anons have contri list
924 $s .= $sep . $this->userContribsLink();
925 }
926 if( $this->showEmailUser( $id ) ) {
927 $s .= $sep . $this->emailUserLink();
928 }
929 }
930 if ( $wgTitle->getArticleId() ) {
931 $s .= "\n<br />";
932 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
933 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
934 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
935 }
936 $s .= "<br />\n" . $this->otherLanguages();
937 }
938 return $s;
939 }
940
941 function pageStats() {
942 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
943 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
944
945 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
946 if ( ! $wgOut->isArticle() ) { return ''; }
947 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
948 if ( 0 == $wgArticle->getID() ) { return ''; }
949
950 $s = '';
951 if ( !$wgDisableCounters ) {
952 $count = $wgLang->formatNum( $wgArticle->getCount() );
953 if ( $count ) {
954 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
955 }
956 }
957
958 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
959 require_once('Credits.php');
960 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
961 } else {
962 $s .= $this->lastModified();
963 }
964
965 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
966 $dbr =& wfGetDB( DB_SLAVE );
967 extract( $dbr->tableNames( 'watchlist' ) );
968 $sql = "SELECT COUNT(*) AS n FROM $watchlist
969 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
970 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
971 $res = $dbr->query( $sql, 'Skin::pageStats');
972 $x = $dbr->fetchObject( $res );
973 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
974 }
975
976 return $s . ' ' . $this->getCopyright();
977 }
978
979 function getCopyright( $type = 'detect' ) {
980 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
981
982 if ( $type == 'detect' ) {
983 $oldid = $wgRequest->getVal( 'oldid' );
984 $diff = $wgRequest->getVal( 'diff' );
985
986 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
987 $type = 'history';
988 } else {
989 $type = 'normal';
990 }
991 }
992
993 if ( $type == 'history' ) {
994 $msg = 'history_copyright';
995 } else {
996 $msg = 'copyright';
997 }
998
999 $out = '';
1000 if( $wgRightsPage ) {
1001 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1002 } elseif( $wgRightsUrl ) {
1003 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1004 } else {
1005 # Give up now
1006 return $out;
1007 }
1008 $out .= wfMsgForContent( $msg, $link );
1009 return $out;
1010 }
1011
1012 function getCopyrightIcon() {
1013 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1014 $out = '';
1015 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1016 $out = $wgCopyrightIcon;
1017 } else if ( $wgRightsIcon ) {
1018 $icon = htmlspecialchars( $wgRightsIcon );
1019 if ( $wgRightsUrl ) {
1020 $url = htmlspecialchars( $wgRightsUrl );
1021 $out .= '<a href="'.$url.'">';
1022 }
1023 $text = htmlspecialchars( $wgRightsText );
1024 $out .= "<img src=\"$icon\" alt='$text' />";
1025 if ( $wgRightsUrl ) {
1026 $out .= '</a>';
1027 }
1028 }
1029 return $out;
1030 }
1031
1032 function getPoweredBy() {
1033 global $wgStylePath;
1034 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1035 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1036 return $img;
1037 }
1038
1039 function lastModified() {
1040 global $wgLang, $wgArticle, $wgLoadBalancer;
1041
1042 $timestamp = $wgArticle->getTimestamp();
1043 if ( $timestamp ) {
1044 $d = $wgLang->timeanddate( $timestamp, true );
1045 $s = ' ' . wfMsg( 'lastmodified', $d );
1046 } else {
1047 $s = '';
1048 }
1049 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1050 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1051 }
1052 return $s;
1053 }
1054
1055 function logoText( $align = '' ) {
1056 if ( '' != $align ) { $a = " align='{$align}'"; }
1057 else { $a = ''; }
1058
1059 $mp = wfMsg( 'mainpage' );
1060 $titleObj = Title::newFromText( $mp );
1061 if ( is_object( $titleObj ) ) {
1062 $url = $titleObj->escapeLocalURL();
1063 } else {
1064 $url = '';
1065 }
1066
1067 $logourl = $this->getLogo();
1068 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1069 return $s;
1070 }
1071
1072 /**
1073 * show a drop-down box of special pages
1074 * @TODO crash bug913. Need to be rewrote completly.
1075 */
1076 function specialPagesList() {
1077 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1078 require_once('SpecialPage.php');
1079 $a = array();
1080 $pages = SpecialPage::getPages();
1081
1082 // special pages without access restriction
1083 foreach ( $pages[''] as $name => $page ) {
1084 $a[$name] = $page->getDescription();
1085 }
1086
1087 // Other special pages that are restricted.
1088 foreach ( $pages['restricted'] as $name => $page ) {
1089 if( $wgUser->isAllowed( $page->getRestriction() ) ) {
1090 $a[$name] = $page->getDescription();
1091 }
1092 }
1093
1094 $go = wfMsg( 'go' );
1095 $sp = wfMsg( 'specialpages' );
1096 $spp = $wgContLang->specialPage( 'Specialpages' );
1097
1098 $s = '<form id="specialpages" method="get" class="inline" ' .
1099 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1100 $s .= "<select name=\"wpDropdown\">\n";
1101 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1102
1103
1104 foreach ( $a as $name => $desc ) {
1105 $p = $wgContLang->specialPage( $name );
1106 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1107 }
1108 $s .= "</select>\n";
1109 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1110 $s .= "</form>\n";
1111 return $s;
1112 }
1113
1114 function mainPageLink() {
1115 $mp = wfMsgForContent( 'mainpage' );
1116 $mptxt = wfMsg( 'mainpage');
1117 $s = $this->makeKnownLink( $mp, $mptxt );
1118 return $s;
1119 }
1120
1121 function copyrightLink() {
1122 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1123 wfMsg( 'copyrightpagename' ) );
1124 return $s;
1125 }
1126
1127 function privacyLink() {
1128 $privacy = wfMsg( 'privacy' );
1129 if ($privacy == '-') {
1130 return '';
1131 } else {
1132 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1133 }
1134 }
1135
1136 function aboutLink() {
1137 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1138 wfMsg( 'aboutsite' ) );
1139 return $s;
1140 }
1141
1142 function disclaimerLink() {
1143 $disclaimers = wfMsg( 'disclaimers' );
1144 if ($disclaimers == '-') {
1145 return '';
1146 } else {
1147 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1148 $disclaimers );
1149 }
1150 }
1151
1152 function editThisPage() {
1153 global $wgOut, $wgTitle;
1154
1155 if ( ! $wgOut->isArticleRelated() ) {
1156 $s = wfMsg( 'protectedpage' );
1157 } else {
1158 if ( $wgTitle->userCanEdit() ) {
1159 $t = wfMsg( 'editthispage' );
1160 } else {
1161 $t = wfMsg( 'viewsource' );
1162 }
1163
1164 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1165 }
1166 return $s;
1167 }
1168
1169 /**
1170 * Return URL options for the 'edit page' link.
1171 * This may include an 'oldid' specifier, if the current page view is such.
1172 *
1173 * @return string
1174 * @private
1175 */
1176 function editUrlOptions() {
1177 global $wgArticle;
1178
1179 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1180 return "action=edit&oldid=" . intval( $this->mRevisionId );
1181 } else {
1182 return "action=edit";
1183 }
1184 }
1185
1186 function deleteThisPage() {
1187 global $wgUser, $wgTitle, $wgRequest;
1188
1189 $diff = $wgRequest->getVal( 'diff' );
1190 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1191 $t = wfMsg( 'deletethispage' );
1192
1193 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1194 } else {
1195 $s = '';
1196 }
1197 return $s;
1198 }
1199
1200 function protectThisPage() {
1201 global $wgUser, $wgTitle, $wgRequest;
1202
1203 $diff = $wgRequest->getVal( 'diff' );
1204 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1205 if ( $wgTitle->isProtected() ) {
1206 $t = wfMsg( 'unprotectthispage' );
1207 $q = 'action=unprotect';
1208 } else {
1209 $t = wfMsg( 'protectthispage' );
1210 $q = 'action=protect';
1211 }
1212 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1213 } else {
1214 $s = '';
1215 }
1216 return $s;
1217 }
1218
1219 function watchThisPage() {
1220 global $wgOut, $wgTitle;
1221
1222 if ( $wgOut->isArticleRelated() ) {
1223 if ( $wgTitle->userIsWatching() ) {
1224 $t = wfMsg( 'unwatchthispage' );
1225 $q = 'action=unwatch';
1226 } else {
1227 $t = wfMsg( 'watchthispage' );
1228 $q = 'action=watch';
1229 }
1230 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1231 } else {
1232 $s = wfMsg( 'notanarticle' );
1233 }
1234 return $s;
1235 }
1236
1237 function moveThisPage() {
1238 global $wgTitle;
1239
1240 if ( $wgTitle->userCanMove() ) {
1241 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
1242 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1243 } else {
1244 // no message if page is protected - would be redundant
1245 return '';
1246 }
1247 }
1248
1249 function historyLink() {
1250 global $wgTitle;
1251
1252 return $this->makeKnownLinkObj( $wgTitle,
1253 wfMsg( 'history' ), 'action=history' );
1254 }
1255
1256 function whatLinksHere() {
1257 global $wgTitle;
1258
1259 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
1260 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1261 }
1262
1263 function userContribsLink() {
1264 global $wgTitle;
1265
1266 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
1267 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1268 }
1269
1270 function showEmailUser( $id ) {
1271 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1272 return $wgEnableEmail &&
1273 $wgEnableUserEmail &&
1274 $wgUser->isLoggedIn() && # show only to signed in users
1275 0 != $id; # we can only email to non-anons ..
1276 # '' != $id->getEmail() && # who must have an email address stored ..
1277 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1278 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1279 }
1280
1281 function emailUserLink() {
1282 global $wgTitle;
1283
1284 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
1285 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1286 }
1287
1288 function watchPageLinksLink() {
1289 global $wgOut, $wgTitle;
1290
1291 if ( ! $wgOut->isArticleRelated() ) {
1292 return '(' . wfMsg( 'notanarticle' ) . ')';
1293 } else {
1294 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
1295 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1296 'target=' . $wgTitle->getPrefixedURL() );
1297 }
1298 }
1299
1300 function trackbackLink() {
1301 global $wgTitle;
1302
1303 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1304 . wfMsg('trackbacklink') . "</a>";
1305 }
1306
1307 function otherLanguages() {
1308 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1309
1310 if ( $wgHideInterlanguageLinks ) {
1311 return '';
1312 }
1313
1314 $a = $wgOut->getLanguageLinks();
1315 if ( 0 == count( $a ) ) {
1316 return '';
1317 }
1318
1319 $s = wfMsg( 'otherlanguages' ) . ': ';
1320 $first = true;
1321 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1322 foreach( $a as $l ) {
1323 if ( ! $first ) { $s .= ' | '; }
1324 $first = false;
1325
1326 $nt = Title::newFromText( $l );
1327 $url = $nt->escapeFullURL();
1328 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1329
1330 if ( '' == $text ) { $text = $l; }
1331 $style = $this->getExternalLinkAttributes( $l, $text );
1332 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1333 }
1334 if($wgContLang->isRTL()) $s .= '</span>';
1335 return $s;
1336 }
1337
1338 function bugReportsLink() {
1339 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1340 wfMsg( 'bugreports' ) );
1341 return $s;
1342 }
1343
1344 function dateLink() {
1345 $t1 = Title::newFromText( gmdate( 'F j' ) );
1346 $t2 = Title::newFromText( gmdate( 'Y' ) );
1347
1348 $id = $t1->getArticleID();
1349
1350 if ( 0 == $id ) {
1351 $s = $this->makeBrokenLink( $t1->getText() );
1352 } else {
1353 $s = $this->makeKnownLink( $t1->getText() );
1354 }
1355 $s .= ', ';
1356
1357 $id = $t2->getArticleID();
1358
1359 if ( 0 == $id ) {
1360 $s .= $this->makeBrokenLink( $t2->getText() );
1361 } else {
1362 $s .= $this->makeKnownLink( $t2->getText() );
1363 }
1364 return $s;
1365 }
1366
1367 function talkLink() {
1368 global $wgTitle;
1369
1370 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1371 # No discussion links for special pages
1372 return '';
1373 }
1374
1375 if( $wgTitle->isTalkPage() ) {
1376 $link = $wgTitle->getSubjectPage();
1377 switch( $link->getNamespace() ) {
1378 case NS_MAIN:
1379 $text = wfMsg('articlepage');
1380 break;
1381 case NS_USER:
1382 $text = wfMsg('userpage');
1383 break;
1384 case NS_PROJECT:
1385 $text = wfMsg('projectpage');
1386 break;
1387 case NS_IMAGE:
1388 $text = wfMsg('imagepage');
1389 break;
1390 default:
1391 $text= wfMsg('articlepage');
1392 }
1393 } else {
1394 $link = $wgTitle->getTalkPage();
1395 $text = wfMsg( 'talkpage' );
1396 }
1397
1398 $s = $this->makeLinkObj( $link, $text );
1399
1400 return $s;
1401 }
1402
1403 function commentLink() {
1404 global $wgTitle, $wgOut;
1405
1406 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1407 return '';
1408 }
1409
1410 # __NEWSECTIONLINK___ changes behaviour here
1411 # If it's present, the link points to this page, otherwise
1412 # it points to the talk page
1413 if( $wgTitle->isTalkPage() ) {
1414 $title =& $wgTitle;
1415 } elseif( $wgOut->showNewSectionLink() ) {
1416 $title =& $wgTitle;
1417 } else {
1418 $title =& $wgTitle->getTalkPage();
1419 }
1420
1421 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1422 }
1423
1424 /* these are used extensively in SkinTemplate, but also some other places */
1425 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1426 $title = Title::makeTitle( NS_SPECIAL, $name );
1427 return $title->getLocalURL( $urlaction );
1428 }
1429
1430 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1431 $title = Title::newFromText( wfMsgForContent($name) );
1432 $this->checkTitle($title, $name);
1433 return $title->getLocalURL( $urlaction );
1434 }
1435
1436 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1437 $title = Title::newFromText( $name );
1438 $this->checkTitle($title, $name);
1439 return $title->getLocalURL( $urlaction );
1440 }
1441
1442 # If url string starts with http, consider as external URL, else
1443 # internal
1444 /*static*/ function makeInternalOrExternalUrl( $name ) {
1445 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1446 return $name;
1447 } else {
1448 return $this->makeUrl( $name );
1449 }
1450 }
1451
1452 # this can be passed the NS number as defined in Language.php
1453 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) {
1454 $title = Title::makeTitleSafe( $namespace, $name );
1455 $this->checkTitle($title, $name);
1456 return $title->getLocalURL( $urlaction );
1457 }
1458
1459 /* these return an array with the 'href' and boolean 'exists' */
1460 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1461 $title = Title::newFromText( $name );
1462 $this->checkTitle($title, $name);
1463 return array(
1464 'href' => $title->getLocalURL( $urlaction ),
1465 'exists' => $title->getArticleID() != 0?true:false
1466 );
1467 }
1468
1469 /**
1470 * Make URL details where the article exists (or at least it's convenient to think so)
1471 */
1472 function makeKnownUrlDetails( $name, $urlaction='' ) {
1473 $title = Title::newFromText( $name );
1474 $this->checkTitle($title, $name);
1475 return array(
1476 'href' => $title->getLocalURL( $urlaction ),
1477 'exists' => true
1478 );
1479 }
1480
1481 # make sure we have some title to operate on
1482 /*static*/ function checkTitle ( &$title, &$name ) {
1483 if(!is_object($title)) {
1484 $title = Title::newFromText( $name );
1485 if(!is_object($title)) {
1486 $title = Title::newFromText( '--error: link target missing--' );
1487 }
1488 }
1489 }
1490
1491 /**
1492 * Build an array that represents the sidebar(s), the navigation bar among them
1493 *
1494 * @return array
1495 * @private
1496 */
1497 function buildSidebar() {
1498 global $wgDBname, $parserMemc, $wgEnableSidebarCache;
1499 global $wgLang, $wgContLang;
1500
1501 $fname = 'SkinTemplate::buildSidebar';
1502
1503 wfProfileIn( $fname );
1504
1505 $key = "{$wgDBname}:sidebar";
1506 $cacheSidebar = $wgEnableSidebarCache &&
1507 ($wgLang->getCode() == $wgContLang->getCode());
1508
1509 if ($cacheSidebar) {
1510 $cachedsidebar = $parserMemc->get( $key );
1511 if ($cachedsidebar!="") {
1512 wfProfileOut($fname);
1513 return $cachedsidebar;
1514 }
1515 }
1516
1517 $bar = array();
1518 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1519 foreach ($lines as $line) {
1520 if (strpos($line, '*') !== 0)
1521 continue;
1522 if (strpos($line, '**') !== 0) {
1523 $line = trim($line, '* ');
1524 $heading = $line;
1525 } else {
1526 if (strpos($line, '|') !== false) { // sanity check
1527 $line = explode( '|' , trim($line, '* '), 2 );
1528 $link = wfMsgForContent( $line[0] );
1529 if ($link == '-')
1530 continue;
1531 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1532 $text = $line[1];
1533 if (wfEmptyMsg($line[0], $link))
1534 $link = $line[0];
1535 $href = $this->makeInternalOrExternalUrl( $link );
1536 $bar[$heading][] = array(
1537 'text' => $text,
1538 'href' => $href,
1539 'id' => 'n-' . strtr($line[1], ' ', '-'),
1540 'active' => false
1541 );
1542 } else { continue; }
1543 }
1544 }
1545 if ($cacheSidebar)
1546 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1547 wfProfileOut( $fname );
1548 return $bar;
1549 }
1550 }
1551 ?>