43c7695ffc62f09c6f280370ab35b6bc191a4b6d
[lhc/web/wiklou.git] / includes / Skin.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4
5 /**
6 *
7 * @package MediaWiki
8 * @subpackage Skins
9 */
10
11 # See skin.txt
12
13 /**
14 * The main skin class that provide methods and properties for all other skins.
15 * This base class is also the "Standard" skin.
16 * @package MediaWiki
17 */
18 class Skin extends Linker {
19 /**#@+
20 * @private
21 */
22 var $lastdate, $lastline;
23 var $rc_cache ; # Cache for Enhanced Recent Changes
24 var $rcCacheIndex ; # Recent Changes Cache Counter for visibility toggle
25 var $rcMoveIndex;
26 /**#@-*/
27
28 /** Constructor, call parent constructor */
29 function Skin() { parent::Linker(); }
30
31 /**
32 * Fetch the set of available skins.
33 * @return array of strings
34 * @static
35 */
36 static function &getSkinNames() {
37 global $wgValidSkinNames;
38 static $skinsInitialised = false;
39 if ( !$skinsInitialised ) {
40 # Get a list of available skins
41 # Build using the regular expression '^(.*).php$'
42 # Array keys are all lower case, array value keep the case used by filename
43 #
44 wfProfileIn( __METHOD__ . '-init' );
45 global $wgStyleDirectory;
46 $skinDir = dir( $wgStyleDirectory );
47
48 # while code from www.php.net
49 while (false !== ($file = $skinDir->read())) {
50 // Skip non-PHP files, hidden files, and '.dep' includes
51 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
52 $aSkin = $matches[1];
53 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
54 }
55 }
56 $skinDir->close();
57 $skinsInitialised = true;
58 wfProfileOut( __METHOD__ . '-init' );
59 }
60 return $wgValidSkinNames;
61 }
62
63 /**
64 * Normalize a skin preference value to a form that can be loaded.
65 * If a skin can't be found, it will fall back to the configured
66 * default (or the old 'Classic' skin if that's broken).
67 * @param string $key
68 * @return string
69 * @static
70 */
71 static function normalizeKey( $key ) {
72 global $wgDefaultSkin;
73 $skinNames = Skin::getSkinNames();
74
75 if( $key == '' ) {
76 // Don't return the default immediately;
77 // in a misconfiguration we need to fall back.
78 $key = $wgDefaultSkin;
79 }
80
81 if( isset( $skinNames[$key] ) ) {
82 return $key;
83 }
84
85 // Older versions of the software used a numeric setting
86 // in the user preferences.
87 $fallback = array(
88 0 => $wgDefaultSkin,
89 1 => 'nostalgia',
90 2 => 'cologneblue' );
91
92 if( isset( $fallback[$key] ) ){
93 $key = $fallback[$key];
94 }
95
96 if( isset( $skinNames[$key] ) ) {
97 return $key;
98 } else {
99 // The old built-in skin
100 return 'standard';
101 }
102 }
103
104 /**
105 * Factory method for loading a skin of a given type
106 * @param string $key 'monobook', 'standard', etc
107 * @return Skin
108 * @static
109 */
110 static function &newFromKey( $key ) {
111 global $wgStyleDirectory;
112
113 $key = Skin::normalizeKey( $key );
114
115 $skinNames = Skin::getSkinNames();
116 $skinName = $skinNames[$key];
117
118 # Grab the skin class and initialise it.
119 wfSuppressWarnings();
120 // Preload base classes to work around APC/PHP5 bug
121 include_once( "{$wgStyleDirectory}/{$skinName}.deps.php" );
122 wfRestoreWarnings();
123 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
124
125 # Check if we got if not failback to default skin
126 $className = 'Skin'.$skinName;
127 if( !class_exists( $className ) ) {
128 # DO NOT die if the class isn't found. This breaks maintenance
129 # scripts and can cause a user account to be unrecoverable
130 # except by SQL manipulation if a previously valid skin name
131 # is no longer valid.
132 wfDebug( "Skin class does not exist: $className\n" );
133 $className = 'SkinStandard';
134 require_once( "{$wgStyleDirectory}/Standard.php" );
135 }
136 $skin = new $className;
137 return $skin;
138 }
139
140 /** @return string path to the skin stylesheet */
141 function getStylesheet() {
142 return 'common/wikistandard.css';
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 $nsname = @$wgCanonicalNamespaceNames[ $wgTitle->getNamespace() ];
304 if ( $nsname === NULL ) $nsname = $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 $action = $wgRequest->getText('action');
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 $t = wfMsg( 'editthispage' );
495 $s = $wgTitle->getFullURL( $this->editUrlOptions() );
496 $s = 'document.location = "' .wfEscapeJSString( $s ) .'";';
497 $a += array ('ondblclick' => $s);
498
499 }
500 $a['onload'] = $wgOut->getOnloadHandler();
501 if( $wgUser->getOption( 'editsectiononrightclick' ) ) {
502 if( $a['onload'] != '' ) {
503 $a['onload'] .= ';';
504 }
505 $a['onload'] .= 'setupRightClickEdit()';
506 }
507 $a['class'] = 'ns-'.$wgTitle->getNamespace().' '.($wgContLang->isRTL() ? "rtl" : "ltr").
508 ' '.Sanitizer::escapeId( 'page-'.$wgTitle->getPrefixedText() );
509 return $a;
510 }
511
512 /**
513 * URL to the logo
514 */
515 function getLogo() {
516 global $wgLogo;
517 return $wgLogo;
518 }
519
520 /**
521 * This will be called immediately after the <body> tag. Split into
522 * two functions to make it easier to subclass.
523 */
524 function beforeContent() {
525 return $this->doBeforeContent();
526 }
527
528 function doBeforeContent() {
529 global $wgContLang;
530 $fname = 'Skin::doBeforeContent';
531 wfProfileIn( $fname );
532
533 $s = '';
534 $qb = $this->qbSetting();
535
536 if( $langlinks = $this->otherLanguages() ) {
537 $rows = 2;
538 $borderhack = '';
539 } else {
540 $rows = 1;
541 $langlinks = false;
542 $borderhack = 'class="top"';
543 }
544
545 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
546 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
547
548 $shove = ($qb != 0);
549 $left = ($qb == 1 || $qb == 3);
550 if($wgContLang->isRTL()) $left = !$left;
551
552 if ( !$shove ) {
553 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
554 $this->logoText() . '</td>';
555 } elseif( $left ) {
556 $s .= $this->getQuickbarCompensator( $rows );
557 }
558 $l = $wgContLang->isRTL() ? 'right' : 'left';
559 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
560
561 $s .= $this->topLinks() ;
562 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
563
564 $r = $wgContLang->isRTL() ? "left" : "right";
565 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
566 $s .= $this->nameAndLogin();
567 $s .= "\n<br />" . $this->searchForm() . "</td>";
568
569 if ( $langlinks ) {
570 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
571 }
572
573 if ( $shove && !$left ) { # Right
574 $s .= $this->getQuickbarCompensator( $rows );
575 }
576 $s .= "</tr>\n</table>\n</div>\n";
577 $s .= "\n<div id='article'>\n";
578
579 $notice = wfGetSiteNotice();
580 if( $notice ) {
581 $s .= "\n<div id='siteNotice'>$notice</div>\n";
582 }
583 $s .= $this->pageTitle();
584 $s .= $this->pageSubtitle() ;
585 $s .= $this->getCategories();
586 wfProfileOut( $fname );
587 return $s;
588 }
589
590
591 function getCategoryLinks () {
592 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
593 global $wgContLang;
594
595 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
596
597 # Separator
598 $sep = wfMsgHtml( 'catseparator' );
599
600 // Use Unicode bidi embedding override characters,
601 // to make sure links don't smash each other up in ugly ways.
602 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
603 $embed = "<span dir='$dir'>";
604 $pop = '</span>';
605 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $wgOut->mCategoryLinks ) . $pop;
606
607 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escape' ), count( $wgOut->mCategoryLinks ) );
608 $s = $this->makeLinkObj( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
609 . ': ' . $t;
610
611 # optional 'dmoz-like' category browser. Will be shown under the list
612 # of categories an article belong to
613 if($wgUseCategoryBrowser) {
614 $s .= '<br /><hr />';
615
616 # get a big array of the parents tree
617 $parenttree = $wgTitle->getParentCategoryTree();
618 # Skin object passed by reference cause it can not be
619 # accessed under the method subfunction drawCategoryBrowser
620 $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
621 # Clean out bogus first entry and sort them
622 unset($tempout[0]);
623 asort($tempout);
624 # Output one per line
625 $s .= implode("<br />\n", $tempout);
626 }
627
628 return $s;
629 }
630
631 /** Render the array as a serie of links.
632 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
633 * @param &skin Object: skin passed by reference
634 * @return String separated by &gt;, terminate with "\n"
635 */
636 function drawCategoryBrowser($tree, &$skin) {
637 $return = '';
638 foreach ($tree as $element => $parent) {
639 if (empty($parent)) {
640 # element start a new list
641 $return .= "\n";
642 } else {
643 # grab the others elements
644 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
645 }
646 # add our current element to the list
647 $eltitle = Title::NewFromText($element);
648 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
649 }
650 return $return;
651 }
652
653 function getCategories() {
654 $catlinks=$this->getCategoryLinks();
655 if(!empty($catlinks)) {
656 return "<p class='catlinks'>{$catlinks}</p>";
657 }
658 }
659
660 function getQuickbarCompensator( $rows = 1 ) {
661 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
662 }
663
664 /**
665 * This gets called shortly before the \</body\> tag.
666 * @return String HTML to be put before \</body\>
667 */
668 function afterContent() {
669 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
670 return $printfooter . $this->doAfterContent();
671 }
672
673 /**
674 * This gets called shortly before the \</body\> tag.
675 * @return String HTML-wrapped JS code to be put before \</body\>
676 */
677 function bottomScripts() {
678 global $wgJsMimeType;
679 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
680 }
681
682 /** @return string Retrievied from HTML text */
683 function printSource() {
684 global $wgTitle;
685 $url = htmlspecialchars( $wgTitle->getFullURL() );
686 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
687 }
688
689 function printFooter() {
690 return "<p>" . $this->printSource() .
691 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
692 }
693
694 /** overloaded by derived classes */
695 function doAfterContent() { }
696
697 function pageTitleLinks() {
698 global $wgOut, $wgTitle, $wgUser, $wgRequest;
699
700 extract( $wgRequest->getValues( 'oldid', '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->makeKnownLink(
762 $wgContLang->SpecialPage( '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 $li = $wgContLang->specialPage( 'Userlogin' );
843 $lo = $wgContLang->specialPage( 'Userlogout' );
844
845 $s = '';
846 if ( $wgUser->isAnon() ) {
847 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
848 $n = wfGetIP();
849
850 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
851 $wgLang->getNsText( NS_TALK ) );
852
853 $s .= $n . ' ('.$tl.')';
854 } else {
855 $s .= wfMsg('notloggedin');
856 }
857
858 $rt = $wgTitle->getPrefixedURL();
859 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
860 $q = '';
861 } else { $q = "returnto={$rt}"; }
862
863 $s .= "\n<br />" . $this->makeKnownLinkObj(
864 SpecialPage::getTitleFor( 'Userlogin' ),
865 wfMsg( 'login' ), $q );
866 } else {
867 $n = $wgUser->getName();
868 $rt = $wgTitle->getPrefixedURL();
869 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
870 $wgLang->getNsText( NS_TALK ) );
871
872 $tl = " ({$tl})";
873
874 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
875 $n ) . "{$tl}<br />" .
876 $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
877 "returnto={$rt}" ) . ' | ' .
878 $this->specialLink( 'preferences' );
879 }
880 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
881 wfMsg( 'help' ) );
882
883 return $s;
884 }
885
886 function getSearchLink() {
887 $searchPage =& SpecialPage::getTitleFor( 'Search' );
888 return $searchPage->getLocalURL();
889 }
890
891 function escapeSearchLink() {
892 return htmlspecialchars( $this->getSearchLink() );
893 }
894
895 function searchForm() {
896 global $wgRequest;
897 $search = $wgRequest->getText( 'search' );
898
899 $s = '<form name="search" class="inline" method="post" action="'
900 . $this->escapeSearchLink() . "\">\n"
901 . '<input type="text" name="search" size="19" value="'
902 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
903 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
904 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
905
906 return $s;
907 }
908
909 function topLinks() {
910 global $wgOut;
911 $sep = " |\n";
912
913 $s = $this->mainPageLink() . $sep
914 . $this->specialLink( 'recentchanges' );
915
916 if ( $wgOut->isArticleRelated() ) {
917 $s .= $sep . $this->editThisPage()
918 . $sep . $this->historyLink();
919 }
920 # Many people don't like this dropdown box
921 #$s .= $sep . $this->specialPagesList();
922
923 $s .= $this->variantLinks();
924
925 $s .= $this->extensionTabLinks();
926
927 return $s;
928 }
929
930 /**
931 * Compatibility for extensions adding functionality through tabs.
932 * Eventually these old skins should be replaced with SkinTemplate-based
933 * versions, sigh...
934 * @return string
935 */
936 function extensionTabLinks() {
937 $tabs = array();
938 $s = '';
939 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
940 foreach( $tabs as $tab ) {
941 $s .= ' | ' . Xml::element( 'a',
942 array( 'href' => $tab['href'] ),
943 $tab['text'] );
944 }
945 return $s;
946 }
947
948 /**
949 * Language/charset variant links for classic-style skins
950 * @return string
951 */
952 function variantLinks() {
953 $s = '';
954 /* show links to different language variants */
955 global $wgDisableLangConversion, $wgContLang, $wgTitle;
956 $variants = $wgContLang->getVariants();
957 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
958 foreach( $variants as $code ) {
959 $varname = $wgContLang->getVariantname( $code );
960 if( $varname == 'disable' )
961 continue;
962 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
963 }
964 }
965 return $s;
966 }
967
968 function bottomLinks() {
969 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
970 $sep = " |\n";
971
972 $s = '';
973 if ( $wgOut->isArticleRelated() ) {
974 $s .= '<strong>' . $this->editThisPage() . '</strong>';
975 if ( $wgUser->isLoggedIn() ) {
976 $s .= $sep . $this->watchThisPage();
977 }
978 $s .= $sep . $this->talkLink()
979 . $sep . $this->historyLink()
980 . $sep . $this->whatLinksHere()
981 . $sep . $this->watchPageLinksLink();
982
983 if ($wgUseTrackbacks)
984 $s .= $sep . $this->trackbackLink();
985
986 if ( $wgTitle->getNamespace() == NS_USER
987 || $wgTitle->getNamespace() == NS_USER_TALK )
988
989 {
990 $id=User::idFromName($wgTitle->getText());
991 $ip=User::isIP($wgTitle->getText());
992
993 if($id || $ip) { # both anons and non-anons have contri list
994 $s .= $sep . $this->userContribsLink();
995 }
996 if( $this->showEmailUser( $id ) ) {
997 $s .= $sep . $this->emailUserLink();
998 }
999 }
1000 if ( $wgTitle->getArticleId() ) {
1001 $s .= "\n<br />";
1002 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1003 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1004 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1005 }
1006 $s .= "<br />\n" . $this->otherLanguages();
1007 }
1008 return $s;
1009 }
1010
1011 function pageStats() {
1012 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1013 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1014
1015 extract( $wgRequest->getValues( 'oldid', '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 $titleObj = Title::newFromText( $mp );
1132 if ( is_object( $titleObj ) ) {
1133 $url = $titleObj->escapeLocalURL();
1134 } else {
1135 $url = '';
1136 }
1137
1138 $logourl = $this->getLogo();
1139 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1140 return $s;
1141 }
1142
1143 /**
1144 * show a drop-down box of special pages
1145 */
1146 function specialPagesList() {
1147 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1148 $a = array();
1149 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1150 foreach ( $pages as $name => $page ) {
1151 $pages[$name] = $page->getDescription();
1152 }
1153
1154 $go = wfMsg( 'go' );
1155 $sp = wfMsg( 'specialpages' );
1156 $spp = $wgContLang->specialPage( 'Specialpages' );
1157
1158 $s = '<form id="specialpages" method="get" class="inline" ' .
1159 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1160 $s .= "<select name=\"wpDropdown\">\n";
1161 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1162
1163
1164 foreach ( $pages as $name => $desc ) {
1165 $p = $wgContLang->specialPage( $name );
1166 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1167 }
1168 $s .= "</select>\n";
1169 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1170 $s .= "</form>\n";
1171 return $s;
1172 }
1173
1174 function mainPageLink() {
1175 $mp = wfMsgForContent( 'mainpage' );
1176 $mptxt = wfMsg( 'mainpage');
1177 $s = $this->makeKnownLink( $mp, $mptxt );
1178 return $s;
1179 }
1180
1181 function copyrightLink() {
1182 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1183 wfMsg( 'copyrightpagename' ) );
1184 return $s;
1185 }
1186
1187 function privacyLink() {
1188 $privacy = wfMsg( 'privacy' );
1189 if ($privacy == '-') {
1190 return '';
1191 } else {
1192 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1193 }
1194 }
1195
1196 function aboutLink() {
1197 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1198 wfMsg( 'aboutsite' ) );
1199 return $s;
1200 }
1201
1202 function disclaimerLink() {
1203 $disclaimers = wfMsg( 'disclaimers' );
1204 if ($disclaimers == '-') {
1205 return '';
1206 } else {
1207 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1208 $disclaimers );
1209 }
1210 }
1211
1212 function editThisPage() {
1213 global $wgOut, $wgTitle;
1214
1215 if ( ! $wgOut->isArticleRelated() ) {
1216 $s = wfMsg( 'protectedpage' );
1217 } else {
1218 if ( $wgTitle->userCanEdit() ) {
1219 $t = wfMsg( 'editthispage' );
1220 } else {
1221 $t = wfMsg( 'viewsource' );
1222 }
1223
1224 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1225 }
1226 return $s;
1227 }
1228
1229 /**
1230 * Return URL options for the 'edit page' link.
1231 * This may include an 'oldid' specifier, if the current page view is such.
1232 *
1233 * @return string
1234 * @private
1235 */
1236 function editUrlOptions() {
1237 global $wgArticle;
1238
1239 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1240 return "action=edit&oldid=" . intval( $this->mRevisionId );
1241 } else {
1242 return "action=edit";
1243 }
1244 }
1245
1246 function deleteThisPage() {
1247 global $wgUser, $wgTitle, $wgRequest;
1248
1249 $diff = $wgRequest->getVal( 'diff' );
1250 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1251 $t = wfMsg( 'deletethispage' );
1252
1253 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1254 } else {
1255 $s = '';
1256 }
1257 return $s;
1258 }
1259
1260 function protectThisPage() {
1261 global $wgUser, $wgTitle, $wgRequest;
1262
1263 $diff = $wgRequest->getVal( 'diff' );
1264 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1265 if ( $wgTitle->isProtected() ) {
1266 $t = wfMsg( 'unprotectthispage' );
1267 $q = 'action=unprotect';
1268 } else {
1269 $t = wfMsg( 'protectthispage' );
1270 $q = 'action=protect';
1271 }
1272 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1273 } else {
1274 $s = '';
1275 }
1276 return $s;
1277 }
1278
1279 function watchThisPage() {
1280 global $wgOut, $wgTitle;
1281
1282 if ( $wgOut->isArticleRelated() ) {
1283 if ( $wgTitle->userIsWatching() ) {
1284 $t = wfMsg( 'unwatchthispage' );
1285 $q = 'action=unwatch';
1286 } else {
1287 $t = wfMsg( 'watchthispage' );
1288 $q = 'action=watch';
1289 }
1290 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1291 } else {
1292 $s = wfMsg( 'notanarticle' );
1293 }
1294 return $s;
1295 }
1296
1297 function moveThisPage() {
1298 global $wgTitle;
1299
1300 if ( $wgTitle->userCanMove() ) {
1301 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1302 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1303 } else {
1304 // no message if page is protected - would be redundant
1305 return '';
1306 }
1307 }
1308
1309 function historyLink() {
1310 global $wgTitle;
1311
1312 return $this->makeKnownLinkObj( $wgTitle,
1313 wfMsg( 'history' ), 'action=history' );
1314 }
1315
1316 function whatLinksHere() {
1317 global $wgTitle;
1318
1319 return $this->makeKnownLinkObj(
1320 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1321 wfMsg( 'whatlinkshere' ) );
1322 }
1323
1324 function userContribsLink() {
1325 global $wgTitle;
1326
1327 return $this->makeKnownLinkObj(
1328 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1329 wfMsg( 'contributions' ) );
1330 }
1331
1332 function showEmailUser( $id ) {
1333 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1334 return $wgEnableEmail &&
1335 $wgEnableUserEmail &&
1336 $wgUser->isLoggedIn() && # show only to signed in users
1337 0 != $id; # we can only email to non-anons ..
1338 # '' != $id->getEmail() && # who must have an email address stored ..
1339 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1340 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1341 }
1342
1343 function emailUserLink() {
1344 global $wgTitle;
1345
1346 return $this->makeKnownLinkObj(
1347 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1348 wfMsg( 'emailuser' ) );
1349 }
1350
1351 function watchPageLinksLink() {
1352 global $wgOut, $wgTitle;
1353
1354 if ( ! $wgOut->isArticleRelated() ) {
1355 return '(' . wfMsg( 'notanarticle' ) . ')';
1356 } else {
1357 return $this->makeKnownLinkObj(
1358 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1359 wfMsg( 'recentchangeslinked' ) );
1360 }
1361 }
1362
1363 function trackbackLink() {
1364 global $wgTitle;
1365
1366 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1367 . wfMsg('trackbacklink') . "</a>";
1368 }
1369
1370 function otherLanguages() {
1371 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1372
1373 if ( $wgHideInterlanguageLinks ) {
1374 return '';
1375 }
1376
1377 $a = $wgOut->getLanguageLinks();
1378 if ( 0 == count( $a ) ) {
1379 return '';
1380 }
1381
1382 $s = wfMsg( 'otherlanguages' ) . ': ';
1383 $first = true;
1384 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1385 foreach( $a as $l ) {
1386 if ( ! $first ) { $s .= ' | '; }
1387 $first = false;
1388
1389 $nt = Title::newFromText( $l );
1390 $url = $nt->escapeFullURL();
1391 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1392
1393 if ( '' == $text ) { $text = $l; }
1394 $style = $this->getExternalLinkAttributes( $l, $text );
1395 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1396 }
1397 if($wgContLang->isRTL()) $s .= '</span>';
1398 return $s;
1399 }
1400
1401 function bugReportsLink() {
1402 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1403 wfMsg( 'bugreports' ) );
1404 return $s;
1405 }
1406
1407 function dateLink() {
1408 $t1 = Title::newFromText( gmdate( 'F j' ) );
1409 $t2 = Title::newFromText( gmdate( 'Y' ) );
1410
1411 $id = $t1->getArticleID();
1412
1413 if ( 0 == $id ) {
1414 $s = $this->makeBrokenLink( $t1->getText() );
1415 } else {
1416 $s = $this->makeKnownLink( $t1->getText() );
1417 }
1418 $s .= ', ';
1419
1420 $id = $t2->getArticleID();
1421
1422 if ( 0 == $id ) {
1423 $s .= $this->makeBrokenLink( $t2->getText() );
1424 } else {
1425 $s .= $this->makeKnownLink( $t2->getText() );
1426 }
1427 return $s;
1428 }
1429
1430 function talkLink() {
1431 global $wgTitle;
1432
1433 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1434 # No discussion links for special pages
1435 return '';
1436 }
1437
1438 if( $wgTitle->isTalkPage() ) {
1439 $link = $wgTitle->getSubjectPage();
1440 switch( $link->getNamespace() ) {
1441 case NS_MAIN:
1442 $text = wfMsg( 'articlepage' );
1443 break;
1444 case NS_USER:
1445 $text = wfMsg( 'userpage' );
1446 break;
1447 case NS_PROJECT:
1448 $text = wfMsg( 'projectpage' );
1449 break;
1450 case NS_IMAGE:
1451 $text = wfMsg( 'imagepage' );
1452 break;
1453 case NS_MEDIAWIKI:
1454 $text = wfMsg( 'mediawikipage' );
1455 break;
1456 case NS_TEMPLATE:
1457 $text = wfMsg( 'templatepage' );
1458 break;
1459 case NS_HELP:
1460 $text = wfMsg( 'viewhelppage' );
1461 break;
1462 case NS_CATEGORY:
1463 $text = wfMsg( 'categorypage' );
1464 break;
1465 default:
1466 $text = wfMsg( 'articlepage' );
1467 }
1468 } else {
1469 $link = $wgTitle->getTalkPage();
1470 $text = wfMsg( 'talkpage' );
1471 }
1472
1473 $s = $this->makeLinkObj( $link, $text );
1474
1475 return $s;
1476 }
1477
1478 function commentLink() {
1479 global $wgTitle, $wgOut;
1480
1481 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1482 return '';
1483 }
1484
1485 # __NEWSECTIONLINK___ changes behaviour here
1486 # If it's present, the link points to this page, otherwise
1487 # it points to the talk page
1488 if( $wgTitle->isTalkPage() ) {
1489 $title =& $wgTitle;
1490 } elseif( $wgOut->showNewSectionLink() ) {
1491 $title =& $wgTitle;
1492 } else {
1493 $title =& $wgTitle->getTalkPage();
1494 }
1495
1496 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1497 }
1498
1499 /* these are used extensively in SkinTemplate, but also some other places */
1500 static function makeSpecialUrl( $name, $urlaction = '' ) {
1501 $title = SpecialPage::getTitleFor( $name );
1502 return $title->getLocalURL( $urlaction );
1503 }
1504
1505 static function makeI18nUrl( $name, $urlaction = '' ) {
1506 $title = Title::newFromText( wfMsgForContent( $name ) );
1507 self::checkTitle( $title, $name );
1508 return $title->getLocalURL( $urlaction );
1509 }
1510
1511 static function makeUrl( $name, $urlaction = '' ) {
1512 $title = Title::newFromText( $name );
1513 self::checkTitle( $title, $name );
1514 return $title->getLocalURL( $urlaction );
1515 }
1516
1517 # If url string starts with http, consider as external URL, else
1518 # internal
1519 static function makeInternalOrExternalUrl( $name ) {
1520 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1521 return $name;
1522 } else {
1523 return self::makeUrl( $name );
1524 }
1525 }
1526
1527 # this can be passed the NS number as defined in Language.php
1528 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1529 $title = Title::makeTitleSafe( $namespace, $name );
1530 self::checkTitle( $title, $name );
1531 return $title->getLocalURL( $urlaction );
1532 }
1533
1534 /* these return an array with the 'href' and boolean 'exists' */
1535 static function makeUrlDetails( $name, $urlaction = '' ) {
1536 $title = Title::newFromText( $name );
1537 self::checkTitle( $title, $name );
1538 return array(
1539 'href' => $title->getLocalURL( $urlaction ),
1540 'exists' => $title->getArticleID() != 0 ? true : false
1541 );
1542 }
1543
1544 /**
1545 * Make URL details where the article exists (or at least it's convenient to think so)
1546 */
1547 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1548 $title = Title::newFromText( $name );
1549 self::checkTitle( $title, $name );
1550 return array(
1551 'href' => $title->getLocalURL( $urlaction ),
1552 'exists' => true
1553 );
1554 }
1555
1556 # make sure we have some title to operate on
1557 static function checkTitle( &$title, &$name ) {
1558 if( !is_object( $title ) ) {
1559 $title = Title::newFromText( $name );
1560 if( !is_object( $title ) ) {
1561 $title = Title::newFromText( '--error: link target missing--' );
1562 }
1563 }
1564 }
1565
1566 /**
1567 * Build an array that represents the sidebar(s), the navigation bar among them
1568 *
1569 * @return array
1570 * @private
1571 */
1572 function buildSidebar() {
1573 global $parserMemc, $wgEnableSidebarCache;
1574 global $wgLang, $wgContLang;
1575
1576 $fname = 'SkinTemplate::buildSidebar';
1577
1578 wfProfileIn( $fname );
1579
1580 $key = wfMemcKey( 'sidebar' );
1581 $cacheSidebar = $wgEnableSidebarCache &&
1582 ($wgLang->getCode() == $wgContLang->getCode());
1583
1584 if ($cacheSidebar) {
1585 $cachedsidebar = $parserMemc->get( $key );
1586 if ($cachedsidebar!="") {
1587 wfProfileOut($fname);
1588 return $cachedsidebar;
1589 }
1590 }
1591
1592 $bar = array();
1593 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1594 foreach ($lines as $line) {
1595 if (strpos($line, '*') !== 0)
1596 continue;
1597 if (strpos($line, '**') !== 0) {
1598 $line = trim($line, '* ');
1599 $heading = $line;
1600 } else {
1601 if (strpos($line, '|') !== false) { // sanity check
1602 $line = explode( '|' , trim($line, '* '), 2 );
1603 $link = wfMsgForContent( $line[0] );
1604 if ($link == '-')
1605 continue;
1606 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1607 $text = $line[1];
1608 if (wfEmptyMsg($line[0], $link))
1609 $link = $line[0];
1610
1611 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1612 $href = $link;
1613 } else {
1614 $title = Title::newFromText( $link );
1615 if ( $title ) {
1616 $title = $title->fixSpecialName();
1617 $href = $title->getLocalURL();
1618 } else {
1619 $href = 'INVALID-TITLE';
1620 }
1621 }
1622
1623 $bar[$heading][] = array(
1624 'text' => $text,
1625 'href' => $href,
1626 'id' => 'n-' . strtr($line[1], ' ', '-'),
1627 'active' => false
1628 );
1629 } else { continue; }
1630 }
1631 }
1632 if ($cacheSidebar)
1633 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1634 wfProfileOut( $fname );
1635 return $bar;
1636 }
1637 }
1638 ?>