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