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