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