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