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