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