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