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