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