fix synxtax
[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, $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 $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{$wgScriptExtension}",
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 $subpages = '';
845 if(!wfRunHooks('SkinSubPageSubtitle', array(&$subpages)))
846 return $retval;
847
848 global $wgOut, $wgTitle, $wgNamespacesWithSubpages;
849 if($wgOut->isArticle() && !empty($wgNamespacesWithSubpages[$wgTitle->getNamespace()])) {
850 $ptext=$wgTitle->getPrefixedText();
851 if(preg_match('/\//',$ptext)) {
852 $links = explode('/',$ptext);
853 $c = 0;
854 $growinglink = '';
855 foreach($links as $link) {
856 $c++;
857 if ($c<count($links)) {
858 $growinglink .= $link;
859 $getlink = $this->makeLink( $growinglink, htmlspecialchars( $link ) );
860 if(preg_match('/class="new"/i',$getlink)) { break; } # this is a hack, but it saves time
861 if ($c>1) {
862 $subpages .= ' | ';
863 } else {
864 $subpages .= '&lt; ';
865 }
866 $subpages .= $getlink;
867 $growinglink .= '/';
868 }
869 }
870 }
871 }
872 return $subpages;
873 }
874
875 /**
876 * Returns true if the IP should be shown in the header
877 */
878 function showIPinHeader() {
879 global $wgShowIPinHeader;
880 return $wgShowIPinHeader && session_id() != '';
881 }
882
883 function nameAndLogin() {
884 global $wgUser, $wgTitle, $wgLang, $wgContLang;
885
886 $lo = $wgContLang->specialPage( 'Userlogout' );
887
888 $s = '';
889 if ( $wgUser->isAnon() ) {
890 if( $this->showIPinHeader() ) {
891 $n = wfGetIP();
892
893 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
894 $wgLang->getNsText( NS_TALK ) );
895
896 $s .= $n . ' ('.$tl.')';
897 } else {
898 $s .= wfMsg('notloggedin');
899 }
900
901 $rt = $wgTitle->getPrefixedURL();
902 if ( 0 == strcasecmp( urlencode( $lo ), $rt ) ) {
903 $q = '';
904 } else { $q = "returnto={$rt}"; }
905
906 $s .= "\n<br />" . $this->makeKnownLinkObj(
907 SpecialPage::getTitleFor( 'Userlogin' ),
908 wfMsg( 'login' ), $q );
909 } else {
910 $n = $wgUser->getName();
911 $rt = $wgTitle->getPrefixedURL();
912 $tl = $this->makeKnownLinkObj( $wgUser->getTalkPage(),
913 $wgLang->getNsText( NS_TALK ) );
914
915 $tl = " ({$tl})";
916
917 $s .= $this->makeKnownLinkObj( $wgUser->getUserPage(),
918 $n ) . "{$tl}<br />" .
919 $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
920 "returnto={$rt}" ) . ' | ' .
921 $this->specialLink( 'preferences' );
922 }
923 $s .= ' | ' . $this->makeKnownLink( wfMsgForContent( 'helppage' ),
924 wfMsg( 'help' ) );
925
926 return $s;
927 }
928
929 function getSearchLink() {
930 $searchPage = SpecialPage::getTitleFor( 'Search' );
931 return $searchPage->getLocalURL();
932 }
933
934 function escapeSearchLink() {
935 return htmlspecialchars( $this->getSearchLink() );
936 }
937
938 function searchForm() {
939 global $wgRequest;
940 $search = $wgRequest->getText( 'search' );
941
942 $s = '<form name="search" class="inline" method="post" action="'
943 . $this->escapeSearchLink() . "\">\n"
944 . '<input type="text" name="search" size="19" value="'
945 . htmlspecialchars(substr($search,0,256)) . "\" />\n"
946 . '<input type="submit" name="go" value="' . wfMsg ('searcharticle') . '" />&nbsp;'
947 . '<input type="submit" name="fulltext" value="' . wfMsg ('searchbutton') . "\" />\n</form>";
948
949 return $s;
950 }
951
952 function topLinks() {
953 global $wgOut;
954 $sep = " |\n";
955
956 $s = $this->mainPageLink() . $sep
957 . $this->specialLink( 'recentchanges' );
958
959 if ( $wgOut->isArticleRelated() ) {
960 $s .= $sep . $this->editThisPage()
961 . $sep . $this->historyLink();
962 }
963 # Many people don't like this dropdown box
964 #$s .= $sep . $this->specialPagesList();
965
966 $s .= $this->variantLinks();
967
968 $s .= $this->extensionTabLinks();
969
970 return $s;
971 }
972
973 /**
974 * Compatibility for extensions adding functionality through tabs.
975 * Eventually these old skins should be replaced with SkinTemplate-based
976 * versions, sigh...
977 * @return string
978 */
979 function extensionTabLinks() {
980 $tabs = array();
981 $s = '';
982 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
983 foreach( $tabs as $tab ) {
984 $s .= ' | ' . Xml::element( 'a',
985 array( 'href' => $tab['href'] ),
986 $tab['text'] );
987 }
988 return $s;
989 }
990
991 /**
992 * Language/charset variant links for classic-style skins
993 * @return string
994 */
995 function variantLinks() {
996 $s = '';
997 /* show links to different language variants */
998 global $wgDisableLangConversion, $wgContLang, $wgTitle;
999 $variants = $wgContLang->getVariants();
1000 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1001 foreach( $variants as $code ) {
1002 $varname = $wgContLang->getVariantname( $code );
1003 if( $varname == 'disable' )
1004 continue;
1005 $s .= ' | <a href="' . $wgTitle->escapeLocalUrl( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>';
1006 }
1007 }
1008 return $s;
1009 }
1010
1011 function bottomLinks() {
1012 global $wgOut, $wgUser, $wgTitle, $wgUseTrackbacks;
1013 $sep = " |\n";
1014
1015 $s = '';
1016 if ( $wgOut->isArticleRelated() ) {
1017 $s .= '<strong>' . $this->editThisPage() . '</strong>';
1018 if ( $wgUser->isLoggedIn() ) {
1019 $s .= $sep . $this->watchThisPage();
1020 }
1021 $s .= $sep . $this->talkLink()
1022 . $sep . $this->historyLink()
1023 . $sep . $this->whatLinksHere()
1024 . $sep . $this->watchPageLinksLink();
1025
1026 if ($wgUseTrackbacks)
1027 $s .= $sep . $this->trackbackLink();
1028
1029 if ( $wgTitle->getNamespace() == NS_USER
1030 || $wgTitle->getNamespace() == NS_USER_TALK )
1031
1032 {
1033 $id=User::idFromName($wgTitle->getText());
1034 $ip=User::isIP($wgTitle->getText());
1035
1036 if($id || $ip) { # both anons and non-anons have contri list
1037 $s .= $sep . $this->userContribsLink();
1038 }
1039 if( $this->showEmailUser( $id ) ) {
1040 $s .= $sep . $this->emailUserLink();
1041 }
1042 }
1043 if ( $wgTitle->getArticleId() ) {
1044 $s .= "\n<br />";
1045 if($wgUser->isAllowed('delete')) { $s .= $this->deleteThisPage(); }
1046 if($wgUser->isAllowed('protect')) { $s .= $sep . $this->protectThisPage(); }
1047 if($wgUser->isAllowed('move')) { $s .= $sep . $this->moveThisPage(); }
1048 }
1049 $s .= "<br />\n" . $this->otherLanguages();
1050 }
1051 return $s;
1052 }
1053
1054 function pageStats() {
1055 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1056 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgTitle, $wgPageShowWatchingUsers;
1057
1058 $oldid = $wgRequest->getVal( 'oldid' );
1059 $diff = $wgRequest->getVal( 'diff' );
1060 if ( ! $wgOut->isArticle() ) { return ''; }
1061 if ( isset( $oldid ) || isset( $diff ) ) { return ''; }
1062 if ( 0 == $wgArticle->getID() ) { return ''; }
1063
1064 $s = '';
1065 if ( !$wgDisableCounters ) {
1066 $count = $wgLang->formatNum( $wgArticle->getCount() );
1067 if ( $count ) {
1068 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1069 }
1070 }
1071
1072 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
1073 require_once('Credits.php');
1074 $s .= ' ' . getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
1075 } else {
1076 $s .= $this->lastModified();
1077 }
1078
1079 if ($wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' )) {
1080 $dbr = wfGetDB( DB_SLAVE );
1081 $watchlist = $dbr->tableName( 'watchlist' );
1082 $sql = "SELECT COUNT(*) AS n FROM $watchlist
1083 WHERE wl_title='" . $dbr->strencode($wgTitle->getDBkey()) .
1084 "' AND wl_namespace=" . $wgTitle->getNamespace() ;
1085 $res = $dbr->query( $sql, 'Skin::pageStats');
1086 $x = $dbr->fetchObject( $res );
1087
1088 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1089 array( 'parseinline' ), $wgLang->formatNum($x->n)
1090 );
1091 }
1092
1093 return $s . ' ' . $this->getCopyright();
1094 }
1095
1096 function getCopyright( $type = 'detect' ) {
1097 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest;
1098
1099 if ( $type == 'detect' ) {
1100 $oldid = $wgRequest->getVal( 'oldid' );
1101 $diff = $wgRequest->getVal( 'diff' );
1102
1103 if ( !is_null( $oldid ) && is_null( $diff ) && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1104 $type = 'history';
1105 } else {
1106 $type = 'normal';
1107 }
1108 }
1109
1110 if ( $type == 'history' ) {
1111 $msg = 'history_copyright';
1112 } else {
1113 $msg = 'copyright';
1114 }
1115
1116 $out = '';
1117 if( $wgRightsPage ) {
1118 $link = $this->makeKnownLink( $wgRightsPage, $wgRightsText );
1119 } elseif( $wgRightsUrl ) {
1120 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1121 } else {
1122 # Give up now
1123 return $out;
1124 }
1125 $out .= wfMsgForContent( $msg, $link );
1126 return $out;
1127 }
1128
1129 function getCopyrightIcon() {
1130 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1131 $out = '';
1132 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1133 $out = $wgCopyrightIcon;
1134 } else if ( $wgRightsIcon ) {
1135 $icon = htmlspecialchars( $wgRightsIcon );
1136 if ( $wgRightsUrl ) {
1137 $url = htmlspecialchars( $wgRightsUrl );
1138 $out .= '<a href="'.$url.'">';
1139 }
1140 $text = htmlspecialchars( $wgRightsText );
1141 $out .= "<img src=\"$icon\" alt='$text' />";
1142 if ( $wgRightsUrl ) {
1143 $out .= '</a>';
1144 }
1145 }
1146 return $out;
1147 }
1148
1149 function getPoweredBy() {
1150 global $wgStylePath;
1151 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1152 $img = '<a href="http://www.mediawiki.org/"><img src="'.$url.'" alt="Powered by MediaWiki" /></a>';
1153 return $img;
1154 }
1155
1156 function lastModified() {
1157 global $wgLang, $wgArticle, $wgLoadBalancer;
1158
1159 $timestamp = $wgArticle->getTimestamp();
1160 if ( $timestamp ) {
1161 $d = $wgLang->date( $timestamp, true );
1162 $t = $wgLang->time( $timestamp, true );
1163 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1164 } else {
1165 $s = '';
1166 }
1167 if ( $wgLoadBalancer->getLaggedSlaveMode() ) {
1168 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1169 }
1170 return $s;
1171 }
1172
1173 function logoText( $align = '' ) {
1174 if ( '' != $align ) { $a = " align='{$align}'"; }
1175 else { $a = ''; }
1176
1177 $mp = wfMsg( 'mainpage' );
1178 $mptitle = Title::newMainPage();
1179 $url = ( is_object($mptitle) ? $mptitle->escapeLocalURL() : '' );
1180
1181 $logourl = $this->getLogo();
1182 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1183 return $s;
1184 }
1185
1186 /**
1187 * show a drop-down box of special pages
1188 */
1189 function specialPagesList() {
1190 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1191 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1192 foreach ( $pages as $name => $page ) {
1193 $pages[$name] = $page->getDescription();
1194 }
1195
1196 $go = wfMsg( 'go' );
1197 $sp = wfMsg( 'specialpages' );
1198 $spp = $wgContLang->specialPage( 'Specialpages' );
1199
1200 $s = '<form id="specialpages" method="get" class="inline" ' .
1201 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1202 $s .= "<select name=\"wpDropdown\">\n";
1203 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1204
1205
1206 foreach ( $pages as $name => $desc ) {
1207 $p = $wgContLang->specialPage( $name );
1208 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1209 }
1210 $s .= "</select>\n";
1211 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1212 $s .= "</form>\n";
1213 return $s;
1214 }
1215
1216 function mainPageLink() {
1217 $s = $this->makeKnownLinkObj( Title::newMainPage(), wfMsg( 'mainpage' ) );
1218 return $s;
1219 }
1220
1221 function copyrightLink() {
1222 $s = $this->makeKnownLink( wfMsgForContent( 'copyrightpage' ),
1223 wfMsg( 'copyrightpagename' ) );
1224 return $s;
1225 }
1226
1227 private function footerLink ( $desc, $page ) {
1228 // if the link description has been set to "-" in the default language,
1229 if ( wfMsgForContent( $desc ) == '-') {
1230 // then it is disabled, for all languages.
1231 return '';
1232 } else {
1233 // Otherwise, we display the link for the user, described in their
1234 // language (which may or may not be the same as the default language),
1235 // but we make the link target be the one site-wide page.
1236 return $this->makeKnownLink( wfMsgForContent( $page ),
1237 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) ) );
1238 }
1239 }
1240
1241 function privacyLink() {
1242 return $this->footerLink( 'privacy', 'privacypage' );
1243 }
1244
1245 function aboutLink() {
1246 return $this->footerLink( 'aboutsite', 'aboutpage' );
1247 }
1248
1249 function disclaimerLink() {
1250 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1251 }
1252
1253 function editThisPage() {
1254 global $wgOut, $wgTitle;
1255
1256 if ( ! $wgOut->isArticleRelated() ) {
1257 $s = wfMsg( 'protectedpage' );
1258 } else {
1259 if ( $wgTitle->userCan( 'edit' ) ) {
1260 $t = wfMsg( 'editthispage' );
1261 } else {
1262 $t = wfMsg( 'viewsource' );
1263 }
1264
1265 $s = $this->makeKnownLinkObj( $wgTitle, $t, $this->editUrlOptions() );
1266 }
1267 return $s;
1268 }
1269
1270 /**
1271 * Return URL options for the 'edit page' link.
1272 * This may include an 'oldid' specifier, if the current page view is such.
1273 *
1274 * @return string
1275 * @private
1276 */
1277 function editUrlOptions() {
1278 global $wgArticle;
1279
1280 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1281 return "action=edit&oldid=" . intval( $this->mRevisionId );
1282 } else {
1283 return "action=edit";
1284 }
1285 }
1286
1287 function deleteThisPage() {
1288 global $wgUser, $wgTitle, $wgRequest;
1289
1290 $diff = $wgRequest->getVal( 'diff' );
1291 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('delete') ) {
1292 $t = wfMsg( 'deletethispage' );
1293
1294 $s = $this->makeKnownLinkObj( $wgTitle, $t, 'action=delete' );
1295 } else {
1296 $s = '';
1297 }
1298 return $s;
1299 }
1300
1301 function protectThisPage() {
1302 global $wgUser, $wgTitle, $wgRequest;
1303
1304 $diff = $wgRequest->getVal( 'diff' );
1305 if ( $wgTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1306 if ( $wgTitle->isProtected() ) {
1307 $t = wfMsg( 'unprotectthispage' );
1308 $q = 'action=unprotect';
1309 } else {
1310 $t = wfMsg( 'protectthispage' );
1311 $q = 'action=protect';
1312 }
1313 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q );
1314 } else {
1315 $s = '';
1316 }
1317 return $s;
1318 }
1319
1320 function watchThisPage() {
1321 global $wgOut, $wgTitle;
1322 ++$this->mWatchLinkNum;
1323
1324 if ( $wgOut->isArticleRelated() ) {
1325 if ( $wgTitle->userIsWatching() ) {
1326 $t = wfMsg( 'unwatchthispage' );
1327 $q = 'action=unwatch';
1328 $id = "mw-unwatch-link".$this->mWatchLinkNum;
1329 } else {
1330 $t = wfMsg( 'watchthispage' );
1331 $q = 'action=watch';
1332 $id = 'mw-watch-link'.$this->mWatchLinkNum;
1333 }
1334 $s = $this->makeKnownLinkObj( $wgTitle, $t, $q, '', '', " id=\"$id\"" );
1335 } else {
1336 $s = wfMsg( 'notanarticle' );
1337 }
1338 return $s;
1339 }
1340
1341 function moveThisPage() {
1342 global $wgTitle;
1343
1344 if ( $wgTitle->userCan( 'move' ) ) {
1345 return $this->makeKnownLinkObj( SpecialPage::getTitleFor( 'Movepage' ),
1346 wfMsg( 'movethispage' ), 'target=' . $wgTitle->getPrefixedURL() );
1347 } else {
1348 // no message if page is protected - would be redundant
1349 return '';
1350 }
1351 }
1352
1353 function historyLink() {
1354 global $wgTitle;
1355
1356 return $this->makeKnownLinkObj( $wgTitle,
1357 wfMsg( 'history' ), 'action=history' );
1358 }
1359
1360 function whatLinksHere() {
1361 global $wgTitle;
1362
1363 return $this->makeKnownLinkObj(
1364 SpecialPage::getTitleFor( 'Whatlinkshere', $wgTitle->getPrefixedDBkey() ),
1365 wfMsg( 'whatlinkshere' ) );
1366 }
1367
1368 function userContribsLink() {
1369 global $wgTitle;
1370
1371 return $this->makeKnownLinkObj(
1372 SpecialPage::getTitleFor( 'Contributions', $wgTitle->getDBkey() ),
1373 wfMsg( 'contributions' ) );
1374 }
1375
1376 function showEmailUser( $id ) {
1377 global $wgEnableEmail, $wgEnableUserEmail, $wgUser;
1378 return $wgEnableEmail &&
1379 $wgEnableUserEmail &&
1380 $wgUser->isLoggedIn() && # show only to signed in users
1381 0 != $id; # we can only email to non-anons ..
1382 # '' != $id->getEmail() && # who must have an email address stored ..
1383 # 0 != $id->getEmailauthenticationtimestamp() && # .. which is authenticated
1384 # 1 != $wgUser->getOption('disablemail'); # and not disabled
1385 }
1386
1387 function emailUserLink() {
1388 global $wgTitle;
1389
1390 return $this->makeKnownLinkObj(
1391 SpecialPage::getTitleFor( 'Emailuser', $wgTitle->getDBkey() ),
1392 wfMsg( 'emailuser' ) );
1393 }
1394
1395 function watchPageLinksLink() {
1396 global $wgOut, $wgTitle;
1397
1398 if ( ! $wgOut->isArticleRelated() ) {
1399 return '(' . wfMsg( 'notanarticle' ) . ')';
1400 } else {
1401 return $this->makeKnownLinkObj(
1402 SpecialPage::getTitleFor( 'Recentchangeslinked', $wgTitle->getPrefixedDBkey() ),
1403 wfMsg( 'recentchangeslinked' ) );
1404 }
1405 }
1406
1407 function trackbackLink() {
1408 global $wgTitle;
1409
1410 return "<a href=\"" . $wgTitle->trackbackURL() . "\">"
1411 . wfMsg('trackbacklink') . "</a>";
1412 }
1413
1414 function otherLanguages() {
1415 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1416
1417 if ( $wgHideInterlanguageLinks ) {
1418 return '';
1419 }
1420
1421 $a = $wgOut->getLanguageLinks();
1422 if ( 0 == count( $a ) ) {
1423 return '';
1424 }
1425
1426 $s = wfMsg( 'otherlanguages' ) . ': ';
1427 $first = true;
1428 if($wgContLang->isRTL()) $s .= '<span dir="LTR">';
1429 foreach( $a as $l ) {
1430 if ( ! $first ) { $s .= ' | '; }
1431 $first = false;
1432
1433 $nt = Title::newFromText( $l );
1434 $url = $nt->escapeFullURL();
1435 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1436
1437 if ( '' == $text ) { $text = $l; }
1438 $style = $this->getExternalLinkAttributes( $l, $text );
1439 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1440 }
1441 if($wgContLang->isRTL()) $s .= '</span>';
1442 return $s;
1443 }
1444
1445 function bugReportsLink() {
1446 $s = $this->makeKnownLink( wfMsgForContent( 'bugreportspage' ),
1447 wfMsg( 'bugreports' ) );
1448 return $s;
1449 }
1450
1451 function talkLink() {
1452 global $wgTitle;
1453
1454 if ( NS_SPECIAL == $wgTitle->getNamespace() ) {
1455 # No discussion links for special pages
1456 return '';
1457 }
1458
1459 if( $wgTitle->isTalkPage() ) {
1460 $link = $wgTitle->getSubjectPage();
1461 switch( $link->getNamespace() ) {
1462 case NS_MAIN:
1463 $text = wfMsg( 'articlepage' );
1464 break;
1465 case NS_USER:
1466 $text = wfMsg( 'userpage' );
1467 break;
1468 case NS_PROJECT:
1469 $text = wfMsg( 'projectpage' );
1470 break;
1471 case NS_IMAGE:
1472 $text = wfMsg( 'imagepage' );
1473 break;
1474 case NS_MEDIAWIKI:
1475 $text = wfMsg( 'mediawikipage' );
1476 break;
1477 case NS_TEMPLATE:
1478 $text = wfMsg( 'templatepage' );
1479 break;
1480 case NS_HELP:
1481 $text = wfMsg( 'viewhelppage' );
1482 break;
1483 case NS_CATEGORY:
1484 $text = wfMsg( 'categorypage' );
1485 break;
1486 default:
1487 $text = wfMsg( 'articlepage' );
1488 }
1489 } else {
1490 $link = $wgTitle->getTalkPage();
1491 $text = wfMsg( 'talkpage' );
1492 }
1493
1494 $s = $this->makeLinkObj( $link, $text );
1495
1496 return $s;
1497 }
1498
1499 function commentLink() {
1500 global $wgTitle, $wgOut;
1501
1502 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
1503 return '';
1504 }
1505
1506 # __NEWSECTIONLINK___ changes behaviour here
1507 # If it's present, the link points to this page, otherwise
1508 # it points to the talk page
1509 if( $wgTitle->isTalkPage() ) {
1510 $title = $wgTitle;
1511 } elseif( $wgOut->showNewSectionLink() ) {
1512 $title = $wgTitle;
1513 } else {
1514 $title = $wgTitle->getTalkPage();
1515 }
1516
1517 return $this->makeKnownLinkObj( $title, wfMsg( 'postcomment' ), 'action=edit&section=new' );
1518 }
1519
1520 /* these are used extensively in SkinTemplate, but also some other places */
1521 static function makeMainPageUrl( $urlaction = '' ) {
1522 $title = Title::newMainPage();
1523 self::checkTitle( $title, '' );
1524 return $title->getLocalURL( $urlaction );
1525 }
1526
1527 static function makeSpecialUrl( $name, $urlaction = '' ) {
1528 $title = SpecialPage::getTitleFor( $name );
1529 return $title->getLocalURL( $urlaction );
1530 }
1531
1532 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1533 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1534 return $title->getLocalURL( $urlaction );
1535 }
1536
1537 static function makeI18nUrl( $name, $urlaction = '' ) {
1538 $title = Title::newFromText( wfMsgForContent( $name ) );
1539 self::checkTitle( $title, $name );
1540 return $title->getLocalURL( $urlaction );
1541 }
1542
1543 static function makeUrl( $name, $urlaction = '' ) {
1544 $title = Title::newFromText( $name );
1545 self::checkTitle( $title, $name );
1546 return $title->getLocalURL( $urlaction );
1547 }
1548
1549 # If url string starts with http, consider as external URL, else
1550 # internal
1551 static function makeInternalOrExternalUrl( $name ) {
1552 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1553 return $name;
1554 } else {
1555 return self::makeUrl( $name );
1556 }
1557 }
1558
1559 # this can be passed the NS number as defined in Language.php
1560 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1561 $title = Title::makeTitleSafe( $namespace, $name );
1562 self::checkTitle( $title, $name );
1563 return $title->getLocalURL( $urlaction );
1564 }
1565
1566 /* these return an array with the 'href' and boolean 'exists' */
1567 static function makeUrlDetails( $name, $urlaction = '' ) {
1568 $title = Title::newFromText( $name );
1569 self::checkTitle( $title, $name );
1570 return array(
1571 'href' => $title->getLocalURL( $urlaction ),
1572 'exists' => $title->getArticleID() != 0 ? true : false
1573 );
1574 }
1575
1576 /**
1577 * Make URL details where the article exists (or at least it's convenient to think so)
1578 */
1579 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1580 $title = Title::newFromText( $name );
1581 self::checkTitle( $title, $name );
1582 return array(
1583 'href' => $title->getLocalURL( $urlaction ),
1584 'exists' => true
1585 );
1586 }
1587
1588 # make sure we have some title to operate on
1589 static function checkTitle( &$title, $name ) {
1590 if( !is_object( $title ) ) {
1591 $title = Title::newFromText( $name );
1592 if( !is_object( $title ) ) {
1593 $title = Title::newFromText( '--error: link target missing--' );
1594 }
1595 }
1596 }
1597
1598 /**
1599 * Build an array that represents the sidebar(s), the navigation bar among them
1600 *
1601 * @return array
1602 * @private
1603 */
1604 function buildSidebar() {
1605 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
1606 global $wgLang, $wgContLang;
1607
1608 $fname = 'SkinTemplate::buildSidebar';
1609
1610 wfProfileIn( $fname );
1611
1612 $key = wfMemcKey( 'sidebar' );
1613 $cacheSidebar = $wgEnableSidebarCache &&
1614 ($wgLang->getCode() == $wgContLang->getCode());
1615
1616 if ($cacheSidebar) {
1617 $cachedsidebar = $parserMemc->get( $key );
1618 if ($cachedsidebar!="") {
1619 wfProfileOut($fname);
1620 return $cachedsidebar;
1621 }
1622 }
1623
1624 $bar = array();
1625 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
1626 $heading = '';
1627 foreach ($lines as $line) {
1628 if (strpos($line, '*') !== 0)
1629 continue;
1630 if (strpos($line, '**') !== 0) {
1631 $line = trim($line, '* ');
1632 $heading = $line;
1633 } else {
1634 if (strpos($line, '|') !== false) { // sanity check
1635 $line = explode( '|' , trim($line, '* '), 2 );
1636 $link = wfMsgForContent( $line[0] );
1637 if ($link == '-')
1638 continue;
1639 if (wfEmptyMsg($line[1], $text = wfMsg($line[1])))
1640 $text = $line[1];
1641 if (wfEmptyMsg($line[0], $link))
1642 $link = $line[0];
1643
1644 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
1645 $href = $link;
1646 } else {
1647 $title = Title::newFromText( $link );
1648 if ( $title ) {
1649 $title = $title->fixSpecialName();
1650 $href = $title->getLocalURL();
1651 } else {
1652 $href = 'INVALID-TITLE';
1653 }
1654 }
1655
1656 $bar[$heading][] = array(
1657 'text' => $text,
1658 'href' => $href,
1659 'id' => 'n-' . strtr($line[1], ' ', '-'),
1660 'active' => false
1661 );
1662 } else { continue; }
1663 }
1664 }
1665 if ($cacheSidebar)
1666 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
1667 wfProfileOut( $fname );
1668 return $bar;
1669 }
1670
1671 }