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