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