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