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