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