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