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