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