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