94dfa7bd5335673c944f77c56be25db52b00e020
[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 /**
11 * The main skin class that provide methods and properties for all other skins.
12 * This base class is also the "Standard" skin.
13 *
14 * See docs/skin.txt for more information.
15 *
16 * @ingroup Skins
17 */
18 class Skin extends Linker {
19 /**#@+
20 * @private
21 */
22 var $mWatchLinkNum = 0; // Appended to end of watch link id's
23 // How many search boxes have we made? Avoid duplicate id's.
24 protected $searchboxes = '';
25 /**#@-*/
26 protected $mRevisionId; // The revision ID we're looking at, null if not applicable.
27 protected $skinname = 'standard';
28 // @todo Fixme: should be protected :-\
29 var $mTitle = null;
30
31 /** Constructor, call parent constructor */
32 function __construct() {
33 parent::__construct();
34 }
35
36 /**
37 * Fetch the set of available skins.
38 * @return array of strings
39 */
40 static function getSkinNames() {
41 global $wgValidSkinNames;
42 static $skinsInitialised = false;
43 if ( !$skinsInitialised ) {
44 # Get a list of available skins
45 # Build using the regular expression '^(.*).php$'
46 # Array keys are all lower case, array value keep the case used by filename
47 #
48 wfProfileIn( __METHOD__ . '-init' );
49 global $wgStyleDirectory;
50 $skinDir = dir( $wgStyleDirectory );
51
52 # while code from www.php.net
53 while( false !== ( $file = $skinDir->read() ) ) {
54 // Skip non-PHP files, hidden files, and '.dep' includes
55 $matches = array();
56 if( preg_match( '/^([^.]*)\.php$/', $file, $matches ) ) {
57 $aSkin = $matches[1];
58 $wgValidSkinNames[strtolower( $aSkin )] = $aSkin;
59 }
60 }
61 $skinDir->close();
62 $skinsInitialised = true;
63 wfProfileOut( __METHOD__ . '-init' );
64 }
65 return $wgValidSkinNames;
66 }
67
68 /**
69 * Fetch the list of usable skins in regards to $wgSkipSkins.
70 * Useful for Special:Preferences and other places where you
71 * only want to show skins users _can_ use.
72 * @return array of strings
73 */
74 public static function getUsableSkins() {
75 global $wgSkipSkins;
76 $usableSkins = self::getSkinNames();
77 foreach ( $wgSkipSkins as $skip ) {
78 unset( $usableSkins[$skip] );
79 }
80 return $usableSkins;
81 }
82
83 /**
84 * Normalize a skin preference value to a form that can be loaded.
85 * If a skin can't be found, it will fall back to the configured
86 * default (or the old 'Classic' skin if that's broken).
87 * @param $key String: 'monobook', 'standard', etc.
88 * @return string
89 */
90 static function normalizeKey( $key ) {
91 global $wgDefaultSkin;
92 $skinNames = Skin::getSkinNames();
93
94 if( $key == '' ) {
95 // Don't return the default immediately;
96 // in a misconfiguration we need to fall back.
97 $key = $wgDefaultSkin;
98 }
99
100 if( isset( $skinNames[$key] ) ) {
101 return $key;
102 }
103
104 // Older versions of the software used a numeric setting
105 // in the user preferences.
106 $fallback = array(
107 0 => $wgDefaultSkin,
108 1 => 'nostalgia',
109 2 => 'cologneblue'
110 );
111
112 if( isset( $fallback[$key] ) ) {
113 $key = $fallback[$key];
114 }
115
116 if( isset( $skinNames[$key] ) ) {
117 return $key;
118 } else if( isset( $skinNames[$wgDefaultSkin] ) ) {
119 return $wgDefaultSkin;
120 } else {
121 return 'vector';
122 }
123 }
124
125 /**
126 * Factory method for loading a skin of a given type
127 * @param $key String: 'monobook', 'standard', etc.
128 * @return Skin
129 */
130 static function &newFromKey( $key ) {
131 global $wgStyleDirectory;
132
133 $key = Skin::normalizeKey( $key );
134
135 $skinNames = Skin::getSkinNames();
136 $skinName = $skinNames[$key];
137 $className = 'Skin' . ucfirst( $key );
138
139 # Grab the skin class and initialise it.
140 if ( !class_exists( $className ) ) {
141 // Preload base classes to work around APC/PHP5 bug
142 $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
143 if( file_exists( $deps ) ) {
144 include_once( $deps );
145 }
146 require_once( "{$wgStyleDirectory}/{$skinName}.php" );
147
148 # Check if we got if not failback to default skin
149 if( !class_exists( $className ) ) {
150 # DO NOT die if the class isn't found. This breaks maintenance
151 # scripts and can cause a user account to be unrecoverable
152 # except by SQL manipulation if a previously valid skin name
153 # is no longer valid.
154 wfDebug( "Skin class does not exist: $className\n" );
155 $className = 'SkinVector';
156 require_once( "{$wgStyleDirectory}/Vector.php" );
157 }
158 }
159 $skin = new $className;
160 return $skin;
161 }
162
163 /** @return string path to the skin stylesheet */
164 function getStylesheet() {
165 return 'common/wikistandard.css';
166 }
167
168 /** @return string skin name */
169 public function getSkinName() {
170 return $this->skinname;
171 }
172
173 function qbSetting() {
174 global $wgOut, $wgUser;
175
176 if ( $wgOut->isQuickbarSuppressed() ) {
177 return 0;
178 }
179 $q = $wgUser->getOption( 'quickbar', 0 );
180 return $q;
181 }
182
183 function initPage( OutputPage $out ) {
184 global $wgFavicon, $wgAppleTouchIcon;
185
186 wfProfileIn( __METHOD__ );
187
188 # Generally the order of the favicon and apple-touch-icon links
189 # should not matter, but Konqueror (3.5.9 at least) incorrectly
190 # uses whichever one appears later in the HTML source. Make sure
191 # apple-touch-icon is specified first to avoid this.
192 if( false !== $wgAppleTouchIcon ) {
193 $out->addLink( array( 'rel' => 'apple-touch-icon', 'href' => $wgAppleTouchIcon ) );
194 }
195
196 if( false !== $wgFavicon ) {
197 $out->addLink( array( 'rel' => 'shortcut icon', 'href' => $wgFavicon ) );
198 }
199
200 # OpenSearch description link
201 $out->addLink( array(
202 'rel' => 'search',
203 'type' => 'application/opensearchdescription+xml',
204 'href' => wfScript( 'opensearch_desc' ),
205 'title' => wfMsgForContent( 'opensearch-desc' ),
206 ));
207
208 $this->addMetadataLinks( $out );
209
210 $this->mRevisionId = $out->mRevisionId;
211
212 $this->preloadExistence();
213
214 wfProfileOut( __METHOD__ );
215 }
216
217 /**
218 * Preload the existence of three commonly-requested pages in a single query
219 */
220 function preloadExistence() {
221 global $wgUser;
222
223 // User/talk link
224 $titles = array( $wgUser->getUserPage(), $wgUser->getTalkPage() );
225
226 // Other tab link
227 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
228 // nothing
229 } elseif ( $this->mTitle->isTalkPage() ) {
230 $titles[] = $this->mTitle->getSubjectPage();
231 } else {
232 $titles[] = $this->mTitle->getTalkPage();
233 }
234
235 $lb = new LinkBatch( $titles );
236 $lb->execute();
237 }
238
239 /**
240 * Adds metadata links (Creative Commons/Dublin Core/copyright) to the HTML
241 * output.
242 * @param $out Object: instance of OutputPage
243 */
244 function addMetadataLinks( OutputPage $out ) {
245 global $wgEnableDublinCoreRdf, $wgEnableCreativeCommonsRdf;
246 global $wgRightsPage, $wgRightsUrl;
247
248 if( $out->isArticleRelated() ) {
249 # note: buggy CC software only reads first "meta" link
250 if( $wgEnableCreativeCommonsRdf ) {
251 $out->addMetadataLink( array(
252 'title' => 'Creative Commons',
253 'type' => 'application/rdf+xml',
254 'href' => $this->mTitle->getLocalURL( 'action=creativecommons' ) )
255 );
256 }
257 if( $wgEnableDublinCoreRdf ) {
258 $out->addMetadataLink( array(
259 'title' => 'Dublin Core',
260 'type' => 'application/rdf+xml',
261 'href' => $this->mTitle->getLocalURL( 'action=dublincore' ) )
262 );
263 }
264 }
265 $copyright = '';
266 if( $wgRightsPage ) {
267 $copy = Title::newFromText( $wgRightsPage );
268 if( $copy ) {
269 $copyright = $copy->getLocalURL();
270 }
271 }
272 if( !$copyright && $wgRightsUrl ) {
273 $copyright = $wgRightsUrl;
274 }
275 if( $copyright ) {
276 $out->addLink( array(
277 'rel' => 'copyright',
278 'href' => $copyright )
279 );
280 }
281 }
282
283 /**
284 * Set some local variables
285 */
286 protected function setMembers() {
287 global $wgUser;
288 $this->mUser = $wgUser;
289 $this->userpage = $wgUser->getUserPage()->getPrefixedText();
290 $this->usercss = false;
291 }
292
293 /**
294 * Set the title
295 * @param $t Title object to use
296 */
297 public function setTitle( $t ) {
298 $this->mTitle = $t;
299 }
300
301 /** Get the title */
302 public function getTitle() {
303 return $this->mTitle;
304 }
305
306 /**
307 * Outputs the HTML generated by other functions.
308 * @param $out Object: instance of OutputPage
309 */
310 function outputPage( OutputPage $out ) {
311 global $wgDebugComments;
312 wfProfileIn( __METHOD__ );
313
314 $this->setMembers();
315 $this->initPage( $out );
316
317 // See self::afterContentHook() for documentation
318 $afterContent = $this->afterContentHook();
319
320 $out->out( $out->headElement( $this ) );
321
322 if ( $wgDebugComments ) {
323 $out->out( "<!-- Wiki debugging output:\n" .
324 $out->mDebugtext . "-->\n" );
325 }
326
327 $out->out( $this->beforeContent() );
328
329 $out->out( $out->mBodytext . "\n" );
330
331 $out->out( $this->afterContent() );
332
333 $out->out( $afterContent );
334
335 $out->out( $this->bottomScripts( $out ) );
336
337 $out->out( wfReportTime() );
338
339 $out->out( "\n</body></html>" );
340 wfProfileOut( __METHOD__ );
341 }
342
343 static function makeVariablesScript( $data ) {
344 if( $data ) {
345 return Html::inlineScript( 'mediaWiki.config.set(' . json_encode( $data ) . ');' );
346 } else {
347 return '';
348 }
349 }
350
351 /**
352 * Make a <script> tag containing global variables
353 * @param $skinName string Name of the skin
354 * The odd calling convention is for backwards compatibility
355 * @todo FIXME: Make this not depend on $wgTitle!
356 */
357 static function makeGlobalVariablesScript( $skinName ) {
358 if ( is_array( $skinName ) ) {
359 # Weird back-compat stuff.
360 $skinName = $skinName['skinname'];
361 }
362 global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension;
363 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
364 global $wgOut, $wgArticle;
365 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
366 global $wgUseAjax, $wgAjaxWatch;
367 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
368 global $wgRestrictionTypes;
369 global $wgDBname, $wgEnableMWSuggest;
370 global $wgSitename;
371
372 $ns = $wgTitle->getNamespace();
373 $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
374 $separatorTransTable = $wgContLang->separatorTransformTable();
375 $separatorTransTable = $separatorTransTable ? $separatorTransTable : array();
376 $compactSeparatorTransTable = array(
377 implode( "\t", array_keys( $separatorTransTable ) ),
378 implode( "\t", $separatorTransTable ),
379 );
380 $digitTransTable = $wgContLang->digitTransformTable();
381 $digitTransTable = $digitTransTable ? $digitTransTable : array();
382 $compactDigitTransTable = array(
383 implode( "\t", array_keys( $digitTransTable ) ),
384 implode( "\t", $digitTransTable ),
385 );
386
387 $mainPage = Title::newMainPage();
388 $vars = array(
389 'skin' => $skinName,
390 'stylepath' => $wgStylePath,
391 'wgUrlProtocols' => wfUrlProtocols(),
392 'wgArticlePath' => $wgArticlePath,
393 'wgScriptPath' => $wgScriptPath,
394 'wgScriptExtension' => $wgScriptExtension,
395 'wgScript' => $wgScript,
396 'wgVariantArticlePath' => $wgVariantArticlePath,
397 'wgActionPaths' => (object)$wgActionPaths,
398 'wgServer' => $wgServer,
399 'wgCanonicalNamespace' => $nsname,
400 'wgCanonicalSpecialPageName' => $ns == NS_SPECIAL ?
401 SpecialPage::resolveAlias( $wgTitle->getDBkey() ) : false, # bug 21115
402 'wgNamespaceNumber' => $wgTitle->getNamespace(),
403 'wgPageName' => $wgTitle->getPrefixedDBKey(),
404 'wgTitle' => $wgTitle->getText(),
405 'wgAction' => $wgRequest->getText( 'action', 'view' ),
406 'wgArticleId' => $wgTitle->getArticleId(),
407 'wgIsArticle' => $wgOut->isArticle(),
408 'wgUserName' => $wgUser->isAnon() ? null : $wgUser->getName(),
409 'wgUserGroups' => $wgUser->getEffectiveGroups(),
410 'wgUserLanguage' => $wgLang->getCode(),
411 'wgContentLanguage' => $wgContLang->getCode(),
412 'wgBreakFrames' => $wgBreakFrames,
413 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
414 'wgVersion' => $wgVersion,
415 'wgEnableAPI' => $wgEnableAPI,
416 'wgEnableWriteAPI' => $wgEnableWriteAPI,
417 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
418 'wgDigitTransformTable' => $compactDigitTransTable,
419 'wgMainPageTitle' => $mainPage ? $mainPage->getPrefixedText() : null,
420 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(),
421 'wgNamespaceIds' => $wgContLang->getNamespaceIds(),
422 'wgSiteName' => $wgSitename,
423 'wgCategories' => $wgOut->getCategories(),
424 );
425 if ( $wgContLang->hasVariants() ) {
426 $vars['wgUserVariant'] = $wgContLang->getPreferredVariant();
427 }
428
429 // if on upload page output the extension list & js_upload
430 if( SpecialPage::resolveAlias( $wgTitle->getDBkey() ) == 'Upload' ) {
431 global $wgFileExtensions;
432 $vars['wgFileExtensions'] = $wgFileExtensions;
433 }
434
435 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ) {
436 $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
437 $vars['wgDBname'] = $wgDBname;
438 $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
439 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
440 }
441
442 foreach( $wgRestrictionTypes as $type ) {
443 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
444 }
445
446 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
447 $msgs = (object)array();
448 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching',
449 'tooltip-ca-watch', 'tooltip-ca-unwatch' ) as $msgName ) {
450 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
451 }
452 $vars['wgAjaxWatch'] = $msgs;
453 }
454
455 // Allow extensions to add their custom variables to the global JS variables
456 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
457
458 return self::makeVariablesScript( $vars );
459 }
460
461 /**
462 * To make it harder for someone to slip a user a fake
463 * user-JavaScript or user-CSS preview, a random token
464 * is associated with the login session. If it's not
465 * passed back with the preview request, we won't render
466 * the code.
467 *
468 * @param $action String: 'edit', 'submit' etc.
469 * @return bool
470 */
471 public function userCanPreview( $action ) {
472 global $wgRequest, $wgUser;
473
474 if( $action != 'submit' ) {
475 return false;
476 }
477 if( !$wgRequest->wasPosted() ) {
478 return false;
479 }
480 if( !$this->mTitle->userCanEditCssSubpage() ) {
481 return false;
482 }
483 if( !$this->mTitle->userCanEditJsSubpage() ) {
484 return false;
485 }
486 return $wgUser->matchEditToken(
487 $wgRequest->getVal( 'wpEditToken' ) );
488 }
489
490 /**
491 * Generated JavaScript action=raw&gen=js
492 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
493 * nated together. For some bizarre reason, it does *not* return any
494 * custom user JS from subpages. Huh?
495 *
496 * There's absolutely no reason to have separate Monobook/Common JSes.
497 * Any JS that cares can just check the skin variable generated at the
498 * top. For now Monobook.js will be maintained, but it should be consi-
499 * dered deprecated.
500 *
501 * @param $skinName String: If set, overrides the skin name
502 * @return string
503 */
504 public function generateUserJs( $skinName = null ) {
505 global $wgStylePath;
506
507 wfProfileIn( __METHOD__ );
508 if( !$skinName ) {
509 $skinName = $this->getSkinName();
510 }
511
512 $s = "/* generated javascript */\n";
513 $s .= "var skin = '" . Xml::escapeJsString( $skinName ) . "';\n";
514 $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
515 $s .= "\n\n/* MediaWiki:Common.js */\n";
516 $commonJs = wfMsgExt( 'common.js', 'content' );
517 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
518 $s .= $commonJs;
519 }
520
521 $s .= "\n\n/* MediaWiki:" . ucfirst( $skinName ) . ".js */\n";
522 // avoid inclusion of non defined user JavaScript (with custom skins only)
523 // by checking for default message content
524 $msgKey = ucfirst( $skinName ) . '.js';
525 $userJS = wfMsgExt( $msgKey, 'content' );
526 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
527 $s .= $userJS;
528 }
529
530 wfProfileOut( __METHOD__ );
531 return $s;
532 }
533
534 /**
535 * Generate user stylesheet for action=raw&gen=css
536 */
537 public function generateUserStylesheet() {
538 wfProfileIn( __METHOD__ );
539 $s = "/* generated user stylesheet */\n" .
540 $this->reallyGenerateUserStylesheet();
541 wfProfileOut( __METHOD__ );
542 return $s;
543 }
544
545 /**
546 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
547 * Anything in here won't be generated if $wgAllowUserCssPrefs is false.
548 */
549 protected function reallyGenerateUserStylesheet() {
550 global $wgUser;
551 $s = '';
552 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
553 $underline = $undopt ? 'underline' : 'none';
554 $s .= "a { text-decoration: $underline; }\n";
555 }
556 if( $wgUser->getOption( 'highlightbroken' ) ) {
557 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
558 } else {
559 $s .= <<<CSS
560 a.new, #quickbar a.new,
561 a.stub, #quickbar a.stub {
562 color: inherit;
563 }
564 a.new:after, #quickbar a.new:after {
565 content: "?";
566 color: #CC2200;
567 }
568 a.stub:after, #quickbar a.stub:after {
569 content: "!";
570 color: #772233;
571 }
572 CSS;
573 }
574 if( $wgUser->getOption( 'justify' ) ) {
575 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
576 }
577 if( !$wgUser->getOption( 'showtoc' ) ) {
578 $s .= "#toc { display: none; }\n";
579 }
580 if( !$wgUser->getOption( 'editsection' ) ) {
581 $s .= ".editsection { display: none; }\n";
582 }
583 $fontstyle = $wgUser->getOption( 'editfont' );
584 if ( $fontstyle !== 'default' ) {
585 $s .= "textarea { font-family: $fontstyle; }\n";
586 }
587 return $s;
588 }
589
590 /**
591 * @private
592 */
593 function setupUserCss( OutputPage $out ) {
594 global $wgRequest, $wgUser;
595 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage;
596
597 wfProfileIn( __METHOD__ );
598
599 $this->setupSkinUserCss( $out );
600
601 $siteargs = array(
602 'action' => 'raw',
603 'maxage' => $wgSquidMaxage,
604 );
605
606 // Add any extension CSS
607 foreach ( $out->getExtStyle() as $url ) {
608 $out->addStyle( $url );
609 }
610
611 // If we use the site's dynamic CSS, throw that in, too
612 // Per-site custom styles
613 if( $wgUseSiteCss ) {
614 global $wgHandheldStyle;
615 $query = wfArrayToCGI( self::getDynamicStylesheetQuery() );
616 # Site settings must override extension css! (bug 15025)
617 $out->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) );
618 $out->addStyle( self::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI ), 'print' );
619 if( $wgHandheldStyle ) {
620 $out->addStyle( self::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI ), 'handheld' );
621 }
622 $out->addStyle( self::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI ) );
623 }
624
625 global $wgAllowUserCssPrefs;
626 if( $wgAllowUserCssPrefs ){
627 if( $wgUser->isLoggedIn() ) {
628 // Ensure that logged-in users' generated CSS isn't clobbered
629 // by anons' publicly cacheable generated CSS.
630 $siteargs['smaxage'] = '0';
631 $siteargs['ts'] = $wgUser->mTouched;
632 }
633 // Per-user styles based on preferences
634 $siteargs['gen'] = 'css';
635 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
636 $siteargs['useskin'] = $us;
637 }
638 $out->addStyle( self::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
639 }
640
641 // Per-user custom style pages
642 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
643 $action = $wgRequest->getVal( 'action' );
644 # If we're previewing the CSS page, use it
645 if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
646 // @FIXME: properly escape the cdata!
647 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
648 } else {
649 $names = array( 'common', $this->getSkinName() );
650 foreach( $names as $name ) {
651 $out->addStyle( self::makeUrl(
652 $this->userpage . '/' . $name . '.css',
653 'action=raw&ctype=text/css' )
654 );
655 }
656 }
657 }
658
659 wfProfileOut( __METHOD__ );
660 }
661
662 /**
663 * Get the query to generate a dynamic stylesheet
664 *
665 * @return array
666 */
667 public static function getDynamicStylesheetQuery() {
668 global $wgSquidMaxage;
669 return array(
670 'action' => 'raw',
671 'maxage' => $wgSquidMaxage,
672 'usemsgcache' => 'yes',
673 'ctype' => 'text/css',
674 'smaxage' => $wgSquidMaxage,
675 );
676 }
677
678 /**
679 * Add skin specific stylesheets
680 * @param $out OutputPage
681 */
682 function setupSkinUserCss( OutputPage $out ) {
683 // This includes the shared.js and oldshared.js files from skins/common/
684 $out->addModuleStyles( 'mediawiki.legacy.shared' );
685 // TODO: Figure out how to best integrate this stuff into ResourceLoader
686 $out->addStyle( $this->getStylesheet() );
687 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
688 }
689
690 function getPageClasses( $title ) {
691 $numeric = 'ns-' . $title->getNamespace();
692 if( $title->getNamespace() == NS_SPECIAL ) {
693 $type = 'ns-special';
694 } elseif( $title->isTalkPage() ) {
695 $type = 'ns-talk';
696 } else {
697 $type = 'ns-subject';
698 }
699 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
700 return "$numeric $type $name";
701 }
702
703 /**
704 * URL to the logo
705 */
706 function getLogo() {
707 global $wgLogo;
708 return $wgLogo;
709 }
710
711 /**
712 * This will be called immediately after the <body> tag. Split into
713 * two functions to make it easier to subclass.
714 */
715 function beforeContent() {
716 return $this->doBeforeContent();
717 }
718
719 function doBeforeContent() {
720 global $wgContLang;
721 wfProfileIn( __METHOD__ );
722
723 $s = '';
724 $qb = $this->qbSetting();
725
726 $langlinks = $this->otherLanguages();
727 if( $langlinks ) {
728 $rows = 2;
729 $borderhack = '';
730 } else {
731 $rows = 1;
732 $langlinks = false;
733 $borderhack = 'class="top"';
734 }
735
736 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
737 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
738
739 $shove = ( $qb != 0 );
740 $left = ( $qb == 1 || $qb == 3 );
741 if( $wgContLang->isRTL() ) {
742 $left = !$left;
743 }
744
745 if( !$shove ) {
746 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
747 $this->logoText() . '</td>';
748 } elseif( $left ) {
749 $s .= $this->getQuickbarCompensator( $rows );
750 }
751 $l = $wgContLang->alignStart();
752 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
753
754 $s .= $this->topLinks();
755 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
756
757 $r = $wgContLang->alignEnd();
758 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
759 $s .= $this->nameAndLogin();
760 $s .= "\n<br />" . $this->searchForm() . '</td>';
761
762 if ( $langlinks ) {
763 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
764 }
765
766 if ( $shove && !$left ) { # Right
767 $s .= $this->getQuickbarCompensator( $rows );
768 }
769 $s .= "</tr>\n</table>\n</div>\n";
770 $s .= "\n<div id='article'>\n";
771
772 $notice = wfGetSiteNotice();
773 if( $notice ) {
774 $s .= "\n<div id='siteNotice'>$notice</div>\n";
775 }
776 $s .= $this->pageTitle();
777 $s .= $this->pageSubtitle();
778 $s .= $this->getCategories();
779 wfProfileOut( __METHOD__ );
780 return $s;
781 }
782
783 function getCategoryLinks() {
784 global $wgOut, $wgUseCategoryBrowser;
785 global $wgContLang, $wgUser;
786
787 if( count( $wgOut->mCategoryLinks ) == 0 ) {
788 return '';
789 }
790
791 # Separator
792 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
793
794 // Use Unicode bidi embedding override characters,
795 // to make sure links don't smash each other up in ugly ways.
796 $dir = $wgContLang->getDir();
797 $embed = "<span dir='$dir'>";
798 $pop = '</span>';
799
800 $allCats = $wgOut->getCategoryLinks();
801 $s = '';
802 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
803 if ( !empty( $allCats['normal'] ) ) {
804 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
805
806 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
807 $s .= '<div id="mw-normal-catlinks">' .
808 $this->link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
809 . $colon . $t . '</div>';
810 }
811
812 # Hidden categories
813 if ( isset( $allCats['hidden'] ) ) {
814 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
815 $class ='mw-hidden-cats-user-shown';
816 } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
817 $class = 'mw-hidden-cats-ns-shown';
818 } else {
819 $class = 'mw-hidden-cats-hidden';
820 }
821 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
822 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
823 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
824 '</div>';
825 }
826
827 # optional 'dmoz-like' category browser. Will be shown under the list
828 # of categories an article belong to
829 if( $wgUseCategoryBrowser ) {
830 $s .= '<br /><hr />';
831
832 # get a big array of the parents tree
833 $parenttree = $this->mTitle->getParentCategoryTree();
834 # Skin object passed by reference cause it can not be
835 # accessed under the method subfunction drawCategoryBrowser
836 $tempout = explode( "\n", $this->drawCategoryBrowser( $parenttree, $this ) );
837 # Clean out bogus first entry and sort them
838 unset( $tempout[0] );
839 asort( $tempout );
840 # Output one per line
841 $s .= implode( "<br />\n", $tempout );
842 }
843
844 return $s;
845 }
846
847 /**
848 * Render the array as a serie of links.
849 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
850 * @param &skin Object: skin passed by reference
851 * @return String separated by &gt;, terminate with "\n"
852 */
853 function drawCategoryBrowser( $tree, &$skin ) {
854 $return = '';
855 foreach( $tree as $element => $parent ) {
856 if( empty( $parent ) ) {
857 # element start a new list
858 $return .= "\n";
859 } else {
860 # grab the others elements
861 $return .= $this->drawCategoryBrowser( $parent, $skin ) . ' &gt; ';
862 }
863 # add our current element to the list
864 $eltitle = Title::newFromText( $element );
865 $return .= $skin->link( $eltitle, $eltitle->getText() );
866 }
867 return $return;
868 }
869
870 function getCategories() {
871 $catlinks = $this->getCategoryLinks();
872
873 $classes = 'catlinks';
874
875 // Check what we're showing
876 global $wgOut, $wgUser;
877 $allCats = $wgOut->getCategoryLinks();
878 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
879 $this->mTitle->getNamespace() == NS_CATEGORY;
880
881 if( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
882 $classes .= ' catlinks-allhidden';
883 }
884
885 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
886 }
887
888 function getQuickbarCompensator( $rows = 1 ) {
889 return "<td width='152' rowspan='{$rows}'>&#160;</td>";
890 }
891
892 /**
893 * This runs a hook to allow extensions placing their stuff after content
894 * and article metadata (e.g. categories).
895 * Note: This function has nothing to do with afterContent().
896 *
897 * This hook is placed here in order to allow using the same hook for all
898 * skins, both the SkinTemplate based ones and the older ones, which directly
899 * use this class to get their data.
900 *
901 * The output of this function gets processed in SkinTemplate::outputPage() for
902 * the SkinTemplate based skins, all other skins should directly echo it.
903 *
904 * Returns an empty string by default, if not changed by any hook function.
905 */
906 protected function afterContentHook() {
907 $data = '';
908
909 if( wfRunHooks( 'SkinAfterContent', array( &$data, $this ) ) ) {
910 // adding just some spaces shouldn't toggle the output
911 // of the whole <div/>, so we use trim() here
912 if( trim( $data ) != '' ) {
913 // Doing this here instead of in the skins to
914 // ensure that the div has the same ID in all
915 // skins
916 $data = "<div id='mw-data-after-content'>\n" .
917 "\t$data\n" .
918 "</div>\n";
919 }
920 } else {
921 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
922 }
923
924 return $data;
925 }
926
927 /**
928 * Generate debug data HTML for displaying at the bottom of the main content
929 * area.
930 * @return String HTML containing debug data, if enabled (otherwise empty).
931 */
932 protected function generateDebugHTML() {
933 global $wgShowDebug, $wgOut;
934 if ( $wgShowDebug ) {
935 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
936 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
937 $listInternals . "</ul>\n";
938 }
939 return '';
940 }
941
942 private function formatDebugHTML( $debugText ) {
943 $lines = explode( "\n", $debugText );
944 $curIdent = 0;
945 $ret = '<li>';
946 foreach( $lines as $line ) {
947 $m = array();
948 $display = ltrim( $line );
949 $ident = strlen( $line ) - strlen( $display );
950 $diff = $ident - $curIdent;
951
952 if ( $display == '' ) {
953 $display = "\xc2\xa0";
954 }
955
956 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
957 $ident = $curIdent;
958 $diff = 0;
959 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
960 } else {
961 $display = htmlspecialchars( $display );
962 }
963
964 if ( $diff < 0 ) {
965 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
966 } elseif ( $diff == 0 ) {
967 $ret .= "</li><li>\n";
968 } else {
969 $ret .= str_repeat( "<ul><li>\n", $diff );
970 }
971 $ret .= $display . "\n";
972
973 $curIdent = $ident;
974 }
975 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
976 return $ret;
977 }
978
979 /**
980 * This gets called shortly before the </body> tag.
981 * @return String HTML to be put before </body>
982 */
983 function afterContent() {
984 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
985 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
986 }
987
988 /**
989 * This gets called shortly before the </body> tag.
990 * @param $out OutputPage object
991 * @return String HTML-wrapped JS code to be put before </body>
992 */
993 function bottomScripts( $out ) {
994 $bottomScriptText = "\n" . $out->getHeadScripts( $this );
995 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
996 return $bottomScriptText;
997 }
998
999 /** @return string Retrievied from HTML text */
1000 function printSource() {
1001 $url = htmlspecialchars( $this->mTitle->getFullURL() );
1002 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
1003 }
1004
1005 function printFooter() {
1006 return "<p>" . $this->printSource() .
1007 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
1008 }
1009
1010 /** overloaded by derived classes */
1011 function doAfterContent() {
1012 return '</div></div>';
1013 }
1014
1015 function pageTitleLinks() {
1016 global $wgOut, $wgUser, $wgRequest, $wgLang;
1017
1018 $oldid = $wgRequest->getVal( 'oldid' );
1019 $diff = $wgRequest->getVal( 'diff' );
1020 $action = $wgRequest->getText( 'action' );
1021
1022 $s[] = $this->printableLink();
1023 $disclaimer = $this->disclaimerLink(); # may be empty
1024 if( $disclaimer ) {
1025 $s[] = $disclaimer;
1026 }
1027 $privacy = $this->privacyLink(); # may be empty too
1028 if( $privacy ) {
1029 $s[] = $privacy;
1030 }
1031
1032 if ( $wgOut->isArticleRelated() ) {
1033 if ( $this->mTitle->getNamespace() == NS_FILE ) {
1034 $name = $this->mTitle->getDBkey();
1035 $image = wfFindFile( $this->mTitle );
1036 if( $image ) {
1037 $link = htmlspecialchars( $image->getURL() );
1038 $style = $this->getInternalLinkAttributes( $link, $name );
1039 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1040 }
1041 }
1042 }
1043 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
1044 $s[] .= $this->link(
1045 $this->mTitle,
1046 wfMsg( 'currentrev' ),
1047 array(),
1048 array(),
1049 array( 'known', 'noclasses' )
1050 );
1051 }
1052
1053 if ( $wgUser->getNewtalk() ) {
1054 # do not show "You have new messages" text when we are viewing our
1055 # own talk page
1056 if( !$this->mTitle->equals( $wgUser->getTalkPage() ) ) {
1057 $tl = $this->link(
1058 $wgUser->getTalkPage(),
1059 wfMsgHtml( 'newmessageslink' ),
1060 array(),
1061 array( 'redirect' => 'no' ),
1062 array( 'known', 'noclasses' )
1063 );
1064
1065 $dl = $this->link(
1066 $wgUser->getTalkPage(),
1067 wfMsgHtml( 'newmessagesdifflink' ),
1068 array(),
1069 array( 'diff' => 'cur' ),
1070 array( 'known', 'noclasses' )
1071 );
1072 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1073 # disable caching
1074 $wgOut->setSquidMaxage( 0 );
1075 $wgOut->enableClientCache( false );
1076 }
1077 }
1078
1079 $undelete = $this->getUndeleteLink();
1080 if( !empty( $undelete ) ) {
1081 $s[] = $undelete;
1082 }
1083 return $wgLang->pipeList( $s );
1084 }
1085
1086 function getUndeleteLink() {
1087 global $wgUser, $wgLang, $wgRequest;
1088
1089 $action = $wgRequest->getVal( 'action', 'view' );
1090
1091 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1092 ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
1093 $n = $this->mTitle->isDeleted();
1094 if ( $n ) {
1095 if ( $wgUser->isAllowed( 'undelete' ) ) {
1096 $msg = 'thisisdeleted';
1097 } else {
1098 $msg = 'viewdeleted';
1099 }
1100 return wfMsg(
1101 $msg,
1102 $this->link(
1103 SpecialPage::getTitleFor( 'Undelete', $this->mTitle->getPrefixedDBkey() ),
1104 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1105 array(),
1106 array(),
1107 array( 'known', 'noclasses' )
1108 )
1109 );
1110 }
1111 }
1112 return '';
1113 }
1114
1115 function printableLink() {
1116 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1117
1118 $s = array();
1119
1120 if ( !$wgOut->isPrintable() ) {
1121 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1122 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1123 }
1124
1125 if( $wgOut->isSyndicated() ) {
1126 foreach( $wgFeedClasses as $format => $class ) {
1127 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1128 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1129 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1130 }
1131 }
1132 return $wgLang->pipeList( $s );
1133 }
1134
1135 /**
1136 * Gets the h1 element with the page title.
1137 * @return string
1138 */
1139 function pageTitle() {
1140 global $wgOut;
1141 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1142 return $s;
1143 }
1144
1145 function pageSubtitle() {
1146 global $wgOut;
1147
1148 $sub = $wgOut->getSubtitle();
1149 if ( $sub == '' ) {
1150 global $wgExtraSubtitle;
1151 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1152 }
1153 $subpages = $this->subPageSubtitle();
1154 $sub .= !empty( $subpages ) ? "</p><p class='subpages'>$subpages" : '';
1155 $s = "<p class='subtitle'>{$sub}</p>\n";
1156 return $s;
1157 }
1158
1159 function subPageSubtitle() {
1160 $subpages = '';
1161 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) ) {
1162 return $subpages;
1163 }
1164
1165 global $wgOut;
1166 if( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
1167 $ptext = $this->mTitle->getPrefixedText();
1168 if( preg_match( '/\//', $ptext ) ) {
1169 $links = explode( '/', $ptext );
1170 array_pop( $links );
1171 $c = 0;
1172 $growinglink = '';
1173 $display = '';
1174 foreach( $links as $link ) {
1175 $growinglink .= $link;
1176 $display .= $link;
1177 $linkObj = Title::newFromText( $growinglink );
1178 if( is_object( $linkObj ) && $linkObj->exists() ) {
1179 $getlink = $this->link(
1180 $linkObj,
1181 htmlspecialchars( $display ),
1182 array(),
1183 array(),
1184 array( 'known', 'noclasses' )
1185 );
1186 $c++;
1187 if( $c > 1 ) {
1188 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1189 } else {
1190 $subpages .= '&lt; ';
1191 }
1192 $subpages .= $getlink;
1193 $display = '';
1194 } else {
1195 $display .= '/';
1196 }
1197 $growinglink .= '/';
1198 }
1199 }
1200 }
1201 return $subpages;
1202 }
1203
1204 /**
1205 * Returns true if the IP should be shown in the header
1206 */
1207 function showIPinHeader() {
1208 global $wgShowIPinHeader;
1209 return $wgShowIPinHeader && session_id() != '';
1210 }
1211
1212 function nameAndLogin() {
1213 global $wgUser, $wgLang, $wgContLang;
1214
1215 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1216
1217 $ret = '';
1218 if ( $wgUser->isAnon() ) {
1219 if( $this->showIPinHeader() ) {
1220 $name = wfGetIP();
1221
1222 $talkLink = $this->link( $wgUser->getTalkPage(),
1223 $wgLang->getNsText( NS_TALK ) );
1224
1225 $ret .= "$name ($talkLink)";
1226 } else {
1227 $ret .= wfMsg( 'notloggedin' );
1228 }
1229
1230 $returnTo = $this->mTitle->getPrefixedDBkey();
1231 $query = array();
1232 if ( $logoutPage != $returnTo ) {
1233 $query['returnto'] = $returnTo;
1234 }
1235
1236 $loginlink = $wgUser->isAllowed( 'createaccount' )
1237 ? 'nav-login-createaccount'
1238 : 'login';
1239 $ret .= "\n<br />" . $this->link(
1240 SpecialPage::getTitleFor( 'Userlogin' ),
1241 wfMsg( $loginlink ), array(), $query
1242 );
1243 } else {
1244 $returnTo = $this->mTitle->getPrefixedDBkey();
1245 $talkLink = $this->link( $wgUser->getTalkPage(),
1246 $wgLang->getNsText( NS_TALK ) );
1247
1248 $ret .= $this->link( $wgUser->getUserPage(),
1249 htmlspecialchars( $wgUser->getName() ) );
1250 $ret .= " ($talkLink)<br />";
1251 $ret .= $wgLang->pipeList( array(
1252 $this->link(
1253 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1254 array(), array( 'returnto' => $returnTo )
1255 ),
1256 $this->specialLink( 'preferences' ),
1257 ) );
1258 }
1259 $ret = $wgLang->pipeList( array(
1260 $ret,
1261 $this->link(
1262 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1263 wfMsg( 'help' )
1264 ),
1265 ) );
1266
1267 return $ret;
1268 }
1269
1270 function getSearchLink() {
1271 $searchPage = SpecialPage::getTitleFor( 'Search' );
1272 return $searchPage->getLocalURL();
1273 }
1274
1275 function escapeSearchLink() {
1276 return htmlspecialchars( $this->getSearchLink() );
1277 }
1278
1279 function searchForm() {
1280 global $wgRequest, $wgUseTwoButtonsSearchForm;
1281 $search = $wgRequest->getText( 'search' );
1282
1283 $s = '<form id="searchform' . $this->searchboxes . '" name="search" class="inline" method="post" action="'
1284 . $this->escapeSearchLink() . "\">\n"
1285 . '<input type="text" id="searchInput' . $this->searchboxes . '" name="search" size="19" value="'
1286 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1287 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1288
1289 if( $wgUseTwoButtonsSearchForm ) {
1290 $s .= '&#160;<input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1291 } else {
1292 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1293 }
1294
1295 $s .= '</form>';
1296
1297 // Ensure unique id's for search boxes made after the first
1298 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1299
1300 return $s;
1301 }
1302
1303 function topLinks() {
1304 global $wgOut;
1305
1306 $s = array(
1307 $this->mainPageLink(),
1308 $this->specialLink( 'recentchanges' )
1309 );
1310
1311 if ( $wgOut->isArticleRelated() ) {
1312 $s[] = $this->editThisPage();
1313 $s[] = $this->historyLink();
1314 }
1315 # Many people don't like this dropdown box
1316 #$s[] = $this->specialPagesList();
1317
1318 if( $this->variantLinks() ) {
1319 $s[] = $this->variantLinks();
1320 }
1321
1322 if( $this->extensionTabLinks() ) {
1323 $s[] = $this->extensionTabLinks();
1324 }
1325
1326 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1327 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1328 }
1329
1330 /**
1331 * Compatibility for extensions adding functionality through tabs.
1332 * Eventually these old skins should be replaced with SkinTemplate-based
1333 * versions, sigh...
1334 * @return string
1335 */
1336 function extensionTabLinks() {
1337 $tabs = array();
1338 $out = '';
1339 $s = array();
1340 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1341 foreach( $tabs as $tab ) {
1342 $s[] = Xml::element( 'a',
1343 array( 'href' => $tab['href'] ),
1344 $tab['text'] );
1345 }
1346
1347 if( count( $s ) ) {
1348 global $wgLang;
1349
1350 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1351 $out .= $wgLang->pipeList( $s );
1352 }
1353
1354 return $out;
1355 }
1356
1357 /**
1358 * Language/charset variant links for classic-style skins
1359 * @return string
1360 */
1361 function variantLinks() {
1362 $s = '';
1363 /* show links to different language variants */
1364 global $wgDisableLangConversion, $wgLang, $wgContLang;
1365 $variants = $wgContLang->getVariants();
1366 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1367 foreach( $variants as $code ) {
1368 $varname = $wgContLang->getVariantname( $code );
1369 if( $varname == 'disable' ) {
1370 continue;
1371 }
1372 $s = $wgLang->pipeList( array(
1373 $s,
1374 '<a href="' . $this->mTitle->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1375 ) );
1376 }
1377 }
1378 return $s;
1379 }
1380
1381 function bottomLinks() {
1382 global $wgOut, $wgUser, $wgUseTrackbacks;
1383 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1384
1385 $s = '';
1386 if ( $wgOut->isArticleRelated() ) {
1387 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1388 if ( $wgUser->isLoggedIn() ) {
1389 $element[] = $this->watchThisPage();
1390 }
1391 $element[] = $this->talkLink();
1392 $element[] = $this->historyLink();
1393 $element[] = $this->whatLinksHere();
1394 $element[] = $this->watchPageLinksLink();
1395
1396 if( $wgUseTrackbacks ) {
1397 $element[] = $this->trackbackLink();
1398 }
1399
1400 if (
1401 $this->mTitle->getNamespace() == NS_USER ||
1402 $this->mTitle->getNamespace() == NS_USER_TALK
1403 )
1404 {
1405 $id = User::idFromName( $this->mTitle->getText() );
1406 $ip = User::isIP( $this->mTitle->getText() );
1407
1408 # Both anons and non-anons have contributions list
1409 if( $id || $ip ) {
1410 $element[] = $this->userContribsLink();
1411 }
1412 if( $this->showEmailUser( $id ) ) {
1413 $element[] = $this->emailUserLink();
1414 }
1415 }
1416
1417 $s = implode( $element, $sep );
1418
1419 if ( $this->mTitle->getArticleId() ) {
1420 $s .= "\n<br />";
1421 // Delete/protect/move links for privileged users
1422 if( $wgUser->isAllowed( 'delete' ) ) {
1423 $s .= $this->deleteThisPage();
1424 }
1425 if( $wgUser->isAllowed( 'protect' ) ) {
1426 $s .= $sep . $this->protectThisPage();
1427 }
1428 if( $wgUser->isAllowed( 'move' ) ) {
1429 $s .= $sep . $this->moveThisPage();
1430 }
1431 }
1432 $s .= "<br />\n" . $this->otherLanguages();
1433 }
1434
1435 return $s;
1436 }
1437
1438 function pageStats() {
1439 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1440 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1441
1442 $oldid = $wgRequest->getVal( 'oldid' );
1443 $diff = $wgRequest->getVal( 'diff' );
1444 if ( !$wgOut->isArticle() ) {
1445 return '';
1446 }
1447 if( !$wgArticle instanceof Article ) {
1448 return '';
1449 }
1450 if ( isset( $oldid ) || isset( $diff ) ) {
1451 return '';
1452 }
1453 if ( 0 == $wgArticle->getID() ) {
1454 return '';
1455 }
1456
1457 $s = '';
1458 if ( !$wgDisableCounters ) {
1459 $count = $wgLang->formatNum( $wgArticle->getCount() );
1460 if ( $count ) {
1461 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1462 }
1463 }
1464
1465 if( $wgMaxCredits != 0 ) {
1466 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1467 } else {
1468 $s .= $this->lastModified();
1469 }
1470
1471 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1472 $dbr = wfGetDB( DB_SLAVE );
1473 $res = $dbr->select(
1474 'watchlist',
1475 array( 'COUNT(*) AS n' ),
1476 array(
1477 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ),
1478 'wl_namespace' => $this->mTitle->getNamespace()
1479 ),
1480 __METHOD__
1481 );
1482 $x = $dbr->fetchObject( $res );
1483
1484 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1485 array( 'parseinline' ), $wgLang->formatNum( $x->n )
1486 );
1487 }
1488
1489 return $s . ' ' . $this->getCopyright();
1490 }
1491
1492 function getCopyright( $type = 'detect' ) {
1493 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1494
1495 if ( $type == 'detect' ) {
1496 $diff = $wgRequest->getVal( 'diff' );
1497 $isCur = $wgArticle && $wgArticle->isCurrent();
1498 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1499 $type = 'history';
1500 } else {
1501 $type = 'normal';
1502 }
1503 }
1504
1505 if ( $type == 'history' ) {
1506 $msg = 'history_copyright';
1507 } else {
1508 $msg = 'copyright';
1509 }
1510
1511 $out = '';
1512 if( $wgRightsPage ) {
1513 $title = Title::newFromText( $wgRightsPage );
1514 $link = $this->linkKnown( $title, $wgRightsText );
1515 } elseif( $wgRightsUrl ) {
1516 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1517 } elseif( $wgRightsText ) {
1518 $link = $wgRightsText;
1519 } else {
1520 # Give up now
1521 return $out;
1522 }
1523 // Allow for site and per-namespace customization of copyright notice.
1524 $forContent = true;
1525 if( isset( $wgArticle ) ) {
1526 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link, &$forContent ) );
1527 }
1528
1529 if ( $forContent ) {
1530 $out .= wfMsgForContent( $msg, $link );
1531 } else {
1532 $out .= wfMsg( $msg, $link );
1533 }
1534 return $out;
1535 }
1536
1537 function getCopyrightIcon() {
1538 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1539 $out = '';
1540 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1541 $out = $wgCopyrightIcon;
1542 } elseif ( $wgRightsIcon ) {
1543 $icon = htmlspecialchars( $wgRightsIcon );
1544 if ( $wgRightsUrl ) {
1545 $url = htmlspecialchars( $wgRightsUrl );
1546 $out .= '<a href="'.$url.'">';
1547 }
1548 $text = htmlspecialchars( $wgRightsText );
1549 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1550 if ( $wgRightsUrl ) {
1551 $out .= '</a>';
1552 }
1553 }
1554 return $out;
1555 }
1556
1557 /**
1558 * Gets the powered by MediaWiki icon.
1559 * @return string
1560 */
1561 function getPoweredBy() {
1562 global $wgStylePath;
1563 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1564 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1565 return $img;
1566 }
1567
1568 function lastModified() {
1569 global $wgLang, $wgArticle;
1570 if( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
1571 $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
1572 } else {
1573 $timestamp = $wgArticle->getTimestamp();
1574 }
1575 if ( $timestamp ) {
1576 $d = $wgLang->date( $timestamp, true );
1577 $t = $wgLang->time( $timestamp, true );
1578 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1579 } else {
1580 $s = '';
1581 }
1582 if ( wfGetLB()->getLaggedSlaveMode() ) {
1583 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1584 }
1585 return $s;
1586 }
1587
1588 function logoText( $align = '' ) {
1589 if ( $align != '' ) {
1590 $a = " align='{$align}'";
1591 } else {
1592 $a = '';
1593 }
1594
1595 $mp = wfMsg( 'mainpage' );
1596 $mptitle = Title::newMainPage();
1597 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
1598
1599 $logourl = $this->getLogo();
1600 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1601 return $s;
1602 }
1603
1604 /**
1605 * Show a drop-down box of special pages
1606 */
1607 function specialPagesList() {
1608 global $wgContLang, $wgServer, $wgRedirectScript;
1609 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1610 foreach ( $pages as $name => $page ) {
1611 $pages[$name] = $page->getDescription();
1612 }
1613
1614 $go = wfMsg( 'go' );
1615 $sp = wfMsg( 'specialpages' );
1616 $spp = $wgContLang->specialPage( 'Specialpages' );
1617
1618 $s = '<form id="specialpages" method="get" ' .
1619 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1620 $s .= "<select name=\"wpDropdown\">\n";
1621 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1622
1623
1624 foreach ( $pages as $name => $desc ) {
1625 $p = $wgContLang->specialPage( $name );
1626 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1627 }
1628 $s .= "</select>\n";
1629 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1630 $s .= "</form>\n";
1631 return $s;
1632 }
1633
1634 /**
1635 * Gets the link to the wiki's main page.
1636 * @return string
1637 */
1638 function mainPageLink() {
1639 $s = $this->link(
1640 Title::newMainPage(),
1641 wfMsg( 'mainpage' ),
1642 array(),
1643 array(),
1644 array( 'known', 'noclasses' )
1645 );
1646 return $s;
1647 }
1648
1649 private function footerLink( $desc, $page ) {
1650 // if the link description has been set to "-" in the default language,
1651 if ( wfMsgForContent( $desc ) == '-') {
1652 // then it is disabled, for all languages.
1653 return '';
1654 } else {
1655 // Otherwise, we display the link for the user, described in their
1656 // language (which may or may not be the same as the default language),
1657 // but we make the link target be the one site-wide page.
1658 $title = Title::newFromText( wfMsgForContent( $page ) );
1659 return $this->linkKnown(
1660 $title,
1661 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1662 );
1663 }
1664 }
1665
1666 /**
1667 * Gets the link to the wiki's privacy policy page.
1668 */
1669 function privacyLink() {
1670 return $this->footerLink( 'privacy', 'privacypage' );
1671 }
1672
1673 /**
1674 * Gets the link to the wiki's about page.
1675 */
1676 function aboutLink() {
1677 return $this->footerLink( 'aboutsite', 'aboutpage' );
1678 }
1679
1680 /**
1681 * Gets the link to the wiki's general disclaimers page.
1682 */
1683 function disclaimerLink() {
1684 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1685 }
1686
1687 function editThisPage() {
1688 global $wgOut;
1689
1690 if ( !$wgOut->isArticleRelated() ) {
1691 $s = wfMsg( 'protectedpage' );
1692 } else {
1693 if( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
1694 $t = wfMsg( 'editthispage' );
1695 } elseif( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
1696 $t = wfMsg( 'create-this-page' );
1697 } else {
1698 $t = wfMsg( 'viewsource' );
1699 }
1700
1701 $s = $this->link(
1702 $this->mTitle,
1703 $t,
1704 array(),
1705 $this->editUrlOptions(),
1706 array( 'known', 'noclasses' )
1707 );
1708 }
1709 return $s;
1710 }
1711
1712 /**
1713 * Return URL options for the 'edit page' link.
1714 * This may include an 'oldid' specifier, if the current page view is such.
1715 *
1716 * @return array
1717 * @private
1718 */
1719 function editUrlOptions() {
1720 global $wgArticle;
1721
1722 $options = array( 'action' => 'edit' );
1723
1724 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1725 $options['oldid'] = intval( $this->mRevisionId );
1726 }
1727
1728 return $options;
1729 }
1730
1731 function deleteThisPage() {
1732 global $wgUser, $wgRequest;
1733
1734 $diff = $wgRequest->getVal( 'diff' );
1735 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1736 $t = wfMsg( 'deletethispage' );
1737
1738 $s = $this->link(
1739 $this->mTitle,
1740 $t,
1741 array(),
1742 array( 'action' => 'delete' ),
1743 array( 'known', 'noclasses' )
1744 );
1745 } else {
1746 $s = '';
1747 }
1748 return $s;
1749 }
1750
1751 function protectThisPage() {
1752 global $wgUser, $wgRequest;
1753
1754 $diff = $wgRequest->getVal( 'diff' );
1755 if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1756 if ( $this->mTitle->isProtected() ) {
1757 $text = wfMsg( 'unprotectthispage' );
1758 $query = array( 'action' => 'unprotect' );
1759 } else {
1760 $text = wfMsg( 'protectthispage' );
1761 $query = array( 'action' => 'protect' );
1762 }
1763
1764 $s = $this->link(
1765 $this->mTitle,
1766 $text,
1767 array(),
1768 $query,
1769 array( 'known', 'noclasses' )
1770 );
1771 } else {
1772 $s = '';
1773 }
1774 return $s;
1775 }
1776
1777 function watchThisPage() {
1778 global $wgOut;
1779 ++$this->mWatchLinkNum;
1780
1781 if ( $wgOut->isArticleRelated() ) {
1782 if ( $this->mTitle->userIsWatching() ) {
1783 $text = wfMsg( 'unwatchthispage' );
1784 $query = array( 'action' => 'unwatch' );
1785 $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
1786 } else {
1787 $text = wfMsg( 'watchthispage' );
1788 $query = array( 'action' => 'watch' );
1789 $id = 'mw-watch-link' . $this->mWatchLinkNum;
1790 }
1791
1792 $s = $this->link(
1793 $this->mTitle,
1794 $text,
1795 array( 'id' => $id ),
1796 $query,
1797 array( 'known', 'noclasses' )
1798 );
1799 } else {
1800 $s = wfMsg( 'notanarticle' );
1801 }
1802 return $s;
1803 }
1804
1805 function moveThisPage() {
1806 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1807 return $this->link(
1808 SpecialPage::getTitleFor( 'Movepage' ),
1809 wfMsg( 'movethispage' ),
1810 array(),
1811 array( 'target' => $this->mTitle->getPrefixedDBkey() ),
1812 array( 'known', 'noclasses' )
1813 );
1814 } else {
1815 // no message if page is protected - would be redundant
1816 return '';
1817 }
1818 }
1819
1820 function historyLink() {
1821 return $this->link(
1822 $this->mTitle,
1823 wfMsgHtml( 'history' ),
1824 array( 'rel' => 'archives' ),
1825 array( 'action' => 'history' )
1826 );
1827 }
1828
1829 function whatLinksHere() {
1830 return $this->link(
1831 SpecialPage::getTitleFor( 'Whatlinkshere', $this->mTitle->getPrefixedDBkey() ),
1832 wfMsgHtml( 'whatlinkshere' ),
1833 array(),
1834 array(),
1835 array( 'known', 'noclasses' )
1836 );
1837 }
1838
1839 function userContribsLink() {
1840 return $this->link(
1841 SpecialPage::getTitleFor( 'Contributions', $this->mTitle->getDBkey() ),
1842 wfMsgHtml( 'contributions' ),
1843 array(),
1844 array(),
1845 array( 'known', 'noclasses' )
1846 );
1847 }
1848
1849 function showEmailUser( $id ) {
1850 global $wgUser;
1851 $targetUser = User::newFromId( $id );
1852 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1853 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1854 }
1855
1856 function emailUserLink() {
1857 return $this->link(
1858 SpecialPage::getTitleFor( 'Emailuser', $this->mTitle->getDBkey() ),
1859 wfMsg( 'emailuser' ),
1860 array(),
1861 array(),
1862 array( 'known', 'noclasses' )
1863 );
1864 }
1865
1866 function watchPageLinksLink() {
1867 global $wgOut;
1868 if ( !$wgOut->isArticleRelated() ) {
1869 return '(' . wfMsg( 'notanarticle' ) . ')';
1870 } else {
1871 return $this->link(
1872 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->mTitle->getPrefixedDBkey() ),
1873 wfMsg( 'recentchangeslinked-toolbox' ),
1874 array(),
1875 array(),
1876 array( 'known', 'noclasses' )
1877 );
1878 }
1879 }
1880
1881 function trackbackLink() {
1882 return '<a href="' . $this->mTitle->trackbackURL() . '">'
1883 . wfMsg( 'trackbacklink' ) . '</a>';
1884 }
1885
1886 function otherLanguages() {
1887 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1888
1889 if ( $wgHideInterlanguageLinks ) {
1890 return '';
1891 }
1892
1893 $a = $wgOut->getLanguageLinks();
1894 if ( 0 == count( $a ) ) {
1895 return '';
1896 }
1897
1898 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1899 $first = true;
1900 if( $wgContLang->isRTL() ) {
1901 $s .= '<span dir="LTR">';
1902 }
1903 foreach( $a as $l ) {
1904 if ( !$first ) {
1905 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1906 }
1907 $first = false;
1908
1909 $nt = Title::newFromText( $l );
1910 $url = $nt->escapeFullURL();
1911 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1912 $title = htmlspecialchars( $nt->getText() );
1913
1914 if ( $text == '' ) {
1915 $text = $l;
1916 }
1917 $style = $this->getExternalLinkAttributes();
1918 $s .= "<a href=\"{$url}\" title=\"{$title}\"{$style}>{$text}</a>";
1919 }
1920 if( $wgContLang->isRTL() ) {
1921 $s .= '</span>';
1922 }
1923 return $s;
1924 }
1925
1926 function talkLink() {
1927 if ( NS_SPECIAL == $this->mTitle->getNamespace() ) {
1928 # No discussion links for special pages
1929 return '';
1930 }
1931
1932 $linkOptions = array();
1933
1934 if( $this->mTitle->isTalkPage() ) {
1935 $link = $this->mTitle->getSubjectPage();
1936 switch( $link->getNamespace() ) {
1937 case NS_MAIN:
1938 $text = wfMsg( 'articlepage' );
1939 break;
1940 case NS_USER:
1941 $text = wfMsg( 'userpage' );
1942 break;
1943 case NS_PROJECT:
1944 $text = wfMsg( 'projectpage' );
1945 break;
1946 case NS_FILE:
1947 $text = wfMsg( 'imagepage' );
1948 # Make link known if image exists, even if the desc. page doesn't.
1949 if( wfFindFile( $link ) )
1950 $linkOptions[] = 'known';
1951 break;
1952 case NS_MEDIAWIKI:
1953 $text = wfMsg( 'mediawikipage' );
1954 break;
1955 case NS_TEMPLATE:
1956 $text = wfMsg( 'templatepage' );
1957 break;
1958 case NS_HELP:
1959 $text = wfMsg( 'viewhelppage' );
1960 break;
1961 case NS_CATEGORY:
1962 $text = wfMsg( 'categorypage' );
1963 break;
1964 default:
1965 $text = wfMsg( 'articlepage' );
1966 }
1967 } else {
1968 $link = $this->mTitle->getTalkPage();
1969 $text = wfMsg( 'talkpage' );
1970 }
1971
1972 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1973
1974 return $s;
1975 }
1976
1977 function commentLink() {
1978 global $wgOut;
1979
1980 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
1981 return '';
1982 }
1983
1984 # __NEWSECTIONLINK___ changes behaviour here
1985 # If it is present, the link points to this page, otherwise
1986 # it points to the talk page
1987 if( $this->mTitle->isTalkPage() ) {
1988 $title = $this->mTitle;
1989 } elseif( $wgOut->showNewSectionLink() ) {
1990 $title = $this->mTitle;
1991 } else {
1992 $title = $this->mTitle->getTalkPage();
1993 }
1994
1995 return $this->link(
1996 $title,
1997 wfMsg( 'postcomment' ),
1998 array(),
1999 array(
2000 'action' => 'edit',
2001 'section' => 'new'
2002 ),
2003 array( 'known', 'noclasses' )
2004 );
2005 }
2006
2007 function getUploadLink() {
2008 global $wgUploadNavigationUrl;
2009
2010 if( $wgUploadNavigationUrl ) {
2011 # Using an empty class attribute to avoid automatic setting of "external" class
2012 return $this->makeExternalLink( $wgUploadNavigationUrl, wfMsgHtml( 'upload' ), false, null, array( 'class' => '') );
2013 } else {
2014 return $this->link(
2015 SpecialPage::getTitleFor('Upload'),
2016 wfMsgHtml( 'upload' ),
2017 array(),
2018 array(),
2019 array( 'known', 'noclasses' )
2020 );
2021 }
2022 }
2023
2024 /* these are used extensively in SkinTemplate, but also some other places */
2025 static function makeMainPageUrl( $urlaction = '' ) {
2026 $title = Title::newMainPage();
2027 self::checkTitle( $title, '' );
2028 return $title->getLocalURL( $urlaction );
2029 }
2030
2031 static function makeSpecialUrl( $name, $urlaction = '' ) {
2032 $title = SpecialPage::getTitleFor( $name );
2033 return $title->getLocalURL( $urlaction );
2034 }
2035
2036 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2037 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
2038 return $title->getLocalURL( $urlaction );
2039 }
2040
2041 static function makeI18nUrl( $name, $urlaction = '' ) {
2042 $title = Title::newFromText( wfMsgForContent( $name ) );
2043 self::checkTitle( $title, $name );
2044 return $title->getLocalURL( $urlaction );
2045 }
2046
2047 static function makeUrl( $name, $urlaction = '' ) {
2048 $title = Title::newFromText( $name );
2049 self::checkTitle( $title, $name );
2050 return $title->getLocalURL( $urlaction );
2051 }
2052
2053 /**
2054 * If url string starts with http, consider as external URL, else
2055 * internal
2056 */
2057 static function makeInternalOrExternalUrl( $name ) {
2058 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2059 return $name;
2060 } else {
2061 return self::makeUrl( $name );
2062 }
2063 }
2064
2065 # this can be passed the NS number as defined in Language.php
2066 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
2067 $title = Title::makeTitleSafe( $namespace, $name );
2068 self::checkTitle( $title, $name );
2069 return $title->getLocalURL( $urlaction );
2070 }
2071
2072 /* these return an array with the 'href' and boolean 'exists' */
2073 static function makeUrlDetails( $name, $urlaction = '' ) {
2074 $title = Title::newFromText( $name );
2075 self::checkTitle( $title, $name );
2076 return array(
2077 'href' => $title->getLocalURL( $urlaction ),
2078 'exists' => $title->getArticleID() != 0 ? true : false
2079 );
2080 }
2081
2082 /**
2083 * Make URL details where the article exists (or at least it's convenient to think so)
2084 */
2085 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2086 $title = Title::newFromText( $name );
2087 self::checkTitle( $title, $name );
2088 return array(
2089 'href' => $title->getLocalURL( $urlaction ),
2090 'exists' => true
2091 );
2092 }
2093
2094 # make sure we have some title to operate on
2095 static function checkTitle( &$title, $name ) {
2096 if( !is_object( $title ) ) {
2097 $title = Title::newFromText( $name );
2098 if( !is_object( $title ) ) {
2099 $title = Title::newFromText( '--error: link target missing--' );
2100 }
2101 }
2102 }
2103
2104 /**
2105 * Build an array that represents the sidebar(s), the navigation bar among them
2106 *
2107 * @return array
2108 */
2109 function buildSidebar() {
2110 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2111 global $wgLang;
2112 wfProfileIn( __METHOD__ );
2113
2114 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2115
2116 if ( $wgEnableSidebarCache ) {
2117 $cachedsidebar = $parserMemc->get( $key );
2118 if ( $cachedsidebar ) {
2119 wfProfileOut( __METHOD__ );
2120 return $cachedsidebar;
2121 }
2122 }
2123
2124 $bar = array();
2125 $this->addToSidebar( $bar, 'sidebar' );
2126
2127 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2128 if ( $wgEnableSidebarCache ) {
2129 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2130 }
2131 wfProfileOut( __METHOD__ );
2132 return $bar;
2133 }
2134 /**
2135 * Add content from a sidebar system message
2136 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2137 *
2138 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2139 *
2140 * @param &$bar array
2141 * @param $message String
2142 */
2143 function addToSidebar( &$bar, $message ) {
2144 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2145 }
2146
2147 /**
2148 * Add content from plain text
2149 * @since 1.17
2150 * @param &$bar array
2151 * @param $text string
2152 */
2153 function addToSidebarPlain( &$bar, $text ) {
2154 $lines = explode( "\n", $text );
2155 $wikiBar = array(); # We need to handle the wikitext on a different variable, to avoid trying to do an array operation on text, which would be a fatal error.
2156
2157 $heading = '';
2158 foreach( $lines as $line ) {
2159 if( strpos( $line, '*' ) !== 0 ) {
2160 continue;
2161 }
2162 if( strpos( $line, '**') !== 0 ) {
2163 $heading = trim( $line, '* ' );
2164 if( !array_key_exists( $heading, $bar ) ) {
2165 $bar[$heading] = array();
2166 }
2167 } else {
2168 $line = trim( $line, '* ' );
2169 if( strpos( $line, '|' ) !== false ) { // sanity check
2170 $line = array_map( 'trim', explode( '|', $line, 2 ) );
2171 $link = wfMsgForContent( $line[0] );
2172 if( $link == '-' ) {
2173 continue;
2174 }
2175
2176 $text = wfMsgExt( $line[1], 'parsemag' );
2177 if( wfEmptyMsg( $line[1], $text ) ) {
2178 $text = $line[1];
2179 }
2180 if( wfEmptyMsg( $line[0], $link ) ) {
2181 $link = $line[0];
2182 }
2183
2184 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2185 $href = $link;
2186 } else {
2187 $title = Title::newFromText( $link );
2188 if ( $title ) {
2189 $title = $title->fixSpecialName();
2190 $href = $title->getLocalURL();
2191 } else {
2192 $href = 'INVALID-TITLE';
2193 }
2194 }
2195
2196 $bar[$heading][] = array(
2197 'text' => $text,
2198 'href' => $href,
2199 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2200 'active' => false
2201 );
2202 } else if ( (substr($line, 0, 2) == '{{') && (substr($line, -2) == '}}') ) {
2203 global $wgParser, $wgTitle;
2204
2205 $line = substr($line, 2, strlen($line) - 4 );
2206
2207 if (is_null($wgParser->mOptions))
2208 $wgParser->mOptions = new ParserOptions();
2209
2210 $wgParser->mOptions->setEditSection(false);
2211 $wikiBar[$heading] = $wgParser->parse( wfMsgForContentNoTrans( $line ) , $wgTitle, $wgParser->mOptions )->getText();
2212 } else {
2213 continue;
2214 }
2215 }
2216 }
2217
2218 if ( count($wikiBar) > 0 )
2219 $bar = array_merge($bar, $wikiBar);
2220
2221 return $bar;
2222 }
2223
2224 /**
2225 * Should we include common/wikiprintable.css? Skins that have their own
2226 * print stylesheet should override this and return false. (This is an
2227 * ugly hack to get Monobook to play nicely with
2228 * OutputPage::headElement().)
2229 *
2230 * @return bool
2231 */
2232 public function commonPrintStylesheet() {
2233 return true;
2234 }
2235
2236 /**
2237 * Gets new talk page messages for the current user.
2238 * @return MediaWiki message or if no new talk page messages, nothing
2239 */
2240 function getNewtalks() {
2241 global $wgUser, $wgOut;
2242 $newtalks = $wgUser->getNewMessageLinks();
2243 $ntl = '';
2244
2245 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2246 $userTitle = $this->mUser->getUserPage();
2247 $userTalkTitle = $userTitle->getTalkPage();
2248
2249 if( !$userTalkTitle->equals( $this->mTitle ) ) {
2250 $newMessagesLink = $this->link(
2251 $userTalkTitle,
2252 wfMsgHtml( 'newmessageslink' ),
2253 array(),
2254 array( 'redirect' => 'no' ),
2255 array( 'known', 'noclasses' )
2256 );
2257
2258 $newMessagesDiffLink = $this->link(
2259 $userTalkTitle,
2260 wfMsgHtml( 'newmessagesdifflink' ),
2261 array(),
2262 array( 'diff' => 'cur' ),
2263 array( 'known', 'noclasses' )
2264 );
2265
2266 $ntl = wfMsg(
2267 'youhavenewmessages',
2268 $newMessagesLink,
2269 $newMessagesDiffLink
2270 );
2271 # Disable Squid cache
2272 $wgOut->setSquidMaxage( 0 );
2273 }
2274 } elseif( count( $newtalks ) ) {
2275 // _>" " for BC <= 1.16
2276 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2277 $msgs = array();
2278 foreach( $newtalks as $newtalk ) {
2279 $msgs[] = Xml::element(
2280 'a',
2281 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2282 );
2283 }
2284 $parts = implode( $sep, $msgs );
2285 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2286 $wgOut->setSquidMaxage( 0 );
2287 }
2288 return $ntl;
2289 }
2290
2291 }