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