Revert revert of setSingleton(), unrelated to broken, accidentally committed code...
[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 $mWatchLinkNum = 0; // Appended to end of watch link id's
20 /**#@-*/
21 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
22 protected $skinname = 'standard' ;
23
24 /** Constructor, call parent constructor */
25 function Skin() { parent::__construct(); }
26
27 /**
28 * Fetch the set of available skins.
29 * @return array of strings
30 * @static
31 */
32 static function getSkinNames() {
33 global $wgValidSkinNames;
34 static $skinsInitialised = false;
35 if ( !$skinsInitialised ) {
36 # Get a list of available skins
37 # Build using the regular expression '^(.*).php$'
38 # Array keys are all lower case, array value keep the case used by filename
39 #
40 wfProfileIn( __METHOD__ . '-init' );
41 global $wgStyleDirectory;
42 $skinDir = dir( $wgStyleDirectory );
43
44 # while code from www.php.net
45 while (false !== ($file = $skinDir->read())) {
46 // Skip non-PHP files, hidden files, and '.dep' includes
47 $matches = array();
48 if(preg_match('/^([^.]*)\.php$/',$file, $matches)) {
49 $aSkin = $matches[1];
50 $wgValidSkinNames[strtolower($aSkin)] = $aSkin;
51 }
52 }
53 $skinDir->close();
54 $skinsInitialised = true;
55 wfProfileOut( __METHOD__ . '-init' );
56 }
57 return $wgValidSkinNames;
58 }
59
60 /**
61 * Normalize a skin preference value to a form that can be loaded.
62 * If a skin can't be found, it will fall back to the configured
63 * default (or the old 'Classic' skin if that's broken).
64 * @param string $key
65 * @return string
66 * @static
67 */
68 static function normalizeKey( $key ) {
69 global $wgDefaultSkin;
70 $skinNames = Skin::getSkinNames();
71
72 if( $key == '' ) {
73 // Don't return the default immediately;
74 // in a misconfiguration we need to fall back.
75 $key = $wgDefaultSkin;
76 }
77
78 if( isset( $skinNames[$key] ) ) {
79 return $key;
80 }
81
82 // Older versions of the software used a numeric setting
83 // in the user preferences.
84 $fallback = array(
85 0 => $wgDefaultSkin,
86 1 => 'nostalgia',
87 2 => 'cologneblue' );
88
89 if( isset( $fallback[$key] ) ){
90 $key = $fallback[$key];
91 }
92
93 if( isset( $skinNames[$key] ) ) {
94 return $key;
95 } else {
96 return 'monobook';
97 }
98 }
99
100 /**
101 * Factory method for loading a skin of a given type
102 * @param string $key 'monobook', 'standard', etc
103 * @return Skin
104 * @static
105 */
106 static function &newFromKey( $key ) {
107 global $wgStyleDirectory;
108
109 $key = Skin::normalizeKey( $key );
110
111 $skinNames = Skin::getSkinNames();
112 $skinName = $skinNames[$key];
113 $className = 'Skin'.ucfirst($key);
114
115 # Grab the skin class and initialise it.
116 if ( !class_exists( $className ) ) {
117 // Preload base classes to work around APC/PHP5 bug
118 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
119 if( file_exists( $deps ) ) include_once( $deps );
120 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
121
122 # Check if we got if not failback to default skin
123 if( !class_exists( $className ) ) {
124 # DO NOT die if the class isn't found. This breaks maintenance
125 # scripts and can cause a user account to be unrecoverable
126 # except by SQL manipulation if a previously valid skin name
127 # is no longer valid.
128 wfDebug( "Skin class does not exist: $className\n" );
129 $className = 'SkinMonobook';
130 require_once( "{$wgStyleDirectory}/MonoBook.php" );
131 }
132 }
133 $skin = new $className;
134 return $skin;
135 }
136
137 /** @return string path to the skin stylesheet */
138 function getStylesheet() {
139 return 'common/wikistandard.css';
140 }
141
142 /** @return string skin name */
143 public function getSkinName() {
144 return $this->skinname;
145 }
146
147 function qbSetting() {
148 global $wgOut, $wgUser;
149
150 if ( $wgOut->isQuickbarSuppressed() ) { return 0; }
151 $q = $wgUser->getOption( 'quickbar', 0 );
152 return $q;
153 }
154
155 function initPage( &$out ) {
156 global $wgFavicon, $wgScriptPath, $wgSitename, $wgContLang;
157
158 wfProfileIn( __METHOD__ );
159
160 if( false !== $wgFavicon ) {
161 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
162 }
163
164 $code = $wgContLang->getCode();
165 $name = $wgContLang->getLanguageName( $code );
166 $langName = $name ? $name : $code;
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 ($langName)",
174 ));
175
176 $this->addMetadataLinks($out);
177
178 $this->mRevisionId = $out->mRevisionId;
179
180 $this->preloadExistence();
181
182 wfProfileOut( __METHOD__ );
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 $wgScript, $wgStylePath, $wgUser;
297 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
298 global $wgTitle, $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
299 global $wgBreakFrames, $wgRequest;
300 global $wgUseAjax, $wgAjaxWatch;
301
302 $ns = $wgTitle->getNamespace();
303 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
304
305 $vars = array(
306 'skin' => $data['skinname'],
307 'stylepath' => $wgStylePath,
308 'wgArticlePath' => $wgArticlePath,
309 'wgScriptPath' => $wgScriptPath,
310 'wgScript' => $wgScript,
311 'wgServer' => $wgServer,
312 'wgCanonicalNamespace' => $nsname,
313 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBKey() ),
314 'wgNamespaceNumber' => $wgTitle->getNamespace(),
315 'wgPageName' => $wgTitle->getPrefixedDBKey(),
316 'wgTitle' => $wgTitle->getText(),
317 'wgAction' => $wgRequest->getText( 'action', 'view' ),
318 'wgRestrictionEdit' => $wgTitle->getRestrictions( 'edit' ),
319 'wgRestrictionMove' => $wgTitle->getRestrictions( 'move' ),
320 'wgArticleId' => $wgTitle->getArticleId(),
321 'wgIsArticle' => $wgOut->isArticle(),
322 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
323 'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
324 'wgUserLanguage' => $wgLang->getCode(),
325 'wgContentLanguage' => $wgContLang->getCode(),
326 'wgBreakFrames' => $wgBreakFrames,
327 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
328 );
329
330 global $wgLivePreview;
331 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
332 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
333 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
334 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
335 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
336 }
337
338 if($wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
339 $msgs = (object)array();
340 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
341 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
342 }
343 $vars['wgAjaxWatch'] = $msgs;
344 }
345
346 return self::makeVariablesScript( $vars );
347 }
348
349 function getHeadScripts( $allowUserJs ) {
350 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion;
351
352 $r = self::makeGlobalVariablesScript( array( 'skinname' => $this->getSkinName() ) );
353
354 $r .= "<script type=\"{$wgJsMimeType}\" src=\"{$wgStylePath}/common/wikibits.js?$wgStyleVersion\"></script>\n";
355 global $wgUseSiteJs;
356 if ($wgUseSiteJs) {
357 $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
358 $r .= "<script type=\"$wgJsMimeType\" src=\"".
359 htmlspecialchars(self::makeUrl('-',
360 "action=raw$jsCache&gen=js&useskin=" .
361 urlencode( $this->getSkinName() ) ) ) .
362 "\"><!-- site js --></script>\n";
363 }
364 if( $allowUserJs && $wgUser->isLoggedIn() ) {
365 $userpage = $wgUser->getUserPage();
366 $userjs = htmlspecialchars( self::makeUrl(
367 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
368 'action=raw&ctype='.$wgJsMimeType));
369 $r .= '<script type="'.$wgJsMimeType.'" src="'.$userjs."\"></script>\n";
370 }
371 return $r;
372 }
373
374 /**
375 * To make it harder for someone to slip a user a fake
376 * user-JavaScript or user-CSS preview, a random token
377 * is associated with the login session. If it's not
378 * passed back with the preview request, we won't render
379 * the code.
380 *
381 * @param string $action
382 * @return bool
383 * @private
384 */
385 function userCanPreview( $action ) {
386 global $wgTitle, $wgRequest, $wgUser;
387
388 if( $action != 'submit' )
389 return false;
390 if( !$wgRequest->wasPosted() )
391 return false;
392 if( !$wgTitle->userCanEditCssJsSubpage() )
393 return false;
394 return $wgUser->matchEditToken(
395 $wgRequest->getVal( 'wpEditToken' ) );
396 }
397
398 # get the user/site-specific stylesheet, SkinTemplate loads via RawPage.php (settings are cached that way)
399 function getUserStylesheet() {
400 global $wgStylePath, $wgRequest, $wgContLang, $wgSquidMaxage, $wgStyleVersion;
401 $sheet = $this->getStylesheet();
402 $s = "@import \"$wgStylePath/common/shared.css?$wgStyleVersion\";\n";
403 $s .= "@import \"$wgStylePath/common/oldshared.css?$wgStyleVersion\";\n";
404 $s .= "@import \"$wgStylePath/$sheet?$wgStyleVersion\";\n";
405 if($wgContLang->isRTL()) $s .= "@import \"$wgStylePath/common/common_rtl.css?$wgStyleVersion\";\n";
406
407 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
408 $s .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) . "\";\n" .
409 '@import "' . self::makeNSUrl( ucfirst( $this->getSkinName() . '.css' ), $query, NS_MEDIAWIKI ) . "\";\n";
410
411 $s .= $this->doGetUserStyles();
412 return $s."\n";
413 }
414
415 /**
416 * This returns MediaWiki:Common.js, and derived classes may add other JS.
417 * Despite its name, it does *not* return any custom user JS from user
418 * subpages. The returned script is sitewide and publicly cacheable and
419 * therefore must not include anything that varies according to user,
420 * interface language, etc. (although it may vary by skin). See
421 * makeGlobalVariablesScript for things that can vary per page view and are
422 * not cacheable.
423 *
424 * @return string Raw JavaScript to be returned
425 */
426 public function getUserJs() {
427 wfProfileIn( __METHOD__ );
428
429 global $wgStylePath;
430 $s = "/* generated javascript */\n";
431 $s .= "var skin = '" . Xml::escapeJsString( $this->getSkinName() ) . "';\n";
432 $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
433 $s .= "\n\n/* MediaWiki:Common.js */\n";
434 $commonJs = wfMsgForContent('common.js');
435 if ( !wfEmptyMsg ( 'common.js', $commonJs ) ) {
436 $s .= $commonJs;
437 }
438 wfProfileOut( __METHOD__ );
439 return $s;
440 }
441
442 /**
443 * Return html code that include User stylesheets
444 */
445 function getUserStyles() {
446 $s = "<style type='text/css'>\n";
447 $s .= "/*/*/ /*<![CDATA[*/\n"; # <-- Hide the styles from Netscape 4 without hiding them from IE/Mac
448 $s .= $this->getUserStylesheet();
449 $s .= "/*]]>*/ /* */\n";
450 $s .= "</style>\n";
451 return $s;
452 }
453
454 /**
455 * Some styles that are set by user through the user settings interface.
456 */
457 function doGetUserStyles() {
458 global $wgUser, $wgUser, $wgRequest, $wgTitle, $wgAllowUserCss;
459
460 $s = '';
461
462 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) { # logged in
463 if($wgTitle->isCssSubpage() && $this->userCanPreview( $wgRequest->getText( 'action' ) ) ) {
464 $s .= $wgRequest->getText('wpTextbox1');
465 } else {
466 $userpage = $wgUser->getUserPage();
467 $s.= '@import "'.self::makeUrl(
468 $userpage->getPrefixedText().'/'.$this->getSkinName().'.css',
469 'action=raw&ctype=text/css').'";'."\n";
470 }
471 }
472
473 return $s . $this->reallyDoGetUserStyles();
474 }
475
476 function reallyDoGetUserStyles() {
477 global $wgUser;
478 $s = '';
479 if (($undopt = $wgUser->getOption("underline")) < 2) {
480 $underline = $undopt ? 'underline' : 'none';
481 $s .= "a { text-decoration: $underline; }\n";
482 }
483 if( $wgUser->getOption( 'highlightbroken' ) ) {
484 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
485 } else {
486 $s .= <<<END
487 a.new, #quickbar a.new,
488 a.stub, #quickbar a.stub {
489 color: inherit;
490 }
491 a.new:after, #quickbar a.new:after {
492 content: "?";
493 color: #CC2200;
494 }
495 a.stub:after, #quickbar a.stub:after {
496 content: "!";
497 color: #772233;
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 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
709 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
710 return $bottomScriptText;
711 }
712
713 /** @return string Retrievied from HTML text */
714 function printSource() {
715 global $wgTitle;
716 $url = htmlspecialchars( $wgTitle->getFullURL() );
717 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
718 }
719
720 function printFooter() {
721 return "<p>" . $this->printSource() .
722 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
723 }
724
725 /** overloaded by derived classes */
726 function doAfterContent() { }
727
728 function pageTitleLinks() {
729 global $wgOut, $wgTitle, $wgUser, $wgRequest;
730
731 $oldid = $wgRequest->getVal( 'oldid' );
732 $diff = $wgRequest->getVal( 'diff' );
733 $action = $wgRequest->getText( 'action' );
734
735 $s = $this->printableLink();
736 $disclaimer = $this->disclaimerLink(); # may be empty
737 if( $disclaimer ) {
738 $s .= ' | ' . $disclaimer;
739 }
740 $privacy = $this->privacyLink(); # may be empty too
741 if( $privacy ) {
742 $s .= ' | ' . $privacy;
743 }
744
745 if ( $wgOut->isArticleRelated() ) {
746 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
747 $name = $wgTitle->getDBkey();
748 $image = wfFindFile( $wgTitle );
749 if( $image ) {
750 $link = htmlspecialchars( $image->getURL() );
751 $style = $this->getInternalLinkAttributes( $link, $name );
752 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
753 }
754 }
755 }
756 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
757 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
758 wfMsg( 'currentrev' ) );
759 }
760
761 if ( $wgUser->getNewtalk() ) {
762 # do not show "You have new messages" text when we are viewing our
763 # own talk page
764 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
765 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
766 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
767 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
768 # disable caching
769 $wgOut->setSquidMaxage(0);
770 $wgOut->enableClientCache(false);
771 }
772 }
773
774 $undelete = $this->getUndeleteLink();
775 if( !empty( $undelete ) ) {
776 $s .= ' | '.$undelete;
777 }
778 return $s;
779 }
780
781 function getUndeleteLink() {
782 global $wgUser, $wgTitle, $wgContLang, $wgLang, $action;
783 if( $wgUser->isAllowed( 'deletedhistory' ) &&
784 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
785 ($n = $wgTitle->isDeleted() ) )
786 {
787 if ( $wgUser->isAllowed( 'undelete' ) ) {
788 $msg = 'thisisdeleted';
789 } else {
790 $msg = 'viewdeleted';
791 }
792 return wfMsg( $msg,
793 $this->makeKnownLinkObj(
794 SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
795 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
796 }
797 return '';
798 }
799
800 function printableLink() {
801 global $wgOut, $wgFeedClasses, $wgRequest;
802
803 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
804
805 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
806 if( $wgOut->isSyndicated() ) {
807 foreach( $wgFeedClasses as $format => $class ) {
808 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
809 $s .= " | <a href=\"$feedurl\">{$format}</a>";
810 }
811 }
812 return $s;
813 }
814
815 function pageTitle() {
816 global $wgOut;
817 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
818 return $s;
819 }
820
821 function pageSubtitle() {
822 global $wgOut;
823
824 $sub = $wgOut->getSubtitle();
825 if ( '' == $sub ) {
826 global $wgExtraSubtitle;
827 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
828 }
829 $subpages = $this->subPageSubtitle();
830 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
831 $s = "<p class='subtitle'>{$sub}</p>\n";
832 return $s;
833 }
834
835 function subPageSubtitle() {
836 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
837 $subpages = '';
838 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
839 $ptext=$wgTitle->getPrefixedText();
840 if(preg_match('/\//',$ptext)) {
841 $links = explode('/',$ptext);
842 $c = 0;
843 $growinglink = '';
844 foreach($links as $link) {
845 $c++;
846 if ($c<count($links)) {
847 $growinglink .= $link;
848 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
849 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
850 if ($c>1) {
851 $subpages .= ' | ';
852 } else {
853 $subpages .= '&lt; ';
854 }
855 $subpages .= $getlink;
856 $growinglink .= '/';
857 }
858 }
859 }
860 }
861 return $subpages;
862 }
863
864 /**
865 * Returns true if the IP should be shown in the header
866 */
867 function showIPinHeader() {
868 global $wgShowIPinHeader;
869 return $wgShowIPinHeader && session_id() != '';
870 }
871
872 function nameAndLogin() {
873 global $wgUser, $wgTitle, $wgLang, $wgContLang;
874
875 $lo = $wgContLang->specialPage( 'Userlogout' );
876
877 $s = '';
878 if ( $wgUser->isAnon() ) {
879 if( $this->showIPinHeader() ) {
880 $n = wfGetIP();
881
882 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
883 $wgLang->getNsText( NS_TALK ) );
884
885 $s .= $n . ' ('.$tl.')';
886 } else {
887 $s .= wfMsg('notloggedin');
888 }
889
890 $rt = $wgTitle->getPrefixedURL();
891 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
892 $q = '';
893 } else { $q = "returnto={$rt}"; }
894
895 $s .= "\n<br />" . $this->makeKnownLinkObj(
896 SpecialPage::getTitleFor( 'Userlogin' ),
897 wfMsg( 'login' ), $q );
898 } else {
899 $n = $wgUser->getName();
900 $rt = $wgTitle->getPrefixedURL();
901 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
902 $wgLang->getNsText( NS_TALK ) );
903
904 $tl = " ({$tl})";
905
906 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
907 $n ) . "{$tl}<br />" .
908 $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
909 "returnto={$rt}" ) . ' | ' .
910 $this->specialLink( 'preferences' );
911 }
912 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
913 wfMsg( 'help' ) );
914
915 return $s;
916 }
917
918 function getSearchLink() {
919 $searchPage = SpecialPage::getTitleFor( 'Search' );
920 return $searchPage->getLocalURL();
921 }
922
923 function escapeSearchLink() {
924 return htmlspecialchars( $this->getSearchLink() );
925 }
926
927 function searchForm() {
928 global $wgRequest;
929 $search = $wgRequest->getText( 'search' );
930
931 $s = '<form name="search" class="inline" method="post" action="'
932 . $this->escapeSearchLink() . "\">\n"
933 . '<input type="text" name="search" size="19" value="'
934 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
935 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
936 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
937
938 return $s;
939 }
940
941 function topLinks() {
942 global $wgOut;
943 $sep = " |\n";
944
945 $s = $this->mainPageLink() . $sep
946 . $this->specialLink( 'recentchanges' );
947
948 if ( $wgOut->isArticleRelated() ) {
949 $s .= $sep . $this->editThisPage()
950 . $sep . $this->historyLink();
951 }
952 # Many people don't like this dropdown box
953 #$s .= $sep . $this->specialPagesList();
954
955 $s .= $this->variantLinks();
956
957 $s .= $this->extensionTabLinks();
958
959 return $s;
960 }
961
962 /**
963 * Compatibility for extensions adding functionality through tabs.
964 * Eventually these old skins should be replaced with SkinTemplate-based
965 * versions, sigh...
966 * @return string
967 */
968 function extensionTabLinks() {
969 $tabs = array();
970 $s = '';
971 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
972 foreach( $tabs as $tab ) {
973 $s .= ' | ' . Xml::element( 'a',
974 array( 'href' => $tab['href'] ),
975 $tab['text'] );
976 }
977 return $s;
978 }
979
980 /**
981 * Language/charset variant links for classic-style skins
982 * @return string
983 */
984 function variantLinks() {
985 $s = '';
986 /* show links to different language variants */
987 global $wgDisableLangConversion, $wgContLang, $wgTitle;
988 $variants = $wgContLang->getVariants();
989 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
990 foreach( $variants as $code ) {
991 $varname = $wgContLang->getVariantname( $code );
992 if( $varname == 'disable' )
993 continue;
994 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
995 }
996 }
997 return $s;
998 }
999
1000 function bottomLinks() {
1001 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1002 $sep = " |\n";
1003
1004 $s = '';
1005 if ( $wgOut->isArticleRelated() ) {
1006 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1007 if ( $wgUser->isLoggedIn() ) {
1008 $s .= $sep . $this->watchThisPage();
1009 }
1010 $s .= $sep . $this->talkLink()
1011 . $sep . $this->historyLink()
1012 . $sep . $this->whatLinksHere()
1013 . $sep . $this->watchPageLinksLink();
1014
1015 if ($wgUseTrackbacks)
1016 $s .= $sep . $this->trackbackLink();
1017
1018 if ( $wgTitle->getNamespace() == NS_USER
1019 || $wgTitle->getNamespace() == NS_USER_TALK )
1020
1021 {
1022 $id=User::idFromName($wgTitle->getText());
1023 $ip=User::isIP($wgTitle->getText());
1024
1025 if($id || $ip) { # both anons and non-anons have contri list
1026 $s .= $sep . $this->userContribsLink();
1027 }
1028 if( $this->showEmailUser( $id ) ) {
1029 $s .= $sep . $this->emailUserLink();
1030 }
1031 }
1032 if ( $wgTitle->getArticleId() ) {
1033 $s .= "\n<br />";
1034 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1035 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1036 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1037 }
1038 $s .= "<br />\n" . $this->otherLanguages();
1039 }
1040 return $s;
1041 }
1042
1043 function pageStats() {
1044 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1045 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1046
1047 $oldid = $wgRequest->getVal( 'oldid' );
1048 $diff = $wgRequest->getVal( 'diff' );
1049 if ( ! $wgOut->isArticle() ) { return ''; }
1050 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1051 if ( 0 == $wgArticle->getID() ) { return ''; }
1052
1053 $s = '';
1054 if ( !$wgDisableCounters ) {
1055 $count = $wgLang->formatNum( $wgArticle->getCount() );
1056 if ( $count ) {
1057 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1058 }
1059 }
1060
1061 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
1062 require_once('Credits.php');
1063 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1064 } else {
1065 $s .= $this->lastModified();
1066 }
1067
1068 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
1069 $dbr = wfGetDB( DB_SLAVE );
1070 $watchlist = $dbr->tableName( 'watchlist' );
1071 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1072 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
1073 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1074 $res = $dbr->query( $sql, 'Skin::pageStats');
1075 $x = $dbr->fetchObject( $res );
1076
1077 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1078 array( 'parseinline' ), $wgLang->formatNum($x->n)
1079 );
1080 }
1081
1082 return $s . ' ' . $this->getCopyright();
1083 }
1084
1085 function getCopyright( $type = 'detect' ) {
1086 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1087
1088 if ( $type == 'detect' ) {
1089 $oldid = $wgRequest->getVal( 'oldid' );
1090 $diff = $wgRequest->getVal( 'diff' );
1091
1092 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1093 $type = 'history';
1094 } else {
1095 $type = 'normal';
1096 }
1097 }
1098
1099 if ( $type == 'history' ) {
1100 $msg = 'history_copyright';
1101 } else {
1102 $msg = 'copyright';
1103 }
1104
1105 $out = '';
1106 if( $wgRightsPage ) {
1107 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1108 } elseif( $wgRightsUrl ) {
1109 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1110 } else {
1111 # Give up now
1112 return $out;
1113 }
1114 $out .= wfMsgForContent( $msg, $link );
1115 return $out;
1116 }
1117
1118 function getCopyrightIcon() {
1119 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1120 $out = '';
1121 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1122 $out = $wgCopyrightIcon;
1123 } else if ( $wgRightsIcon ) {
1124 $icon = htmlspecialchars( $wgRightsIcon );
1125 if ( $wgRightsUrl ) {
1126 $url = htmlspecialchars( $wgRightsUrl );
1127 $out .= '<a href="'.$url.'">';
1128 }
1129 $text = htmlspecialchars( $wgRightsText );
1130 $out .= "<img src=\"$icon\" alt='$text' />";
1131 if ( $wgRightsUrl ) {
1132 $out .= '</a>';
1133 }
1134 }
1135 return $out;
1136 }
1137
1138 function getPoweredBy() {
1139 global $wgStylePath;
1140 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1141 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1142 return $img;
1143 }
1144
1145 function lastModified() {
1146 global $wgLang, $wgArticle, $wgLoadBalancer;
1147
1148 $timestamp = $wgArticle->getTimestamp();
1149 if ( $timestamp ) {
1150 $d = $wgLang->date( $timestamp, true );
1151 $t = $wgLang->time( $timestamp, true );
1152 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1153 } else {
1154 $s = '';
1155 }
1156 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1157 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1158 }
1159 return $s;
1160 }
1161
1162 function logoText( $align = '' ) {
1163 if ( '' != $align ) { $a = " align='{$align}'"; }
1164 else { $a = ''; }
1165
1166 $mp = wfMsg( 'mainpage' );
1167 $mptitle = Title::newMainPage();
1168 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1169
1170 $logourl = $this->getLogo();
1171 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1172 return $s;
1173 }
1174
1175 /**
1176 * show a drop-down box of special pages
1177 */
1178 function specialPagesList() {
1179 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1180 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1181 foreach ( $pages as $name => $page ) {
1182 $pages[$name] = $page->getDescription();
1183 }
1184
1185 $go = wfMsg( 'go' );
1186 $sp = wfMsg( 'specialpages' );
1187 $spp = $wgContLang->specialPage( 'Specialpages' );
1188
1189 $s = '<form id="specialpages" method="get" class="inline" ' .
1190 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1191 $s .= "<select name=\"wpDropdown\">\n";
1192 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1193
1194
1195 foreach ( $pages as $name => $desc ) {
1196 $p = $wgContLang->specialPage( $name );
1197 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1198 }
1199 $s .= "</select>\n";
1200 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1201 $s .= "</form>\n";
1202 return $s;
1203 }
1204
1205 function mainPageLink() {
1206 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1207 return $s;
1208 }
1209
1210 function copyrightLink() {
1211 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1212 wfMsg( 'copyrightpagename' ) );
1213 return $s;
1214 }
1215
1216 private function footerLink ( $desc, $page ) {
1217 // if the link description has been set to "-" in the default language,
1218 if ( wfMsgForContent( $desc ) == '-') {
1219 // then it is disabled, for all languages.
1220 return '';
1221 } else {
1222 // Otherwise, we display the link for the user, described in their
1223 // language (which may or may not be the same as the default language),
1224 // but we make the link target be the one site-wide page.
1225 return $this->makeKnownLink( wfMsgForContent( $page ),
1226 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1227 }
1228 }
1229
1230 function privacyLink() {
1231 return $this->footerLink( 'privacy', 'privacypage' );
1232 }
1233
1234 function aboutLink() {
1235 return $this->footerLink( 'aboutsite', 'aboutpage' );
1236 }
1237
1238 function disclaimerLink() {
1239 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1240 }
1241
1242 function editThisPage() {
1243 global $wgOut, $wgTitle;
1244
1245 if ( ! $wgOut->isArticleRelated() ) {
1246 $s = wfMsg( 'protectedpage' );
1247 } else {
1248 if ( $wgTitle->userCan( 'edit' ) ) {
1249 $t = wfMsg( 'editthispage' );
1250 } else {
1251 $t = wfMsg( 'viewsource' );
1252 }
1253
1254 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1255 }
1256 return $s;
1257 }
1258
1259 /**
1260 * Return URL options for the 'edit page' link.
1261 * This may include an 'oldid' specifier, if the current page view is such.
1262 *
1263 * @return string
1264 * @private
1265 */
1266 function editUrlOptions() {
1267 global $wgArticle;
1268
1269 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1270 return "action=edit&oldid=" . intval( $this->mRevisionId );
1271 } else {
1272 return "action=edit";
1273 }
1274 }
1275
1276 function deleteThisPage() {
1277 global $wgUser, $wgTitle, $wgRequest;
1278
1279 $diff = $wgRequest->getVal( 'diff' );
1280 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1281 $t = wfMsg( 'deletethispage' );
1282
1283 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1284 } else {
1285 $s = '';
1286 }
1287 return $s;
1288 }
1289
1290 function protectThisPage() {
1291 global $wgUser, $wgTitle, $wgRequest;
1292
1293 $diff = $wgRequest->getVal( 'diff' );
1294 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1295 if ( $wgTitle->isProtected() ) {
1296 $t = wfMsg( 'unprotectthispage' );
1297 $q = 'action=unprotect';
1298 } else {
1299 $t = wfMsg( 'protectthispage' );
1300 $q = 'action=protect';
1301 }
1302 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1303 } else {
1304 $s = '';
1305 }
1306 return $s;
1307 }
1308
1309 function watchThisPage() {
1310 global $wgOut, $wgTitle;
1311 ++$this->mWatchLinkNum;
1312
1313 if ( $wgOut->isArticleRelated() ) {
1314 if ( $wgTitle->userIsWatching() ) {
1315 $t = wfMsg( 'unwatchthispage' );
1316 $q = 'action=unwatch';
1317 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1318 } else {
1319 $t = wfMsg( 'watchthispage' );
1320 $q = 'action=watch';
1321 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1322 }
1323 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1324 } else {
1325 $s = wfMsg( 'notanarticle' );
1326 }
1327 return $s;
1328 }
1329
1330 function moveThisPage() {
1331 global $wgTitle;
1332
1333 if ( $wgTitle->userCan( 'move' ) ) {
1334 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1335 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1336 } else {
1337 // no message if page is protected - would be redundant
1338 return '';
1339 }
1340 }
1341
1342 function historyLink() {
1343 global $wgTitle;
1344
1345 return $this->makeKnownLinkObj( $wgTitle,
1346 wfMsg( 'history' ), 'action=history' );
1347 }
1348
1349 function whatLinksHere() {
1350 global $wgTitle;
1351
1352 return $this->makeKnownLinkObj(
1353 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1354 wfMsg( 'whatlinkshere' ) );
1355 }
1356
1357 function userContribsLink() {
1358 global $wgTitle;
1359
1360 return $this->makeKnownLinkObj(
1361 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1362 wfMsg( 'contributions' ) );
1363 }
1364
1365 function showEmailUser( $id ) {
1366 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1367 return $wgEnableEmail &&
1368 $wgEnableUserEmail &&
1369 $wgUser->isLoggedIn() && # show only to signed in users
1370 0 != $id; # we can only email to non-anons ..
1371 # '' != $id->getEmail() && # who must have an email address stored ..
1372 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1373 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1374 }
1375
1376 function emailUserLink() {
1377 global $wgTitle;
1378
1379 return $this->makeKnownLinkObj(
1380 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1381 wfMsg( 'emailuser' ) );
1382 }
1383
1384 function watchPageLinksLink() {
1385 global $wgOut, $wgTitle;
1386
1387 if ( ! $wgOut->isArticleRelated() ) {
1388 return '(' . wfMsg( 'notanarticle' ) . ')';
1389 } else {
1390 return $this->makeKnownLinkObj(
1391 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1392 wfMsg( 'recentchangeslinked' ) );
1393 }
1394 }
1395
1396 function trackbackLink() {
1397 global $wgTitle;
1398
1399 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1400 . wfMsg('trackbacklink') . "</a>";
1401 }
1402
1403 function otherLanguages() {
1404 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1405
1406 if ( $wgHideInterlanguageLinks ) {
1407 return '';
1408 }
1409
1410 $a = $wgOut->getLanguageLinks();
1411 if ( 0 == count( $a ) ) {
1412 return '';
1413 }
1414
1415 $s = wfMsg( 'otherlanguages' ) . ': ';
1416 $first = true;
1417 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1418 foreach( $a as $l ) {
1419 if ( ! $first ) { $s .= ' | '; }
1420 $first = false;
1421
1422 $nt = Title::newFromText( $l );
1423 $url = $nt->escapeFullURL();
1424 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1425
1426 if ( '' == $text ) { $text = $l; }
1427 $style = $this->getExternalLinkAttributes( $l, $text );
1428 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1429 }
1430 if($wgContLang->isRTL()) $s .= '</span>';
1431 return $s;
1432 }
1433
1434 function bugReportsLink() {
1435 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1436 wfMsg( 'bugreports' ) );
1437 return $s;
1438 }
1439
1440 function talkLink() {
1441 global $wgTitle;
1442
1443 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1444 # No discussion links for special pages
1445 return '';
1446 }
1447
1448 if( $wgTitle->isTalkPage() ) {
1449 $link = $wgTitle->getSubjectPage();
1450 switch( $link->getNamespace() ) {
1451 case NS_MAIN:
1452 $text = wfMsg( 'articlepage' );
1453 break;
1454 case NS_USER:
1455 $text = wfMsg( 'userpage' );
1456 break;
1457 case NS_PROJECT:
1458 $text = wfMsg( 'projectpage' );
1459 break;
1460 case NS_IMAGE:
1461 $text = wfMsg( 'imagepage' );
1462 break;
1463 case NS_MEDIAWIKI:
1464 $text = wfMsg( 'mediawikipage' );
1465 break;
1466 case NS_TEMPLATE:
1467 $text = wfMsg( 'templatepage' );
1468 break;
1469 case NS_HELP:
1470 $text = wfMsg( 'viewhelppage' );
1471 break;
1472 case NS_CATEGORY:
1473 $text = wfMsg( 'categorypage' );
1474 break;
1475 default:
1476 $text = wfMsg( 'articlepage' );
1477 }
1478 } else {
1479 $link = $wgTitle->getTalkPage();
1480 $text = wfMsg( 'talkpage' );
1481 }
1482
1483 $s = $this->makeLinkObj( $link, $text );
1484
1485 return $s;
1486 }
1487
1488 function commentLink() {
1489 global $wgTitle, $wgOut;
1490
1491 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1492 return '';
1493 }
1494
1495 # __NEWSECTIONLINK___ changes behaviour here
1496 # If it's present, the link points to this page, otherwise
1497 # it points to the talk page
1498 if( $wgTitle->isTalkPage() ) {
1499 $title = $wgTitle;
1500 } elseif( $wgOut->showNewSectionLink() ) {
1501 $title = $wgTitle;
1502 } else {
1503 $title = $wgTitle->getTalkPage();
1504 }
1505
1506 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1507 }
1508
1509 /* these are used extensively in SkinTemplate, but also some other places */
1510 static function makeMainPageUrl( $urlaction = '' ) {
1511 $title = Title::newMainPage();
1512 self::checkTitle( $title, '' );
1513 return $title->getLocalURL( $urlaction );
1514 }
1515
1516 static function makeSpecialUrl( $name, $urlaction = '' ) {
1517 $title = SpecialPage::getTitleFor( $name );
1518 return $title->getLocalURL( $urlaction );
1519 }
1520
1521 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1522 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1523 return $title->getLocalURL( $urlaction );
1524 }
1525
1526 static function makeI18nUrl( $name, $urlaction = '' ) {
1527 $title = Title::newFromText( wfMsgForContent( $name ) );
1528 self::checkTitle( $title, $name );
1529 return $title->getLocalURL( $urlaction );
1530 }
1531
1532 static function makeUrl( $name, $urlaction = '' ) {
1533 $title = Title::newFromText( $name );
1534 self::checkTitle( $title, $name );
1535 return $title->getLocalURL( $urlaction );
1536 }
1537
1538 # If url string starts with http, consider as external URL, else
1539 # internal
1540 static function makeInternalOrExternalUrl( $name ) {
1541 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1542 return $name;
1543 } else {
1544 return self::makeUrl( $name );
1545 }
1546 }
1547
1548 # this can be passed the NS number as defined in Language.php
1549 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1550 $title = Title::makeTitleSafe( $namespace, $name );
1551 self::checkTitle( $title, $name );
1552 return $title->getLocalURL( $urlaction );
1553 }
1554
1555 /* these return an array with the 'href' and boolean 'exists' */
1556 static function makeUrlDetails( $name, $urlaction = '' ) {
1557 $title = Title::newFromText( $name );
1558 self::checkTitle( $title, $name );
1559 return array(
1560 'href' => $title->getLocalURL( $urlaction ),
1561 'exists' => $title->getArticleID() != 0 ? true : false
1562 );
1563 }
1564
1565 /**
1566 * Make URL details where the article exists (or at least it's convenient to think so)
1567 */
1568 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1569 $title = Title::newFromText( $name );
1570 self::checkTitle( $title, $name );
1571 return array(
1572 'href' => $title->getLocalURL( $urlaction ),
1573 'exists' => true
1574 );
1575 }
1576
1577 # make sure we have some title to operate on
1578 static function checkTitle( &$title, $name ) {
1579 if( !is_object( $title ) ) {
1580 $title = Title::newFromText( $name );
1581 if( !is_object( $title ) ) {
1582 $title = Title::newFromText( '--error: link target missing--' );
1583 }
1584 }
1585 }
1586
1587 /**
1588 * Build an array that represents the sidebar(s), the navigation bar among them
1589 *
1590 * @return array
1591 * @private
1592 */
1593 function buildSidebar() {
1594 global $parserMemc, $wgEnableSidebarCache;
1595 global $wgLang, $wgContLang;
1596
1597 $fname = 'SkinTemplate::buildSidebar';
1598
1599 wfProfileIn( $fname );
1600
1601 $key = wfMemcKey( 'sidebar' );
1602 $cacheSidebar = $wgEnableSidebarCache &&
1603 ($wgLang->getCode() == $wgContLang->getCode());
1604
1605 if ($cacheSidebar) {
1606 $cachedsidebar = $parserMemc->get( $key );
1607 if ($cachedsidebar!="") {
1608 wfProfileOut($fname);
1609 return $cachedsidebar;
1610 }
1611 }
1612
1613 $bar = array();
1614 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1615 foreach ($lines as $line) {
1616 if (strpos($line, '*') !== 0)
1617 continue;
1618 if (strpos($line, '**') !== 0) {
1619 $line = trim($line, '* ');
1620 $heading = $line;
1621 } else {
1622 if (strpos($line, '|') !== false) { // sanity check
1623 $line = explode( '|' , trim($line, '* '), 2 );
1624 $link = wfMsgForContent( $line[0] );
1625 if ($link == '-')
1626 continue;
1627 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1628 $text = $line[1];
1629 if (wfEmptyMsg($line[0], $link))
1630 $link = $line[0];
1631
1632 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1633 $href = $link;
1634 } else {
1635 $title = Title::newFromText( $link );
1636 if ( $title ) {
1637 $title = $title->fixSpecialName();
1638 $href = $title->getLocalURL();
1639 } else {
1640 $href = 'INVALID-TITLE';
1641 }
1642 }
1643
1644 $bar[$heading][] = array(
1645 'text' => $text,
1646 'href' => $href,
1647 'id' => 'n-' . strtr($line[1], ' ', '-'),
1648 'active' => false
1649 );
1650 } else { continue; }
1651 }
1652 }
1653 if ($cacheSidebar)
1654 $parserMemc->set( $key, $bar, 86400 );
1655 wfProfileOut( $fname );
1656 return $bar;
1657 }
1658
1659 }