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