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