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