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