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