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