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