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