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