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