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