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