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