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