Revert r53841 (Favicon, apple-touch-icon links matching the defaults should not be...
[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 if( $data ) {
335 $r = array();
336 foreach ( $data as $name => $value ) {
337 $encValue = Xml::encodeJsVar( $value );
338 $r[] = "$name=$encValue";
339 }
340 $js = 'var ' . implode( ",\n", $r ) . ';';
341 return Html::inlineScript( "\n$js\n" );
342 } else {
343 return '';
344 }
345 }
346
347 /**
348 * Make a <script> tag containing global variables
349 * @param $skinName string Name of the skin
350 * The odd calling convention is for backwards compatibility
351 * @TODO @FIXME Make this not depend on $wgTitle!
352 */
353 static function makeGlobalVariablesScript( $skinName ) {
354 if ( is_array( $skinName ) ) {
355 # Weird back-compat stuff.
356 $skinName = $skinName['skinname'];
357 }
358 global $wgScript, $wgTitle, $wgStylePath, $wgUser;
359 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang, $wgVariant;
360 global $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
361 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
362 global $wgUseAjax, $wgAjaxWatch;
363 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
364 global $wgRestrictionTypes, $wgLivePreview;
365 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
366
367 $ns = $wgTitle->getNamespace();
368 $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
369 $separatorTransTable = $wgContLang->separatorTransformTable();
370 $separatorTransTable = $separatorTransTable ? $separatorTransTable : array();
371 $compactSeparatorTransTable = array(
372 implode( "\t", array_keys( $separatorTransTable ) ),
373 implode( "\t", $separatorTransTable ),
374 );
375 $digitTransTable = $wgContLang->digitTransformTable();
376 $digitTransTable = $digitTransTable ? $digitTransTable : array();
377 $compactDigitTransTable = array(
378 implode( "\t", array_keys( $digitTransTable ) ),
379 implode( "\t", $digitTransTable ),
380 );
381
382 $mainPage = Title::newFromText( wfMsgForContent( 'mainpage' ) );
383 $vars = array(
384 'skin' => $skinName,
385 'stylepath' => $wgStylePath,
386 'wgArticlePath' => $wgArticlePath,
387 'wgScriptPath' => $wgScriptPath,
388 'wgScript' => $wgScript,
389 'wgVariantArticlePath' => $wgVariantArticlePath,
390 'wgActionPaths' => (object)$wgActionPaths,
391 'wgServer' => $wgServer,
392 'wgCanonicalNamespace' => $nsname,
393 'wgCanonicalSpecialPageName' => SpecialPage::resolveAlias( $wgTitle->getDBkey() ),
394 'wgNamespaceNumber' => $wgTitle->getNamespace(),
395 'wgPageName' => $wgTitle->getPrefixedDBKey(),
396 'wgTitle' => $wgTitle->getText(),
397 'wgAction' => $wgRequest->getText( 'action', 'view' ),
398 'wgArticleId' => $wgTitle->getArticleId(),
399 'wgIsArticle' => $wgOut->isArticle(),
400 'wgUserName' => $wgUser->isAnon() ? NULL : $wgUser->getName(),
401 'wgUserGroups' => $wgUser->isAnon() ? NULL : $wgUser->getEffectiveGroups(),
402 'wgUserVariant' => $wgVariant->getCode(),
403 'wgUserLanguage' => $wgLang->getCode(),
404 'wgContentLanguage' => $wgContLang->getCode(),
405 'wgBreakFrames' => $wgBreakFrames,
406 'wgCurRevisionId' => isset( $wgArticle ) ? $wgArticle->getLatest() : 0,
407 'wgVersion' => $wgVersion,
408 'wgEnableAPI' => $wgEnableAPI,
409 'wgEnableWriteAPI' => $wgEnableWriteAPI,
410 'wgSeparatorTransformTable' => $compactSeparatorTransTable,
411 'wgDigitTransformTable' => $compactDigitTransTable,
412 'wgMainPageTitle' => $mainPage ? $mainPage->getPrefixedText() : null,
413 );
414 if ( !( $wgContLang->hasVariants() ) ) {
415 unset( $vars['wgUserVariant'] );
416 }
417
418 //if on upload page output the extension list & js_upload
419 if( SpecialPage::resolveAlias( $wgTitle->getDBkey() ) == "Upload" ){
420 global $wgFileExtensions, $wgAjaxUploadInterface;
421 $vars['wgFileExtensions'] = $wgFileExtensions;
422 $vars['wgAjaxUploadInterface'] = $wgAjaxUploadInterface;
423 }
424
425 if( $wgUseAjax && $wgEnableMWSuggest && !$wgUser->getOption( 'disablesuggest', false ) ){
426 $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate();
427 $vars['wgDBname'] = $wgDBname;
428 $vars['wgSearchNamespaces'] = SearchEngine::userNamespaces( $wgUser );
429 $vars['wgMWSuggestMessages'] = array( wfMsg( 'search-mwsuggest-enabled' ), wfMsg( 'search-mwsuggest-disabled' ) );
430 }
431
432 foreach( $wgRestrictionTypes as $type )
433 $vars['wgRestriction' . ucfirst( $type )] = $wgTitle->getRestrictions( $type );
434
435 if ( $wgLivePreview && $wgUser->getOption( 'uselivepreview' ) ) {
436 $vars['wgLivepreviewMessageLoading'] = wfMsg( 'livepreview-loading' );
437 $vars['wgLivepreviewMessageReady'] = wfMsg( 'livepreview-ready' );
438 $vars['wgLivepreviewMessageFailed'] = wfMsg( 'livepreview-failed' );
439 $vars['wgLivepreviewMessageError'] = wfMsg( 'livepreview-error' );
440 }
441
442 if ( $wgOut->isArticleRelated() && $wgUseAjax && $wgAjaxWatch && $wgUser->isLoggedIn() ) {
443 $msgs = (object)array();
444 foreach ( array( 'watch', 'unwatch', 'watching', 'unwatching' ) as $msgName ) {
445 $msgs->{$msgName . 'Msg'} = wfMsg( $msgName );
446 }
447 $vars['wgAjaxWatch'] = $msgs;
448 }
449
450 // Allow extensions to add their custom variables to the global JS variables
451 wfRunHooks( 'MakeGlobalVariablesScript', array( &$vars ) );
452
453 return self::makeVariablesScript( $vars );
454 }
455 /**
456 * Return a random selection of the scripts we want in the header,
457 * according to no particular rhyme or reason. Various other scripts are
458 * returned from a haphazard assortment of other functions scattered over
459 * various files. This entire hackish system needs to be burned to the
460 * ground and rebuilt.
461 *
462 * @param $out OutputPage object, should be $wgOut
463 *
464 * @return string Raw HTML to output to <head>
465 */
466 function getHeadScripts( OutputPage $out ) {
467 global $wgStylePath, $wgUser, $wgJsMimeType, $wgStyleVersion, $wgOut;
468 global $wgUseSiteJs;
469
470 $vars = self::makeGlobalVariablesScript( $this->getSkinName() );
471
472 //moved wikibits to be called earlier on
473 //$out->addScriptFile( "{$wgStylePath}/common/wikibits.js" );
474 if( $wgUseSiteJs ) {
475 $jsCache = $wgUser->isLoggedIn() ? '&smaxage=0' : '';
476 $wgOut->addScriptFile( self::makeUrl( '-',
477 "action=raw$jsCache&gen=js&useskin=" .
478 urlencode( $this->getSkinName() )
479 )
480 );
481 }
482 if( $out->isUserJsAllowed() && $wgUser->isLoggedIn() ) {
483 $userpage = $wgUser->getUserPage();
484 $userjs = self::makeUrl(
485 $userpage->getPrefixedText().'/'.$this->getSkinName().'.js',
486 'action=raw&ctype='.$wgJsMimeType );
487 $wgOut->addScriptFile( $userjs );
488 }
489 return $vars . "\n" . $out->mScripts;
490 }
491
492 /**
493 * To make it harder for someone to slip a user a fake
494 * user-JavaScript or user-CSS preview, a random token
495 * is associated with the login session. If it's not
496 * passed back with the preview request, we won't render
497 * the code.
498 *
499 * @param string $action
500 * @return bool
501 * @private
502 */
503 function userCanPreview( $action ) {
504 global $wgRequest, $wgUser;
505
506 if( $action != 'submit' )
507 return false;
508 if( !$wgRequest->wasPosted() )
509 return false;
510 if( !$this->mTitle->userCanEditCssSubpage() )
511 return false;
512 if( !$this->mTitle->userCanEditJsSubpage() )
513 return false;
514 return $wgUser->matchEditToken(
515 $wgRequest->getVal( 'wpEditToken' ) );
516 }
517
518 /**
519 * generated JavaScript action=raw&gen=js
520 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
521 * nated together. For some bizarre reason, it does *not* return any
522 * custom user JS from subpages. Huh?
523 *
524 * There's absolutely no reason to have separate Monobook/Common JSes.
525 * Any JS that cares can just check the skin variable generated at the
526 * top. For now Monobook.js will be maintained, but it should be consi-
527 * dered deprecated.
528 *
529 * @param force_skin lets you override the skin name
530 *
531 * @return string
532 */
533 public function generateUserJs( $skinName = null) {
534 global $wgStylePath;
535
536 wfProfileIn( __METHOD__ );
537 if(!$skinName){
538 $skinName = $this->getSkinName();
539 }
540
541 $s = "/* generated javascript */\n";
542 $s .= "var skin = '" . Xml::escapeJsString($skinName ) . "';\n";
543 $s .= "var stylepath = '" . Xml::escapeJsString( $wgStylePath ) . "';";
544 $s .= "\n\n/* MediaWiki:Common.js */\n";
545 $commonJs = wfMsgForContent( 'common.js' );
546 if ( !wfEmptyMsg( 'common.js', $commonJs ) ) {
547 $s .= $commonJs;
548 }
549
550 $s .= "\n\n/* MediaWiki:".ucfirst( $skinName ).".js */\n";
551 // avoid inclusion of non defined user JavaScript (with custom skins only)
552 // by checking for default message content
553 $msgKey = ucfirst( $skinName ).'.js';
554 $userJS = wfMsgForContent( $msgKey );
555 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
556 $s .= $userJS;
557 }
558
559 wfProfileOut( __METHOD__ );
560 return $s;
561 }
562
563 /**
564 * Generate user stylesheet for action=raw&gen=css
565 */
566 public function generateUserStylesheet() {
567 wfProfileIn( __METHOD__ );
568 $s = "/* generated user stylesheet */\n" .
569 $this->reallyGenerateUserStylesheet();
570 wfProfileOut( __METHOD__ );
571 return $s;
572 }
573
574 /**
575 * Split for easier subclassing in SkinSimple, SkinStandard and SkinCologneBlue
576 */
577 protected function reallyGenerateUserStylesheet(){
578 global $wgUser;
579 $s = '';
580 if( ( $undopt = $wgUser->getOption( 'underline' ) ) < 2 ) {
581 $underline = $undopt ? 'underline' : 'none';
582 $s .= "a { text-decoration: $underline; }\n";
583 }
584 if( $wgUser->getOption( 'highlightbroken' ) ) {
585 $s .= "a.new, #quickbar a.new { color: #CC2200; }\n";
586 } else {
587 $s .= <<<END
588 a.new, #quickbar a.new,
589 a.stub, #quickbar a.stub {
590 color: inherit;
591 }
592 a.new:after, #quickbar a.new:after {
593 content: "?";
594 color: #CC2200;
595 }
596 a.stub:after, #quickbar a.stub:after {
597 content: "!";
598 color: #772233;
599 }
600 END;
601 }
602 if( $wgUser->getOption( 'justify' ) ) {
603 $s .= "#article, #bodyContent, #mw_content { text-align: justify; }\n";
604 }
605 if( !$wgUser->getOption( 'showtoc' ) ) {
606 $s .= "#toc { display: none; }\n";
607 }
608 if( !$wgUser->getOption( 'editsection' ) ) {
609 $s .= ".editsection { display: none; }\n";
610 }
611 $fontstyle = $wgUser->getOption( 'editfont' );
612 if ( $fontstyle !== 'default' ) {
613 $s .= "textarea { font-family: $fontstyle; }\n";
614 }
615 return $s;
616 }
617
618 /**
619 * @private
620 */
621 function setupUserCss( OutputPage $out ) {
622 global $wgRequest, $wgContLang, $wgUser;
623 global $wgAllowUserCss, $wgUseSiteCss, $wgSquidMaxage, $wgStylePath;
624
625 wfProfileIn( __METHOD__ );
626
627 $this->setupSkinUserCss( $out );
628
629 $siteargs = array(
630 'action' => 'raw',
631 'maxage' => $wgSquidMaxage,
632 );
633
634 // Add any extension CSS
635 foreach ( $out->getExtStyle() as $url ) {
636 $out->addStyle( $url );
637 }
638
639 // If we use the site's dynamic CSS, throw that in, too
640 // Per-site custom styles
641 if( $wgUseSiteCss ) {
642 global $wgHandheldStyle;
643 $query = wfArrayToCGI( array(
644 'usemsgcache' => 'yes',
645 'ctype' => 'text/css',
646 'smaxage' => $wgSquidMaxage
647 ) + $siteargs );
648 # Site settings must override extension css! (bug 15025)
649 $out->addStyle( self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI ) );
650 $out->addStyle( self::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI ), 'print' );
651 if( $wgHandheldStyle ) {
652 $out->addStyle( self::makeNSUrl( 'Handheld.css', $query, NS_MEDIAWIKI ), 'handheld' );
653 }
654 $out->addStyle( self::makeNSUrl( $this->getSkinName() . '.css', $query, NS_MEDIAWIKI ) );
655 }
656
657 if( $wgUser->isLoggedIn() ) {
658 // Ensure that logged-in users' generated CSS isn't clobbered
659 // by anons' publicly cacheable generated CSS.
660 $siteargs['smaxage'] = '0';
661 $siteargs['ts'] = $wgUser->mTouched;
662 }
663 // Per-user styles based on preferences
664 $siteargs['gen'] = 'css';
665 if( ( $us = $wgRequest->getVal( 'useskin', '' ) ) !== '' ) {
666 $siteargs['useskin'] = $us;
667 }
668 $out->addStyle( self::makeUrl( '-', wfArrayToCGI( $siteargs ) ) );
669
670 // Per-user custom style pages
671 if( $wgAllowUserCss && $wgUser->isLoggedIn() ) {
672 $action = $wgRequest->getVal( 'action' );
673 # If we're previewing the CSS page, use it
674 if( $this->mTitle->isCssSubpage() && $this->userCanPreview( $action ) ) {
675 $previewCss = $wgRequest->getText( 'wpTextbox1' );
676 // @FIXME: properly escape the cdata!
677 $this->usercss = "/*<![CDATA[*/\n" . $previewCss . "/*]]>*/";
678 } else {
679 $out->addStyle( self::makeUrl( $this->userpage . '/' . $this->getSkinName() .'.css',
680 'action=raw&ctype=text/css' ) );
681 }
682 }
683
684 wfProfileOut( __METHOD__ );
685 }
686
687 /**
688 * Add skin specific stylesheets
689 * @param $out OutputPage
690 */
691 function setupSkinUserCss( OutputPage $out ) {
692 $out->addStyle( 'common/shared.css' );
693 $out->addStyle( 'common/oldshared.css' );
694 $out->addStyle( $this->getStylesheet() );
695 $out->addStyle( 'common/common_rtl.css', '', '', 'rtl' );
696 }
697
698 function getBodyOptions() {
699 global $wgUser, $wgOut, $wgRequest, $wgContLang;
700
701 extract( $wgRequest->getValues( 'oldid', 'redirect', 'diff' ) );
702
703 if ( 0 != $this->mTitle->getNamespace() ) {
704 $a = array( 'bgcolor' => '#ffffec' );
705 }
706 else $a = array( 'bgcolor' => '#FFFFFF' );
707 if( $wgOut->isArticle() && $wgUser->getOption( 'editondblclick' ) &&
708 $this->mTitle->quickUserCan( 'edit' ) ) {
709 $s = $this->mTitle->getFullURL( $this->editUrlOptions() );
710 $s = 'document.location = "' .Xml::escapeJsString( $s ) .'";';
711 $a += array( 'ondblclick' => $s );
712 }
713 $a['onload'] = $wgOut->getOnloadHandler();
714 $a['class'] =
715 'mediawiki' .
716 ' '.( $wgContLang->getDir() ).
717 ' '.$this->getPageClasses( $this->mTitle ) .
718 ' skin-'. Sanitizer::escapeClass( $this->getSkinName() );
719 return $a;
720 }
721
722 function getPageClasses( $title ) {
723 $numeric = 'ns-'.$title->getNamespace();
724 if( $title->getNamespace() == NS_SPECIAL ) {
725 $type = 'ns-special';
726 } elseif( $title->isTalkPage() ) {
727 $type = 'ns-talk';
728 } else {
729 $type = 'ns-subject';
730 }
731 $name = Sanitizer::escapeClass( 'page-'.$title->getPrefixedText() );
732 return "$numeric $type $name";
733 }
734
735 /**
736 * URL to the logo
737 */
738 function getLogo() {
739 global $wgLogo;
740 return $wgLogo;
741 }
742
743 /**
744 * This will be called immediately after the <body> tag. Split into
745 * two functions to make it easier to subclass.
746 */
747 function beforeContent() {
748 return $this->doBeforeContent();
749 }
750
751 function doBeforeContent() {
752 global $wgContLang;
753 wfProfileIn( __METHOD__ );
754
755 $s = '';
756 $qb = $this->qbSetting();
757
758 if( $langlinks = $this->otherLanguages() ) {
759 $rows = 2;
760 $borderhack = '';
761 } else {
762 $rows = 1;
763 $langlinks = false;
764 $borderhack = 'class="top"';
765 }
766
767 $s .= "\n<div id='content'>\n<div id='topbar'>\n" .
768 "<table border='0' cellspacing='0' width='98%'>\n<tr>\n";
769
770 $shove = ( $qb != 0 );
771 $left = ( $qb == 1 || $qb == 3 );
772 if( $wgContLang->isRTL() ) $left = !$left;
773
774 if( !$shove ) {
775 $s .= "<td class='top' align='left' valign='top' rowspan='{$rows}'>\n" .
776 $this->logoText() . '</td>';
777 } elseif( $left ) {
778 $s .= $this->getQuickbarCompensator( $rows );
779 }
780 $l = $wgContLang->alignStart();
781 $s .= "<td {$borderhack} align='$l' valign='top'>\n";
782
783 $s .= $this->topLinks();
784 $s .= "<p class='subtitle'>" . $this->pageTitleLinks() . "</p>\n";
785
786 $r = $wgContLang->alignEnd();
787 $s .= "</td>\n<td {$borderhack} valign='top' align='$r' nowrap='nowrap'>";
788 $s .= $this->nameAndLogin();
789 $s .= "\n<br />" . $this->searchForm() . "</td>";
790
791 if ( $langlinks ) {
792 $s .= "</tr>\n<tr>\n<td class='top' colspan=\"2\">$langlinks</td>\n";
793 }
794
795 if ( $shove && !$left ) { # Right
796 $s .= $this->getQuickbarCompensator( $rows );
797 }
798 $s .= "</tr>\n</table>\n</div>\n";
799 $s .= "\n<div id='article'>\n";
800
801 $notice = wfGetSiteNotice();
802 if( $notice ) {
803 $s .= "\n<div id='siteNotice'>$notice</div>\n";
804 }
805 $s .= $this->pageTitle();
806 $s .= $this->pageSubtitle();
807 $s .= $this->getCategories();
808 wfProfileOut( __METHOD__ );
809 return $s;
810 }
811
812
813 function getCategoryLinks() {
814 global $wgOut, $wgUseCategoryBrowser;
815 global $wgContLang, $wgUser;
816
817 if( count( $wgOut->mCategoryLinks ) == 0 ) return '';
818
819 # Separator
820 $sep = wfMsgExt( 'catseparator', array( 'parsemag', 'escapenoentities' ) );
821
822 // Use Unicode bidi embedding override characters,
823 // to make sure links don't smash each other up in ugly ways.
824 $dir = $wgContLang->getDir();
825 $embed = "<span dir='$dir'>";
826 $pop = '</span>';
827
828 $allCats = $wgOut->getCategoryLinks();
829 $s = '';
830 $colon = wfMsgExt( 'colon-separator', 'escapenoentities' );
831 if ( !empty( $allCats['normal'] ) ) {
832 $t = $embed . implode( "{$pop} {$sep} {$embed}" , $allCats['normal'] ) . $pop;
833
834 $msg = wfMsgExt( 'pagecategories', array( 'parsemag', 'escapenoentities' ), count( $allCats['normal'] ) );
835 $s .= '<div id="mw-normal-catlinks">' .
836 $this->link( Title::newFromText( wfMsgForContent( 'pagecategorieslink' ) ), $msg )
837 . $colon . $t . '</div>';
838 }
839
840 # Hidden categories
841 if ( isset( $allCats['hidden'] ) ) {
842 if ( $wgUser->getBoolOption( 'showhiddencats' ) ) {
843 $class ='mw-hidden-cats-user-shown';
844 } elseif ( $this->mTitle->getNamespace() == NS_CATEGORY ) {
845 $class = 'mw-hidden-cats-ns-shown';
846 } else {
847 $class = 'mw-hidden-cats-hidden';
848 }
849 $s .= "<div id=\"mw-hidden-catlinks\" class=\"$class\">" .
850 wfMsgExt( 'hidden-categories', array( 'parsemag', 'escapenoentities' ), count( $allCats['hidden'] ) ) .
851 $colon . $embed . implode( "$pop $sep $embed", $allCats['hidden'] ) . $pop .
852 "</div>";
853 }
854
855 # optional 'dmoz-like' category browser. Will be shown under the list
856 # of categories an article belong to
857 if( $wgUseCategoryBrowser ){
858 $s .= '<br /><hr />';
859
860 # get a big array of the parents tree
861 $parenttree = $this->mTitle->getParentCategoryTree();
862 # Skin object passed by reference cause it can not be
863 # accessed under the method subfunction drawCategoryBrowser
864 $tempout = explode( "\n", Skin::drawCategoryBrowser( $parenttree, $this ) );
865 # Clean out bogus first entry and sort them
866 unset( $tempout[0] );
867 asort( $tempout );
868 # Output one per line
869 $s .= implode( "<br />\n", $tempout );
870 }
871
872 return $s;
873 }
874
875 /**
876 * Render the array as a serie of links.
877 * @param $tree Array: categories tree returned by Title::getParentCategoryTree
878 * @param &skin Object: skin passed by reference
879 * @return String separated by &gt;, terminate with "\n"
880 */
881 function drawCategoryBrowser( $tree, &$skin ){
882 $return = '';
883 foreach( $tree as $element => $parent ) {
884 if( empty( $parent ) ) {
885 # element start a new list
886 $return .= "\n";
887 } else {
888 # grab the others elements
889 $return .= Skin::drawCategoryBrowser( $parent, $skin ) . ' &gt; ';
890 }
891 # add our current element to the list
892 $eltitle = Title::newFromText( $element );
893 $return .= $skin->link( $eltitle, $eltitle->getText() );
894 }
895 return $return;
896 }
897
898 function getCategories() {
899 $catlinks=$this->getCategoryLinks();
900
901 $classes = 'catlinks';
902
903 if( strpos( $catlinks, '<div id="mw-normal-catlinks">' ) === false ) {
904 $classes .= ' catlinks-allhidden';
905 }
906
907 return "<div id='catlinks' class='$classes'>{$catlinks}</div>";
908 }
909
910 function getQuickbarCompensator( $rows = 1 ) {
911 return "<td width='152' rowspan='{$rows}'>&nbsp;</td>";
912 }
913
914 /**
915 * This runs a hook to allow extensions placing their stuff after content
916 * and article metadata (e.g. categories).
917 * Note: This function has nothing to do with afterContent().
918 *
919 * This hook is placed here in order to allow using the same hook for all
920 * skins, both the SkinTemplate based ones and the older ones, which directly
921 * use this class to get their data.
922 *
923 * The output of this function gets processed in SkinTemplate::outputPage() for
924 * the SkinTemplate based skins, all other skins should directly echo it.
925 *
926 * Returns an empty string by default, if not changed by any hook function.
927 */
928 protected function afterContentHook() {
929 $data = '';
930
931 if( wfRunHooks( 'SkinAfterContent', array( &$data ) ) ){
932 // adding just some spaces shouldn't toggle the output
933 // of the whole <div/>, so we use trim() here
934 if( trim( $data ) != '' ){
935 // Doing this here instead of in the skins to
936 // ensure that the div has the same ID in all
937 // skins
938 $data = "<div id='mw-data-after-content'>\n" .
939 "\t$data\n" .
940 "</div>\n";
941 }
942 } else {
943 wfDebug( "Hook SkinAfterContent changed output processing.\n" );
944 }
945
946 return $data;
947 }
948
949 /**
950 * Generate debug data HTML for displaying at the bottom of the main content
951 * area.
952 * @return String HTML containing debug data, if enabled (otherwise empty).
953 */
954 protected function generateDebugHTML() {
955 global $wgShowDebug, $wgOut;
956 if ( $wgShowDebug ) {
957 $listInternals = str_replace( "\n", "</li>\n<li>", htmlspecialchars( $wgOut->mDebugtext ) );
958 return "\n<hr>\n<strong>Debug data:</strong><ul style=\"font-family:monospace;\"><li>" .
959 $listInternals . "</li></ul>\n";
960 }
961 return '';
962 }
963
964 /**
965 * This gets called shortly before the </body> tag.
966 * @return String HTML to be put before </body>
967 */
968 function afterContent() {
969 $printfooter = "<div class=\"printfooter\">\n" . $this->printFooter() . "</div>\n";
970 return $printfooter . $this->generateDebugHTML() . $this->doAfterContent();
971 }
972
973 /**
974 * This gets called shortly before the </body> tag.
975 * @return String HTML-wrapped JS code to be put before </body>
976 */
977 function bottomScripts() {
978 $bottomScriptText = "\n" . Html::inlineScript( 'if (window.runOnloadHook) runOnloadHook();' ) . "\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 ( !$wgOut->isPrintable() ) {
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\" width=\"88\" height=\"31\" />";
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.'" height="31" width="88" 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 private function footerLink ( $desc, $page ) {
1587 // if the link description has been set to "-" in the default language,
1588 if ( wfMsgForContent( $desc ) == '-') {
1589 // then it is disabled, for all languages.
1590 return '';
1591 } else {
1592 // Otherwise, we display the link for the user, described in their
1593 // language (which may or may not be the same as the default language),
1594 // but we make the link target be the one site-wide page.
1595 $title = Title::newFromText( wfMsgForContent( $page ) );
1596 return $this->linkKnown(
1597 $title,
1598 wfMsgExt( $desc, array( 'parsemag', 'escapenoentities' ) )
1599 );
1600 }
1601 }
1602
1603 function privacyLink() {
1604 return $this->footerLink( 'privacy', 'privacypage' );
1605 }
1606
1607 function aboutLink() {
1608 return $this->footerLink( 'aboutsite', 'aboutpage' );
1609 }
1610
1611 function disclaimerLink() {
1612 return $this->footerLink( 'disclaimers', 'disclaimerpage' );
1613 }
1614
1615 function editThisPage() {
1616 global $wgOut;
1617
1618 if ( !$wgOut->isArticleRelated() ) {
1619 $s = wfMsg( 'protectedpage' );
1620 } else {
1621 if( $this->mTitle->quickUserCan( 'edit' ) && $this->mTitle->exists() ) {
1622 $t = wfMsg( 'editthispage' );
1623 } elseif( $this->mTitle->quickUserCan( 'create' ) && !$this->mTitle->exists() ) {
1624 $t = wfMsg( 'create-this-page' );
1625 } else {
1626 $t = wfMsg( 'viewsource' );
1627 }
1628
1629 $s = $this->link(
1630 $this->mTitle,
1631 $t,
1632 array(),
1633 $this->editUrlOptions(),
1634 array( 'known', 'noclasses' )
1635 );
1636 }
1637 return $s;
1638 }
1639
1640 /**
1641 * Return URL options for the 'edit page' link.
1642 * This may include an 'oldid' specifier, if the current page view is such.
1643 *
1644 * @return array
1645 * @private
1646 */
1647 function editUrlOptions() {
1648 global $wgArticle;
1649
1650 $options = array( 'action' => 'edit' );
1651
1652 if( $this->mRevisionId && ! $wgArticle->isCurrent() ) {
1653 $options['oldid'] = intval( $this->mRevisionId );
1654 }
1655
1656 return $options;
1657 }
1658
1659 function deleteThisPage() {
1660 global $wgUser, $wgRequest;
1661
1662 $diff = $wgRequest->getVal( 'diff' );
1663 if ( $this->mTitle->getArticleId() && ( !$diff ) && $wgUser->isAllowed( 'delete' ) ) {
1664 $t = wfMsg( 'deletethispage' );
1665
1666 $s = $this->link(
1667 $this->mTitle,
1668 $t,
1669 array(),
1670 array( 'action' => 'delete' ),
1671 array( 'known', 'noclasses' )
1672 );
1673 } else {
1674 $s = '';
1675 }
1676 return $s;
1677 }
1678
1679 function protectThisPage() {
1680 global $wgUser, $wgRequest;
1681
1682 $diff = $wgRequest->getVal( 'diff' );
1683 if ( $this->mTitle->getArticleId() && ( ! $diff ) && $wgUser->isAllowed('protect') ) {
1684 if ( $this->mTitle->isProtected() ) {
1685 $text = wfMsg( 'unprotectthispage' );
1686 $query = array( 'action' => 'unprotect' );
1687 } else {
1688 $text = wfMsg( 'protectthispage' );
1689 $query = array( 'action' => 'protect' );
1690 }
1691
1692 $s = $this->link(
1693 $this->mTitle,
1694 $text,
1695 array(),
1696 $query,
1697 array( 'known', 'noclasses' )
1698 );
1699 } else {
1700 $s = '';
1701 }
1702 return $s;
1703 }
1704
1705 function watchThisPage() {
1706 global $wgOut;
1707 ++$this->mWatchLinkNum;
1708
1709 if ( $wgOut->isArticleRelated() ) {
1710 if ( $this->mTitle->userIsWatching() ) {
1711 $text = wfMsg( 'unwatchthispage' );
1712 $query = array( 'action' => 'unwatch' );
1713 $id = 'mw-unwatch-link' . $this->mWatchLinkNum;
1714 } else {
1715 $text = wfMsg( 'watchthispage' );
1716 $query = array( 'action' => 'watch' );
1717 $id = 'mw-watch-link' . $this->mWatchLinkNum;
1718 }
1719
1720 $s = $this->link(
1721 $this->mTitle,
1722 $text,
1723 array( 'id' => $id ),
1724 $query,
1725 array( 'known', 'noclasses' )
1726 );
1727 } else {
1728 $s = wfMsg( 'notanarticle' );
1729 }
1730 return $s;
1731 }
1732
1733 function moveThisPage() {
1734 if ( $this->mTitle->quickUserCan( 'move' ) ) {
1735 return $this->link(
1736 SpecialPage::getTitleFor( 'Movepage' ),
1737 wfMsg( 'movethispage' ),
1738 array(),
1739 array( 'target' => $this->mTitle->getPrefixedDBkey() ),
1740 array( 'known', 'noclasses' )
1741 );
1742 } else {
1743 // no message if page is protected - would be redundant
1744 return '';
1745 }
1746 }
1747
1748 function historyLink() {
1749 return $this->link(
1750 $this->mTitle,
1751 wfMsgHtml( 'history' ),
1752 array( 'rel' => 'archives' ),
1753 array( 'action' => 'history' )
1754 );
1755 }
1756
1757 function whatLinksHere() {
1758 return $this->link(
1759 SpecialPage::getTitleFor( 'Whatlinkshere', $this->mTitle->getPrefixedDBkey() ),
1760 wfMsgHtml( 'whatlinkshere' ),
1761 array(),
1762 array(),
1763 array( 'known', 'noclasses' )
1764 );
1765 }
1766
1767 function userContribsLink() {
1768 return $this->link(
1769 SpecialPage::getTitleFor( 'Contributions', $this->mTitle->getDBkey() ),
1770 wfMsgHtml( 'contributions' ),
1771 array(),
1772 array(),
1773 array( 'known', 'noclasses' )
1774 );
1775 }
1776
1777 function showEmailUser( $id ) {
1778 global $wgUser;
1779 $targetUser = User::newFromId( $id );
1780 return $wgUser->canSendEmail() && # the sending user must have a confirmed email address
1781 $targetUser->canReceiveEmail(); # the target user must have a confirmed email address and allow emails from users
1782 }
1783
1784 function emailUserLink() {
1785 return $this->link(
1786 SpecialPage::getTitleFor( 'Emailuser', $this->mTitle->getDBkey() ),
1787 wfMsg( 'emailuser' ),
1788 array(),
1789 array(),
1790 array( 'known', 'noclasses' )
1791 );
1792 }
1793
1794 function watchPageLinksLink() {
1795 global $wgOut;
1796 if ( ! $wgOut->isArticleRelated() ) {
1797 return '(' . wfMsg( 'notanarticle' ) . ')';
1798 } else {
1799 return $this->link(
1800 SpecialPage::getTitleFor( 'Recentchangeslinked', $this->mTitle->getPrefixedDBkey() ),
1801 wfMsg( 'recentchangeslinked-toolbox' ),
1802 array(),
1803 array(),
1804 array( 'known', 'noclasses' )
1805 );
1806 }
1807 }
1808
1809 function trackbackLink() {
1810 return '<a href="' . $this->mTitle->trackbackURL() . '">'
1811 . wfMsg( 'trackbacklink' ) . '</a>';
1812 }
1813
1814 function otherLanguages() {
1815 global $wgOut, $wgContLang, $wgHideInterlanguageLinks;
1816
1817 if ( $wgHideInterlanguageLinks ) {
1818 return '';
1819 }
1820
1821 $a = $wgOut->getLanguageLinks();
1822 if ( 0 == count( $a ) ) {
1823 return '';
1824 }
1825
1826 $s = wfMsg( 'otherlanguages' ) . wfMsg( 'colon-separator' );
1827 $first = true;
1828 if( $wgContLang->isRTL() ) $s .= '<span dir="LTR">';
1829 foreach( $a as $l ) {
1830 if ( !$first ) {
1831 $s .= wfMsgExt( 'pipe-separator', 'escapenoentities' );
1832 }
1833 $first = false;
1834
1835 $nt = Title::newFromText( $l );
1836 $url = $nt->escapeFullURL();
1837 $text = $wgContLang->getLanguageName( $nt->getInterwiki() );
1838
1839 if ( '' == $text ) { $text = $l; }
1840 $style = $this->getExternalLinkAttributes();
1841 $s .= "<a href=\"{$url}\"{$style}>{$text}</a>";
1842 }
1843 if( $wgContLang->isRTL() ) $s .= '</span>';
1844 return $s;
1845 }
1846
1847 function talkLink() {
1848 if ( NS_SPECIAL == $this->mTitle->getNamespace() ) {
1849 # No discussion links for special pages
1850 return '';
1851 }
1852
1853 $linkOptions = array();
1854
1855 if( $this->mTitle->isTalkPage() ) {
1856 $link = $this->mTitle->getSubjectPage();
1857 switch( $link->getNamespace() ) {
1858 case NS_MAIN:
1859 $text = wfMsg( 'articlepage' );
1860 break;
1861 case NS_USER:
1862 $text = wfMsg( 'userpage' );
1863 break;
1864 case NS_PROJECT:
1865 $text = wfMsg( 'projectpage' );
1866 break;
1867 case NS_FILE:
1868 $text = wfMsg( 'imagepage' );
1869 # Make link known if image exists, even if the desc. page doesn't.
1870 if( wfFindFile( $link ) )
1871 $linkOptions[] = 'known';
1872 break;
1873 case NS_MEDIAWIKI:
1874 $text = wfMsg( 'mediawikipage' );
1875 break;
1876 case NS_TEMPLATE:
1877 $text = wfMsg( 'templatepage' );
1878 break;
1879 case NS_HELP:
1880 $text = wfMsg( 'viewhelppage' );
1881 break;
1882 case NS_CATEGORY:
1883 $text = wfMsg( 'categorypage' );
1884 break;
1885 default:
1886 $text = wfMsg( 'articlepage' );
1887 }
1888 } else {
1889 $link = $this->mTitle->getTalkPage();
1890 $text = wfMsg( 'talkpage' );
1891 }
1892
1893 $s = $this->link( $link, $text, array(), array(), $linkOptions );
1894
1895 return $s;
1896 }
1897
1898 function commentLink() {
1899 global $wgOut;
1900
1901 if ( $this->mTitle->getNamespace() == NS_SPECIAL ) {
1902 return '';
1903 }
1904
1905 # __NEWSECTIONLINK___ changes behaviour here
1906 # If it is present, the link points to this page, otherwise
1907 # it points to the talk page
1908 if( $this->mTitle->isTalkPage() ) {
1909 $title = $this->mTitle;
1910 } elseif( $wgOut->showNewSectionLink() ) {
1911 $title = $this->mTitle;
1912 } else {
1913 $title = $this->mTitle->getTalkPage();
1914 }
1915
1916 return $this->link(
1917 $title,
1918 wfMsg( 'postcomment' ),
1919 array(),
1920 array(
1921 'action' => 'edit',
1922 'section' => 'new'
1923 ),
1924 array( 'known', 'noclasses' )
1925 );
1926 }
1927
1928 /* these are used extensively in SkinTemplate, but also some other places */
1929 static function makeMainPageUrl( $urlaction = '' ) {
1930 $title = Title::newMainPage();
1931 self::checkTitle( $title, '' );
1932 return $title->getLocalURL( $urlaction );
1933 }
1934
1935 static function makeSpecialUrl( $name, $urlaction = '' ) {
1936 $title = SpecialPage::getTitleFor( $name );
1937 return $title->getLocalURL( $urlaction );
1938 }
1939
1940 static function makeSpecialUrlSubpage( $name, $subpage, $urlaction = '' ) {
1941 $title = SpecialPage::getSafeTitleFor( $name, $subpage );
1942 return $title->getLocalURL( $urlaction );
1943 }
1944
1945 static function makeI18nUrl( $name, $urlaction = '' ) {
1946 $title = Title::newFromText( wfMsgForContent( $name ) );
1947 self::checkTitle( $title, $name );
1948 return $title->getLocalURL( $urlaction );
1949 }
1950
1951 static function makeUrl( $name, $urlaction = '' ) {
1952 $title = Title::newFromText( $name );
1953 self::checkTitle( $title, $name );
1954 return $title->getLocalURL( $urlaction );
1955 }
1956
1957 # If url string starts with http, consider as external URL, else
1958 # internal
1959 static function makeInternalOrExternalUrl( $name ) {
1960 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $name ) ) {
1961 return $name;
1962 } else {
1963 return self::makeUrl( $name );
1964 }
1965 }
1966
1967 # this can be passed the NS number as defined in Language.php
1968 static function makeNSUrl( $name, $urlaction = '', $namespace = NS_MAIN ) {
1969 $title = Title::makeTitleSafe( $namespace, $name );
1970 self::checkTitle( $title, $name );
1971 return $title->getLocalURL( $urlaction );
1972 }
1973
1974 /* these return an array with the 'href' and boolean 'exists' */
1975 static function makeUrlDetails( $name, $urlaction = '' ) {
1976 $title = Title::newFromText( $name );
1977 self::checkTitle( $title, $name );
1978 return array(
1979 'href' => $title->getLocalURL( $urlaction ),
1980 'exists' => $title->getArticleID() != 0 ? true : false
1981 );
1982 }
1983
1984 /**
1985 * Make URL details where the article exists (or at least it's convenient to think so)
1986 */
1987 static function makeKnownUrlDetails( $name, $urlaction = '' ) {
1988 $title = Title::newFromText( $name );
1989 self::checkTitle( $title, $name );
1990 return array(
1991 'href' => $title->getLocalURL( $urlaction ),
1992 'exists' => true
1993 );
1994 }
1995
1996 # make sure we have some title to operate on
1997 static function checkTitle( &$title, $name ) {
1998 if( !is_object( $title ) ) {
1999 $title = Title::newFromText( $name );
2000 if( !is_object( $title ) ) {
2001 $title = Title::newFromText( '--error: link target missing--' );
2002 }
2003 }
2004 }
2005
2006 /**
2007 * Build an array that represents the sidebar(s), the navigation bar among them
2008 *
2009 * @return array
2010 */
2011 function buildSidebar() {
2012 global $parserMemc, $wgEnableSidebarCache, $wgSidebarCacheExpiry;
2013 global $wgLang;
2014 wfProfileIn( __METHOD__ );
2015
2016 $key = wfMemcKey( 'sidebar', $wgLang->getCode() );
2017
2018 if ( $wgEnableSidebarCache ) {
2019 $cachedsidebar = $parserMemc->get( $key );
2020 if ( $cachedsidebar ) {
2021 wfProfileOut( __METHOD__ );
2022 return $cachedsidebar;
2023 }
2024 }
2025
2026 $bar = array();
2027 $lines = explode( "\n", wfMsgForContent( 'sidebar' ) );
2028 $heading = '';
2029 foreach( $lines as $line ) {
2030 if( strpos( $line, '*' ) !== 0 )
2031 continue;
2032 if( strpos( $line, '**') !== 0 ) {
2033 $heading = trim( $line, '* ' );
2034 if( !array_key_exists( $heading, $bar ) ) $bar[$heading] = array();
2035 } else {
2036 if( strpos( $line, '|' ) !== false ) { // sanity check
2037 $line = array_map( 'trim', explode( '|', trim( $line, '* ' ), 2 ) );
2038 $link = wfMsgForContent( $line[0] );
2039 if( $link == '-' )
2040 continue;
2041
2042 $text = wfMsgExt( $line[1], 'parsemag' );
2043 if( wfEmptyMsg( $line[1], $text ) )
2044 $text = $line[1];
2045 if( wfEmptyMsg( $line[0], $link ) )
2046 $link = $line[0];
2047
2048 if ( preg_match( '/^(?:' . wfUrlProtocols() . ')/', $link ) ) {
2049 $href = $link;
2050 } else {
2051 $title = Title::newFromText( $link );
2052 if ( $title ) {
2053 $title = $title->fixSpecialName();
2054 $href = $title->getLocalURL();
2055 } else {
2056 $href = 'INVALID-TITLE';
2057 }
2058 }
2059
2060 $bar[$heading][] = array(
2061 'text' => $text,
2062 'href' => $href,
2063 'id' => 'n-' . strtr( $line[1], ' ', '-' ),
2064 'active' => false
2065 );
2066 } else { continue; }
2067 }
2068 }
2069 wfRunHooks( 'SkinBuildSidebar', array( $this, &$bar ) );
2070 if ( $wgEnableSidebarCache ) $parserMemc->set( $key, $bar, $wgSidebarCacheExpiry );
2071 wfProfileOut( __METHOD__ );
2072 return $bar;
2073 }
2074
2075 /**
2076 * Should we include common/wikiprintable.css? Skins that have their own
2077 * print stylesheet should override this and return false. (This is an
2078 * ugly hack to get Monobook to play nicely with
2079 * OutputPage::headElement().)
2080 *
2081 * @return bool
2082 */
2083 public function commonPrintStylesheet() {
2084 return true;
2085 }
2086 }