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