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