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