4c91987dc31be0af1f32f358e291937c0b68c76d
[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 ('go') . '" />&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 require_once('SpecialPage.php');
1091 $a = array();
1092 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1093 foreach ( $pages as $name => $page ) {
1094 $pages[$name] = $page->getDescription();
1095 }
1096
1097 $go = wfMsg( 'go' );
1098 $sp = wfMsg( 'specialpages' );
1099 $spp = $wgContLang->specialPage( 'Specialpages' );
1100
1101 $s = '<form id="specialpages" method="get" class="inline" ' .
1102 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1103 $s .= "<select name=\"wpDropdown\">\n";
1104 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1105
1106
1107 foreach ( $pages as $name => $desc ) {
1108 $p = $wgContLang->specialPage( $name );
1109 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1110 }
1111 $s .= "</select>\n";
1112 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1113 $s .= "</form>\n";
1114 return $s;
1115 }
1116
1117 function mainPageLink() {
1118 $mp = wfMsgForContent( 'mainpage' );
1119 $mptxt = wfMsg( 'mainpage');
1120 $s = $this->makeKnownLink( $mp, $mptxt );
1121 return $s;
1122 }
1123
1124 function copyrightLink() {
1125 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1126 wfMsg( 'copyrightpagename' ) );
1127 return $s;
1128 }
1129
1130 function privacyLink() {
1131 $privacy = wfMsg( 'privacy' );
1132 if ($privacy == '-') {
1133 return '';
1134 } else {
1135 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1136 }
1137 }
1138
1139 function aboutLink() {
1140 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1141 wfMsg( 'aboutsite' ) );
1142 return $s;
1143 }
1144
1145 function disclaimerLink() {
1146 $disclaimers = wfMsg( 'disclaimers' );
1147 if ($disclaimers == '-') {
1148 return '';
1149 } else {
1150 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1151 $disclaimers );
1152 }
1153 }
1154
1155 function editThisPage() {
1156 global $wgOut, $wgTitle;
1157
1158 if ( ! $wgOut->isArticleRelated() ) {
1159 $s = wfMsg( 'protectedpage' );
1160 } else {
1161 if ( $wgTitle->userCanEdit() ) {
1162 $t = wfMsg( 'editthispage' );
1163 } else {
1164 $t = wfMsg( 'viewsource' );
1165 }
1166
1167 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1168 }
1169 return $s;
1170 }
1171
1172 /**
1173 * Return URL options for the 'edit page' link.
1174 * This may include an 'oldid' specifier, if the current page view is such.
1175 *
1176 * @return string
1177 * @private
1178 */
1179 function editUrlOptions() {
1180 global $wgArticle;
1181
1182 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1183 return "action=edit&oldid=" . intval( $this->mRevisionId );
1184 } else {
1185 return "action=edit";
1186 }
1187 }
1188
1189 function deleteThisPage() {
1190 global $wgUser, $wgTitle, $wgRequest;
1191
1192 $diff = $wgRequest->getVal( 'diff' );
1193 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1194 $t = wfMsg( 'deletethispage' );
1195
1196 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1197 } else {
1198 $s = '';
1199 }
1200 return $s;
1201 }
1202
1203 function protectThisPage() {
1204 global $wgUser, $wgTitle, $wgRequest;
1205
1206 $diff = $wgRequest->getVal( 'diff' );
1207 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1208 if ( $wgTitle->isProtected() ) {
1209 $t = wfMsg( 'unprotectthispage' );
1210 $q = 'action=unprotect';
1211 } else {
1212 $t = wfMsg( 'protectthispage' );
1213 $q = 'action=protect';
1214 }
1215 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1216 } else {
1217 $s = '';
1218 }
1219 return $s;
1220 }
1221
1222 function watchThisPage() {
1223 global $wgOut, $wgTitle;
1224
1225 if ( $wgOut->isArticleRelated() ) {
1226 if ( $wgTitle->userIsWatching() ) {
1227 $t = wfMsg( 'unwatchthispage' );
1228 $q = 'action=unwatch';
1229 } else {
1230 $t = wfMsg( 'watchthispage' );
1231 $q = 'action=watch';
1232 }
1233 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1234 } else {
1235 $s = wfMsg( 'notanarticle' );
1236 }
1237 return $s;
1238 }
1239
1240 function moveThisPage() {
1241 global $wgTitle;
1242
1243 if ( $wgTitle->userCanMove() ) {
1244 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
1245 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1246 } else {
1247 // no message if page is protected - would be redundant
1248 return '';
1249 }
1250 }
1251
1252 function historyLink() {
1253 global $wgTitle;
1254
1255 return $this->makeKnownLinkObj( $wgTitle,
1256 wfMsg( 'history' ), 'action=history' );
1257 }
1258
1259 function whatLinksHere() {
1260 global $wgTitle;
1261
1262 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
1263 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1264 }
1265
1266 function userContribsLink() {
1267 global $wgTitle;
1268
1269 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
1270 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1271 }
1272
1273 function showEmailUser( $id ) {
1274 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1275 return $wgEnableEmail &&
1276 $wgEnableUserEmail &&
1277 $wgUser->isLoggedIn() && # show only to signed in users
1278 0 != $id; # we can only email to non-anons ..
1279 # '' != $id->getEmail() && # who must have an email address stored ..
1280 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1281 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1282 }
1283
1284 function emailUserLink() {
1285 global $wgTitle;
1286
1287 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
1288 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1289 }
1290
1291 function watchPageLinksLink() {
1292 global $wgOut, $wgTitle;
1293
1294 if ( ! $wgOut->isArticleRelated() ) {
1295 return '(' . wfMsg( 'notanarticle' ) . ')';
1296 } else {
1297 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
1298 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1299 'target=' . $wgTitle->getPrefixedURL() );
1300 }
1301 }
1302
1303 function trackbackLink() {
1304 global $wgTitle;
1305
1306 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1307 . wfMsg('trackbacklink') . "</a>";
1308 }
1309
1310 function otherLanguages() {
1311 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1312
1313 if ( $wgHideInterlanguageLinks ) {
1314 return '';
1315 }
1316
1317 $a = $wgOut->getLanguageLinks();
1318 if ( 0 == count( $a ) ) {
1319 return '';
1320 }
1321
1322 $s = wfMsg( 'otherlanguages' ) . ': ';
1323 $first = true;
1324 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1325 foreach( $a as $l ) {
1326 if ( ! $first ) { $s .= ' | '; }
1327 $first = false;
1328
1329 $nt = Title::newFromText( $l );
1330 $url = $nt->escapeFullURL();
1331 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1332
1333 if ( '' == $text ) { $text = $l; }
1334 $style = $this->getExternalLinkAttributes( $l, $text );
1335 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1336 }
1337 if($wgContLang->isRTL()) $s .= '</span>';
1338 return $s;
1339 }
1340
1341 function bugReportsLink() {
1342 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1343 wfMsg( 'bugreports' ) );
1344 return $s;
1345 }
1346
1347 function dateLink() {
1348 $t1 = Title::newFromText( gmdate( 'F j' ) );
1349 $t2 = Title::newFromText( gmdate( 'Y' ) );
1350
1351 $id = $t1->getArticleID();
1352
1353 if ( 0 == $id ) {
1354 $s = $this->makeBrokenLink( $t1->getText() );
1355 } else {
1356 $s = $this->makeKnownLink( $t1->getText() );
1357 }
1358 $s .= ', ';
1359
1360 $id = $t2->getArticleID();
1361
1362 if ( 0 == $id ) {
1363 $s .= $this->makeBrokenLink( $t2->getText() );
1364 } else {
1365 $s .= $this->makeKnownLink( $t2->getText() );
1366 }
1367 return $s;
1368 }
1369
1370 function talkLink() {
1371 global $wgTitle;
1372
1373 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1374 # No discussion links for special pages
1375 return '';
1376 }
1377
1378 if( $wgTitle->isTalkPage() ) {
1379 $link = $wgTitle->getSubjectPage();
1380 switch( $link->getNamespace() ) {
1381 case NS_MAIN:
1382 $text = wfMsg( 'articlepage' );
1383 break;
1384 case NS_USER:
1385 $text = wfMsg( 'userpage' );
1386 break;
1387 case NS_PROJECT:
1388 $text = wfMsg( 'projectpage' );
1389 break;
1390 case NS_IMAGE:
1391 $text = wfMsg( 'imagepage' );
1392 break;
1393 case NS_MEDIAWIKI:
1394 $text = wfMsg( 'mediawikipage' );
1395 break;
1396 case NS_TEMPLATE:
1397 $text = wfMsg( 'templatepage' );
1398 break;
1399 case NS_HELP:
1400 $text = wfMsg( 'viewhelppage' );
1401 break;
1402 case NS_CATEGORY:
1403 $text = wfMsg( 'categorypage' );
1404 break;
1405 default:
1406 $text = wfMsg( 'articlepage' );
1407 }
1408 } else {
1409 $link = $wgTitle->getTalkPage();
1410 $text = wfMsg( 'talkpage' );
1411 }
1412
1413 $s = $this->makeLinkObj( $link, $text );
1414
1415 return $s;
1416 }
1417
1418 function commentLink() {
1419 global $wgTitle, $wgOut;
1420
1421 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1422 return '';
1423 }
1424
1425 # __NEWSECTIONLINK___ changes behaviour here
1426 # If it's present, the link points to this page, otherwise
1427 # it points to the talk page
1428 if( $wgTitle->isTalkPage() ) {
1429 $title =& $wgTitle;
1430 } elseif( $wgOut->showNewSectionLink() ) {
1431 $title =& $wgTitle;
1432 } else {
1433 $title =& $wgTitle->getTalkPage();
1434 }
1435
1436 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1437 }
1438
1439 /* these are used extensively in SkinTemplate, but also some other places */
1440 static function makeSpecialUrl( $name, $urlaction = '' ) {
1441 $title = Title::makeTitle( NS_SPECIAL, $name );
1442 return $title->getLocalURL( $urlaction );
1443 }
1444
1445 static function makeI18nUrl( $name, $urlaction = '' ) {
1446 $title = Title::newFromText( wfMsgForContent( $name ) );
1447 self::checkTitle( $title, $name );
1448 return $title->getLocalURL( $urlaction );
1449 }
1450
1451 static function makeUrl( $name, $urlaction = '' ) {
1452 $title = Title::newFromText( $name );
1453 self::checkTitle( $title, $name );
1454 return $title->getLocalURL( $urlaction );
1455 }
1456
1457 # If url string starts with http, consider as external URL, else
1458 # internal
1459 static function makeInternalOrExternalUrl( $name ) {
1460 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1461 return $name;
1462 } else {
1463 return self::makeUrl( $name );
1464 }
1465 }
1466
1467 # this can be passed the NS number as defined in Language.php
1468 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1469 $title = Title::makeTitleSafe( $namespace, $name );
1470 self::checkTitle( $title, $name );
1471 return $title->getLocalURL( $urlaction );
1472 }
1473
1474 /* these return an array with the 'href' and boolean 'exists' */
1475 static function makeUrlDetails( $name, $urlaction = '' ) {
1476 $title = Title::newFromText( $name );
1477 self::checkTitle( $title, $name );
1478 return array(
1479 'href' => $title->getLocalURL( $urlaction ),
1480 'exists' => $title->getArticleID() != 0 ? true : false
1481 );
1482 }
1483
1484 /**
1485 * Make URL details where the article exists (or at least it's convenient to think so)
1486 */
1487 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1488 $title = Title::newFromText( $name );
1489 self::checkTitle( $title, $name );
1490 return array(
1491 'href' => $title->getLocalURL( $urlaction ),
1492 'exists' => true
1493 );
1494 }
1495
1496 # make sure we have some title to operate on
1497 static function checkTitle( &$title, &$name ) {
1498 if( !is_object( $title ) ) {
1499 $title = Title::newFromText( $name );
1500 if( !is_object( $title ) ) {
1501 $title = Title::newFromText( '--error: link target missing--' );
1502 }
1503 }
1504 }
1505
1506 /**
1507 * Build an array that represents the sidebar(s), the navigation bar among them
1508 *
1509 * @return array
1510 * @private
1511 */
1512 function buildSidebar() {
1513 global $wgDBname, $parserMemc, $wgEnableSidebarCache;
1514 global $wgLang, $wgContLang;
1515
1516 $fname = 'SkinTemplate::buildSidebar';
1517
1518 wfProfileIn( $fname );
1519
1520 $key = "{$wgDBname}:sidebar";
1521 $cacheSidebar = $wgEnableSidebarCache &&
1522 ($wgLang->getCode() == $wgContLang->getCode());
1523
1524 if ($cacheSidebar) {
1525 $cachedsidebar = $parserMemc->get( $key );
1526 if ($cachedsidebar!="") {
1527 wfProfileOut($fname);
1528 return $cachedsidebar;
1529 }
1530 }
1531
1532 $bar = array();
1533 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1534 foreach ($lines as $line) {
1535 if (strpos($line, '*') !== 0)
1536 continue;
1537 if (strpos($line, '**') !== 0) {
1538 $line = trim($line, '* ');
1539 $heading = $line;
1540 } else {
1541 if (strpos($line, '|') !== false) { // sanity check
1542 $line = explode( '|' , trim($line, '* '), 2 );
1543 $link = wfMsgForContent( $line[0] );
1544 if ($link == '-')
1545 continue;
1546 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1547 $text = $line[1];
1548 if (wfEmptyMsg($line[0], $link))
1549 $link = $line[0];
1550 $href = self::makeInternalOrExternalUrl( $link );
1551 $bar[$heading][] = array(
1552 'text' => $text,
1553 'href' => $href,
1554 'id' => 'n-' . strtr($line[1], ' ', '-'),
1555 'active' => false
1556 );
1557 } else { continue; }
1558 }
1559 }
1560 if ($cacheSidebar)
1561 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1562 wfProfileOut( $fname );
1563 return $bar;
1564 }
1565 }
1566 ?>