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