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