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