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