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