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