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