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