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