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