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