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