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