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