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