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