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