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