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