* Add tab links from extensions to classic-based skins (SkinTemplateTab hook)
[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 = Skin::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 = Skin::normalizeKey( $key );
114
115 $skinNames = Skin::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 = $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Categories' ),
583 $msg, 'article=' . urlencode( $wgTitle->getPrefixedDBkey() ) )
584 . ': ' . $t;
585
586 # optional 'dmoz-like' category browser. Will be shown under the list
587 # of categories an article belong to
588 if($wgUseCategoryBrowser) {
589 $s .= '<br /><hr />';
590
591 # get a big array of the parents tree
592 $parenttree = $wgTitle->getParentCategoryTree();
593 # Skin object passed by reference cause it can not be
594 # accessed under the method subfunction drawCategoryBrowser
595 $tempout = explode("\n", Skin::drawCategoryBrowser($parenttree, $this) );
596 # Clean out bogus first entry and sort them
597 unset($tempout[0]);
598 asort($tempout);
599 # Output one per line
600 $s .= implode("<br />\n", $tempout);
601 }
602
603 return $s;
604 }
605
606 /** Render the array as a serie 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 */
611 function drawCategoryBrowser($tree, &$skin) {
612 $return = '';
613 foreach ($tree as $element => $parent) {
614 if (empty($parent)) {
615 # element start a new list
616 $return .= "\n";
617 } else {
618 # grab the others elements
619 $return .= Skin::drawCategoryBrowser($parent, $skin) . ' &gt; ';
620 }
621 # add our current element to the list
622 $eltitle = Title::NewFromText($element);
623 $return .= $skin->makeLinkObj( $eltitle, $eltitle->getText() ) ;
624 }
625 return $return;
626 }
627
628 function getCategories() {
629 $catlinks=$this->getCategoryLinks();
630 if(!empty($catlinks)) {
631 return "<p class='catlinks'>{$catlinks}</p>";
632 }
633 }
634
635 function getQuickbarCompensator( $rows = 1 ) {
636 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
637 }
638
639 /**
640 * This gets called shortly before the \</body\> tag.
641 * @return String HTML to be put before \</body\>
642 */
643 function afterContent() {
644 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
645 return $printfooter . $this->doAfterContent();
646 }
647
648 /**
649 * This gets called shortly before the \</body\> tag.
650 * @return String HTML-wrapped JS code to be put before \</body\>
651 */
652 function bottomScripts() {
653 global $wgJsMimeType;
654 return "\n\t\t<script type=\"$wgJsMimeType\">if (window.runOnloadHook) runOnloadHook();</script>\n";
655 }
656
657 /** @return string Retrievied from HTML text */
658 function printSource() {
659 global $wgTitle;
660 $url = htmlspecialchars( $wgTitle->getFullURL() );
661 return wfMsg( 'retrievedfrom', '<a href="'.$url.'">'.$url.'</a>' );
662 }
663
664 function printFooter() {
665 return "<p>" . $this->printSource() .
666 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
667 }
668
669 /** overloaded by derived classes */
670 function doAfterContent() { }
671
672 function pageTitleLinks() {
673 global $wgOut, $wgTitle, $wgUser, $wgRequest;
674
675 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
676 $action = $wgRequest->getText( 'action' );
677
678 $s = $this->printableLink();
679 $disclaimer = $this->disclaimerLink(); # may be empty
680 if( $disclaimer ) {
681 $s .= ' | ' . $disclaimer;
682 }
683 $privacy = $this->privacyLink(); # may be empty too
684 if( $privacy ) {
685 $s .= ' | ' . $privacy;
686 }
687
688 if ( $wgOut->isArticleRelated() ) {
689 if ( $wgTitle->getNamespace() == NS_IMAGE ) {
690 $name = $wgTitle->getDBkey();
691 $image = new Image( $wgTitle );
692 if( $image->exists() ) {
693 $link = htmlspecialchars( $image->getURL() );
694 $style = $this->getInternalLinkAttributes( $link, $name );
695 $s .= " | <a href=\"{$link}\"{$style}>{$name}</a>";
696 }
697 }
698 }
699 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
700 $s .= ' | ' . $this->makeKnownLinkObj( $wgTitle,
701 wfMsg( 'currentrev' ) );
702 }
703
704 if ( $wgUser->getNewtalk() ) {
705 # do not show "You have new messages" text when we are viewing our
706 # own talk page
707 if( !$wgTitle->equals( $wgUser->getTalkPage() ) ) {
708 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessageslink' ), 'redirect=no' );
709 $dl = $this->makeKnownLinkObj( $wgUser->getTalkPage(), wfMsgHtml( 'newmessagesdifflink' ), 'diff=cur' );
710 $s.= ' | <strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
711 # disable caching
712 $wgOut->setSquidMaxage(0);
713 $wgOut->enableClientCache(false);
714 }
715 }
716
717 $undelete = $this->getUndeleteLink();
718 if( !empty( $undelete ) ) {
719 $s .= ' | '.$undelete;
720 }
721 return $s;
722 }
723
724 function getUndeleteLink() {
725 global $wgUser, $wgTitle, $wgContLang, $action;
726 if( $wgUser->isAllowed( 'deletedhistory' ) &&
727 (($wgTitle->getArticleId() == 0) || ($action == "history")) &&
728 ($n = $wgTitle->isDeleted() ) )
729 {
730 if ( $wgUser->isAllowed( 'delete' ) ) {
731 $msg = 'thisisdeleted';
732 } else {
733 $msg = 'viewdeleted';
734 }
735 return wfMsg( $msg,
736 $this->makeKnownLink(
737 $wgContLang->SpecialPage( 'Undelete/' . $wgTitle->getPrefixedDBkey() ),
738 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $n ) ) );
739 }
740 return '';
741 }
742
743 function printableLink() {
744 global $wgOut, $wgFeedClasses, $wgRequest;
745
746 $baseurl = $_SERVER['REQUEST_URI'];
747 if( strpos( '?', $baseurl ) == false ) {
748 $baseurl .= '?';
749 } else {
750 $baseurl .= '&';
751 }
752 $baseurl = htmlspecialchars( $baseurl );
753 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
754
755 $s = "<a href=\"$printurl\">" . wfMsg( 'printableversion' ) . '</a>';
756 if( $wgOut->isSyndicated() ) {
757 foreach( $wgFeedClasses as $format => $class ) {
758 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
759 $s .= " | <a href=\"$feedurl\">{$format}</a>";
760 }
761 }
762 return $s;
763 }
764
765 function pageTitle() {
766 global $wgOut;
767 $s = '<h1 class="pagetitle">' . htmlspecialchars( $wgOut->getPageTitle() ) . '</h1>';
768 return $s;
769 }
770
771 function pageSubtitle() {
772 global $wgOut;
773
774 $sub = $wgOut->getSubtitle();
775 if ( '' == $sub ) {
776 global $wgExtraSubtitle;
777 $sub = wfMsg( 'tagline' ) . $wgExtraSubtitle;
778 }
779 $subpages = $this->subPageSubtitle();
780 $sub .= !empty($subpages)?"</p><p class='subpages'>$subpages":'';
781 $s = "<p class='subtitle'>{$sub}</p>\n";
782 return $s;
783 }
784
785 function subPageSubtitle() {
786 global $wgOut,$wgTitle,$wgNamespacesWithSubpages;
787 $subpages = '';
788 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
789 $ptext=$wgTitle->getPrefixedText();
790 if(preg_match('/\//',$ptext)) {
791 $links = explode('/',$ptext);
792 $c = 0;
793 $growinglink = '';
794 foreach($links as $link) {
795 $c++;
796 if ($c<count($links)) {
797 $growinglink .= $link;
798 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
799 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
800 if ($c>1) {
801 $subpages .= ' | ';
802 } else {
803 $subpages .= '&lt; ';
804 }
805 $subpages .= $getlink;
806 $growinglink .= '/';
807 }
808 }
809 }
810 }
811 return $subpages;
812 }
813
814 function nameAndLogin() {
815 global $wgUser, $wgTitle, $wgLang, $wgContLang, $wgShowIPinHeader;
816
817 $li = $wgContLang->specialPage( 'Userlogin' );
818 $lo = $wgContLang->specialPage( 'Userlogout' );
819
820 $s = '';
821 if ( $wgUser->isAnon() ) {
822 if( $wgShowIPinHeader && isset( $_COOKIE[ini_get('session.name')] ) ) {
823 $n = wfGetIP();
824
825 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
826 $wgLang->getNsText( NS_TALK ) );
827
828 $s .= $n . ' ('.$tl.')';
829 } else {
830 $s .= wfMsg('notloggedin');
831 }
832
833 $rt = $wgTitle->getPrefixedURL();
834 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
835 $q = '';
836 } else { $q = "returnto={$rt}"; }
837
838 $s .= "\n<br />" . $this->makeKnownLinkObj(
839 SpecialPage::getTitleFor( 'Userlogin' ),
840 wfMsg( 'login' ), $q );
841 } else {
842 $n = $wgUser->getName();
843 $rt = $wgTitle->getPrefixedURL();
844 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
845 $wgLang->getNsText( NS_TALK ) );
846
847 $tl = " ({$tl})";
848
849 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
850 $n ) . "{$tl}<br />" .
851 $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
852 "returnto={$rt}" ) . ' | ' .
853 $this->specialLink( 'preferences' );
854 }
855 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
856 wfMsg( 'help' ) );
857
858 return $s;
859 }
860
861 function getSearchLink() {
862 $searchPage =& SpecialPage::getTitleFor( 'Search' );
863 return $searchPage->getLocalURL();
864 }
865
866 function escapeSearchLink() {
867 return htmlspecialchars( $this->getSearchLink() );
868 }
869
870 function searchForm() {
871 global $wgRequest;
872 $search = $wgRequest->getText( 'search' );
873
874 $s = '<form name="search" class="inline" method="post" action="'
875 . $this->escapeSearchLink() . "\">\n"
876 . '<input type="text" name="search" size="19" value="'
877 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
878 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
879 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
880
881 return $s;
882 }
883
884 function topLinks() {
885 global $wgOut;
886 $sep = " |\n";
887
888 $s = $this->mainPageLink() . $sep
889 . $this->specialLink( 'recentchanges' );
890
891 if ( $wgOut->isArticleRelated() ) {
892 $s .= $sep . $this->editThisPage()
893 . $sep . $this->historyLink();
894 }
895 # Many people don't like this dropdown box
896 #$s .= $sep . $this->specialPagesList();
897
898 $s .= $this->variantLinks();
899
900 $s .= $this->extensionTabLinks();
901
902 return $s;
903 }
904
905 /**
906 * Compatibility for extensions adding functionality through tabs.
907 * Eventually these old skins should be replaced with SkinTemplate-based
908 * versions, sigh...
909 * @return string
910 */
911 function extensionTabLinks() {
912 $tabs = array();
913 $s = '';
914 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
915 foreach( $tabs as $tab ) {
916 $s .= ' | ' . Xml::element( 'a',
917 array( 'href' => $tab['href'] ),
918 $tab['text'] );
919 }
920 return $s;
921 }
922
923 /**
924 * Language/charset variant links for classic-style skins
925 * @return string
926 */
927 function variantLinks() {
928 $s = '';
929 /* show links to different language variants */
930 global $wgDisableLangConversion, $wgContLang, $wgTitle;
931 $variants = $wgContLang->getVariants();
932 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
933 foreach( $variants as $code ) {
934 $varname = $wgContLang->getVariantname( $code );
935 if( $varname == 'disable' )
936 continue;
937 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
938 }
939 }
940 return $s;
941 }
942
943 function bottomLinks() {
944 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
945 $sep = " |\n";
946
947 $s = '';
948 if ( $wgOut->isArticleRelated() ) {
949 $s .= '<strong>' . $this->editThisPage() . '</strong>';
950 if ( $wgUser->isLoggedIn() ) {
951 $s .= $sep . $this->watchThisPage();
952 }
953 $s .= $sep . $this->talkLink()
954 . $sep . $this->historyLink()
955 . $sep . $this->whatLinksHere()
956 . $sep . $this->watchPageLinksLink();
957
958 if ($wgUseTrackbacks)
959 $s .= $sep . $this->trackbackLink();
960
961 if ( $wgTitle->getNamespace() == NS_USER
962 || $wgTitle->getNamespace() == NS_USER_TALK )
963
964 {
965 $id=User::idFromName($wgTitle->getText());
966 $ip=User::isIP($wgTitle->getText());
967
968 if($id || $ip) { # both anons and non-anons have contri list
969 $s .= $sep . $this->userContribsLink();
970 }
971 if( $this->showEmailUser( $id ) ) {
972 $s .= $sep . $this->emailUserLink();
973 }
974 }
975 if ( $wgTitle->getArticleId() ) {
976 $s .= "\n<br />";
977 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
978 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
979 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
980 }
981 $s .= "<br />\n" . $this->otherLanguages();
982 }
983 return $s;
984 }
985
986 function pageStats() {
987 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
988 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
989
990 extract( $wgRequest->getValues( 'oldid', 'diff' ) );
991 if ( ! $wgOut->isArticle() ) { return ''; }
992 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
993 if ( 0 == $wgArticle->getID() ) { return ''; }
994
995 $s = '';
996 if ( !$wgDisableCounters ) {
997 $count = $wgLang->formatNum( $wgArticle->getCount() );
998 if ( $count ) {
999 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1000 }
1001 }
1002
1003 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
1004 require_once('Credits.php');
1005 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1006 } else {
1007 $s .= $this->lastModified();
1008 }
1009
1010 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
1011 $dbr =& wfGetDB( DB_SLAVE );
1012 extract( $dbr->tableNames( 'watchlist' ) );
1013 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1014 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBKey()) .
1015 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1016 $res = $dbr->query( $sql, 'Skin::pageStats');
1017 $x = $dbr->fetchObject( $res );
1018 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
1019 }
1020
1021 return $s . ' ' . $this->getCopyright();
1022 }
1023
1024 function getCopyright( $type = 'detect' ) {
1025 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1026
1027 if ( $type == 'detect' ) {
1028 $oldid = $wgRequest->getVal( 'oldid' );
1029 $diff = $wgRequest->getVal( 'diff' );
1030
1031 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1032 $type = 'history';
1033 } else {
1034 $type = 'normal';
1035 }
1036 }
1037
1038 if ( $type == 'history' ) {
1039 $msg = 'history_copyright';
1040 } else {
1041 $msg = 'copyright';
1042 }
1043
1044 $out = '';
1045 if( $wgRightsPage ) {
1046 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1047 } elseif( $wgRightsUrl ) {
1048 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1049 } else {
1050 # Give up now
1051 return $out;
1052 }
1053 $out .= wfMsgForContent( $msg, $link );
1054 return $out;
1055 }
1056
1057 function getCopyrightIcon() {
1058 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1059 $out = '';
1060 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1061 $out = $wgCopyrightIcon;
1062 } else if ( $wgRightsIcon ) {
1063 $icon = htmlspecialchars( $wgRightsIcon );
1064 if ( $wgRightsUrl ) {
1065 $url = htmlspecialchars( $wgRightsUrl );
1066 $out .= '<a href="'.$url.'">';
1067 }
1068 $text = htmlspecialchars( $wgRightsText );
1069 $out .= "<img src=\"$icon\" alt='$text' />";
1070 if ( $wgRightsUrl ) {
1071 $out .= '</a>';
1072 }
1073 }
1074 return $out;
1075 }
1076
1077 function getPoweredBy() {
1078 global $wgStylePath;
1079 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1080 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="MediaWiki" /></a>';
1081 return $img;
1082 }
1083
1084 function lastModified() {
1085 global $wgLang, $wgArticle, $wgLoadBalancer;
1086
1087 $timestamp = $wgArticle->getTimestamp();
1088 if ( $timestamp ) {
1089 $d = $wgLang->date( $timestamp, true );
1090 $t = $wgLang->time( $timestamp, true );
1091 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1092 } else {
1093 $s = '';
1094 }
1095 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1096 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1097 }
1098 return $s;
1099 }
1100
1101 function logoText( $align = '' ) {
1102 if ( '' != $align ) { $a = " align='{$align}'"; }
1103 else { $a = ''; }
1104
1105 $mp = wfMsg( 'mainpage' );
1106 $titleObj = Title::newFromText( $mp );
1107 if ( is_object( $titleObj ) ) {
1108 $url = $titleObj->escapeLocalURL();
1109 } else {
1110 $url = '';
1111 }
1112
1113 $logourl = $this->getLogo();
1114 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1115 return $s;
1116 }
1117
1118 /**
1119 * show a drop-down box of special pages
1120 */
1121 function specialPagesList() {
1122 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1123 $a = array();
1124 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1125 foreach ( $pages as $name => $page ) {
1126 $pages[$name] = $page->getDescription();
1127 }
1128
1129 $go = wfMsg( 'go' );
1130 $sp = wfMsg( 'specialpages' );
1131 $spp = $wgContLang->specialPage( 'Specialpages' );
1132
1133 $s = '<form id="specialpages" method="get" class="inline" ' .
1134 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1135 $s .= "<select name=\"wpDropdown\">\n";
1136 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1137
1138
1139 foreach ( $pages as $name => $desc ) {
1140 $p = $wgContLang->specialPage( $name );
1141 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1142 }
1143 $s .= "</select>\n";
1144 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1145 $s .= "</form>\n";
1146 return $s;
1147 }
1148
1149 function mainPageLink() {
1150 $mp = wfMsgForContent( 'mainpage' );
1151 $mptxt = wfMsg( 'mainpage');
1152 $s = $this->makeKnownLink( $mp, $mptxt );
1153 return $s;
1154 }
1155
1156 function copyrightLink() {
1157 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1158 wfMsg( 'copyrightpagename' ) );
1159 return $s;
1160 }
1161
1162 function privacyLink() {
1163 $privacy = wfMsg( 'privacy' );
1164 if ($privacy == '-') {
1165 return '';
1166 } else {
1167 return $this->makeKnownLink( wfMsgForContent( 'privacypage' ), $privacy);
1168 }
1169 }
1170
1171 function aboutLink() {
1172 $s = $this->makeKnownLink( wfMsgForContent( 'aboutpage' ),
1173 wfMsg( 'aboutsite' ) );
1174 return $s;
1175 }
1176
1177 function disclaimerLink() {
1178 $disclaimers = wfMsg( 'disclaimers' );
1179 if ($disclaimers == '-') {
1180 return '';
1181 } else {
1182 return $this->makeKnownLink( wfMsgForContent( 'disclaimerpage' ),
1183 $disclaimers );
1184 }
1185 }
1186
1187 function editThisPage() {
1188 global $wgOut, $wgTitle;
1189
1190 if ( ! $wgOut->isArticleRelated() ) {
1191 $s = wfMsg( 'protectedpage' );
1192 } else {
1193 if ( $wgTitle->userCanEdit() ) {
1194 $t = wfMsg( 'editthispage' );
1195 } else {
1196 $t = wfMsg( 'viewsource' );
1197 }
1198
1199 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1200 }
1201 return $s;
1202 }
1203
1204 /**
1205 * Return URL options for the 'edit page' link.
1206 * This may include an 'oldid' specifier, if the current page view is such.
1207 *
1208 * @return string
1209 * @private
1210 */
1211 function editUrlOptions() {
1212 global $wgArticle;
1213
1214 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1215 return "action=edit&oldid=" . intval( $this->mRevisionId );
1216 } else {
1217 return "action=edit";
1218 }
1219 }
1220
1221 function deleteThisPage() {
1222 global $wgUser, $wgTitle, $wgRequest;
1223
1224 $diff = $wgRequest->getVal( 'diff' );
1225 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1226 $t = wfMsg( 'deletethispage' );
1227
1228 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1229 } else {
1230 $s = '';
1231 }
1232 return $s;
1233 }
1234
1235 function protectThisPage() {
1236 global $wgUser, $wgTitle, $wgRequest;
1237
1238 $diff = $wgRequest->getVal( 'diff' );
1239 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1240 if ( $wgTitle->isProtected() ) {
1241 $t = wfMsg( 'unprotectthispage' );
1242 $q = 'action=unprotect';
1243 } else {
1244 $t = wfMsg( 'protectthispage' );
1245 $q = 'action=protect';
1246 }
1247 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1248 } else {
1249 $s = '';
1250 }
1251 return $s;
1252 }
1253
1254 function watchThisPage() {
1255 global $wgOut, $wgTitle;
1256
1257 if ( $wgOut->isArticleRelated() ) {
1258 if ( $wgTitle->userIsWatching() ) {
1259 $t = wfMsg( 'unwatchthispage' );
1260 $q = 'action=unwatch';
1261 } else {
1262 $t = wfMsg( 'watchthispage' );
1263 $q = 'action=watch';
1264 }
1265 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1266 } else {
1267 $s = wfMsg( 'notanarticle' );
1268 }
1269 return $s;
1270 }
1271
1272 function moveThisPage() {
1273 global $wgTitle;
1274
1275 if ( $wgTitle->userCanMove() ) {
1276 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1277 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1278 } else {
1279 // no message if page is protected - would be redundant
1280 return '';
1281 }
1282 }
1283
1284 function historyLink() {
1285 global $wgTitle;
1286
1287 return $this->makeKnownLinkObj( $wgTitle,
1288 wfMsg( 'history' ), 'action=history' );
1289 }
1290
1291 function whatLinksHere() {
1292 global $wgTitle;
1293
1294 return $this->makeKnownLinkObj(
1295 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1296 wfMsg( 'whatlinkshere' ) );
1297 }
1298
1299 function userContribsLink() {
1300 global $wgTitle;
1301
1302 return $this->makeKnownLinkObj(
1303 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1304 wfMsg( 'contributions' ) );
1305 }
1306
1307 function showEmailUser( $id ) {
1308 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1309 return $wgEnableEmail &&
1310 $wgEnableUserEmail &&
1311 $wgUser->isLoggedIn() && # show only to signed in users
1312 0 != $id; # we can only email to non-anons ..
1313 # '' != $id->getEmail() && # who must have an email address stored ..
1314 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1315 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1316 }
1317
1318 function emailUserLink() {
1319 global $wgTitle;
1320
1321 return $this->makeKnownLinkObj(
1322 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1323 wfMsg( 'emailuser' ) );
1324 }
1325
1326 function watchPageLinksLink() {
1327 global $wgOut, $wgTitle;
1328
1329 if ( ! $wgOut->isArticleRelated() ) {
1330 return '(' . wfMsg( 'notanarticle' ) . ')';
1331 } else {
1332 return $this->makeKnownLinkObj(
1333 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1334 wfMsg( 'recentchangeslinked' ) );
1335 }
1336 }
1337
1338 function trackbackLink() {
1339 global $wgTitle;
1340
1341 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1342 . wfMsg('trackbacklink') . "</a>";
1343 }
1344
1345 function otherLanguages() {
1346 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1347
1348 if ( $wgHideInterlanguageLinks ) {
1349 return '';
1350 }
1351
1352 $a = $wgOut->getLanguageLinks();
1353 if ( 0 == count( $a ) ) {
1354 return '';
1355 }
1356
1357 $s = wfMsg( 'otherlanguages' ) . ': ';
1358 $first = true;
1359 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1360 foreach( $a as $l ) {
1361 if ( ! $first ) { $s .= ' | '; }
1362 $first = false;
1363
1364 $nt = Title::newFromText( $l );
1365 $url = $nt->escapeFullURL();
1366 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1367
1368 if ( '' == $text ) { $text = $l; }
1369 $style = $this->getExternalLinkAttributes( $l, $text );
1370 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1371 }
1372 if($wgContLang->isRTL()) $s .= '</span>';
1373 return $s;
1374 }
1375
1376 function bugReportsLink() {
1377 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1378 wfMsg( 'bugreports' ) );
1379 return $s;
1380 }
1381
1382 function dateLink() {
1383 $t1 = Title::newFromText( gmdate( 'F j' ) );
1384 $t2 = Title::newFromText( gmdate( 'Y' ) );
1385
1386 $id = $t1->getArticleID();
1387
1388 if ( 0 == $id ) {
1389 $s = $this->makeBrokenLink( $t1->getText() );
1390 } else {
1391 $s = $this->makeKnownLink( $t1->getText() );
1392 }
1393 $s .= ', ';
1394
1395 $id = $t2->getArticleID();
1396
1397 if ( 0 == $id ) {
1398 $s .= $this->makeBrokenLink( $t2->getText() );
1399 } else {
1400 $s .= $this->makeKnownLink( $t2->getText() );
1401 }
1402 return $s;
1403 }
1404
1405 function talkLink() {
1406 global $wgTitle;
1407
1408 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1409 # No discussion links for special pages
1410 return '';
1411 }
1412
1413 if( $wgTitle->isTalkPage() ) {
1414 $link = $wgTitle->getSubjectPage();
1415 switch( $link->getNamespace() ) {
1416 case NS_MAIN:
1417 $text = wfMsg( 'articlepage' );
1418 break;
1419 case NS_USER:
1420 $text = wfMsg( 'userpage' );
1421 break;
1422 case NS_PROJECT:
1423 $text = wfMsg( 'projectpage' );
1424 break;
1425 case NS_IMAGE:
1426 $text = wfMsg( 'imagepage' );
1427 break;
1428 case NS_MEDIAWIKI:
1429 $text = wfMsg( 'mediawikipage' );
1430 break;
1431 case NS_TEMPLATE:
1432 $text = wfMsg( 'templatepage' );
1433 break;
1434 case NS_HELP:
1435 $text = wfMsg( 'viewhelppage' );
1436 break;
1437 case NS_CATEGORY:
1438 $text = wfMsg( 'categorypage' );
1439 break;
1440 default:
1441 $text = wfMsg( 'articlepage' );
1442 }
1443 } else {
1444 $link = $wgTitle->getTalkPage();
1445 $text = wfMsg( 'talkpage' );
1446 }
1447
1448 $s = $this->makeLinkObj( $link, $text );
1449
1450 return $s;
1451 }
1452
1453 function commentLink() {
1454 global $wgTitle, $wgOut;
1455
1456 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1457 return '';
1458 }
1459
1460 # __NEWSECTIONLINK___ changes behaviour here
1461 # If it's present, the link points to this page, otherwise
1462 # it points to the talk page
1463 if( $wgTitle->isTalkPage() ) {
1464 $title =& $wgTitle;
1465 } elseif( $wgOut->showNewSectionLink() ) {
1466 $title =& $wgTitle;
1467 } else {
1468 $title =& $wgTitle->getTalkPage();
1469 }
1470
1471 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1472 }
1473
1474 /* these are used extensively in SkinTemplate, but also some other places */
1475 static function makeSpecialUrl( $name, $urlaction = '' ) {
1476 $title = SpecialPage::getTitleFor( $name );
1477 return $title->getLocalURL( $urlaction );
1478 }
1479
1480 static function makeI18nUrl( $name, $urlaction = '' ) {
1481 $title = Title::newFromText( wfMsgForContent( $name ) );
1482 self::checkTitle( $title, $name );
1483 return $title->getLocalURL( $urlaction );
1484 }
1485
1486 static function makeUrl( $name, $urlaction = '' ) {
1487 $title = Title::newFromText( $name );
1488 self::checkTitle( $title, $name );
1489 return $title->getLocalURL( $urlaction );
1490 }
1491
1492 # If url string starts with http, consider as external URL, else
1493 # internal
1494 static function makeInternalOrExternalUrl( $name ) {
1495 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1496 return $name;
1497 } else {
1498 return self::makeUrl( $name );
1499 }
1500 }
1501
1502 # this can be passed the NS number as defined in Language.php
1503 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1504 $title = Title::makeTitleSafe( $namespace, $name );
1505 self::checkTitle( $title, $name );
1506 return $title->getLocalURL( $urlaction );
1507 }
1508
1509 /* these return an array with the 'href' and boolean 'exists' */
1510 static function makeUrlDetails( $name, $urlaction = '' ) {
1511 $title = Title::newFromText( $name );
1512 self::checkTitle( $title, $name );
1513 return array(
1514 'href' => $title->getLocalURL( $urlaction ),
1515 'exists' => $title->getArticleID() != 0 ? true : false
1516 );
1517 }
1518
1519 /**
1520 * Make URL details where the article exists (or at least it's convenient to think so)
1521 */
1522 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1523 $title = Title::newFromText( $name );
1524 self::checkTitle( $title, $name );
1525 return array(
1526 'href' => $title->getLocalURL( $urlaction ),
1527 'exists' => true
1528 );
1529 }
1530
1531 # make sure we have some title to operate on
1532 static function checkTitle( &$title, &$name ) {
1533 if( !is_object( $title ) ) {
1534 $title = Title::newFromText( $name );
1535 if( !is_object( $title ) ) {
1536 $title = Title::newFromText( '--error: link target missing--' );
1537 }
1538 }
1539 }
1540
1541 /**
1542 * Build an array that represents the sidebar(s), the navigation bar among them
1543 *
1544 * @return array
1545 * @private
1546 */
1547 function buildSidebar() {
1548 global $parserMemc, $wgEnableSidebarCache;
1549 global $wgLang, $wgContLang;
1550
1551 $fname = 'SkinTemplate::buildSidebar';
1552
1553 wfProfileIn( $fname );
1554
1555 $key = wfMemcKey( 'sidebar' );
1556 $cacheSidebar = $wgEnableSidebarCache &&
1557 ($wgLang->getCode() == $wgContLang->getCode());
1558
1559 if ($cacheSidebar) {
1560 $cachedsidebar = $parserMemc->get( $key );
1561 if ($cachedsidebar!="") {
1562 wfProfileOut($fname);
1563 return $cachedsidebar;
1564 }
1565 }
1566
1567 $bar = array();
1568 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1569 foreach ($lines as $line) {
1570 if (strpos($line, '*') !== 0)
1571 continue;
1572 if (strpos($line, '**') !== 0) {
1573 $line = trim($line, '* ');
1574 $heading = $line;
1575 } else {
1576 if (strpos($line, '|') !== false) { // sanity check
1577 $line = explode( '|' , trim($line, '* '), 2 );
1578 $link = wfMsgForContent( $line[0] );
1579 if ($link == '-')
1580 continue;
1581 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1582 $text = $line[1];
1583 if (wfEmptyMsg($line[0], $link))
1584 $link = $line[0];
1585
1586 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1587 $href = $link;
1588 } else {
1589 $title = Title::newFromText( $link );
1590 $title = $title->fixSpecialName();
1591 $href = $title->getLocalURL();
1592 }
1593
1594 $bar[$heading][] = array(
1595 'text' => $text,
1596 'href' => $href,
1597 'id' => 'n-' . strtr($line[1], ' ', '-'),
1598 'active' => false
1599 );
1600 } else { continue; }
1601 }
1602 }
1603 if ($cacheSidebar)
1604 $cachednotice = $parserMemc->set( $key, $bar, 86400 );
1605 wfProfileOut( $fname );
1606 return $bar;
1607 }
1608 }
1609 ?>