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