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