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