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