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