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