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