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