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