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