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