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