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