(bug 5378) General logs link in Special:Contributions
[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
690 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
691 return $s;
692 }
693
694 function pageSubtitle() {
695 global $wgOut;
696
697 $sub = $wgOut->getSubtitle();
698 if ( '' == $sub ) {
699 global $wgExtraSubtitle;
700 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
701 }
702 $subpages = $this->subPageSubtitle();
703 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
704 $s = "<p class='subtitle'>{$sub}</p>\n";
705 return $s;
706 }
707
708 function subPageSubtitle() {
709 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
710 $subpages = '';
711 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
712 $ptext=$wgTitle->getPrefixedText();
713 if(preg_match('/\//',$ptext)) {
714 $links = explode('/',$ptext);
715 $c = 0;
716 $growinglink = '';
717 foreach($links as $link) {
718 $c++;
719 if ($c<count($links)) {
720 $growinglink .= $link;
721 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
722 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
723 if ($c>1) {
724 $subpages .= ' | ';
725 } else {
726 $subpages .= '&lt; ';
727 }
728 $subpages .= $getlink;
729 $growinglink .= '/';
730 }
731 }
732 }
733 }
734 return $subpages;
735 }
736
737 function nameAndLogin() {
738 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
739
740 $li = $wgContLang->specialPage( 'Userlogin' );
741 $lo = $wgContLang->specialPage( 'Userlogout' );
742
743 $s = '';
744 if ( $wgUser->isAnon() ) {
745 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
746 $n = wfGetIP();
747
748 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
749 $wgLang->getNsText( NS_TALK ) );
750
751 $s .= $n . ' ('.$tl.')';
752 } else {
753 $s .= wfMsg('notloggedin');
754 }
755
756 $rt = $wgTitle->getPrefixedURL();
757 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
758 $q = '';
759 } else { $q = "returnto={$rt}"; }
760
761 $s .= "\n<br />" . $this->makeKnownLinkObj(
762 Title::makeTitle( NS_SPECIAL, 'Userlogin' ),
763 wfMsg( 'login' ), $q );
764 } else {
765 $n = $wgUser->getName();
766 $rt = $wgTitle->getPrefixedURL();
767 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
768 $wgLang->getNsText( NS_TALK ) );
769
770 $tl = " ({$tl})";
771
772 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
773 $n ) . "{$tl}<br />" .
774 $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Userlogout' ), wfMsg( 'logout' ),
775 "returnto={$rt}" ) . ' | ' .
776 $this->specialLink( 'preferences' );
777 }
778 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
779 wfMsg( 'help' ) );
780
781 return $s;
782 }
783
784 function getSearchLink() {
785 $searchPage =& Title::makeTitle( NS_SPECIAL, 'Search' );
786 return $searchPage->getLocalURL();
787 }
788
789 function escapeSearchLink() {
790 return htmlspecialchars( $this->getSearchLink() );
791 }
792
793 function searchForm() {
794 global $wgRequest;
795 $search = $wgRequest->getText( 'search' );
796
797 $s = '<form name="search" class="inline" method="post" action="'
798 . $this->escapeSearchLink() . "\">\n"
799 . '<input type="text" name="search" size="19" value="'
800 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
801 . '<input type="submit" name="go" value="' . wfMsg ('go') . '" />&nbsp;'
802 . '<input type="submit" name="fulltext" value="' . wfMsg ('search') . "\" />\n</form>";
803
804 return $s;
805 }
806
807 function topLinks() {
808 global $wgOut;
809 $sep = " |\n";
810
811 $s = $this->mainPageLink() . $sep
812 . $this->specialLink( 'recentchanges' );
813
814 if ( $wgOut->isArticleRelated() ) {
815 $s .= $sep . $this->editThisPage()
816 . $sep . $this->historyLink();
817 }
818 # Many people don't like this dropdown box
819 #$s .= $sep . $this->specialPagesList();
820
821 /* show links to different language variants */
822 global $wgDisableLangConversion, $wgContLang, $wgTitle;
823 $variants = $wgContLang->getVariants();
824 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
825 foreach( $variants as $code ) {
826 $varname = $wgContLang->getVariantname( $code );
827 if( $varname == 'disable' )
828 continue;
829 $s .= ' | <a href="' . $wgTitle->getLocalUrl( 'variant=' . $code ) . '">' . $varname . '</a>';
830 }
831 }
832
833 return $s;
834 }
835
836 function bottomLinks() {
837 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
838 $sep = " |\n";
839
840 $s = '';
841 if ( $wgOut->isArticleRelated() ) {
842 $s .= '<strong>' . $this->editThisPage() . '</strong>';
843 if ( $wgUser->isLoggedIn() ) {
844 $s .= $sep . $this->watchThisPage();
845 }
846 $s .= $sep . $this->talkLink()
847 . $sep . $this->historyLink()
848 . $sep . $this->whatLinksHere()
849 . $sep . $this->watchPageLinksLink();
850
851 if ($wgUseTrackbacks)
852 $s .= $sep . $this->trackbackLink();
853
854 if ( $wgTitle->getNamespace() == NS_USER
855 || $wgTitle->getNamespace() == NS_USER_TALK )
856
857 {
858 $id=User::idFromName($wgTitle->getText());
859 $ip=User::isIP($wgTitle->getText());
860
861 if($id || $ip) { # both anons and non-anons have contri list
862 $s .= $sep . $this->userContribsLink();
863 }
864 if( $this->showEmailUser( $id ) ) {
865 $s .= $sep . $this->emailUserLink();
866 }
867 }
868 if ( $wgTitle->getArticleId() ) {
869 $s .= "\n<br />";
870 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
871 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
872 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
873 }
874 $s .= "<br />\n" . $this->otherLanguages();
875 }
876 return $s;
877 }
878
879 function pageStats() {
880 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
881 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
882
883 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
884 if ( ! $wgOut->isArticle() ) { return ''; }
885 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
886 if ( 0 == $wgArticle->getID() ) { return ''; }
887
888 $s = '';
889 if ( !$wgDisableCounters ) {
890 $count = $wgLang->formatNum( $wgArticle->getCount() );
891 if ( $count ) {
892 $s = wfMsg( 'viewcount', $count );
893 }
894 }
895
896 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
897 require_once('Credits.php');
898 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
899 } else {
900 $s .= $this->lastModified();
901 }
902
903 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
904 $dbr =& wfGetDB( DB_SLAVE );
905 extract( $dbr->tableNames( 'watchlist' ) );
906 $sql = "SELECT COUNT(*) AS n FROM $watchlist
907 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
908 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
909 $res = $dbr->query( $sql, 'Skin::pageStats');
910 $x = $dbr->fetchObject( $res );
911 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
912 }
913
914 return $s . ' ' . $this->getCopyright();
915 }
916
917 function getCopyright( $type = 'detect' ) {
918 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
919
920 if ( $type == 'detect' ) {
921 $oldid = $wgRequest->getVal( 'oldid' );
922 $diff = $wgRequest->getVal( 'diff' );
923
924 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
925 $type = 'history';
926 } else {
927 $type = 'normal';
928 }
929 }
930
931 if ( $type == 'history' ) {
932 $msg = 'history_copyright';
933 } else {
934 $msg = 'copyright';
935 }
936
937 $out = '';
938 if( $wgRightsPage ) {
939 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
940 } elseif( $wgRightsUrl ) {
941 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
942 } else {
943 # Give up now
944 return $out;
945 }
946 $out .= wfMsgForContent( $msg, $link );
947 return $out;
948 }
949
950 function getCopyrightIcon() {
951 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
952 $out = '';
953 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
954 $out = $wgCopyrightIcon;
955 } else if ( $wgRightsIcon ) {
956 $icon = htmlspecialchars( $wgRightsIcon );
957 if ( $wgRightsUrl ) {
958 $url = htmlspecialchars( $wgRightsUrl );
959 $out .= '<a href="'.$url.'">';
960 }
961 $text = htmlspecialchars( $wgRightsText );
962 $out .= "<img src=\"$icon\" alt='$text' />";
963 if ( $wgRightsUrl ) {
964 $out .= '</a>';
965 }
966 }
967 return $out;
968 }
969
970 function getPoweredBy() {
971 global $wgStylePath;
972 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
973 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
974 return $img;
975 }
976
977 function lastModified() {
978 global $wgLang, $wgArticle, $wgLoadBalancer;
979
980 $timestamp = $wgArticle->getTimestamp();
981 if ( $timestamp ) {
982 $d = $wgLang->timeanddate( $timestamp, true );
983 $s = ' ' . wfMsg( 'lastmodified', $d );
984 } else {
985 $s = '';
986 }
987 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
988 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
989 }
990 return $s;
991 }
992
993 function logoText( $align = '' ) {
994 if ( '' != $align ) { $a = " align='{$align}'"; }
995 else { $a = ''; }
996
997 $mp = wfMsg( 'mainpage' );
998 $titleObj = Title::newFromText( $mp );
999 if ( is_object( $titleObj ) ) {
1000 $url = $titleObj->escapeLocalURL();
1001 } else {
1002 $url = '';
1003 }
1004
1005 $logourl = $this->getLogo();
1006 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1007 return $s;
1008 }
1009
1010 /**
1011 * show a drop-down box of special pages
1012 * @TODO crash bug913. Need to be rewrote completly.
1013 */
1014 function specialPagesList() {
1015 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript, $wgAvailableRights;
1016 require_once('SpecialPage.php');
1017 $a = array();
1018 $pages = SpecialPage::getPages();
1019
1020 // special pages without access restriction
1021 foreach ( $pages[''] as $name => $page ) {
1022 $a[$name] = $page->getDescription();
1023 }
1024
1025 // Other special pages that are restricted.
1026 // Copied from SpecialSpecialpages.php
1027 foreach($wgAvailableRights as $right) {
1028 if( $wgUser->isAllowed($right) ) {
1029 /** Add all pages for this right */
1030 if(isset($pages[$right])) {
1031 foreach($pages[$right] as $name => $page) {
1032 $a[$name] = $page->getDescription();
1033 }
1034 }
1035 }
1036 }
1037
1038 $go = wfMsg( 'go' );
1039 $sp = wfMsg( 'specialpages' );
1040 $spp = $wgContLang->specialPage( 'Specialpages' );
1041
1042 $s = '<form id="specialpages" method="get" class="inline" ' .
1043 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1044 $s .= "<select name=\"wpDropdown\">\n";
1045 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1046
1047
1048 foreach ( $a as $name => $desc ) {
1049 $p = $wgContLang->specialPage( $name );
1050 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1051 }
1052 $s .= "</select>\n";
1053 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1054 $s .= "</form>\n";
1055 return $s;
1056 }
1057
1058 function mainPageLink() {
1059 $mp = wfMsgForContent( 'mainpage' );
1060 $mptxt = wfMsg( 'mainpage');
1061 $s = $this->makeKnownLink( $mp, $mptxt );
1062 return $s;
1063 }
1064
1065 function copyrightLink() {
1066 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1067 wfMsg( 'copyrightpagename' ) );
1068 return $s;
1069 }
1070
1071 function privacyLink() {
1072 $privacy = wfMsg( 'privacy' );
1073 if ($privacy == '-') {
1074 return '';
1075 } else {
1076 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1077 }
1078 }
1079
1080 function aboutLink() {
1081 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1082 wfMsg( 'aboutsite' ) );
1083 return $s;
1084 }
1085
1086 function disclaimerLink() {
1087 $disclaimers = wfMsg( 'disclaimers' );
1088 if ($disclaimers == '-') {
1089 return '';
1090 } else {
1091 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1092 $disclaimers );
1093 }
1094 }
1095
1096 function editThisPage() {
1097 global $wgOut, $wgTitle;
1098
1099 if ( ! $wgOut->isArticleRelated() ) {
1100 $s = wfMsg( 'protectedpage' );
1101 } else {
1102 if ( $wgTitle->userCanEdit() ) {
1103 $t = wfMsg( 'editthispage' );
1104 } else {
1105 $t = wfMsg( 'viewsource' );
1106 }
1107
1108 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1109 }
1110 return $s;
1111 }
1112
1113 /**
1114 * Return URL options for the 'edit page' link.
1115 * This may include an 'oldid' specifier, if the current page view is such.
1116 *
1117 * @return string
1118 * @access private
1119 */
1120 function editUrlOptions() {
1121 global $wgArticle;
1122
1123 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1124 return "action=edit&oldid=" . intval( $this->mRevisionId );
1125 } else {
1126 return "action=edit";
1127 }
1128 }
1129
1130 function deleteThisPage() {
1131 global $wgUser, $wgTitle, $wgRequest;
1132
1133 $diff = $wgRequest->getVal( 'diff' );
1134 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1135 $t = wfMsg( 'deletethispage' );
1136
1137 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1138 } else {
1139 $s = '';
1140 }
1141 return $s;
1142 }
1143
1144 function protectThisPage() {
1145 global $wgUser, $wgTitle, $wgRequest;
1146
1147 $diff = $wgRequest->getVal( 'diff' );
1148 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1149 if ( $wgTitle->isProtected() ) {
1150 $t = wfMsg( 'unprotectthispage' );
1151 $q = 'action=unprotect';
1152 } else {
1153 $t = wfMsg( 'protectthispage' );
1154 $q = 'action=protect';
1155 }
1156 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1157 } else {
1158 $s = '';
1159 }
1160 return $s;
1161 }
1162
1163 function watchThisPage() {
1164 global $wgOut, $wgTitle;
1165
1166 if ( $wgOut->isArticleRelated() ) {
1167 if ( $wgTitle->userIsWatching() ) {
1168 $t = wfMsg( 'unwatchthispage' );
1169 $q = 'action=unwatch';
1170 } else {
1171 $t = wfMsg( 'watchthispage' );
1172 $q = 'action=watch';
1173 }
1174 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1175 } else {
1176 $s = wfMsg( 'notanarticle' );
1177 }
1178 return $s;
1179 }
1180
1181 function moveThisPage() {
1182 global $wgTitle;
1183
1184 if ( $wgTitle->userCanMove() ) {
1185 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Movepage' ),
1186 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1187 } else {
1188 // no message if page is protected - would be redundant
1189 return '';
1190 }
1191 }
1192
1193 function historyLink() {
1194 global $wgTitle;
1195
1196 return $this->makeKnownLinkObj( $wgTitle,
1197 wfMsg( 'history' ), 'action=history' );
1198 }
1199
1200 function whatLinksHere() {
1201 global $wgTitle;
1202
1203 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Whatlinkshere' ),
1204 wfMsg( 'whatlinkshere' ), 'target=' . $wgTitle->getPrefixedURL() );
1205 }
1206
1207 function userContribsLink() {
1208 global $wgTitle;
1209
1210 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Contributions' ),
1211 wfMsg( 'contributions' ), 'target=' . $wgTitle->getPartialURL() );
1212 }
1213
1214 function showEmailUser( $id ) {
1215 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1216 return $wgEnableEmail &&
1217 $wgEnableUserEmail &&
1218 $wgUser->isLoggedIn() && # show only to signed in users
1219 0 != $id; # we can only email to non-anons ..
1220 # '' != $id->getEmail() && # who must have an email address stored ..
1221 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1222 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1223 }
1224
1225 function emailUserLink() {
1226 global $wgTitle;
1227
1228 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL, 'Emailuser' ),
1229 wfMsg( 'emailuser' ), 'target=' . $wgTitle->getPartialURL() );
1230 }
1231
1232 function watchPageLinksLink() {
1233 global $wgOut, $wgTitle;
1234
1235 if ( ! $wgOut->isArticleRelated() ) {
1236 return '(' . wfMsg( 'notanarticle' ) . ')';
1237 } else {
1238 return $this->makeKnownLinkObj( Title::makeTitle( NS_SPECIAL,
1239 'Recentchangeslinked' ), wfMsg( 'recentchangeslinked' ),
1240 'target=' . $wgTitle->getPrefixedURL() );
1241 }
1242 }
1243
1244 function trackbackLink() {
1245 global $wgTitle;
1246
1247 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1248 . wfMsg('trackbacklink') . "</a>";
1249 }
1250
1251 function otherLanguages() {
1252 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1253
1254 if ( $wgHideInterlanguageLinks ) {
1255 return '';
1256 }
1257
1258 $a = $wgOut->getLanguageLinks();
1259 if ( 0 == count( $a ) ) {
1260 return '';
1261 }
1262
1263 $s = wfMsg( 'otherlanguages' ) . ': ';
1264 $first = true;
1265 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1266 foreach( $a as $l ) {
1267 if ( ! $first ) { $s .= ' | '; }
1268 $first = false;
1269
1270 $nt = Title::newFromText( $l );
1271 $url = $nt->escapeFullURL();
1272 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1273
1274 if ( '' == $text ) { $text = $l; }
1275 $style = $this->getExternalLinkAttributes( $l, $text );
1276 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1277 }
1278 if($wgContLang->isRTL()) $s .= '</span>';
1279 return $s;
1280 }
1281
1282 function bugReportsLink() {
1283 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1284 wfMsg( 'bugreports' ) );
1285 return $s;
1286 }
1287
1288 function dateLink() {
1289 $t1 = Title::newFromText( gmdate( 'F j' ) );
1290 $t2 = Title::newFromText( gmdate( 'Y' ) );
1291
1292 $id = $t1->getArticleID();
1293
1294 if ( 0 == $id ) {
1295 $s = $this->makeBrokenLink( $t1->getText() );
1296 } else {
1297 $s = $this->makeKnownLink( $t1->getText() );
1298 }
1299 $s .= ', ';
1300
1301 $id = $t2->getArticleID();
1302
1303 if ( 0 == $id ) {
1304 $s .= $this->makeBrokenLink( $t2->getText() );
1305 } else {
1306 $s .= $this->makeKnownLink( $t2->getText() );
1307 }
1308 return $s;
1309 }
1310
1311 function talkLink() {
1312 global $wgTitle;
1313
1314 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1315 # No discussion links for special pages
1316 return '';
1317 }
1318
1319 if( $wgTitle->isTalkPage() ) {
1320 $link = $wgTitle->getSubjectPage();
1321 switch( $link->getNamespace() ) {
1322 case NS_MAIN:
1323 $text = wfMsg('articlepage');
1324 break;
1325 case NS_USER:
1326 $text = wfMsg('userpage');
1327 break;
1328 case NS_PROJECT:
1329 $text = wfMsg('wikipediapage');
1330 break;
1331 case NS_IMAGE:
1332 $text = wfMsg('imagepage');
1333 break;
1334 default:
1335 $text= wfMsg('articlepage');
1336 }
1337 } else {
1338 $link = $wgTitle->getTalkPage();
1339 $text = wfMsg( 'talkpage' );
1340 }
1341
1342 $s = $this->makeLinkObj( $link, $text );
1343
1344 return $s;
1345 }
1346
1347 function commentLink() {
1348 global $wgTitle;
1349
1350 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1351 return '';
1352 }
1353 return $this->makeKnownLinkObj( $wgTitle->getTalkPage(),
1354 wfMsg( 'postcomment' ), 'action=edit&section=new' );
1355 }
1356
1357 /* these are used extensively in SkinTemplate, but also some other places */
1358 /*static*/ function makeSpecialUrl( $name, $urlaction='' ) {
1359 $title = Title::makeTitle( NS_SPECIAL, $name );
1360 return $title->getLocalURL( $urlaction );
1361 }
1362
1363 /*static*/ function makeI18nUrl ( $name, $urlaction='' ) {
1364 $title = Title::newFromText( wfMsgForContent($name) );
1365 $this->checkTitle($title, $name);
1366 return $title->getLocalURL( $urlaction );
1367 }
1368
1369 /*static*/ function makeUrl ( $name, $urlaction='' ) {
1370 $title = Title::newFromText( $name );
1371 $this->checkTitle($title, $name);
1372 return $title->getLocalURL( $urlaction );
1373 }
1374
1375 # If url string starts with http, consider as external URL, else
1376 # internal
1377 /*static*/ function makeInternalOrExternalUrl( $name ) {
1378 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1379 return $name;
1380 } else {
1381 return $this->makeUrl( $name );
1382 }
1383 }
1384
1385 # this can be passed the NS number as defined in Language.php
1386 /*static*/ function makeNSUrl( $name, $urlaction='', $namespace=NS_MAIN ) {
1387 $title = Title::makeTitleSafe( $namespace, $name );
1388 $this->checkTitle($title, $name);
1389 return $title->getLocalURL( $urlaction );
1390 }
1391
1392 /* these return an array with the 'href' and boolean 'exists' */
1393 /*static*/ function makeUrlDetails ( $name, $urlaction='' ) {
1394 $title = Title::newFromText( $name );
1395 $this->checkTitle($title, $name);
1396 return array(
1397 'href' => $title->getLocalURL( $urlaction ),
1398 'exists' => $title->getArticleID() != 0?true:false
1399 );
1400 }
1401
1402 /**
1403 * Make URL details where the article exists (or at least it's convenient to think so)
1404 */
1405 function makeKnownUrlDetails( $name, $urlaction='' ) {
1406 $title = Title::newFromText( $name );
1407 $this->checkTitle($title, $name);
1408 return array(
1409 'href' => $title->getLocalURL( $urlaction ),
1410 'exists' => true
1411 );
1412 }
1413
1414 # make sure we have some title to operate on
1415 /*static*/ function checkTitle ( &$title, &$name ) {
1416 if(!is_object($title)) {
1417 $title = Title::newFromText( $name );
1418 if(!is_object($title)) {
1419 $title = Title::newFromText( '--error: link target missing--' );
1420 }
1421 }
1422 }
1423
1424 /**
1425 * Build an array that represents the sidebar(s), the navigation bar among them
1426 *
1427 * @return array
1428 * @access private
1429 */
1430 function buildSidebar() {
1431 global $wgDBname, $parserMemc;
1432 global $wgLanguageCode, $wgContLanguageCode;
1433
1434 $fname = 'SkinTemplate::buildSidebar';
1435
1436 wfProfileIn( $fname );
1437
1438 if ($wgLanguageCode == $wgContLanguageCode)
1439 $cacheSidebar = true;
1440 else
1441 $cacheSidebar = false;
1442
1443 if ($cacheSidebar) {
1444 $cachedsidebar=$parserMemc->get("{$wgDBname}:sidebar");
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("{$wgDBname}:sidebar",$bar,86400);
1481 wfProfileOut( $fname );
1482 return $bar;
1483 }
1484 }
1485 ?>