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