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