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