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