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