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