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