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