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