move newtalk stuff from SkinTemplate to its own function in Skin
[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 Title $t The title 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::newFromText( wfMsgForContent( 'mainpage' ) );
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->isAnon() ? null : $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, $wgAjaxUploadInterface;
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( array(
620 'usemsgcache' => 'yes',
621 'ctype' => 'text/css',
622 'smaxage' => $wgSquidMaxage
623 ) + $siteargs );
624 # Site settings must override extension css! (bug 15025)
625 $out->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) );
626 $out->addStyle( self::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI ), 'print' );
627 if( $wgHandheldStyle ) {
628 $out->addStyle( self::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI ), 'handheld' );
629 }
630 $out->addStyle( self::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI ) );
631 }
632
633 global $wgAllowUserCssPrefs;
634 if( $wgAllowUserCssPrefs ){
635 if( $wgUser->isLoggedIn() ) {
636 // Ensure that logged-in users' generated CSS isn't clobbered
637 // by anons' publicly cacheable generated CSS.
638 $siteargs['smaxage'] = '0';
639 $siteargs['ts'] = $wgUser->mTouched;
640 }
641 // Per-user styles based on preferences
642 $siteargs['gen'] = 'css';
643 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
644 $siteargs['useskin'] = $us;
645 }
646 $out->addStyle( self::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
647 }
648
649 // Per-user custom style pages
650 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
651 $action = $wgRequest->getVal( 'action' );
652 # If we're previewing the CSS page, use it
653 if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
654 // @FIXME: properly escape the cdata!
655 $out->addInlineStyle( $wgRequest->getText( 'wpTextbox1' ) );
656 } else {
657 $names = array( 'common', $this->getSkinName() );
658 foreach( $names as $name ) {
659 $out->addStyle( self::makeUrl(
660 $this->userpage . '/' . $name . '.css',
661 'action=raw&ctype=text/css' )
662 );
663 }
664 }
665 }
666
667 wfProfileOut( __METHOD__ );
668 }
669
670 /**
671 * Add skin specific stylesheets
672 * @param $out OutputPage
673 */
674 function setupSkinUserCss( OutputPage $out ) {
675 $out->addStyle( 'common/shared.css' );
676 $out->addStyle( 'common/oldshared.css' );
677 $out->addStyle( $this->getStylesheet() );
678 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
679 }
680
681 function getPageClasses( $title ) {
682 $numeric = 'ns-' . $title->getNamespace();
683 if( $title->getNamespace() == NS_SPECIAL ) {
684 $type = 'ns-special';
685 } elseif( $title->isTalkPage() ) {
686 $type = 'ns-talk';
687 } else {
688 $type = 'ns-subject';
689 }
690 $name = Sanitizer::escapeClass( 'page-' . $title->getPrefixedText() );
691 return "$numeric $type $name";
692 }
693
694 /**
695 * URL to the logo
696 */
697 function getLogo() {
698 global $wgLogo;
699 return $wgLogo;
700 }
701
702 /**
703 * This will be called immediately after the <body> tag. Split into
704 * two functions to make it easier to subclass.
705 */
706 function beforeContent() {
707 return $this->doBeforeContent();
708 }
709
710 function doBeforeContent() {
711 global $wgContLang;
712 wfProfileIn( __METHOD__ );
713
714 $s = '';
715 $qb = $this->qbSetting();
716
717 $langlinks = $this->otherLanguages();
718 if( $langlinks ) {
719 $rows = 2;
720 $borderhack = '';
721 } else {
722 $rows = 1;
723 $langlinks = false;
724 $borderhack = 'class="top"';
725 }
726
727 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
728 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
729
730 $shove = ( $qb != 0 );
731 $left = ( $qb == 1 || $qb == 3 );
732 if( $wgContLang->isRTL() ) {
733 $left = !$left;
734 }
735
736 if( !$shove ) {
737 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
738 $this->logoText() . '</td>';
739 } elseif( $left ) {
740 $s .= $this->getQuickbarCompensator( $rows );
741 }
742 $l = $wgContLang->alignStart();
743 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
744
745 $s .= $this->topLinks();
746 $s .= '<p class="subtitle">' . $this->pageTitleLinks() . "</p>\n";
747
748 $r = $wgContLang->alignEnd();
749 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
750 $s .= $this->nameAndLogin();
751 $s .= "\n<br />" . $this->searchForm() . '</td>';
752
753 if ( $langlinks ) {
754 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
755 }
756
757 if ( $shove && !$left ) { # Right
758 $s .= $this->getQuickbarCompensator( $rows );
759 }
760 $s .= "</tr>\n</table>\n</div>\n";
761 $s .= "\n<div id='article'>\n";
762
763 $notice = wfGetSiteNotice();
764 if( $notice ) {
765 $s .= "\n<div id='siteNotice'>$notice</div>\n";
766 }
767 $s .= $this->pageTitle();
768 $s .= $this->pageSubtitle();
769 $s .= $this->getCategories();
770 wfProfileOut( __METHOD__ );
771 return $s;
772 }
773
774 function getCategoryLinks() {
775 global $wgOut, $wgUseCategoryBrowser;
776 global $wgContLang, $wgUser;
777
778 if( count( $wgOut->mCategoryLinks ) == 0 ) {
779 return '';
780 }
781
782 # Separator
783 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
784
785 // Use Unicode bidi embedding override characters,
786 // to make sure links don't smash each other up in ugly ways.
787 $dir = $wgContLang->getDir();
788 $embed = "<span dir='$dir'>";
789 $pop = '</span>';
790
791 $allCats = $wgOut->getCategoryLinks();
792 $s = '';
793 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
794 if ( !empty( $allCats['normal'] ) ) {
795 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
796
797 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
798 $s .= '<div id="mw-normal-catlinks">' .
799 $this->link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
800 . $colon . $t . '</div>';
801 }
802
803 # Hidden categories
804 if ( isset( $allCats['hidden'] ) ) {
805 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
806 $class ='mw-hidden-cats-user-shown';
807 } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
808 $class = 'mw-hidden-cats-ns-shown';
809 } else {
810 $class = 'mw-hidden-cats-hidden';
811 }
812 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
813 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
814 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
815 '</div>';
816 }
817
818 # optional 'dmoz-like' category browser. Will be shown under the list
819 # of categories an article belong to
820 if( $wgUseCategoryBrowser ) {
821 $s .= '<br /><hr />';
822
823 # get a big array of the parents tree
824 $parenttree = $this->mTitle->getParentCategoryTree();
825 # Skin object passed by reference cause it can not be
826 # accessed under the method subfunction drawCategoryBrowser
827 $tempout = explode( "\n", Skin::drawCategoryBrowser( $parenttree, $this ) );
828 # Clean out bogus first entry and sort them
829 unset( $tempout[0] );
830 asort( $tempout );
831 # Output one per line
832 $s .= implode( "<br />\n", $tempout );
833 }
834
835 return $s;
836 }
837
838 /**
839 * Render the array as a serie of links.
840 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
841 * @param &skin Object: skin passed by reference
842 * @return String separated by &gt;, terminate with "\n"
843 */
844 function drawCategoryBrowser( $tree, &$skin ) {
845 $return = '';
846 foreach( $tree as $element => $parent ) {
847 if( empty( $parent ) ) {
848 # element start a new list
849 $return .= "\n";
850 } else {
851 # grab the others elements
852 $return .= Skin::drawCategoryBrowser( $parent, $skin ) . ' &gt; ';
853 }
854 # add our current element to the list
855 $eltitle = Title::newFromText( $element );
856 $return .= $skin->link( $eltitle, $eltitle->getText() );
857 }
858 return $return;
859 }
860
861 function getCategories() {
862 $catlinks = $this->getCategoryLinks();
863
864 $classes = 'catlinks';
865
866 // Check what we're showing
867 global $wgOut, $wgUser;
868 $allCats = $wgOut->getCategoryLinks();
869 $showHidden = $wgUser->getBoolOption( 'showhiddencats' ) ||
870 $this->mTitle->getNamespace() == NS_CATEGORY;
871
872 if( empty( $allCats['normal'] ) && !( !empty( $allCats['hidden'] ) && $showHidden ) ) {
873 $classes .= ' catlinks-allhidden';
874 }
875
876 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
877 }
878
879 function getQuickbarCompensator( $rows = 1 ) {
880 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
881 }
882
883 /**
884 * This runs a hook to allow extensions placing their stuff after content
885 * and article metadata (e.g. categories).
886 * Note: This function has nothing to do with afterContent().
887 *
888 * This hook is placed here in order to allow using the same hook for all
889 * skins, both the SkinTemplate based ones and the older ones, which directly
890 * use this class to get their data.
891 *
892 * The output of this function gets processed in SkinTemplate::outputPage() for
893 * the SkinTemplate based skins, all other skins should directly echo it.
894 *
895 * Returns an empty string by default, if not changed by any hook function.
896 */
897 protected function afterContentHook() {
898 $data = '';
899
900 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ) {
901 // adding just some spaces shouldn't toggle the output
902 // of the whole <div/>, so we use trim() here
903 if( trim( $data ) != '' ) {
904 // Doing this here instead of in the skins to
905 // ensure that the div has the same ID in all
906 // skins
907 $data = "<div id='mw-data-after-content'>\n" .
908 "\t$data\n" .
909 "</div>\n";
910 }
911 } else {
912 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
913 }
914
915 return $data;
916 }
917
918 /**
919 * Generate debug data HTML for displaying at the bottom of the main content
920 * area.
921 * @return String HTML containing debug data, if enabled (otherwise empty).
922 */
923 protected function generateDebugHTML() {
924 global $wgShowDebug, $wgOut;
925 if ( $wgShowDebug ) {
926 $listInternals = $this->formatDebugHTML( $wgOut->mDebugtext );
927 return "\n<hr />\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\" id=\"mw-debug-html\">" .
928 $listInternals . "</ul>\n";
929 }
930 return '';
931 }
932
933 private function formatDebugHTML( $debugText ) {
934 $lines = explode( "\n", $debugText );
935 $curIdent = 0;
936 $ret = '<li>';
937 foreach( $lines as $line ) {
938 $m = array();
939 $display = ltrim( $line );
940 $ident = strlen( $line ) - strlen( $display );
941 $diff = $ident - $curIdent;
942
943 if ( $display == '' ) {
944 $display = "\xc2\xa0";
945 }
946
947 if ( !$ident && $diff < 0 && substr( $display, 0, 9 ) != 'Entering ' && substr( $display, 0, 8 ) != 'Exiting ' ) {
948 $ident = $curIdent;
949 $diff = 0;
950 $display = '<span style="background:yellow;">' . htmlspecialchars( $display ) . '</span>';
951 } else {
952 $display = htmlspecialchars( $display );
953 }
954
955 if ( $diff < 0 ) {
956 $ret .= str_repeat( "</li></ul>\n", -$diff ) . "</li><li>\n";
957 } elseif ( $diff == 0 ) {
958 $ret .= "</li><li>\n";
959 } else {
960 $ret .= str_repeat( "<ul><li>\n", $diff );
961 }
962 $ret .= $display . "\n";
963
964 $curIdent = $ident;
965 }
966 $ret .= str_repeat( '</li></ul>', $curIdent ) . '</li>';
967 return $ret;
968 }
969
970 /**
971 * This gets called shortly before the </body> tag.
972 * @return String HTML to be put before </body>
973 */
974 function afterContent() {
975 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
976 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
977 }
978
979 /**
980 * This gets called shortly before the </body> tag.
981 * @return String HTML-wrapped JS code to be put before </body>
982 */
983 function bottomScripts() {
984 $bottomScriptText = "\n" . Html::inlineScript( 'if (window.runOnloadHook) runOnloadHook();' ) . "\n";
985 wfRunHooks( 'SkinAfterBottomScripts', array( $this, &$bottomScriptText ) );
986 return $bottomScriptText;
987 }
988
989 /** @return string Retrievied from HTML text */
990 function printSource() {
991 $url = htmlspecialchars( $this->mTitle->getFullURL() );
992 return wfMsg( 'retrievedfrom', '<a href="' . $url . '">' . $url . '</a>' );
993 }
994
995 function printFooter() {
996 return "<p>" . $this->printSource() .
997 "</p>\n\n<p>" . $this->pageStats() . "</p>\n";
998 }
999
1000 /** overloaded by derived classes */
1001 function doAfterContent() {
1002 return '</div></div>';
1003 }
1004
1005 function pageTitleLinks() {
1006 global $wgOut, $wgUser, $wgRequest, $wgLang;
1007
1008 $oldid = $wgRequest->getVal( 'oldid' );
1009 $diff = $wgRequest->getVal( 'diff' );
1010 $action = $wgRequest->getText( 'action' );
1011
1012 $s[] = $this->printableLink();
1013 $disclaimer = $this->disclaimerLink(); # may be empty
1014 if( $disclaimer ) {
1015 $s[] = $disclaimer;
1016 }
1017 $privacy = $this->privacyLink(); # may be empty too
1018 if( $privacy ) {
1019 $s[] = $privacy;
1020 }
1021
1022 if ( $wgOut->isArticleRelated() ) {
1023 if ( $this->mTitle->getNamespace() == NS_FILE ) {
1024 $name = $this->mTitle->getDBkey();
1025 $image = wfFindFile( $this->mTitle );
1026 if( $image ) {
1027 $link = htmlspecialchars( $image->getURL() );
1028 $style = $this->getInternalLinkAttributes( $link, $name );
1029 $s[] = "<a href=\"{$link}\"{$style}>{$name}</a>";
1030 }
1031 }
1032 }
1033 if ( 'history' == $action || isset( $diff ) || isset( $oldid ) ) {
1034 $s[] .= $this->link(
1035 $this->mTitle,
1036 wfMsg( 'currentrev' ),
1037 array(),
1038 array(),
1039 array( 'known', 'noclasses' )
1040 );
1041 }
1042
1043 if ( $wgUser->getNewtalk() ) {
1044 # do not show "You have new messages" text when we are viewing our
1045 # own talk page
1046 if( !$this->mTitle->equals( $wgUser->getTalkPage() ) ) {
1047 $tl = $this->link(
1048 $wgUser->getTalkPage(),
1049 wfMsgHtml( 'newmessageslink' ),
1050 array(),
1051 array( 'redirect' => 'no' ),
1052 array( 'known', 'noclasses' )
1053 );
1054
1055 $dl = $this->link(
1056 $wgUser->getTalkPage(),
1057 wfMsgHtml( 'newmessagesdifflink' ),
1058 array(),
1059 array( 'diff' => 'cur' ),
1060 array( 'known', 'noclasses' )
1061 );
1062 $s[] = '<strong>'. wfMsg( 'youhavenewmessages', $tl, $dl ) . '</strong>';
1063 # disable caching
1064 $wgOut->setSquidMaxage( 0 );
1065 $wgOut->enableClientCache( false );
1066 }
1067 }
1068
1069 $undelete = $this->getUndeleteLink();
1070 if( !empty( $undelete ) ) {
1071 $s[] = $undelete;
1072 }
1073 return $wgLang->pipeList( $s );
1074 }
1075
1076 function getUndeleteLink() {
1077 global $wgUser, $wgContLang, $wgLang, $wgRequest;
1078
1079 $action = $wgRequest->getVal( 'action', 'view' );
1080
1081 if ( $wgUser->isAllowed( 'deletedhistory' ) &&
1082 ( $this->mTitle->getArticleId() == 0 || $action == 'history' ) ) {
1083 $n = $this->mTitle->isDeleted();
1084 if ( $n ) {
1085 if ( $wgUser->isAllowed( 'undelete' ) ) {
1086 $msg = 'thisisdeleted';
1087 } else {
1088 $msg = 'viewdeleted';
1089 }
1090 return wfMsg(
1091 $msg,
1092 $this->link(
1093 SpecialPage::getTitleFor( 'Undelete', $this->mTitle->getPrefixedDBkey() ),
1094 wfMsgExt( 'restorelink', array( 'parsemag', 'escape' ), $wgLang->formatNum( $n ) ),
1095 array(),
1096 array(),
1097 array( 'known', 'noclasses' )
1098 )
1099 );
1100 }
1101 }
1102 return '';
1103 }
1104
1105 function printableLink() {
1106 global $wgOut, $wgFeedClasses, $wgRequest, $wgLang;
1107
1108 $s = array();
1109
1110 if ( !$wgOut->isPrintable() ) {
1111 $printurl = $wgRequest->escapeAppendQuery( 'printable=yes' );
1112 $s[] = "<a href=\"$printurl\" rel=\"alternate\">" . wfMsg( 'printableversion' ) . '</a>';
1113 }
1114
1115 if( $wgOut->isSyndicated() ) {
1116 foreach( $wgFeedClasses as $format => $class ) {
1117 $feedurl = $wgRequest->escapeAppendQuery( "feed=$format" );
1118 $s[] = "<a href=\"$feedurl\" rel=\"alternate\" type=\"application/{$format}+xml\""
1119 . " class=\"feedlink\">" . wfMsgHtml( "feed-$format" ) . "</a>";
1120 }
1121 }
1122 return $wgLang->pipeList( $s );
1123 }
1124
1125 /**
1126 * Gets the h1 element with the page title.
1127 * @return string
1128 */
1129 function pageTitle() {
1130 global $wgOut;
1131 $s = '<h1 class="pagetitle">' . $wgOut->getPageTitle() . '</h1>';
1132 return $s;
1133 }
1134
1135 function pageSubtitle() {
1136 global $wgOut;
1137
1138 $sub = $wgOut->getSubtitle();
1139 if ( $sub == '' ) {
1140 global $wgExtraSubtitle;
1141 $sub = wfMsgExt( 'tagline', 'parsemag' ) . $wgExtraSubtitle;
1142 }
1143 $subpages = $this->subPageSubtitle();
1144 $sub .= !empty( $subpages ) ? "</p><p class='subpages'>$subpages" : '';
1145 $s = "<p class='subtitle'>{$sub}</p>\n";
1146 return $s;
1147 }
1148
1149 function subPageSubtitle() {
1150 $subpages = '';
1151 if( !wfRunHooks( 'SkinSubPageSubtitle', array( &$subpages ) ) ) {
1152 return $subpages;
1153 }
1154
1155 global $wgOut;
1156 if( $wgOut->isArticle() && MWNamespace::hasSubpages( $this->mTitle->getNamespace() ) ) {
1157 $ptext = $this->mTitle->getPrefixedText();
1158 if( preg_match( '/\//', $ptext ) ) {
1159 $links = explode( '/', $ptext );
1160 array_pop( $links );
1161 $c = 0;
1162 $growinglink = '';
1163 $display = '';
1164 foreach( $links as $link ) {
1165 $growinglink .= $link;
1166 $display .= $link;
1167 $linkObj = Title::newFromText( $growinglink );
1168 if( is_object( $linkObj ) && $linkObj->exists() ) {
1169 $getlink = $this->link(
1170 $linkObj,
1171 htmlspecialchars( $display ),
1172 array(),
1173 array(),
1174 array( 'known', 'noclasses' )
1175 );
1176 $c++;
1177 if( $c > 1 ) {
1178 $subpages .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1179 } else {
1180 $subpages .= '&lt; ';
1181 }
1182 $subpages .= $getlink;
1183 $display = '';
1184 } else {
1185 $display .= '/';
1186 }
1187 $growinglink .= '/';
1188 }
1189 }
1190 }
1191 return $subpages;
1192 }
1193
1194 /**
1195 * Returns true if the IP should be shown in the header
1196 */
1197 function showIPinHeader() {
1198 global $wgShowIPinHeader;
1199 return $wgShowIPinHeader && session_id() != '';
1200 }
1201
1202 function nameAndLogin() {
1203 global $wgUser, $wgLang, $wgContLang;
1204
1205 $logoutPage = $wgContLang->specialPage( 'Userlogout' );
1206
1207 $ret = '';
1208 if ( $wgUser->isAnon() ) {
1209 if( $this->showIPinHeader() ) {
1210 $name = wfGetIP();
1211
1212 $talkLink = $this->link( $wgUser->getTalkPage(),
1213 $wgLang->getNsText( NS_TALK ) );
1214
1215 $ret .= "$name ($talkLink)";
1216 } else {
1217 $ret .= wfMsg( 'notloggedin' );
1218 }
1219
1220 $returnTo = $this->mTitle->getPrefixedDBkey();
1221 $query = array();
1222 if ( $logoutPage != $returnTo ) {
1223 $query['returnto'] = $returnTo;
1224 }
1225
1226 $loginlink = $wgUser->isAllowed( 'createaccount' )
1227 ? 'nav-login-createaccount'
1228 : 'login';
1229 $ret .= "\n<br />" . $this->link(
1230 SpecialPage::getTitleFor( 'Userlogin' ),
1231 wfMsg( $loginlink ), array(), $query
1232 );
1233 } else {
1234 $returnTo = $this->mTitle->getPrefixedDBkey();
1235 $talkLink = $this->link( $wgUser->getTalkPage(),
1236 $wgLang->getNsText( NS_TALK ) );
1237
1238 $ret .= $this->link( $wgUser->getUserPage(),
1239 htmlspecialchars( $wgUser->getName() ) );
1240 $ret .= " ($talkLink)<br />";
1241 $ret .= $wgLang->pipeList( array(
1242 $this->link(
1243 SpecialPage::getTitleFor( 'Userlogout' ), wfMsg( 'logout' ),
1244 array(), array( 'returnto' => $returnTo )
1245 ),
1246 $this->specialLink( 'preferences' ),
1247 ) );
1248 }
1249 $ret = $wgLang->pipeList( array(
1250 $ret,
1251 $this->link(
1252 Title::newFromText( wfMsgForContent( 'helppage' ) ),
1253 wfMsg( 'help' )
1254 ),
1255 ) );
1256
1257 return $ret;
1258 }
1259
1260 function getSearchLink() {
1261 $searchPage = SpecialPage::getTitleFor( 'Search' );
1262 return $searchPage->getLocalURL();
1263 }
1264
1265 function escapeSearchLink() {
1266 return htmlspecialchars( $this->getSearchLink() );
1267 }
1268
1269 function searchForm() {
1270 global $wgRequest, $wgUseTwoButtonsSearchForm;
1271 $search = $wgRequest->getText( 'search' );
1272
1273 $s = '<form id="searchform' . $this->searchboxes . '" name="search" class="inline" method="post" action="'
1274 . $this->escapeSearchLink() . "\">\n"
1275 . '<input type="text" id="searchInput' . $this->searchboxes . '" name="search" size="19" value="'
1276 . htmlspecialchars( substr( $search, 0, 256 ) ) . "\" />\n"
1277 . '<input type="submit" name="go" value="' . wfMsg( 'searcharticle' ) . '" />';
1278
1279 if( $wgUseTwoButtonsSearchForm ) {
1280 $s .= '&nbsp;<input type="submit" name="fulltext" value="' . wfMsg( 'searchbutton' ) . "\" />\n";
1281 } else {
1282 $s .= ' <a href="' . $this->escapeSearchLink() . '" rel="search">' . wfMsg( 'powersearch-legend' ) . "</a>\n";
1283 }
1284
1285 $s .= '</form>';
1286
1287 // Ensure unique id's for search boxes made after the first
1288 $this->searchboxes = $this->searchboxes == '' ? 2 : $this->searchboxes + 1;
1289
1290 return $s;
1291 }
1292
1293 function topLinks() {
1294 global $wgOut;
1295
1296 $s = array(
1297 $this->mainPageLink(),
1298 $this->specialLink( 'recentchanges' )
1299 );
1300
1301 if ( $wgOut->isArticleRelated() ) {
1302 $s[] = $this->editThisPage();
1303 $s[] = $this->historyLink();
1304 }
1305 # Many people don't like this dropdown box
1306 #$s[] = $this->specialPagesList();
1307
1308 if( $this->variantLinks() ) {
1309 $s[] = $this->variantLinks();
1310 }
1311
1312 if( $this->extensionTabLinks() ) {
1313 $s[] = $this->extensionTabLinks();
1314 }
1315
1316 // FIXME: Is using Language::pipeList impossible here? Do not quite understand the use of the newline
1317 return implode( $s, wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n" );
1318 }
1319
1320 /**
1321 * Compatibility for extensions adding functionality through tabs.
1322 * Eventually these old skins should be replaced with SkinTemplate-based
1323 * versions, sigh...
1324 * @return string
1325 */
1326 function extensionTabLinks() {
1327 $tabs = array();
1328 $out = '';
1329 $s = array();
1330 wfRunHooks( 'SkinTemplateTabs', array( $this, &$tabs ) );
1331 foreach( $tabs as $tab ) {
1332 $s[] = Xml::element( 'a',
1333 array( 'href' => $tab['href'] ),
1334 $tab['text'] );
1335 }
1336
1337 if( count( $s ) ) {
1338 global $wgLang;
1339
1340 $out = wfMsgExt( 'pipe-separator' , 'escapenoentities' );
1341 $out .= $wgLang->pipeList( $s );
1342 }
1343
1344 return $out;
1345 }
1346
1347 /**
1348 * Language/charset variant links for classic-style skins
1349 * @return string
1350 */
1351 function variantLinks() {
1352 $s = '';
1353 /* show links to different language variants */
1354 global $wgDisableLangConversion, $wgLang, $wgContLang;
1355 $variants = $wgContLang->getVariants();
1356 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
1357 foreach( $variants as $code ) {
1358 $varname = $wgContLang->getVariantname( $code );
1359 if( $varname == 'disable' ) {
1360 continue;
1361 }
1362 $s = $wgLang->pipeList( array(
1363 $s,
1364 '<a href="' . $this->mTitle->escapeLocalURL( 'variant=' . $code ) . '">' . htmlspecialchars( $varname ) . '</a>'
1365 ) );
1366 }
1367 }
1368 return $s;
1369 }
1370
1371 function bottomLinks() {
1372 global $wgOut, $wgUser, $wgUseTrackbacks;
1373 $sep = wfMsgExt( 'pipe-separator', 'escapenoentities' ) . "\n";
1374
1375 $s = '';
1376 if ( $wgOut->isArticleRelated() ) {
1377 $element[] = '<strong>' . $this->editThisPage() . '</strong>';
1378 if ( $wgUser->isLoggedIn() ) {
1379 $element[] = $this->watchThisPage();
1380 }
1381 $element[] = $this->talkLink();
1382 $element[] = $this->historyLink();
1383 $element[] = $this->whatLinksHere();
1384 $element[] = $this->watchPageLinksLink();
1385
1386 if( $wgUseTrackbacks ) {
1387 $element[] = $this->trackbackLink();
1388 }
1389
1390 if (
1391 $this->mTitle->getNamespace() == NS_USER ||
1392 $this->mTitle->getNamespace() == NS_USER_TALK
1393 )
1394 {
1395 $id = User::idFromName( $this->mTitle->getText() );
1396 $ip = User::isIP( $this->mTitle->getText() );
1397
1398 # Both anons and non-anons have contributions list
1399 if( $id || $ip ) {
1400 $element[] = $this->userContribsLink();
1401 }
1402 if( $this->showEmailUser( $id ) ) {
1403 $element[] = $this->emailUserLink();
1404 }
1405 }
1406
1407 $s = implode( $element, $sep );
1408
1409 if ( $this->mTitle->getArticleId() ) {
1410 $s .= "\n<br />";
1411 // Delete/protect/move links for privileged users
1412 if( $wgUser->isAllowed( 'delete' ) ) {
1413 $s .= $this->deleteThisPage();
1414 }
1415 if( $wgUser->isAllowed( 'protect' ) ) {
1416 $s .= $sep . $this->protectThisPage();
1417 }
1418 if( $wgUser->isAllowed( 'move' ) ) {
1419 $s .= $sep . $this->moveThisPage();
1420 }
1421 }
1422 $s .= "<br />\n" . $this->otherLanguages();
1423 }
1424
1425 return $s;
1426 }
1427
1428 function pageStats() {
1429 global $wgOut, $wgLang, $wgArticle, $wgRequest, $wgUser;
1430 global $wgDisableCounters, $wgMaxCredits, $wgShowCreditsIfMax, $wgPageShowWatchingUsers;
1431
1432 $oldid = $wgRequest->getVal( 'oldid' );
1433 $diff = $wgRequest->getVal( 'diff' );
1434 if ( !$wgOut->isArticle() ) {
1435 return '';
1436 }
1437 if( !$wgArticle instanceof Article ) {
1438 return '';
1439 }
1440 if ( isset( $oldid ) || isset( $diff ) ) {
1441 return '';
1442 }
1443 if ( 0 == $wgArticle->getID() ) {
1444 return '';
1445 }
1446
1447 $s = '';
1448 if ( !$wgDisableCounters ) {
1449 $count = $wgLang->formatNum( $wgArticle->getCount() );
1450 if ( $count ) {
1451 $s = wfMsgExt( 'viewcount', array( 'parseinline' ), $count );
1452 }
1453 }
1454
1455 if( $wgMaxCredits != 0 ) {
1456 $s .= ' ' . Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
1457 } else {
1458 $s .= $this->lastModified();
1459 }
1460
1461 if( $wgPageShowWatchingUsers && $wgUser->getOption( 'shownumberswatching' ) ) {
1462 $dbr = wfGetDB( DB_SLAVE );
1463 $res = $dbr->select(
1464 'watchlist',
1465 array( 'COUNT(*) AS n' ),
1466 array(
1467 'wl_title' => $dbr->strencode( $this->mTitle->getDBkey() ),
1468 'wl_namespace' => $this->mTitle->getNamespace()
1469 ),
1470 __METHOD__
1471 );
1472 $x = $dbr->fetchObject( $res );
1473
1474 $s .= ' ' . wfMsgExt( 'number_of_watching_users_pageview',
1475 array( 'parseinline' ), $wgLang->formatNum( $x->n )
1476 );
1477 }
1478
1479 return $s . ' ' . $this->getCopyright();
1480 }
1481
1482 function getCopyright( $type = 'detect' ) {
1483 global $wgRightsPage, $wgRightsUrl, $wgRightsText, $wgRequest, $wgArticle;
1484
1485 if ( $type == 'detect' ) {
1486 $diff = $wgRequest->getVal( 'diff' );
1487 $isCur = $wgArticle && $wgArticle->isCurrent();
1488 if ( is_null( $diff ) && !$isCur && wfMsgForContent( 'history_copyright' ) !== '-' ) {
1489 $type = 'history';
1490 } else {
1491 $type = 'normal';
1492 }
1493 }
1494
1495 if ( $type == 'history' ) {
1496 $msg = 'history_copyright';
1497 } else {
1498 $msg = 'copyright';
1499 }
1500
1501 $out = '';
1502 if( $wgRightsPage ) {
1503 $title = Title::newFromText( $wgRightsPage );
1504 $link = $this->linkKnown( $title, $wgRightsText );
1505 } elseif( $wgRightsUrl ) {
1506 $link = $this->makeExternalLink( $wgRightsUrl, $wgRightsText );
1507 } elseif( $wgRightsText ) {
1508 $link = $wgRightsText;
1509 } else {
1510 # Give up now
1511 return $out;
1512 }
1513 // Allow for site and per-namespace customization of copyright notice.
1514 if( isset( $wgArticle ) ) {
1515 wfRunHooks( 'SkinCopyrightFooter', array( $wgArticle->getTitle(), $type, &$msg, &$link ) );
1516 }
1517
1518 $out .= wfMsgForContent( $msg, $link );
1519 return $out;
1520 }
1521
1522 function getCopyrightIcon() {
1523 global $wgRightsUrl, $wgRightsText, $wgRightsIcon, $wgCopyrightIcon;
1524 $out = '';
1525 if ( isset( $wgCopyrightIcon ) && $wgCopyrightIcon ) {
1526 $out = $wgCopyrightIcon;
1527 } elseif ( $wgRightsIcon ) {
1528 $icon = htmlspecialchars( $wgRightsIcon );
1529 if ( $wgRightsUrl ) {
1530 $url = htmlspecialchars( $wgRightsUrl );
1531 $out .= '<a href="'.$url.'">';
1532 }
1533 $text = htmlspecialchars( $wgRightsText );
1534 $out .= "<img src=\"$icon\" alt=\"$text\" width=\"88\" height=\"31\" />";
1535 if ( $wgRightsUrl ) {
1536 $out .= '</a>';
1537 }
1538 }
1539 return $out;
1540 }
1541
1542 /**
1543 * Gets the powered by MediaWiki icon.
1544 * @return string
1545 */
1546 function getPoweredBy() {
1547 global $wgStylePath;
1548 $url = htmlspecialchars( "$wgStylePath/common/images/poweredby_mediawiki_88x31.png" );
1549 $img = '<a href="http://www.mediawiki.org/"><img src="' . $url . '" height="31" width="88" alt="Powered by MediaWiki" /></a>';
1550 return $img;
1551 }
1552
1553 function lastModified() {
1554 global $wgLang, $wgArticle;
1555 if( $this->mRevisionId && $this->mRevisionId != $wgArticle->getLatest() ) {
1556 $timestamp = Revision::getTimestampFromId( $wgArticle->getTitle(), $this->mRevisionId );
1557 } else {
1558 $timestamp = $wgArticle->getTimestamp();
1559 }
1560 if ( $timestamp ) {
1561 $d = $wgLang->date( $timestamp, true );
1562 $t = $wgLang->time( $timestamp, true );
1563 $s = ' ' . wfMsg( 'lastmodifiedat', $d, $t );
1564 } else {
1565 $s = '';
1566 }
1567 if ( wfGetLB()->getLaggedSlaveMode() ) {
1568 $s .= ' <strong>' . wfMsg( 'laggedslavemode' ) . '</strong>';
1569 }
1570 return $s;
1571 }
1572
1573 function logoText( $align = '' ) {
1574 if ( $align != '' ) {
1575 $a = " align='{$align}'";
1576 } else {
1577 $a = '';
1578 }
1579
1580 $mp = wfMsg( 'mainpage' );
1581 $mptitle = Title::newMainPage();
1582 $url = ( is_object( $mptitle ) ? $mptitle->escapeLocalURL() : '' );
1583
1584 $logourl = $this->getLogo();
1585 $s = "<a href='{$url}'><img{$a} src='{$logourl}' alt='[{$mp}]' /></a>";
1586 return $s;
1587 }
1588
1589 /**
1590 * Show a drop-down box of special pages
1591 */
1592 function specialPagesList() {
1593 global $wgUser, $wgContLang, $wgServer, $wgRedirectScript;
1594 $pages = array_merge( SpecialPage::getRegularPages(), SpecialPage::getRestrictedPages() );
1595 foreach ( $pages as $name => $page ) {
1596 $pages[$name] = $page->getDescription();
1597 }
1598
1599 $go = wfMsg( 'go' );
1600 $sp = wfMsg( 'specialpages' );
1601 $spp = $wgContLang->specialPage( 'Specialpages' );
1602
1603 $s = '<form id="specialpages" method="get" ' .
1604 'action="' . htmlspecialchars( "{$wgServer}{$wgRedirectScript}" ) . "\">\n";
1605 $s .= "<select name=\"wpDropdown\">\n";
1606 $s .= "<option value=\"{$spp}\">{$sp}</option>\n";
1607
1608
1609 foreach ( $pages as $name => $desc ) {
1610 $p = $wgContLang->specialPage( $name );
1611 $s .= "<option value=\"{$p}\">{$desc}</option>\n";
1612 }
1613 $s .= "</select>\n";
1614 $s .= "<input type='submit' value=\"{$go}\" name='redirect' />\n";
1615 $s .= "</form>\n";
1616 return $s;
1617 }
1618
1619 /**
1620 * Gets the link to the wiki's main page.
1621 * @return string
1622 */
1623 function mainPageLink() {
1624 $s = $this->link(
1625 Title::newMainPage(),
1626 wfMsg( 'mainpage' ),
1627 array(),
1628 array(),
1629 array( 'known', 'noclasses' )
1630 );
1631 return $s;
1632 }
1633
1634 private function footerLink( $desc, $page ) {
1635 // if the link description has been set to "-" in the default language,
1636 if ( wfMsgForContent( $desc ) == '-') {
1637 // then it is disabled, for all languages.
1638 return '';
1639 } else {
1640 // Otherwise, we display the link for the user, described in their
1641 // language (which may or may not be the same as the default language),
1642 // but we make the link target be the one site-wide page.
1643 $title = Title::newFromText( wfMsgForContent( $page ) );
1644 return $this->linkKnown(
1645 $title,
1646 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1647 );
1648 }
1649 }
1650
1651 /**
1652 * Gets the link to the wiki's privacy policy page.
1653 */
1654 function privacyLink() {
1655 return $this->footerLink( 'privacy', 'privacypage' );
1656 }
1657
1658 /**
1659 * Gets the link to the wiki's about page.
1660 */
1661 function aboutLink() {
1662 return $this->footerLink( 'aboutsite', 'aboutpage' );
1663 }
1664
1665 /**
1666 * Gets the link to the wiki's general disclaimers page.
1667 */
1668 function disclaimerLink() {
1669 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1670 }
1671
1672 function editThisPage() {
1673 global $wgOut;
1674
1675 if ( !$wgOut->isArticleRelated() ) {
1676 $s = wfMsg( 'protectedpage' );
1677 } else {
1678 if( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
1679 $t = wfMsg( 'editthispage' );
1680 } elseif( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
1681 $t = wfMsg( 'create-this-page' );
1682 } else {
1683 $t = wfMsg( 'viewsource' );
1684 }
1685
1686 $s = $this->link(
1687 $this->mTitle,
1688 $t,
1689 array(),
1690 $this->editUrlOptions(),
1691 array( 'known', 'noclasses' )
1692 );
1693 }
1694 return $s;
1695 }
1696
1697 /**
1698 * Return URL options for the 'edit page' link.
1699 * This may include an 'oldid' specifier, if the current page view is such.
1700 *
1701 * @return array
1702 * @private
1703 */
1704 function editUrlOptions() {
1705 global $wgArticle;
1706
1707 $options = array( 'action' => 'edit' );
1708
1709 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1710 $options['oldid'] = intval( $this->mRevisionId );
1711 }
1712
1713 return $options;
1714 }
1715
1716 function deleteThisPage() {
1717 global $wgUser, $wgRequest;
1718
1719 $diff = $wgRequest->getVal( 'diff' );
1720 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1721 $t = wfMsg( 'deletethispage' );
1722
1723 $s = $this->link(
1724 $this->mTitle,
1725 $t,
1726 array(),
1727 array( 'action' => 'delete' ),
1728 array( 'known', 'noclasses' )
1729 );
1730 } else {
1731 $s = '';
1732 }
1733 return $s;
1734 }
1735
1736 function protectThisPage() {
1737 global $wgUser, $wgRequest;
1738
1739 $diff = $wgRequest->getVal( 'diff' );
1740 if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1741 if ( $this->mTitle->isProtected() ) {
1742 $text = wfMsg( 'unprotectthispage' );
1743 $query = array( 'action' => 'unprotect' );
1744 } else {
1745 $text = wfMsg( 'protectthispage' );
1746 $query = array( 'action' => 'protect' );
1747 }
1748
1749 $s = $this->link(
1750 $this->mTitle,
1751 $text,
1752 array(),
1753 $query,
1754 array( 'known', 'noclasses' )
1755 );
1756 } else {
1757 $s = '';
1758 }
1759 return $s;
1760 }
1761
1762 function watchThisPage() {
1763 global $wgOut;
1764 ++$this->mWatchLinkNum;
1765
1766 if ( $wgOut->isArticleRelated() ) {
1767 if ( $this->mTitle->userIsWatching() ) {
1768 $text = wfMsg( 'unwatchthispage' );
1769 $query = array( 'action' => 'unwatch' );
1770 $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
1771 } else {
1772 $text = wfMsg( 'watchthispage' );
1773 $query = array( 'action' => 'watch' );
1774 $id = 'mw-watch-link' . $this->mWatchLinkNum;
1775 }
1776
1777 $s = $this->link(
1778 $this->mTitle,
1779 $text,
1780 array( 'id' => $id ),
1781 $query,
1782 array( 'known', 'noclasses' )
1783 );
1784 } else {
1785 $s = wfMsg( 'notanarticle' );
1786 }
1787 return $s;
1788 }
1789
1790 function moveThisPage() {
1791 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1792 return $this->link(
1793 SpecialPage::getTitleFor( 'Movepage' ),
1794 wfMsg( 'movethispage' ),
1795 array(),
1796 array( 'target' => $this->mTitle->getPrefixedDBkey() ),
1797 array( 'known', 'noclasses' )
1798 );
1799 } else {
1800 // no message if page is protected - would be redundant
1801 return '';
1802 }
1803 }
1804
1805 function historyLink() {
1806 return $this->link(
1807 $this->mTitle,
1808 wfMsgHtml( 'history' ),
1809 array( 'rel' => 'archives' ),
1810 array( 'action' => 'history' )
1811 );
1812 }
1813
1814 function whatLinksHere() {
1815 return $this->link(
1816 SpecialPage::getTitleFor( 'Whatlinkshere', $this->mTitle->getPrefixedDBkey() ),
1817 wfMsgHtml( 'whatlinkshere' ),
1818 array(),
1819 array(),
1820 array( 'known', 'noclasses' )
1821 );
1822 }
1823
1824 function userContribsLink() {
1825 return $this->link(
1826 SpecialPage::getTitleFor( 'Contributions', $this->mTitle->getDBkey() ),
1827 wfMsgHtml( 'contributions' ),
1828 array(),
1829 array(),
1830 array( 'known', 'noclasses' )
1831 );
1832 }
1833
1834 function showEmailUser( $id ) {
1835 global $wgUser;
1836 $targetUser = User::newFromId( $id );
1837 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1838 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1839 }
1840
1841 function emailUserLink() {
1842 return $this->link(
1843 SpecialPage::getTitleFor( 'Emailuser', $this->mTitle->getDBkey() ),
1844 wfMsg( 'emailuser' ),
1845 array(),
1846 array(),
1847 array( 'known', 'noclasses' )
1848 );
1849 }
1850
1851 function watchPageLinksLink() {
1852 global $wgOut;
1853 if ( !$wgOut->isArticleRelated() ) {
1854 return '(' . wfMsg( 'notanarticle' ) . ')';
1855 } else {
1856 return $this->link(
1857 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->mTitle->getPrefixedDBkey() ),
1858 wfMsg( 'recentchangeslinked-toolbox' ),
1859 array(),
1860 array(),
1861 array( 'known', 'noclasses' )
1862 );
1863 }
1864 }
1865
1866 function trackbackLink() {
1867 return '<a href="' . $this->mTitle->trackbackURL() . '">'
1868 . wfMsg( 'trackbacklink' ) . '</a>';
1869 }
1870
1871 function otherLanguages() {
1872 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1873
1874 if ( $wgHideInterlanguageLinks ) {
1875 return '';
1876 }
1877
1878 $a = $wgOut->getLanguageLinks();
1879 if ( 0 == count( $a ) ) {
1880 return '';
1881 }
1882
1883 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1884 $first = true;
1885 if( $wgContLang->isRTL() ) {
1886 $s .= '<span dir="LTR">';
1887 }
1888 foreach( $a as $l ) {
1889 if ( !$first ) {
1890 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1891 }
1892 $first = false;
1893
1894 $nt = Title::newFromText( $l );
1895 $url = $nt->escapeFullURL();
1896 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1897
1898 if ( $text == '' ) {
1899 $text = $l;
1900 }
1901 $style = $this->getExternalLinkAttributes();
1902 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1903 }
1904 if( $wgContLang->isRTL() ) {
1905 $s .= '</span>';
1906 }
1907 return $s;
1908 }
1909
1910 function talkLink() {
1911 if ( NS_SPECIAL == $this->mTitle->getNamespace() ) {
1912 # No discussion links for special pages
1913 return '';
1914 }
1915
1916 $linkOptions = array();
1917
1918 if( $this->mTitle->isTalkPage() ) {
1919 $link = $this->mTitle->getSubjectPage();
1920 switch( $link->getNamespace() ) {
1921 case NS_MAIN:
1922 $text = wfMsg( 'articlepage' );
1923 break;
1924 case NS_USER:
1925 $text = wfMsg( 'userpage' );
1926 break;
1927 case NS_PROJECT:
1928 $text = wfMsg( 'projectpage' );
1929 break;
1930 case NS_FILE:
1931 $text = wfMsg( 'imagepage' );
1932 # Make link known if image exists, even if the desc. page doesn't.
1933 if( wfFindFile( $link ) )
1934 $linkOptions[] = 'known';
1935 break;
1936 case NS_MEDIAWIKI:
1937 $text = wfMsg( 'mediawikipage' );
1938 break;
1939 case NS_TEMPLATE:
1940 $text = wfMsg( 'templatepage' );
1941 break;
1942 case NS_HELP:
1943 $text = wfMsg( 'viewhelppage' );
1944 break;
1945 case NS_CATEGORY:
1946 $text = wfMsg( 'categorypage' );
1947 break;
1948 default:
1949 $text = wfMsg( 'articlepage' );
1950 }
1951 } else {
1952 $link = $this->mTitle->getTalkPage();
1953 $text = wfMsg( 'talkpage' );
1954 }
1955
1956 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1957
1958 return $s;
1959 }
1960
1961 function commentLink() {
1962 global $wgOut;
1963
1964 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
1965 return '';
1966 }
1967
1968 # __NEWSECTIONLINK___ changes behaviour here
1969 # If it is present, the link points to this page, otherwise
1970 # it points to the talk page
1971 if( $this->mTitle->isTalkPage() ) {
1972 $title = $this->mTitle;
1973 } elseif( $wgOut->showNewSectionLink() ) {
1974 $title = $this->mTitle;
1975 } else {
1976 $title = $this->mTitle->getTalkPage();
1977 }
1978
1979 return $this->link(
1980 $title,
1981 wfMsg( 'postcomment' ),
1982 array(),
1983 array(
1984 'action' => 'edit',
1985 'section' => 'new'
1986 ),
1987 array( 'known', 'noclasses' )
1988 );
1989 }
1990
1991 /* these are used extensively in SkinTemplate, but also some other places */
1992 static function makeMainPageUrl( $urlaction = '' ) {
1993 $title = Title::newMainPage();
1994 self::checkTitle( $title, '' );
1995 return $title->getLocalURL( $urlaction );
1996 }
1997
1998 static function makeSpecialUrl( $name, $urlaction = '' ) {
1999 $title = SpecialPage::getTitleFor( $name );
2000 return $title->getLocalURL( $urlaction );
2001 }
2002
2003 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
2004 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
2005 return $title->getLocalURL( $urlaction );
2006 }
2007
2008 static function makeI18nUrl( $name, $urlaction = '' ) {
2009 $title = Title::newFromText( wfMsgForContent( $name ) );
2010 self::checkTitle( $title, $name );
2011 return $title->getLocalURL( $urlaction );
2012 }
2013
2014 static function makeUrl( $name, $urlaction = '' ) {
2015 $title = Title::newFromText( $name );
2016 self::checkTitle( $title, $name );
2017 return $title->getLocalURL( $urlaction );
2018 }
2019
2020 /**
2021 * If url string starts with http, consider as external URL, else
2022 * internal
2023 */
2024 static function makeInternalOrExternalUrl( $name ) {
2025 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
2026 return $name;
2027 } else {
2028 return self::makeUrl( $name );
2029 }
2030 }
2031
2032 # this can be passed the NS number as defined in Language.php
2033 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
2034 $title = Title::makeTitleSafe( $namespace, $name );
2035 self::checkTitle( $title, $name );
2036 return $title->getLocalURL( $urlaction );
2037 }
2038
2039 /* these return an array with the 'href' and boolean 'exists' */
2040 static function makeUrlDetails( $name, $urlaction = '' ) {
2041 $title = Title::newFromText( $name );
2042 self::checkTitle( $title, $name );
2043 return array(
2044 'href' => $title->getLocalURL( $urlaction ),
2045 'exists' => $title->getArticleID() != 0 ? true : false
2046 );
2047 }
2048
2049 /**
2050 * Make URL details where the article exists (or at least it's convenient to think so)
2051 */
2052 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
2053 $title = Title::newFromText( $name );
2054 self::checkTitle( $title, $name );
2055 return array(
2056 'href' => $title->getLocalURL( $urlaction ),
2057 'exists' => true
2058 );
2059 }
2060
2061 # make sure we have some title to operate on
2062 static function checkTitle( &$title, $name ) {
2063 if( !is_object( $title ) ) {
2064 $title = Title::newFromText( $name );
2065 if( !is_object( $title ) ) {
2066 $title = Title::newFromText( '--error: link target missing--' );
2067 }
2068 }
2069 }
2070
2071 /**
2072 * Build an array that represents the sidebar(s), the navigation bar among them
2073 *
2074 * @return array
2075 */
2076 function buildSidebar() {
2077 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2078 global $wgLang;
2079 wfProfileIn( __METHOD__ );
2080
2081 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2082
2083 if ( $wgEnableSidebarCache ) {
2084 $cachedsidebar = $parserMemc->get( $key );
2085 if ( $cachedsidebar ) {
2086 wfProfileOut( __METHOD__ );
2087 return $cachedsidebar;
2088 }
2089 }
2090
2091 $bar = array();
2092 $this->addToSidebar( $bar, 'sidebar' );
2093
2094 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2095 if ( $wgEnableSidebarCache ) {
2096 $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2097 }
2098 wfProfileOut( __METHOD__ );
2099 return $bar;
2100 }
2101 /**
2102 * Add content from a sidebar system message
2103 * Currently only used for MediaWiki:Sidebar (but may be used by Extensions)
2104 *
2105 * This is just a wrapper around addToSidebarPlain() for backwards compatibility
2106 *
2107 * @param &$bar array
2108 * @param $message String
2109 */
2110 function addToSidebar( &$bar, $message ) {
2111 $this->addToSidebarPlain( $bar, wfMsgForContent( $message ) );
2112 }
2113
2114 /**
2115 * Add content from plain text
2116 * @since 1.17
2117 * @param &$bar array
2118 * @param $text string
2119 */
2120 function addToSidebarPlain( &$bar, $text ) {
2121 $lines = explode( "\n", $text );
2122 $heading = '';
2123 foreach( $lines as $line ) {
2124 if( strpos( $line, '*' ) !== 0 ) {
2125 continue;
2126 }
2127 if( strpos( $line, '**') !== 0 ) {
2128 $heading = trim( $line, '* ' );
2129 if( !array_key_exists( $heading, $bar ) ) {
2130 $bar[$heading] = array();
2131 }
2132 } else {
2133 if( strpos( $line, '|' ) !== false ) { // sanity check
2134 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
2135 $link = wfMsgForContent( $line[0] );
2136 if( $link == '-' ) {
2137 continue;
2138 }
2139
2140 $text = wfMsgExt( $line[1], 'parsemag' );
2141 if( wfEmptyMsg( $line[1], $text ) ) {
2142 $text = $line[1];
2143 }
2144 if( wfEmptyMsg( $line[0], $link ) ) {
2145 $link = $line[0];
2146 }
2147
2148 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2149 $href = $link;
2150 } else {
2151 $title = Title::newFromText( $link );
2152 if ( $title ) {
2153 $title = $title->fixSpecialName();
2154 $href = $title->getLocalURL();
2155 } else {
2156 $href = 'INVALID-TITLE';
2157 }
2158 }
2159
2160 $bar[$heading][] = array(
2161 'text' => $text,
2162 'href' => $href,
2163 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2164 'active' => false
2165 );
2166 } else {
2167 continue;
2168 }
2169 }
2170 }
2171 }
2172
2173 /**
2174 * Should we include common/wikiprintable.css? Skins that have their own
2175 * print stylesheet should override this and return false. (This is an
2176 * ugly hack to get Monobook to play nicely with
2177 * OutputPage::headElement().)
2178 *
2179 * @return bool
2180 */
2181 public function commonPrintStylesheet() {
2182 return true;
2183 }
2184
2185 /**
2186 * Gets new talk page messages for the current user.
2187 * @return MediaWiki message or if no new talk page messages, nothing
2188 */
2189 function getNewtalks() {
2190 global $wgUser, $wgOut;
2191 $newtalks = $wgUser->getNewMessageLinks();
2192
2193 if( count( $newtalks ) == 1 && $newtalks[0]['wiki'] === wfWikiID() ) {
2194 $userTitle = $this->mUser->getUserPage();
2195 $userTalkTitle = $userTitle->getTalkPage();
2196
2197 if( !$userTalkTitle->equals( $this->mTitle ) ) {
2198 $newMessagesLink = $this->link(
2199 $userTalkTitle,
2200 wfMsgHtml( 'newmessageslink' ),
2201 array(),
2202 array( 'redirect' => 'no' ),
2203 array( 'known', 'noclasses' )
2204 );
2205
2206 $newMessagesDiffLink = $this->link(
2207 $userTalkTitle,
2208 wfMsgHtml( 'newmessagesdifflink' ),
2209 array(),
2210 array( 'diff' => 'cur' ),
2211 array( 'known', 'noclasses' )
2212 );
2213
2214 $ntl = wfMsg(
2215 'youhavenewmessages',
2216 $newMessagesLink,
2217 $newMessagesDiffLink
2218 );
2219 # Disable Squid cache
2220 $wgOut->setSquidMaxage( 0 );
2221 }
2222 } elseif( count( $newtalks ) ) {
2223 // _>" " for BC <= 1.16
2224 $sep = str_replace( '_', ' ', wfMsgHtml( 'newtalkseparator' ) );
2225 $msgs = array();
2226 foreach( $newtalks as $newtalk ) {
2227 $msgs[] = Xml::element(
2228 'a',
2229 array( 'href' => $newtalk['link'] ), $newtalk['wiki']
2230 );
2231 }
2232 $parts = implode( $sep, $msgs );
2233 $ntl = wfMsgHtml( 'youhavenewmessagesmulti', $parts );
2234 $wgOut->setSquidMaxage( 0 );
2235 } else {
2236 $ntl = '';
2237 }
2238 return $ntl;
2239 }
2240
2241 }