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