92e593cf8a4e85f7aa82f557a251ca59b9c51c08
[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 ns-'.$wgTitle->getNamespace().
592 ' '.( $wgContLang->isRTL() ? "rtl" : "ltr" ).
593 ' '.Sanitizer::escapeClass( 'page-'.$wgTitle->getPrefixedText() ).
594 ' '.( $wgTitle->isTalkPage() ? "ns-talk" : ( $wgTitle->isTalkPage() ? "ns-talk" : ( $wgTitle->getNamespace() == NS_SPECIAL ? "ns-special" : "ns-subject" ) ) ).
595 ' skin-'. Sanitizer::escapeClass( $this->getSkinName( ) );
596 return $a;
597 }
598
599 /**
600 * URL to the logo
601 */
602 function getLogo() {
603 global $wgLogo;
604 return $wgLogo;
605 }
606
607 /**
608 * This will be called immediately after the <body> tag. Split into
609 * two functions to make it easier to subclass.
610 */
611 function beforeContent() {
612 return $this->doBeforeContent();
613 }
614
615 function doBeforeContent() {
616 global $wgContLang;
617 $fname = 'Skin::doBeforeContent';
618 wfProfileIn( $fname );
619
620 $s = '';
621 $qb = $this->qbSetting();
622
623 if( $langlinks = $this->otherLanguages() ) {
624 $rows = 2;
625 $borderhack = '';
626 } else {
627 $rows = 1;
628 $langlinks = false;
629 $borderhack = 'class="top"';
630 }
631
632 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
633 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
634
635 $shove = ($qb != 0);
636 $left = ($qb == 1 || $qb == 3);
637 if($wgContLang->isRTL()) $left = !$left;
638
639 if ( !$shove ) {
640 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
641 $this->logoText() . '</td>';
642 } elseif( $left ) {
643 $s .= $this->getQuickbarCompensator( $rows );
644 }
645 $l = $wgContLang->isRTL() ? 'right' : 'left';
646 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
647
648 $s .= $this->topLinks() ;
649 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
650
651 $r = $wgContLang->isRTL() ? "left" : "right";
652 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
653 $s .= $this->nameAndLogin();
654 $s .= "\n<br />" . $this->searchForm() . "</td>";
655
656 if ( $langlinks ) {
657 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
658 }
659
660 if ( $shove && !$left ) { # Right
661 $s .= $this->getQuickbarCompensator( $rows );
662 }
663 $s .= "</tr>\n</table>\n</div>\n";
664 $s .= "\n<div id='article'>\n";
665
666 $notice = wfGetSiteNotice();
667 if( $notice ) {
668 $s .= "\n<div id='siteNotice'>$notice</div>\n";
669 }
670 $s .= $this->pageTitle();
671 $s .= $this->pageSubtitle() ;
672 $s .= $this->getCategories();
673 wfProfileOut( $fname );
674 return $s;
675 }
676
677
678 function getCategoryLinks() {
679 global $wgOut, $wgTitle, $wgUseCategoryBrowser;
680 global $wgContLang, $wgUser;
681
682 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
683
684 # Separator
685 $sep = wfMsgHtml( 'catseparator' );
686
687 // Use Unicode bidi embedding override characters,
688 // to make sure links don't smash each other up in ugly ways.
689 $dir = $wgContLang->isRTL() ? 'rtl' : 'ltr';
690 $embed = "<span dir='$dir'>";
691 $pop = '</span>';
692
693 $allCats = $wgOut->getCategoryLinks();
694 $s = '';
695 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
696 if ( !empty( $allCats['normal'] ) ) {
697 $t = $embed . implode ( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
698
699 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
700 $s .= '<div id="mw-normal-catlinks">' .
701 $this->link( Title::newFromText( wfMsgForContent('pagecategorieslink') ), $msg )
702 . $colon . $t . '</div>';
703 }
704
705 # Hidden categories
706 if ( isset( $allCats['hidden'] ) ) {
707 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
708 $class ='mw-hidden-cats-user-shown';
709 } elseif ( $wgTitle->getNamespace() == NS_CATEGORY ) {
710 $class = 'mw-hidden-cats-ns-shown';
711 } else {
712 $class = 'mw-hidden-cats-hidden';
713 }
714 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
715 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
716 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
717 "</div>";
718 }
719
720 # optional 'dmoz-like' category browser. Will be shown under the list
721 # of categories an article belong to
722 if($wgUseCategoryBrowser) {
723 $s .= '<br /><hr />';
724
725 # get a big array of the parents tree
726 $parenttree = $wgTitle->getParentCategoryTree();
727 # Skin object passed by reference cause it can not be
728 # accessed under the method subfunction drawCategoryBrowser
729 $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
730 # Clean out bogus first entry and sort them
731 unset($tempout[0]);
732 asort($tempout);
733 # Output one per line
734 $s .= implode("<br />\n", $tempout);
735 }
736
737 return $s;
738 }
739
740 /** Render the array as a serie of links.
741 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
742 * @param &skin Object: skin passed by reference
743 * @return String separated by &gt;, terminate with "\n"
744 */
745 function drawCategoryBrowser($tree, &$skin) {
746 $return = '';
747 foreach ($tree as $element => $parent) {
748 if (empty($parent)) {
749 # element start a new list
750 $return .= "\n";
751 } else {
752 # grab the others elements
753 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
754 }
755 # add our current element to the list
756 $eltitle = Title::newFromText($element);
757 $return .= $skin->link( $eltitle, $eltitle->getText() ) ;
758 }
759 return $return;
760 }
761
762 function getCategories() {
763 $catlinks=$this->getCategoryLinks();
764
765 $classes = 'catlinks';
766
767 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false &&
768 strpos( $catlinks, '<div id="mw-hidden-catlinks" class="mw-hidden-cats-hidden">' ) !== false ) {
769 $classes .= ' catlinks-allhidden';
770 }
771
772 if( !empty( $catlinks ) ){
773 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
774 }
775 }
776
777 function getQuickbarCompensator( $rows = 1 ) {
778 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
779 }
780
781 /**
782 * This runs a hook to allow extensions placing their stuff after content
783 * and article metadata (e.g. categories).
784 * Note: This function has nothing to do with afterContent().
785 *
786 * This hook is placed here in order to allow using the same hook for all
787 * skins, both the SkinTemplate based ones and the older ones, which directly
788 * use this class to get their data.
789 *
790 * The output of this function gets processed in SkinTemplate::outputPage() for
791 * the SkinTemplate based skins, all other skins should directly echo it.
792 *
793 * Returns an empty string by default, if not changed by any hook function.
794 */
795 protected function afterContentHook () {
796 $data = "";
797
798 if (wfRunHooks ('SkinAfterContent', array (&$data))) {
799 // adding just some spaces shouldn't toggle the output
800 // of the whole <div/>, so we use trim() here
801 if (trim ($data) != "") {
802 // Doing this here instead of in the skins to
803 // ensure that the div has the same ID in all
804 // skins
805 $data = "<div id='mw-data-after-content'>\n" .
806 "\t$data\n" .
807 "</div>\n";
808 }
809 } else {
810 wfDebug ('Hook SkinAfterContent changed output processing.');
811 }
812
813 return $data;
814 }
815
816 /**
817 * This gets called shortly before the \</body\> tag.
818 * @return String HTML to be put before \</body\>
819 */
820 function afterContent() {
821 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
822 return $printfooter . $this->doAfterContent();
823 }
824
825 /**
826 * This gets called shortly before the \</body\> tag.
827 * @return String HTML-wrapped JS code to be put before \</body\>
828 */
829 function bottomScripts() {
830 global $wgJsMimeType;
831 $bottomScriptText = "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
832 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
833 return $bottomScriptText;
834 }
835
836 /** @return string Retrievied from HTML text */
837 function printSource() {
838 global $wgTitle;
839 $url = htmlspecialchars( $wgTitle->getFullURL() );
840 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
841 }
842
843 function printFooter() {
844 return "<p>" . $this->printSource() .
845 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
846 }
847
848 /** overloaded by derived classes */
849 function doAfterContent() { }
850
851 function pageTitleLinks() {
852 global $wgOut, $wgTitle, $wgUser, $wgRequest;
853
854 $oldid = $wgRequest->getVal( 'oldid' );
855 $diff = $wgRequest->getVal( 'diff' );
856 $action = $wgRequest->getText( 'action' );
857
858 $s = $this->printableLink();
859 $disclaimer = $this->disclaimerLink(); # may be empty
860 if( $disclaimer ) {
861 $s .= ' | ' . $disclaimer;
862 }
863 $privacy = $this->privacyLink(); # may be empty too
864 if( $privacy ) {
865 $s .= ' | ' . $privacy;
866 }
867
868 if ( $wgOut->isArticleRelated() ) {
869 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
870 $name = $wgTitle->getDBkey();
871 $image = wfFindFile( $wgTitle );
872 if( $image ) {
873 $link = htmlspecialchars( $image->getURL() );
874 $style = $this->getInternalLinkAttributes( $link, $name );
875 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
876 }
877 }
878 }
879 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
880 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
881 wfMsg( 'currentrev' ) );
882 }
883
884 if ( $wgUser->getNewtalk() ) {
885 # do not show "You have new messages" text when we are viewing our
886 # own talk page
887 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
888 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
889 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
890 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
891 # disable caching
892 $wgOut->setSquidMaxage(0);
893 $wgOut->enableClientCache(false);
894 }
895 }
896
897 $undelete = $this->getUndeleteLink();
898 if( !empty( $undelete ) ) {
899 $s .= ' | '.$undelete;
900 }
901 return $s;
902 }
903
904 function getUndeleteLink() {
905 global $wgUser, $wgTitle, $wgContLang, $wgLang, $action;
906 if( $wgUser->isAllowed( 'deletedhistory' ) &&
907 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
908 ($n = $wgTitle->isDeleted() ) )
909 {
910 if ( $wgUser->isAllowed( 'undelete' ) ) {
911 $msg = 'thisisdeleted';
912 } else {
913 $msg = 'viewdeleted';
914 }
915 return wfMsg( $msg,
916 $this->makeKnownLinkObj(
917 SpecialPage::getTitleFor( 'Undelete', $wgTitle->getPrefixedDBkey() ),
918 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ) ) );
919 }
920 return '';
921 }
922
923 function printableLink() {
924 global $wgOut, $wgFeedClasses, $wgRequest;
925
926 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
927
928 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
929 if( $wgOut->isSyndicated() ) {
930 foreach( $wgFeedClasses as $format => $class ) {
931 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
932 $s .= " | <a href=\"$feedurl\">{$format}</a>";
933 }
934 }
935 return $s;
936 }
937
938 function pageTitle() {
939 global $wgOut;
940 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
941 return $s;
942 }
943
944 function pageSubtitle() {
945 global $wgOut;
946
947 $sub = $wgOut->getSubtitle();
948 if ( '' == $sub ) {
949 global $wgExtraSubtitle;
950 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
951 }
952 $subpages = $this->subPageSubtitle();
953 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
954 $s = "<p class='subtitle'>{$sub}</p>\n";
955 return $s;
956 }
957
958 function subPageSubtitle() {
959 $subpages = '';
960 if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages)))
961 return $subpages;
962
963 global $wgOut, $wgTitle;
964 if($wgOut->isArticle() && MWNamespace::hasSubpages( $wgTitle->getNamespace() )) {
965 $ptext=$wgTitle->getPrefixedText();
966 if(preg_match('/\//',$ptext)) {
967 $links = explode('/',$ptext);
968 array_pop( $links );
969 $c = 0;
970 $growinglink = '';
971 $display = '';
972 foreach($links as $link) {
973 $growinglink .= $link;
974 $display .= $link;
975 $linkObj = Title::newFromText( $growinglink );
976 if( is_object( $linkObj ) && $linkObj->exists() ){
977 $getlink = $this->makeKnownLinkObj( $linkObj, htmlspecialchars( $display ) );
978 $c++;
979 if ($c>1) {
980 $subpages .= ' | ';
981 } else {
982 $subpages .= '&lt; ';
983 }
984 $subpages .= $getlink;
985 $display = '';
986 } else {
987 $display .= '/';
988 }
989 $growinglink .= '/';
990 }
991 }
992 }
993 return $subpages;
994 }
995
996 /**
997 * Returns true if the IP should be shown in the header
998 */
999 function showIPinHeader() {
1000 global $wgShowIPinHeader;
1001 return $wgShowIPinHeader && session_id() != '';
1002 }
1003
1004 function nameAndLogin() {
1005 global $wgUser, $wgTitle, $wgLang, $wgContLang;
1006
1007 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1008
1009 $ret = '';
1010 if ( $wgUser->isAnon() ) {
1011 if( $this->showIPinHeader() ) {
1012 $name = wfGetIP();
1013
1014 $talkLink = $this->link( $wgUser->getTalkPage(),
1015 $wgLang->getNsText( NS_TALK ) );
1016
1017 $ret .= "$name ($talkLink)";
1018 } else {
1019 $ret .= wfMsg( 'notloggedin' );
1020 }
1021
1022 $returnTo = $wgTitle->getPrefixedDBkey();
1023 $query = array();
1024 if ( $logoutPage != $returnTo ) {
1025 $query['returnto'] = $returnTo;
1026 }
1027
1028 $loginlink = $wgUser->isAllowed( 'createaccount' )
1029 ? 'nav-login-createaccount'
1030 : 'login';
1031 $ret .= "\n<br />" . $this->link(
1032 SpecialPage::getTitleFor( 'Userlogin' ),
1033 wfMsg( $loginlink ), array(), $query
1034 );
1035 } else {
1036 $returnTo = $wgTitle->getPrefixedDBkey();
1037 $talkLink = $this->link( $wgUser->getTalkPage(),
1038 $wgLang->getNsText( NS_TALK ) );
1039
1040 $ret .= $this->link( $wgUser->getUserPage(),
1041 htmlspecialchars( $wgUser->getName() ) );
1042 $ret .= " ($talkLink)<br />";
1043 $ret .= $this->link(
1044 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1045 array(), array( 'returnto' => $returnTo )
1046 );
1047 $ret .= ' | ' . $this->specialLink( 'preferences' );
1048 }
1049 $ret .= ' | ' . $this->link(
1050 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1051 wfMsg( 'help' )
1052 );
1053
1054 return $ret;
1055 }
1056
1057 function getSearchLink() {
1058 $searchPage = SpecialPage::getTitleFor( 'Search' );
1059 return $searchPage->getLocalURL();
1060 }
1061
1062 function escapeSearchLink() {
1063 return htmlspecialchars( $this->getSearchLink() );
1064 }
1065
1066 function searchForm() {
1067 global $wgRequest;
1068 $search = $wgRequest->getText( 'search' );
1069
1070 $s = '<form id="searchform'.$this->searchboxes.'" name="search" class="inline" method="post" action="'
1071 . $this->escapeSearchLink() . "\">\n"
1072 . '<input type="text" id="searchInput'.$this->searchboxes.'" name="search" size="19" value="'
1073 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
1074 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
1075 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
1076
1077 // Ensure unique id's for search boxes made after the first
1078 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1079
1080 return $s;
1081 }
1082
1083 function topLinks() {
1084 global $wgOut;
1085 $sep = " |\n";
1086
1087 $s = $this->mainPageLink() . $sep
1088 . $this->specialLink( 'recentchanges' );
1089
1090 if ( $wgOut->isArticleRelated() ) {
1091 $s .= $sep . $this->editThisPage()
1092 . $sep . $this->historyLink();
1093 }
1094 # Many people don't like this dropdown box
1095 #$s .= $sep . $this->specialPagesList();
1096
1097 $s .= $this->variantLinks();
1098
1099 $s .= $this->extensionTabLinks();
1100
1101 return $s;
1102 }
1103
1104 /**
1105 * Compatibility for extensions adding functionality through tabs.
1106 * Eventually these old skins should be replaced with SkinTemplate-based
1107 * versions, sigh...
1108 * @return string
1109 */
1110 function extensionTabLinks() {
1111 $tabs = array();
1112 $s = '';
1113 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1114 foreach( $tabs as $tab ) {
1115 $s .= ' | ' . Xml::element( 'a',
1116 array( 'href' => $tab['href'] ),
1117 $tab['text'] );
1118 }
1119 return $s;
1120 }
1121
1122 /**
1123 * Language/charset variant links for classic-style skins
1124 * @return string
1125 */
1126 function variantLinks() {
1127 $s = '';
1128 /* show links to different language variants */
1129 global $wgDisableLangConversion, $wgContLang, $wgTitle;
1130 $variants = $wgContLang->getVariants();
1131 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1132 foreach( $variants as $code ) {
1133 $varname = $wgContLang->getVariantname( $code );
1134 if( $varname == 'disable' )
1135 continue;
1136 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
1137 }
1138 }
1139 return $s;
1140 }
1141
1142 function bottomLinks() {
1143 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1144 $sep = " |\n";
1145
1146 $s = '';
1147 if ( $wgOut->isArticleRelated() ) {
1148 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1149 if ( $wgUser->isLoggedIn() ) {
1150 $s .= $sep . $this->watchThisPage();
1151 }
1152 $s .= $sep . $this->talkLink()
1153 . $sep . $this->historyLink()
1154 . $sep . $this->whatLinksHere()
1155 . $sep . $this->watchPageLinksLink();
1156
1157 if ($wgUseTrackbacks)
1158 $s .= $sep . $this->trackbackLink();
1159
1160 if ( $wgTitle->getNamespace() == NS_USER
1161 || $wgTitle->getNamespace() == NS_USER_TALK )
1162
1163 {
1164 $id=User::idFromName($wgTitle->getText());
1165 $ip=User::isIP($wgTitle->getText());
1166
1167 if($id || $ip) { # both anons and non-anons have contri list
1168 $s .= $sep . $this->userContribsLink();
1169 }
1170 if( $this->showEmailUser( $id ) ) {
1171 $s .= $sep . $this->emailUserLink();
1172 }
1173 }
1174 if ( $wgTitle->getArticleId() ) {
1175 $s .= "\n<br />";
1176 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1177 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1178 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1179 }
1180 $s .= "<br />\n" . $this->otherLanguages();
1181 }
1182 return $s;
1183 }
1184
1185 function pageStats() {
1186 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1187 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1188
1189 $oldid = $wgRequest->getVal( 'oldid' );
1190 $diff = $wgRequest->getVal( 'diff' );
1191 if ( ! $wgOut->isArticle() ) { return ''; }
1192 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1193 if ( 0 == $wgArticle->getID() ) { return ''; }
1194
1195 $s = '';
1196 if ( !$wgDisableCounters ) {
1197 $count = $wgLang->formatNum( $wgArticle->getCount() );
1198 if ( $count ) {
1199 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1200 }
1201 }
1202
1203 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
1204 require_once('Credits.php');
1205 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1206 } else {
1207 $s .= $this->lastModified();
1208 }
1209
1210 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
1211 $dbr = wfGetDB( DB_SLAVE );
1212 $watchlist = $dbr->tableName( 'watchlist' );
1213 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1214 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) .
1215 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1216 $res = $dbr->query( $sql, 'Skin::pageStats');
1217 $x = $dbr->fetchObject( $res );
1218
1219 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1220 array( 'parseinline' ), $wgLang->formatNum($x->n)
1221 );
1222 }
1223
1224 return $s . ' ' . $this->getCopyright();
1225 }
1226
1227 function getCopyright( $type = 'detect' ) {
1228 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1229
1230 if ( $type == 'detect' ) {
1231 $oldid = $wgRequest->getVal( 'oldid' );
1232 $diff = $wgRequest->getVal( 'diff' );
1233
1234 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1235 $type = 'history';
1236 } else {
1237 $type = 'normal';
1238 }
1239 }
1240
1241 if ( $type == 'history' ) {
1242 $msg = 'history_copyright';
1243 } else {
1244 $msg = 'copyright';
1245 }
1246
1247 $out = '';
1248 if( $wgRightsPage ) {
1249 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1250 } elseif( $wgRightsUrl ) {
1251 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1252 } else {
1253 # Give up now
1254 return $out;
1255 }
1256 $out .= wfMsgForContent( $msg, $link );
1257 return $out;
1258 }
1259
1260 function getCopyrightIcon() {
1261 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1262 $out = '';
1263 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1264 $out = $wgCopyrightIcon;
1265 } else if ( $wgRightsIcon ) {
1266 $icon = htmlspecialchars( $wgRightsIcon );
1267 if ( $wgRightsUrl ) {
1268 $url = htmlspecialchars( $wgRightsUrl );
1269 $out .= '<a href="'.$url.'">';
1270 }
1271 $text = htmlspecialchars( $wgRightsText );
1272 $out .= "<img src=\"$icon\" alt='$text' />";
1273 if ( $wgRightsUrl ) {
1274 $out .= '</a>';
1275 }
1276 }
1277 return $out;
1278 }
1279
1280 function getPoweredBy() {
1281 global $wgStylePath;
1282 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1283 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1284 return $img;
1285 }
1286
1287 function lastModified() {
1288 global $wgLang, $wgArticle;
1289 if( $this->mRevisionId ) {
1290 $timestamp = Revision::getTimestampFromId( $this->mRevisionId, $wgArticle->getId() );
1291 } else {
1292 $timestamp = $wgArticle->getTimestamp();
1293 }
1294 if ( $timestamp ) {
1295 $d = $wgLang->date( $timestamp, true );
1296 $t = $wgLang->time( $timestamp, true );
1297 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1298 } else {
1299 $s = '';
1300 }
1301 if ( wfGetLB()->getLaggedSlaveMode() ) {
1302 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1303 }
1304 return $s;
1305 }
1306
1307 function logoText( $align = '' ) {
1308 if ( '' != $align ) { $a = " align='{$align}'"; }
1309 else { $a = ''; }
1310
1311 $mp = wfMsg( 'mainpage' );
1312 $mptitle = Title::newMainPage();
1313 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1314
1315 $logourl = $this->getLogo();
1316 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1317 return $s;
1318 }
1319
1320 /**
1321 * show a drop-down box of special pages
1322 */
1323 function specialPagesList() {
1324 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1325 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1326 foreach ( $pages as $name => $page ) {
1327 $pages[$name] = $page->getDescription();
1328 }
1329
1330 $go = wfMsg( 'go' );
1331 $sp = wfMsg( 'specialpages' );
1332 $spp = $wgContLang->specialPage( 'Specialpages' );
1333
1334 $s = '<form id="specialpages" method="get" class="inline" ' .
1335 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1336 $s .= "<select name=\"wpDropdown\">\n";
1337 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1338
1339
1340 foreach ( $pages as $name => $desc ) {
1341 $p = $wgContLang->specialPage( $name );
1342 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1343 }
1344 $s .= "</select>\n";
1345 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1346 $s .= "</form>\n";
1347 return $s;
1348 }
1349
1350 function mainPageLink() {
1351 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1352 return $s;
1353 }
1354
1355 function copyrightLink() {
1356 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1357 wfMsg( 'copyrightpagename' ) );
1358 return $s;
1359 }
1360
1361 private function footerLink ( $desc, $page ) {
1362 // if the link description has been set to "-" in the default language,
1363 if ( wfMsgForContent( $desc ) == '-') {
1364 // then it is disabled, for all languages.
1365 return '';
1366 } else {
1367 // Otherwise, we display the link for the user, described in their
1368 // language (which may or may not be the same as the default language),
1369 // but we make the link target be the one site-wide page.
1370 return $this->makeKnownLink( wfMsgForContent( $page ),
1371 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1372 }
1373 }
1374
1375 function privacyLink() {
1376 return $this->footerLink( 'privacy', 'privacypage' );
1377 }
1378
1379 function aboutLink() {
1380 return $this->footerLink( 'aboutsite', 'aboutpage' );
1381 }
1382
1383 function disclaimerLink() {
1384 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1385 }
1386
1387 function editThisPage() {
1388 global $wgOut, $wgTitle;
1389
1390 if ( !$wgOut->isArticleRelated() ) {
1391 $s = wfMsg( 'protectedpage' );
1392 } else {
1393 if( $wgTitle->userCan( 'edit' ) && $wgTitle->exists() ) {
1394 $t = wfMsg( 'editthispage' );
1395 } elseif( $wgTitle->userCan( 'create' ) && !$wgTitle->exists() ) {
1396 $t = wfMsg( 'create-this-page' );
1397 } else {
1398 $t = wfMsg( 'viewsource' );
1399 }
1400
1401 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1402 }
1403 return $s;
1404 }
1405
1406 /**
1407 * Return URL options for the 'edit page' link.
1408 * This may include an 'oldid' specifier, if the current page view is such.
1409 *
1410 * @return string
1411 * @private
1412 */
1413 function editUrlOptions() {
1414 global $wgArticle;
1415
1416 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1417 return "action=edit&oldid=" . intval( $this->mRevisionId );
1418 } else {
1419 return "action=edit";
1420 }
1421 }
1422
1423 function deleteThisPage() {
1424 global $wgUser, $wgTitle, $wgRequest;
1425
1426 $diff = $wgRequest->getVal( 'diff' );
1427 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1428 $t = wfMsg( 'deletethispage' );
1429
1430 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1431 } else {
1432 $s = '';
1433 }
1434 return $s;
1435 }
1436
1437 function protectThisPage() {
1438 global $wgUser, $wgTitle, $wgRequest;
1439
1440 $diff = $wgRequest->getVal( 'diff' );
1441 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1442 if ( $wgTitle->isProtected() ) {
1443 $t = wfMsg( 'unprotectthispage' );
1444 $q = 'action=unprotect';
1445 } else {
1446 $t = wfMsg( 'protectthispage' );
1447 $q = 'action=protect';
1448 }
1449 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1450 } else {
1451 $s = '';
1452 }
1453 return $s;
1454 }
1455
1456 function watchThisPage() {
1457 global $wgOut, $wgTitle;
1458 ++$this->mWatchLinkNum;
1459
1460 if ( $wgOut->isArticleRelated() ) {
1461 if ( $wgTitle->userIsWatching() ) {
1462 $t = wfMsg( 'unwatchthispage' );
1463 $q = 'action=unwatch';
1464 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1465 } else {
1466 $t = wfMsg( 'watchthispage' );
1467 $q = 'action=watch';
1468 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1469 }
1470 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1471 } else {
1472 $s = wfMsg( 'notanarticle' );
1473 }
1474 return $s;
1475 }
1476
1477 function moveThisPage() {
1478 global $wgTitle;
1479
1480 if ( $wgTitle->userCan( 'move' ) ) {
1481 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1482 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1483 } else {
1484 // no message if page is protected - would be redundant
1485 return '';
1486 }
1487 }
1488
1489 function historyLink() {
1490 global $wgTitle;
1491
1492 return $this->makeKnownLinkObj( $wgTitle,
1493 wfMsg( 'history' ), 'action=history' );
1494 }
1495
1496 function whatLinksHere() {
1497 global $wgTitle;
1498
1499 return $this->makeKnownLinkObj(
1500 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1501 wfMsg( 'whatlinkshere' ) );
1502 }
1503
1504 function userContribsLink() {
1505 global $wgTitle;
1506
1507 return $this->makeKnownLinkObj(
1508 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1509 wfMsg( 'contributions' ) );
1510 }
1511
1512 function showEmailUser( $id ) {
1513 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1514 return $wgEnableEmail &&
1515 $wgEnableUserEmail &&
1516 $wgUser->isLoggedIn() && # show only to signed in users
1517 0 != $id; # we can only email to non-anons ..
1518 # '' != $id->getEmail() && # who must have an email address stored ..
1519 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1520 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1521 }
1522
1523 function emailUserLink() {
1524 global $wgTitle;
1525
1526 return $this->makeKnownLinkObj(
1527 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1528 wfMsg( 'emailuser' ) );
1529 }
1530
1531 function watchPageLinksLink() {
1532 global $wgOut, $wgTitle;
1533
1534 if ( ! $wgOut->isArticleRelated() ) {
1535 return '(' . wfMsg( 'notanarticle' ) . ')';
1536 } else {
1537 return $this->makeKnownLinkObj(
1538 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1539 wfMsg( 'recentchangeslinked' ) );
1540 }
1541 }
1542
1543 function trackbackLink() {
1544 global $wgTitle;
1545
1546 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1547 . wfMsg('trackbacklink') . "</a>";
1548 }
1549
1550 function otherLanguages() {
1551 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1552
1553 if ( $wgHideInterlanguageLinks ) {
1554 return '';
1555 }
1556
1557 $a = $wgOut->getLanguageLinks();
1558 if ( 0 == count( $a ) ) {
1559 return '';
1560 }
1561
1562 $s = wfMsg( 'otherlanguages' ) . ': ';
1563 $first = true;
1564 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1565 foreach( $a as $l ) {
1566 if ( ! $first ) { $s .= ' | '; }
1567 $first = false;
1568
1569 $nt = Title::newFromText( $l );
1570 $url = $nt->escapeFullURL();
1571 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1572
1573 if ( '' == $text ) { $text = $l; }
1574 $style = $this->getExternalLinkAttributes( $l, $text );
1575 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1576 }
1577 if($wgContLang->isRTL()) $s .= '</span>';
1578 return $s;
1579 }
1580
1581 function bugReportsLink() {
1582 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1583 wfMsg( 'bugreports' ) );
1584 return $s;
1585 }
1586
1587 function talkLink() {
1588 global $wgTitle;
1589
1590 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1591 # No discussion links for special pages
1592 return '';
1593 }
1594
1595 if( $wgTitle->isTalkPage() ) {
1596 $link = $wgTitle->getSubjectPage();
1597 switch( $link->getNamespace() ) {
1598 case NS_MAIN:
1599 $text = wfMsg( 'articlepage' );
1600 break;
1601 case NS_USER:
1602 $text = wfMsg( 'userpage' );
1603 break;
1604 case NS_PROJECT:
1605 $text = wfMsg( 'projectpage' );
1606 break;
1607 case NS_IMAGE:
1608 $text = wfMsg( 'imagepage' );
1609 break;
1610 case NS_MEDIAWIKI:
1611 $text = wfMsg( 'mediawikipage' );
1612 break;
1613 case NS_TEMPLATE:
1614 $text = wfMsg( 'templatepage' );
1615 break;
1616 case NS_HELP:
1617 $text = wfMsg( 'viewhelppage' );
1618 break;
1619 case NS_CATEGORY:
1620 $text = wfMsg( 'categorypage' );
1621 break;
1622 default:
1623 $text = wfMsg( 'articlepage' );
1624 }
1625 } else {
1626 $link = $wgTitle->getTalkPage();
1627 $text = wfMsg( 'talkpage' );
1628 }
1629
1630 $s = $this->makeLinkObj( $link, $text );
1631
1632 return $s;
1633 }
1634
1635 function commentLink() {
1636 global $wgTitle, $wgOut;
1637
1638 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1639 return '';
1640 }
1641
1642 # __NEWSECTIONLINK___ changes behaviour here
1643 # If it's present, the link points to this page, otherwise
1644 # it points to the talk page
1645 if( $wgTitle->isTalkPage() ) {
1646 $title = $wgTitle;
1647 } elseif( $wgOut->showNewSectionLink() ) {
1648 $title = $wgTitle;
1649 } else {
1650 $title = $wgTitle->getTalkPage();
1651 }
1652
1653 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1654 }
1655
1656 /* these are used extensively in SkinTemplate, but also some other places */
1657 static function makeMainPageUrl( $urlaction = '' ) {
1658 $title = Title::newMainPage();
1659 self::checkTitle( $title, '' );
1660 return $title->getLocalURL( $urlaction );
1661 }
1662
1663 static function makeSpecialUrl( $name, $urlaction = '' ) {
1664 $title = SpecialPage::getTitleFor( $name );
1665 return $title->getLocalURL( $urlaction );
1666 }
1667
1668 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1669 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1670 return $title->getLocalURL( $urlaction );
1671 }
1672
1673 static function makeI18nUrl( $name, $urlaction = '' ) {
1674 $title = Title::newFromText( wfMsgForContent( $name ) );
1675 self::checkTitle( $title, $name );
1676 return $title->getLocalURL( $urlaction );
1677 }
1678
1679 static function makeUrl( $name, $urlaction = '' ) {
1680 $title = Title::newFromText( $name );
1681 self::checkTitle( $title, $name );
1682 return $title->getLocalURL( $urlaction );
1683 }
1684
1685 # If url string starts with http, consider as external URL, else
1686 # internal
1687 static function makeInternalOrExternalUrl( $name ) {
1688 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1689 return $name;
1690 } else {
1691 return self::makeUrl( $name );
1692 }
1693 }
1694
1695 # this can be passed the NS number as defined in Language.php
1696 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1697 $title = Title::makeTitleSafe( $namespace, $name );
1698 self::checkTitle( $title, $name );
1699 return $title->getLocalURL( $urlaction );
1700 }
1701
1702 /* these return an array with the 'href' and boolean 'exists' */
1703 static function makeUrlDetails( $name, $urlaction = '' ) {
1704 $title = Title::newFromText( $name );
1705 self::checkTitle( $title, $name );
1706 return array(
1707 'href' => $title->getLocalURL( $urlaction ),
1708 'exists' => $title->getArticleID() != 0 ? true : false
1709 );
1710 }
1711
1712 /**
1713 * Make URL details where the article exists (or at least it's convenient to think so)
1714 */
1715 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1716 $title = Title::newFromText( $name );
1717 self::checkTitle( $title, $name );
1718 return array(
1719 'href' => $title->getLocalURL( $urlaction ),
1720 'exists' => true
1721 );
1722 }
1723
1724 # make sure we have some title to operate on
1725 static function checkTitle( &$title, $name ) {
1726 if( !is_object( $title ) ) {
1727 $title = Title::newFromText( $name );
1728 if( !is_object( $title ) ) {
1729 $title = Title::newFromText( '--error: link target missing--' );
1730 }
1731 }
1732 }
1733
1734 /**
1735 * Build an array that represents the sidebar(s), the navigation bar among them
1736 *
1737 * @return array
1738 */
1739 function buildSidebar() {
1740 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1741 global $wgLang;
1742 wfProfileIn( __METHOD__ );
1743
1744 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
1745
1746 if ( $wgEnableSidebarCache ) {
1747 $cachedsidebar = $parserMemc->get( $key );
1748 if ( $cachedsidebar ) {
1749 wfProfileOut( __METHOD__ );
1750 return $cachedsidebar;
1751 }
1752 }
1753
1754 $bar = array();
1755 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1756 $heading = '';
1757 foreach ($lines as $line) {
1758 if (strpos($line, '*') !== 0)
1759 continue;
1760 if (strpos($line, '**') !== 0) {
1761 $line = trim($line, '* ');
1762 $heading = $line;
1763 if( !array_key_exists($heading, $bar) ) $bar[$heading] = array();
1764 } else {
1765 if (strpos($line, '|') !== false) { // sanity check
1766 $line = array_map('trim', explode( '|' , trim($line, '* '), 2 ) );
1767 $link = wfMsgForContent( $line[0] );
1768 if ($link == '-')
1769 continue;
1770 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1771 $text = $line[1];
1772 if (wfEmptyMsg($line[0], $link))
1773 $link = $line[0];
1774
1775 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1776 $href = $link;
1777 } else {
1778 $title = Title::newFromText( $link );
1779 if ( $title ) {
1780 $title = $title->fixSpecialName();
1781 $href = $title->getLocalURL();
1782 } else {
1783 $href = 'INVALID-TITLE';
1784 }
1785 }
1786
1787 $bar[$heading][] = array(
1788 'text' => $text,
1789 'href' => $href,
1790 'id' => 'n-' . strtr($line[1], ' ', '-'),
1791 'active' => false
1792 );
1793 } else { continue; }
1794 }
1795 }
1796 wfRunHooks('SkinBuildSidebar', array($this, &$bar));
1797 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1798 wfProfileOut( __METHOD__ );
1799 return $bar;
1800 }
1801 }