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