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