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