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