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