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