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