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