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