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