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