(bug 11562) API: Added a user_registration parameter/field to the list=allusers query...
[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, $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' ), $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 $s .= ' ' . wfMsg('number_of_watching_users_pageview', $x->n );
1083 }
1084
1085 return $s . ' ' . $this->getCopyright();
1086 }
1087
1088 function getCopyright( $type = 'detect' ) {
1089 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1090
1091 if ( $type == 'detect' ) {
1092 $oldid = $wgRequest->getVal( 'oldid' );
1093 $diff = $wgRequest->getVal( 'diff' );
1094
1095 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1096 $type = 'history';
1097 } else {
1098 $type = 'normal';
1099 }
1100 }
1101
1102 if ( $type == 'history' ) {
1103 $msg = 'history_copyright';
1104 } else {
1105 $msg = 'copyright';
1106 }
1107
1108 $out = '';
1109 if( $wgRightsPage ) {
1110 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1111 } elseif( $wgRightsUrl ) {
1112 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1113 } else {
1114 # Give up now
1115 return $out;
1116 }
1117 $out .= wfMsgForContent( $msg, $link );
1118 return $out;
1119 }
1120
1121 function getCopyrightIcon() {
1122 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1123 $out = '';
1124 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1125 $out = $wgCopyrightIcon;
1126 } else if ( $wgRightsIcon ) {
1127 $icon = htmlspecialchars( $wgRightsIcon );
1128 if ( $wgRightsUrl ) {
1129 $url = htmlspecialchars( $wgRightsUrl );
1130 $out .= '<a href="'.$url.'">';
1131 }
1132 $text = htmlspecialchars( $wgRightsText );
1133 $out .= "<img src=\"$icon\" alt='$text' />";
1134 if ( $wgRightsUrl ) {
1135 $out .= '</a>';
1136 }
1137 }
1138 return $out;
1139 }
1140
1141 function getPoweredBy() {
1142 global $wgStylePath;
1143 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1144 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1145 return $img;
1146 }
1147
1148 function lastModified() {
1149 global $wgLang, $wgArticle, $wgLoadBalancer;
1150
1151 $timestamp = $wgArticle->getTimestamp();
1152 if ( $timestamp ) {
1153 $d = $wgLang->date( $timestamp, true );
1154 $t = $wgLang->time( $timestamp, true );
1155 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1156 } else {
1157 $s = '';
1158 }
1159 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1160 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1161 }
1162 return $s;
1163 }
1164
1165 function logoText( $align = '' ) {
1166 if ( '' != $align ) { $a = " align='{$align}'"; }
1167 else { $a = ''; }
1168
1169 $mp = wfMsg( 'mainpage' );
1170 $mptitle = Title::newMainPage();
1171 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1172
1173 $logourl = $this->getLogo();
1174 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1175 return $s;
1176 }
1177
1178 /**
1179 * show a drop-down box of special pages
1180 */
1181 function specialPagesList() {
1182 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1183 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1184 foreach ( $pages as $name => $page ) {
1185 $pages[$name] = $page->getDescription();
1186 }
1187
1188 $go = wfMsg( 'go' );
1189 $sp = wfMsg( 'specialpages' );
1190 $spp = $wgContLang->specialPage( 'Specialpages' );
1191
1192 $s = '<form id="specialpages" method="get" class="inline" ' .
1193 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1194 $s .= "<select name=\"wpDropdown\">\n";
1195 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1196
1197
1198 foreach ( $pages as $name => $desc ) {
1199 $p = $wgContLang->specialPage( $name );
1200 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1201 }
1202 $s .= "</select>\n";
1203 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1204 $s .= "</form>\n";
1205 return $s;
1206 }
1207
1208 function mainPageLink() {
1209 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1210 return $s;
1211 }
1212
1213 function copyrightLink() {
1214 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1215 wfMsg( 'copyrightpagename' ) );
1216 return $s;
1217 }
1218
1219 private function footerLink ( $desc, $page ) {
1220 // if the link description has been set to "-" in the default language,
1221 if ( wfMsgForContent( $desc ) == '-') {
1222 // then it is disabled, for all languages.
1223 return '';
1224 } else {
1225 // Otherwise, we display the link for the user, described in their
1226 // language (which may or may not be the same as the default language),
1227 // but we make the link target be the one site-wide page.
1228 return $this->makeKnownLink( wfMsgForContent( $page ),
1229 wfMsgExt( $desc, array( 'parsemag', 'escape' ) ) );
1230 }
1231 }
1232
1233 function privacyLink() {
1234 return $this->footerLink( 'privacy', 'privacypage' );
1235 }
1236
1237 function aboutLink() {
1238 return $this->footerLink( 'aboutsite', 'aboutpage' );
1239 }
1240
1241 function disclaimerLink() {
1242 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1243 }
1244
1245 function editThisPage() {
1246 global $wgOut, $wgTitle;
1247
1248 if ( ! $wgOut->isArticleRelated() ) {
1249 $s = wfMsg( 'protectedpage' );
1250 } else {
1251 if ( $wgTitle->userCan( 'edit' ) ) {
1252 $t = wfMsg( 'editthispage' );
1253 } else {
1254 $t = wfMsg( 'viewsource' );
1255 }
1256
1257 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1258 }
1259 return $s;
1260 }
1261
1262 /**
1263 * Return URL options for the 'edit page' link.
1264 * This may include an 'oldid' specifier, if the current page view is such.
1265 *
1266 * @return string
1267 * @private
1268 */
1269 function editUrlOptions() {
1270 global $wgArticle;
1271
1272 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1273 return "action=edit&oldid=" . intval( $this->mRevisionId );
1274 } else {
1275 return "action=edit";
1276 }
1277 }
1278
1279 function deleteThisPage() {
1280 global $wgUser, $wgTitle, $wgRequest;
1281
1282 $diff = $wgRequest->getVal( 'diff' );
1283 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1284 $t = wfMsg( 'deletethispage' );
1285
1286 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1287 } else {
1288 $s = '';
1289 }
1290 return $s;
1291 }
1292
1293 function protectThisPage() {
1294 global $wgUser, $wgTitle, $wgRequest;
1295
1296 $diff = $wgRequest->getVal( 'diff' );
1297 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1298 if ( $wgTitle->isProtected() ) {
1299 $t = wfMsg( 'unprotectthispage' );
1300 $q = 'action=unprotect';
1301 } else {
1302 $t = wfMsg( 'protectthispage' );
1303 $q = 'action=protect';
1304 }
1305 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1306 } else {
1307 $s = '';
1308 }
1309 return $s;
1310 }
1311
1312 function watchThisPage() {
1313 global $wgOut, $wgTitle;
1314 ++$this->mWatchLinkNum;
1315
1316 if ( $wgOut->isArticleRelated() ) {
1317 if ( $wgTitle->userIsWatching() ) {
1318 $t = wfMsg( 'unwatchthispage' );
1319 $q = 'action=unwatch';
1320 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1321 } else {
1322 $t = wfMsg( 'watchthispage' );
1323 $q = 'action=watch';
1324 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1325 }
1326 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1327 } else {
1328 $s = wfMsg( 'notanarticle' );
1329 }
1330 return $s;
1331 }
1332
1333 function moveThisPage() {
1334 global $wgTitle;
1335
1336 if ( $wgTitle->userCan( 'move' ) ) {
1337 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1338 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1339 } else {
1340 // no message if page is protected - would be redundant
1341 return '';
1342 }
1343 }
1344
1345 function historyLink() {
1346 global $wgTitle;
1347
1348 return $this->makeKnownLinkObj( $wgTitle,
1349 wfMsg( 'history' ), 'action=history' );
1350 }
1351
1352 function whatLinksHere() {
1353 global $wgTitle;
1354
1355 return $this->makeKnownLinkObj(
1356 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1357 wfMsg( 'whatlinkshere' ) );
1358 }
1359
1360 function userContribsLink() {
1361 global $wgTitle;
1362
1363 return $this->makeKnownLinkObj(
1364 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1365 wfMsg( 'contributions' ) );
1366 }
1367
1368 function showEmailUser( $id ) {
1369 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1370 return $wgEnableEmail &&
1371 $wgEnableUserEmail &&
1372 $wgUser->isLoggedIn() && # show only to signed in users
1373 0 != $id; # we can only email to non-anons ..
1374 # '' != $id->getEmail() && # who must have an email address stored ..
1375 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1376 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1377 }
1378
1379 function emailUserLink() {
1380 global $wgTitle;
1381
1382 return $this->makeKnownLinkObj(
1383 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1384 wfMsg( 'emailuser' ) );
1385 }
1386
1387 function watchPageLinksLink() {
1388 global $wgOut, $wgTitle;
1389
1390 if ( ! $wgOut->isArticleRelated() ) {
1391 return '(' . wfMsg( 'notanarticle' ) . ')';
1392 } else {
1393 return $this->makeKnownLinkObj(
1394 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1395 wfMsg( 'recentchangeslinked' ) );
1396 }
1397 }
1398
1399 function trackbackLink() {
1400 global $wgTitle;
1401
1402 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1403 . wfMsg('trackbacklink') . "</a>";
1404 }
1405
1406 function otherLanguages() {
1407 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1408
1409 if ( $wgHideInterlanguageLinks ) {
1410 return '';
1411 }
1412
1413 $a = $wgOut->getLanguageLinks();
1414 if ( 0 == count( $a ) ) {
1415 return '';
1416 }
1417
1418 $s = wfMsg( 'otherlanguages' ) . ': ';
1419 $first = true;
1420 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1421 foreach( $a as $l ) {
1422 if ( ! $first ) { $s .= ' | '; }
1423 $first = false;
1424
1425 $nt = Title::newFromText( $l );
1426 $url = $nt->escapeFullURL();
1427 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1428
1429 if ( '' == $text ) { $text = $l; }
1430 $style = $this->getExternalLinkAttributes( $l, $text );
1431 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1432 }
1433 if($wgContLang->isRTL()) $s .= '</span>';
1434 return $s;
1435 }
1436
1437 function bugReportsLink() {
1438 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1439 wfMsg( 'bugreports' ) );
1440 return $s;
1441 }
1442
1443 function talkLink() {
1444 global $wgTitle;
1445
1446 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1447 # No discussion links for special pages
1448 return '';
1449 }
1450
1451 if( $wgTitle->isTalkPage() ) {
1452 $link = $wgTitle->getSubjectPage();
1453 switch( $link->getNamespace() ) {
1454 case NS_MAIN:
1455 $text = wfMsg( 'articlepage' );
1456 break;
1457 case NS_USER:
1458 $text = wfMsg( 'userpage' );
1459 break;
1460 case NS_PROJECT:
1461 $text = wfMsg( 'projectpage' );
1462 break;
1463 case NS_IMAGE:
1464 $text = wfMsg( 'imagepage' );
1465 break;
1466 case NS_MEDIAWIKI:
1467 $text = wfMsg( 'mediawikipage' );
1468 break;
1469 case NS_TEMPLATE:
1470 $text = wfMsg( 'templatepage' );
1471 break;
1472 case NS_HELP:
1473 $text = wfMsg( 'viewhelppage' );
1474 break;
1475 case NS_CATEGORY:
1476 $text = wfMsg( 'categorypage' );
1477 break;
1478 default:
1479 $text = wfMsg( 'articlepage' );
1480 }
1481 } else {
1482 $link = $wgTitle->getTalkPage();
1483 $text = wfMsg( 'talkpage' );
1484 }
1485
1486 $s = $this->makeLinkObj( $link, $text );
1487
1488 return $s;
1489 }
1490
1491 function commentLink() {
1492 global $wgTitle, $wgOut;
1493
1494 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1495 return '';
1496 }
1497
1498 # __NEWSECTIONLINK___ changes behaviour here
1499 # If it's present, the link points to this page, otherwise
1500 # it points to the talk page
1501 if( $wgTitle->isTalkPage() ) {
1502 $title =& $wgTitle;
1503 } elseif( $wgOut->showNewSectionLink() ) {
1504 $title =& $wgTitle;
1505 } else {
1506 $title =& $wgTitle->getTalkPage();
1507 }
1508
1509 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1510 }
1511
1512 /* these are used extensively in SkinTemplate, but also some other places */
1513 static function makeMainPageUrl( $urlaction = '' ) {
1514 $title = Title::newMainPage();
1515 self::checkTitle( $title, '' );
1516 return $title->getLocalURL( $urlaction );
1517 }
1518
1519 static function makeSpecialUrl( $name, $urlaction = '' ) {
1520 $title = SpecialPage::getTitleFor( $name );
1521 return $title->getLocalURL( $urlaction );
1522 }
1523
1524 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1525 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1526 return $title->getLocalURL( $urlaction );
1527 }
1528
1529 static function makeI18nUrl( $name, $urlaction = '' ) {
1530 $title = Title::newFromText( wfMsgForContent( $name ) );
1531 self::checkTitle( $title, $name );
1532 return $title->getLocalURL( $urlaction );
1533 }
1534
1535 static function makeUrl( $name, $urlaction = '' ) {
1536 $title = Title::newFromText( $name );
1537 self::checkTitle( $title, $name );
1538 return $title->getLocalURL( $urlaction );
1539 }
1540
1541 # If url string starts with http, consider as external URL, else
1542 # internal
1543 static function makeInternalOrExternalUrl( $name ) {
1544 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1545 return $name;
1546 } else {
1547 return self::makeUrl( $name );
1548 }
1549 }
1550
1551 # this can be passed the NS number as defined in Language.php
1552 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1553 $title = Title::makeTitleSafe( $namespace, $name );
1554 self::checkTitle( $title, $name );
1555 return $title->getLocalURL( $urlaction );
1556 }
1557
1558 /* these return an array with the 'href' and boolean 'exists' */
1559 static function makeUrlDetails( $name, $urlaction = '' ) {
1560 $title = Title::newFromText( $name );
1561 self::checkTitle( $title, $name );
1562 return array(
1563 'href' => $title->getLocalURL( $urlaction ),
1564 'exists' => $title->getArticleID() != 0 ? true : false
1565 );
1566 }
1567
1568 /**
1569 * Make URL details where the article exists (or at least it's convenient to think so)
1570 */
1571 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1572 $title = Title::newFromText( $name );
1573 self::checkTitle( $title, $name );
1574 return array(
1575 'href' => $title->getLocalURL( $urlaction ),
1576 'exists' => true
1577 );
1578 }
1579
1580 # make sure we have some title to operate on
1581 static function checkTitle( &$title, $name ) {
1582 if( !is_object( $title ) ) {
1583 $title = Title::newFromText( $name );
1584 if( !is_object( $title ) ) {
1585 $title = Title::newFromText( '--error: link target missing--' );
1586 }
1587 }
1588 }
1589
1590 /**
1591 * Build an array that represents the sidebar(s), the navigation bar among them
1592 *
1593 * @return array
1594 * @private
1595 */
1596 function buildSidebar() {
1597 global $parserMemc, $wgEnableSidebarCache;
1598 global $wgLang, $wgContLang;
1599
1600 $fname = 'SkinTemplate::buildSidebar';
1601
1602 wfProfileIn( $fname );
1603
1604 $key = wfMemcKey( 'sidebar' );
1605 $cacheSidebar = $wgEnableSidebarCache &&
1606 ($wgLang->getCode() == $wgContLang->getCode());
1607
1608 if ($cacheSidebar) {
1609 $cachedsidebar = $parserMemc->get( $key );
1610 if ($cachedsidebar!="") {
1611 wfProfileOut($fname);
1612 return $cachedsidebar;
1613 }
1614 }
1615
1616 $bar = array();
1617 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1618 foreach ($lines as $line) {
1619 if (strpos($line, '*') !== 0)
1620 continue;
1621 if (strpos($line, '**') !== 0) {
1622 $line = trim($line, '* ');
1623 $heading = $line;
1624 } else {
1625 if (strpos($line, '|') !== false) { // sanity check
1626 $line = explode( '|' , trim($line, '* '), 2 );
1627 $link = wfMsgForContent( $line[0] );
1628 if ($link == '-')
1629 continue;
1630 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1631 $text = $line[1];
1632 if (wfEmptyMsg($line[0], $link))
1633 $link = $line[0];
1634
1635 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1636 $href = $link;
1637 } else {
1638 $title = Title::newFromText( $link );
1639 if ( $title ) {
1640 $title = $title->fixSpecialName();
1641 $href = $title->getLocalURL();
1642 } else {
1643 $href = 'INVALID-TITLE';
1644 }
1645 }
1646
1647 $bar[$heading][] = array(
1648 'text' => $text,
1649 'href' => $href,
1650 'id' => 'n-' . strtr($line[1], ' ', '-'),
1651 'active' => false
1652 );
1653 } else { continue; }
1654 }
1655 }
1656 if ($cacheSidebar)
1657 $parserMemc->set( $key, $bar, 86400 );
1658 wfProfileOut( $fname );
1659 return $bar;
1660 }
1661
1662 }