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