Add MediaWiki:Print.css back in. Now applies to printable=yes -and- actual printing...
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21 * Wrapper object for MediaWiki's localization functions,
22 * to be passed to the template engine.
23 *
24 * @private
25 * @ingroup Skins
26 */
27 class MediaWiki_I18N {
28 var $_context = array();
29
30 function set($varName, $value) {
31 $this->_context[$varName] = $value;
32 }
33
34 function translate($value) {
35 wfProfileIn( __METHOD__ );
36
37 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
38 $value = preg_replace( '/^string:/', '', $value );
39
40 $value = wfMsg( $value );
41 // interpolate variables
42 $m = array();
43 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
44 list($src, $var) = $m;
45 wfSuppressWarnings();
46 $varValue = $this->_context[$var];
47 wfRestoreWarnings();
48 $value = str_replace($src, $varValue, $value);
49 }
50 wfProfileOut( __METHOD__ );
51 return $value;
52 }
53 }
54
55 /**
56 * Template-filler skin base class
57 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
58 * Based on Brion's smarty skin
59 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
60 *
61 * @todo Needs some serious refactoring into functions that correspond
62 * to the computations individual esi snippets need. Most importantly no body
63 * parsing for most of those of course.
64 *
65 * @ingroup Skins
66 */
67 class SkinTemplate extends Skin {
68 /**#@+
69 * @private
70 */
71
72 /**
73 * Name of our skin, set in initPage()
74 * It probably need to be all lower case.
75 */
76 var $skinname;
77
78 /**
79 * Stylesheets set to use
80 * Sub directory in ./skins/ where various stylesheets are located
81 */
82 var $stylename;
83
84 /**
85 * For QuickTemplate, the name of the subclass which
86 * will actually fill the template.
87 */
88 var $template;
89
90 /**
91 * An array of strings representing extra CSS files to load. May include:
92 * 'IE', 'IE50', 'IE55', 'IE60', 'IE70', 'rtl'.
93 */
94 var $cssfiles;
95
96 /**#@-*/
97
98 /**
99 * Setup the base parameters...
100 * Child classes should override this to set the name,
101 * style subdirectory, and template filler callback.
102 *
103 * @param OutputPage $out
104 */
105 function initPage( &$out ) {
106 parent::initPage( $out );
107 $this->skinname = 'monobook';
108 $this->stylename = 'monobook';
109 $this->template = 'QuickTemplate';
110 $this->cssfiles = array();
111 }
112
113 /**
114 * Create the template engine object; we feed it a bunch of data
115 * and eventually it spits out some HTML. Should have interface
116 * roughly equivalent to PHPTAL 0.7.
117 *
118 * @param string $callback (or file)
119 * @param string $repository subdirectory where we keep template files
120 * @param string $cache_dir
121 * @return object
122 * @private
123 */
124 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
125 return new $classname();
126 }
127
128 /**
129 * initialize various variables and generate the template
130 *
131 * @param OutputPage $out
132 * @public
133 */
134 function outputPage( &$out ) {
135 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang, $wgOut;
136 global $wgScript, $wgStylePath, $wgContLanguageCode;
137 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
138 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
139 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks;
143 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
144
145 wfProfileIn( __METHOD__ );
146
147 $oldid = $wgRequest->getVal( 'oldid' );
148 $diff = $wgRequest->getVal( 'diff' );
149
150 wfProfileIn( __METHOD__."-init" );
151 $this->initPage( $out );
152
153 $this->mTitle =& $wgTitle;
154 $this->mUser =& $wgUser;
155
156 $tpl = $this->setupTemplate( $this->template, 'skins' );
157
158 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
159 $tpl->setTranslator(new MediaWiki_I18N());
160 #}
161 wfProfileOut( __METHOD__."-init" );
162
163 wfProfileIn( __METHOD__."-stuff" );
164 $this->thispage = $this->mTitle->getPrefixedDbKey();
165 $this->thisurl = $this->mTitle->getPrefixedURL();
166 $this->loggedin = $wgUser->isLoggedIn();
167 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
168 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
169 $this->username = $wgUser->getName();
170 $userPage = $wgUser->getUserPage();
171 $this->userpage = $userPage->getPrefixedText();
172
173 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
174 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
175 } else {
176 # This won't be used in the standard skins, but we define it to preserve the interface
177 # To save time, we check for existence
178 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
179 }
180
181 $this->usercss = $this->userjs = $this->userjsprev = false;
182 $this->setupUserCss();
183 $this->setupUserJs( $out->isUserJsAllowed() );
184 $this->titletxt = $this->mTitle->getPrefixedText();
185 wfProfileOut( __METHOD__."-stuff" );
186
187 wfProfileIn( __METHOD__."-stuff2" );
188 $tpl->set( 'title', $wgOut->getPageTitle() );
189 $tpl->set( 'pagetitle', $wgOut->getHTMLTitle() );
190 $tpl->set( 'displaytitle', $wgOut->mPageLinkTitle );
191 $tpl->set( 'pageclass', Sanitizer::escapeClass( 'page-'.$this->mTitle->getPrefixedText() ) );
192
193 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
194 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
195 $this->mTitle->getNsText();
196
197 $tpl->set( 'nscanonical', $nsname );
198 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
199 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
200 $tpl->set( 'titletext', $this->mTitle->getText() );
201 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
202 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
203
204 $tpl->set( 'isarticle', $wgOut->isArticle() );
205
206 $tpl->setRef( "thispage", $this->thispage );
207 $subpagestr = $this->subPageSubtitle();
208 $tpl->set(
209 'subtitle', !empty($subpagestr)?
210 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
211 $out->getSubtitle()
212 );
213 $undelete = $this->getUndeleteLink();
214 $tpl->set(
215 "undelete", !empty($undelete)?
216 '<span class="subpages">'.$undelete.'</span>':
217 ''
218 );
219
220 $tpl->set( 'catlinks', $this->getCategories());
221 if( $wgOut->isSyndicated() ) {
222 $feeds = array();
223 foreach( $wgOut->getSyndicationLinks() as $format => $link ) {
224 $feeds[$format] = array(
225 'text' => wfMsg( "feed-$format" ),
226 'href' => $link );
227 }
228 $tpl->setRef( 'feeds', $feeds );
229 } else {
230 $tpl->set( 'feeds', false );
231 }
232 if ($wgUseTrackbacks && $out->isArticleRelated()) {
233 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
234 } else {
235 $tpl->set( 'trackbackhtml', null );
236 }
237
238 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
239 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
240 $tpl->setRef( 'mimetype', $wgMimeType );
241 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
242 $tpl->setRef( 'charset', $wgOutputEncoding );
243 $tpl->set( 'headlinks', $out->getHeadLinks() );
244 $tpl->set('headscripts', $out->getScript() );
245 $tpl->setRef( 'wgScript', $wgScript );
246 $tpl->setRef( 'skinname', $this->skinname );
247 $tpl->set( 'skinclass', get_class( $this ) );
248 $tpl->setRef( 'stylename', $this->stylename );
249 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
250 $tpl->setRef( 'loggedin', $this->loggedin );
251 $tpl->set('nsclass', 'ns-'.$this->mTitle->getNamespace());
252 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
253 /* XXX currently unused, might get useful later
254 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
255 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
256 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
257 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
258 $tpl->set( "helppage", wfMsg('helppage'));
259 */
260 $tpl->set( 'searchaction', $this->escapeSearchLink() );
261 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
262 $tpl->setRef( 'stylepath', $wgStylePath );
263 $tpl->setRef( 'articlepath', $wgArticlePath );
264 $tpl->setRef( 'scriptpath', $wgScriptPath );
265 $tpl->setRef( 'serverurl', $wgServer );
266 $tpl->setRef( 'logopath', $wgLogo );
267 $tpl->setRef( "lang", $wgContLanguageCode );
268 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
269 $tpl->set( 'rtl', $wgContLang->isRTL() );
270 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
271 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
272 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
273 $tpl->setRef( 'userpage', $this->userpage);
274 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
275 $tpl->set( 'userlang', $wgLang->getCode() );
276 $tpl->set( 'pagecss', $this->setupPageCss() );
277 $tpl->set( 'printcss', $this->getPrintCss() );
278 $tpl->setRef( 'usercss', $this->usercss);
279 $tpl->setRef( 'userjs', $this->userjs);
280 $tpl->setRef( 'userjsprev', $this->userjsprev);
281 global $wgUseSiteJs;
282 if ($wgUseSiteJs) {
283 $jsCache = $this->loggedin ? '&smaxage=0' : '';
284 $tpl->set( 'jsvarurl',
285 self::makeUrl('-',
286 "action=raw$jsCache&gen=js&useskin=" .
287 urlencode( $this->getSkinName() ) ) );
288 } else {
289 $tpl->set('jsvarurl', false);
290 }
291 $newtalks = $wgUser->getNewMessageLinks();
292
293 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
294 $usertitle = $this->mUser->getUserPage();
295 $usertalktitle = $usertitle->getTalkPage();
296 if( !$usertalktitle->equals( $this->mTitle ) ) {
297 $ntl = wfMsg( 'youhavenewmessages',
298 $this->makeKnownLinkObj(
299 $usertalktitle,
300 wfMsgHtml( 'newmessageslink' ),
301 'redirect=no'
302 ),
303 $this->makeKnownLinkObj(
304 $usertalktitle,
305 wfMsgHtml( 'newmessagesdifflink' ),
306 'diff=cur'
307 )
308 );
309 # Disable Cache
310 $wgOut->setSquidMaxage(0);
311 }
312 } else if (count($newtalks)) {
313 $sep = str_replace("_", " ", wfMsgHtml("newtalkseperator"));
314 $msgs = array();
315 foreach ($newtalks as $newtalk) {
316 $msgs[] = wfElement("a",
317 array('href' => $newtalk["link"]), $newtalk["wiki"]);
318 }
319 $parts = implode($sep, $msgs);
320 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
321 $wgOut->setSquidMaxage(0);
322 } else {
323 $ntl = '';
324 }
325 wfProfileOut( __METHOD__."-stuff2" );
326
327 wfProfileIn( __METHOD__."-stuff3" );
328 $tpl->setRef( 'newtalk', $ntl );
329 $tpl->setRef( 'skin', $this);
330 $tpl->set( 'logo', $this->logoText() );
331 if ( $wgOut->isArticle() and (!isset( $oldid ) or isset( $diff )) and
332 $wgArticle and 0 != $wgArticle->getID() )
333 {
334 if ( !$wgDisableCounters ) {
335 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
336 if ( $viewcount ) {
337 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
338 } else {
339 $tpl->set('viewcount', false);
340 }
341 } else {
342 $tpl->set('viewcount', false);
343 }
344
345 if ($wgPageShowWatchingUsers) {
346 $dbr = wfGetDB( DB_SLAVE );
347 $watchlist = $dbr->tableName( 'watchlist' );
348 $sql = "SELECT COUNT(*) AS n FROM $watchlist
349 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
350 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
351 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
352 $x = $dbr->fetchObject( $res );
353 $numberofwatchingusers = $x->n;
354 if ($numberofwatchingusers > 0) {
355 $tpl->set('numberofwatchingusers',
356 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
357 $wgLang->formatNum($numberofwatchingusers))
358 );
359 } else {
360 $tpl->set('numberofwatchingusers', false);
361 }
362 } else {
363 $tpl->set('numberofwatchingusers', false);
364 }
365
366 $tpl->set('copyright',$this->getCopyright());
367
368 $this->credits = false;
369
370 if (isset($wgMaxCredits) && $wgMaxCredits != 0) {
371 require_once("Credits.php");
372 $this->credits = getCredits($wgArticle, $wgMaxCredits, $wgShowCreditsIfMax);
373 } else {
374 $tpl->set('lastmod', $this->lastModified());
375 }
376
377 $tpl->setRef( 'credits', $this->credits );
378
379 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
380 $tpl->set('copyright', $this->getCopyright());
381 $tpl->set('viewcount', false);
382 $tpl->set('lastmod', false);
383 $tpl->set('credits', false);
384 $tpl->set('numberofwatchingusers', false);
385 } else {
386 $tpl->set('copyright', false);
387 $tpl->set('viewcount', false);
388 $tpl->set('lastmod', false);
389 $tpl->set('credits', false);
390 $tpl->set('numberofwatchingusers', false);
391 }
392 wfProfileOut( __METHOD__."-stuff3" );
393
394 wfProfileIn( __METHOD__."-stuff4" );
395 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
396 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
397 $tpl->set( 'disclaimer', $this->disclaimerLink() );
398 $tpl->set( 'privacy', $this->privacyLink() );
399 $tpl->set( 'about', $this->aboutLink() );
400
401 $tpl->setRef( 'debug', $out->mDebugtext );
402 $tpl->set( 'reporttime', wfReportTime() );
403 $tpl->set( 'sitenotice', wfGetSiteNotice() );
404 $tpl->set( 'bottomscripts', $this->bottomScripts() );
405
406 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
407 $out->mBodytext .= $printfooter ;
408 $tpl->setRef( 'bodytext', $out->mBodytext );
409
410 # Language links
411 $language_urls = array();
412
413 if ( !$wgHideInterlanguageLinks ) {
414 foreach( $wgOut->getLanguageLinks() as $l ) {
415 $tmp = explode( ':', $l, 2 );
416 $class = 'interwiki-' . $tmp[0];
417 unset($tmp);
418 $nt = Title::newFromText( $l );
419 $language_urls[] = array(
420 'href' => $nt->getFullURL(),
421 'text' => ($wgContLang->getLanguageName( $nt->getInterwiki()) != ''?$wgContLang->getLanguageName( $nt->getInterwiki()) : $l),
422 'class' => $class
423 );
424 }
425 }
426 if(count($language_urls)) {
427 $tpl->setRef( 'language_urls', $language_urls);
428 } else {
429 $tpl->set('language_urls', false);
430 }
431 wfProfileOut( __METHOD__."-stuff4" );
432
433 # Personal toolbar
434 $tpl->set('personal_urls', $this->buildPersonalUrls());
435 $content_actions = $this->buildContentActionUrls();
436 $tpl->setRef('content_actions', $content_actions);
437
438 // XXX: attach this from javascript, same with section editing
439 if($this->iseditable && $wgUser->getOption("editondblclick") )
440 {
441 $encEditUrl = wfEscapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
442 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
443 } else {
444 $tpl->set('body_ondblclick', false);
445 }
446 $tpl->set( 'body_onload', false );
447 $tpl->set( 'sidebar', $this->buildSidebar() );
448 $tpl->set( 'nav_urls', $this->buildNavUrls() );
449
450 // original version by hansm
451 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
452 wfDebug( __METHOD__ . ': Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!' );
453 }
454
455 // execute template
456 wfProfileIn( __METHOD__."-execute" );
457 $res = $tpl->execute();
458 wfProfileOut( __METHOD__."-execute" );
459
460 // result may be an error
461 $this->printOrError( $res );
462 wfProfileOut( __METHOD__ );
463 }
464
465 /**
466 * Output the string, or print error message if it's
467 * an error object of the appropriate type.
468 * For the base class, assume strings all around.
469 *
470 * @param mixed $str
471 * @private
472 */
473 function printOrError( $str ) {
474 echo $str;
475 }
476
477 /**
478 * build array of urls for personal toolbar
479 * @return array
480 * @private
481 */
482 function buildPersonalUrls() {
483 global $wgTitle, $wgRequest;
484
485 $pageurl = $wgTitle->getLocalURL();
486 wfProfileIn( __METHOD__ );
487
488 /* set up the default links for the personal toolbar */
489 $personal_urls = array();
490 if ($this->loggedin) {
491 $personal_urls['userpage'] = array(
492 'text' => $this->username,
493 'href' => &$this->userpageUrlDetails['href'],
494 'class' => $this->userpageUrlDetails['exists']?false:'new',
495 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
496 );
497 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
498 $personal_urls['mytalk'] = array(
499 'text' => wfMsg('mytalk'),
500 'href' => &$usertalkUrlDetails['href'],
501 'class' => $usertalkUrlDetails['exists']?false:'new',
502 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
503 );
504 $href = self::makeSpecialUrl( 'Preferences' );
505 $personal_urls['preferences'] = array(
506 'text' => wfMsg( 'mypreferences' ),
507 'href' => $href,
508 'active' => ( $href == $pageurl )
509 );
510 $href = self::makeSpecialUrl( 'Watchlist' );
511 $personal_urls['watchlist'] = array(
512 'text' => wfMsg( 'mywatchlist' ),
513 'href' => $href,
514 'active' => ( $href == $pageurl )
515 );
516
517 # We need to do an explicit check for Special:Contributions, as we
518 # have to match both the title, and the target (which could come
519 # from request values or be specified in "sub page" form. The plot
520 # thickens, because $wgTitle is altered for special pages, so doesn't
521 # contain the original alias-with-subpage.
522 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
523 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
524 list( $spName, $spPar ) =
525 SpecialPage::resolveAliasWithSubpage( $title->getText() );
526 $active = $spName == 'Contributions'
527 && ( ( $spPar && $spPar == $this->username )
528 || $wgRequest->getText( 'target' ) == $this->username );
529 } else {
530 $active = false;
531 }
532
533 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
534 $personal_urls['mycontris'] = array(
535 'text' => wfMsg( 'mycontris' ),
536 'href' => $href,
537 'active' => $active
538 );
539 $personal_urls['logout'] = array(
540 'text' => wfMsg( 'userlogout' ),
541 'href' => self::makeSpecialUrl( 'Userlogout',
542 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
543 ),
544 'active' => false
545 );
546 } else {
547 global $wgUser;
548 $loginlink = $wgUser->isAllowed( 'createaccount' )
549 ? 'nav-login-createaccount'
550 : 'login';
551 if( $this->showIPinHeader() ) {
552 $href = &$this->userpageUrlDetails['href'];
553 $personal_urls['anonuserpage'] = array(
554 'text' => $this->username,
555 'href' => $href,
556 'class' => $this->userpageUrlDetails['exists']?false:'new',
557 'active' => ( $pageurl == $href )
558 );
559 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
560 $href = &$usertalkUrlDetails['href'];
561 $personal_urls['anontalk'] = array(
562 'text' => wfMsg('anontalk'),
563 'href' => $href,
564 'class' => $usertalkUrlDetails['exists']?false:'new',
565 'active' => ( $pageurl == $href )
566 );
567 $personal_urls['anonlogin'] = array(
568 'text' => wfMsg( $loginlink ),
569 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
570 'active' => $wgTitle->isSpecial( 'Userlogin' )
571 );
572 } else {
573
574 $personal_urls['login'] = array(
575 'text' => wfMsg( $loginlink ),
576 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
577 'active' => $wgTitle->isSpecial( 'Userlogin' )
578 );
579 }
580 }
581
582 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
583 wfProfileOut( __METHOD__ );
584 return $personal_urls;
585 }
586
587 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
588 $classes = array();
589 if( $selected ) {
590 $classes[] = 'selected';
591 }
592 if( $checkEdit && !$title->isAlwaysKnown() && $title->getArticleId() == 0 ) {
593 $classes[] = 'new';
594 $query = 'action=edit';
595 }
596
597 $text = wfMsg( $message );
598 if ( wfEmptyMsg( $message, $text ) ) {
599 global $wgContLang;
600 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
601 }
602
603 $result = array();
604 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
605 $title, $message, $selected, $checkEdit,
606 &$classes, &$query, &$text, &$result)) ) {
607 return $result;
608 }
609
610 return array(
611 'class' => implode( ' ', $classes ),
612 'text' => $text,
613 'href' => $title->getLocalUrl( $query ) );
614 }
615
616 function makeTalkUrlDetails( $name, $urlaction = '' ) {
617 $title = Title::newFromText( $name );
618 if( !is_object($title) ) {
619 throw new MWException( __METHOD__." given invalid pagename $name" );
620 }
621 $title = $title->getTalkPage();
622 self::checkTitle( $title, $name );
623 return array(
624 'href' => $title->getLocalURL( $urlaction ),
625 'exists' => $title->getArticleID() != 0 ? true : false
626 );
627 }
628
629 function makeArticleUrlDetails( $name, $urlaction = '' ) {
630 $title = Title::newFromText( $name );
631 $title= $title->getSubjectPage();
632 self::checkTitle( $title, $name );
633 return array(
634 'href' => $title->getLocalURL( $urlaction ),
635 'exists' => $title->getArticleID() != 0 ? true : false
636 );
637 }
638
639 /**
640 * an array of edit links by default used for the tabs
641 * @return array
642 * @private
643 */
644 function buildContentActionUrls () {
645 global $wgContLang, $wgLang, $wgOut;
646 wfProfileIn( __METHOD__ );
647
648 global $wgUser, $wgRequest;
649 $action = $wgRequest->getText( 'action' );
650 $section = $wgRequest->getText( 'section' );
651 $content_actions = array();
652
653 $prevent_active_tabs = false ;
654 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
655
656 if( $this->iscontent ) {
657 $subjpage = $this->mTitle->getSubjectPage();
658 $talkpage = $this->mTitle->getTalkPage();
659
660 $nskey = $this->mTitle->getNamespaceKey();
661 $content_actions[$nskey] = $this->tabAction(
662 $subjpage,
663 $nskey,
664 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
665 '', true);
666
667 $content_actions['talk'] = $this->tabAction(
668 $talkpage,
669 'talk',
670 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
671 '',
672 true);
673
674 wfProfileIn( __METHOD__."-edit" );
675 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
676 $istalk = $this->mTitle->isTalkPage();
677 $istalkclass = $istalk?' istalk':'';
678 $content_actions['edit'] = array(
679 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
680 'text' => $this->mTitle->exists()
681 ? wfMsg( 'edit' )
682 : wfMsg( 'create' ),
683 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
684 );
685
686 if ( $istalk || $wgOut->showNewSectionLink() ) {
687 $content_actions['addsection'] = array(
688 'class' => $section == 'new'?'selected':false,
689 'text' => wfMsg('addsection'),
690 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
691 );
692 }
693 } elseif ( $this->mTitle->exists() || $this->mTitle->isAlwaysKnown() ) {
694 $content_actions['viewsource'] = array(
695 'class' => ($action == 'edit') ? 'selected' : false,
696 'text' => wfMsg('viewsource'),
697 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
698 );
699 }
700 wfProfileOut( __METHOD__."-edit" );
701
702 wfProfileIn( __METHOD__."-live" );
703 if ( $this->mTitle->getArticleId() ) {
704
705 $content_actions['history'] = array(
706 'class' => ($action == 'history') ? 'selected' : false,
707 'text' => wfMsg('history_short'),
708 'href' => $this->mTitle->getLocalUrl( 'action=history')
709 );
710
711 if($wgUser->isAllowed('delete')){
712 $content_actions['delete'] = array(
713 'class' => ($action == 'delete') ? 'selected' : false,
714 'text' => wfMsg('delete'),
715 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
716 );
717 }
718 if ( $this->mTitle->quickUserCan( 'move' ) ) {
719 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
720 $content_actions['move'] = array(
721 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
722 'text' => wfMsg('move'),
723 'href' => $moveTitle->getLocalUrl()
724 );
725 }
726
727 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
728 if(!$this->mTitle->isProtected()){
729 $content_actions['protect'] = array(
730 'class' => ($action == 'protect') ? 'selected' : false,
731 'text' => wfMsg('protect'),
732 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
733 );
734
735 } else {
736 $content_actions['unprotect'] = array(
737 'class' => ($action == 'unprotect') ? 'selected' : false,
738 'text' => wfMsg('unprotect'),
739 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
740 );
741 }
742 }
743 } else {
744 //article doesn't exist or is deleted
745 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
746 if( $n = $this->mTitle->isDeleted() ) {
747 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
748 $content_actions['undelete'] = array(
749 'class' => false,
750 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
751 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
752 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
753 );
754 }
755 }
756
757 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
758 if( !$this->mTitle->getRestrictions( 'create' ) ) {
759 $content_actions['protect'] = array(
760 'class' => ($action == 'protect') ? 'selected' : false,
761 'text' => wfMsg('protect'),
762 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
763 );
764
765 } else {
766 $content_actions['unprotect'] = array(
767 'class' => ($action == 'unprotect') ? 'selected' : false,
768 'text' => wfMsg('unprotect'),
769 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
770 );
771 }
772 }
773 }
774
775 wfProfileOut( __METHOD__."-live" );
776
777 if( $this->loggedin ) {
778 if( !$this->mTitle->userIsWatching()) {
779 $content_actions['watch'] = array(
780 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
781 'text' => wfMsg('watch'),
782 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
783 );
784 } else {
785 $content_actions['unwatch'] = array(
786 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
787 'text' => wfMsg('unwatch'),
788 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
789 );
790 }
791 }
792
793
794 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
795 } else {
796 /* show special page tab */
797
798 $content_actions[$this->mTitle->getNamespaceKey()] = array(
799 'class' => 'selected',
800 'text' => wfMsg('nstab-special'),
801 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
802 );
803
804 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
805 }
806
807 /* show links to different language variants */
808 global $wgDisableLangConversion;
809 $variants = $wgContLang->getVariants();
810 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
811 $preferred = $wgContLang->getPreferredVariant();
812 $vcount=0;
813 foreach( $variants as $code ) {
814 $varname = $wgContLang->getVariantname( $code );
815 if( $varname == 'disable' )
816 continue;
817 $selected = ( $code == $preferred )? 'selected' : false;
818 $content_actions['varlang-' . $vcount] = array(
819 'class' => $selected,
820 'text' => $varname,
821 'href' => $this->mTitle->getLocalURL('',$code)
822 );
823 $vcount ++;
824 }
825 }
826
827 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
828
829 wfProfileOut( __METHOD__ );
830 return $content_actions;
831 }
832
833
834
835 /**
836 * build array of common navigation links
837 * @return array
838 * @private
839 */
840 function buildNavUrls () {
841 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
842 global $wgEnableUploads, $wgUploadNavigationUrl;
843
844 wfProfileIn( __METHOD__ );
845
846 $action = $wgRequest->getText( 'action' );
847
848 $nav_urls = array();
849 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
850 if( $wgEnableUploads ) {
851 if ($wgUploadNavigationUrl) {
852 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
853 } else {
854 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
855 }
856 } else {
857 if ($wgUploadNavigationUrl)
858 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
859 else
860 $nav_urls['upload'] = false;
861 }
862 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
863
864 // default permalink to being off, will override it as required below.
865 $nav_urls['permalink'] = false;
866
867 // A print stylesheet is attached to all pages, but nobody ever
868 // figures that out. :) Add a link...
869 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
870 $nav_urls['print'] = array(
871 'text' => wfMsg( 'printableversion' ),
872 'href' => $wgRequest->appendQuery( 'printable=yes' )
873 );
874
875 // Also add a "permalink" while we're at it
876 if ( $this->mRevisionId ) {
877 $nav_urls['permalink'] = array(
878 'text' => wfMsg( 'permalink' ),
879 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
880 );
881 }
882
883 // Copy in case this undocumented, shady hook tries to mess with internals
884 $revid = $this->mRevisionId;
885 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
886 }
887
888 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
889 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
890 $nav_urls['whatlinkshere'] = array(
891 'href' => $wlhTitle->getLocalUrl()
892 );
893 if( $this->mTitle->getArticleId() ) {
894 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
895 $nav_urls['recentchangeslinked'] = array(
896 'href' => $rclTitle->getLocalUrl()
897 );
898 } else {
899 $nav_urls['recentchangeslinked'] = false;
900 }
901 if ($wgUseTrackbacks)
902 $nav_urls['trackbacklink'] = array(
903 'href' => $wgTitle->trackbackURL()
904 );
905 }
906
907 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
908 $id = User::idFromName($this->mTitle->getText());
909 $ip = User::isIP($this->mTitle->getText());
910 } else {
911 $id = 0;
912 $ip = false;
913 }
914
915 if($id || $ip) { # both anons and non-anons have contribs list
916 $nav_urls['contributions'] = array(
917 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
918 );
919
920 if( $id ) {
921 $logPage = SpecialPage::getTitleFor( 'Log' );
922 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
923 . $this->mTitle->getPartialUrl() ) );
924 } else {
925 $nav_urls['log'] = false;
926 }
927
928 if ( $wgUser->isAllowed( 'block' ) ) {
929 $nav_urls['blockip'] = array(
930 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
931 );
932 } else {
933 $nav_urls['blockip'] = false;
934 }
935 } else {
936 $nav_urls['contributions'] = false;
937 $nav_urls['log'] = false;
938 $nav_urls['blockip'] = false;
939 }
940 $nav_urls['emailuser'] = false;
941 if( $this->showEmailUser( $id ) ) {
942 $nav_urls['emailuser'] = array(
943 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
944 );
945 }
946 wfProfileOut( __METHOD__ );
947 return $nav_urls;
948 }
949
950 /**
951 * Generate strings used for xml 'id' names
952 * @return string
953 * @private
954 */
955 function getNameSpaceKey () {
956 return $this->mTitle->getNamespaceKey();
957 }
958
959 /**
960 * @private
961 */
962 function setupUserCss() {
963 wfProfileIn( __METHOD__ );
964
965 global $wgRequest, $wgAllowUserCss, $wgUseSiteCss,
966 $wgContLang, $wgSquidMaxage, $wgStylePath, $wgUser, $wgOut;
967
968 $sitecss = '';
969 $usercss = '';
970 $siteargs = '&maxage=' . $wgSquidMaxage;
971 if( $this->loggedin ) {
972 // Ensure that logged-in users' generated CSS isn't clobbered
973 // by anons' publicly cacheable generated CSS.
974 $siteargs .= '&smaxage=0';
975 }
976
977 # Add user-specific code if this is a user and we allow that kind of thing
978
979 if ( $wgAllowUserCss && $this->loggedin ) {
980 $action = $wgRequest->getText('action');
981
982 # if we're previewing the CSS page, use it
983 if( $this->mTitle->isCssSubpage() and $this->userCanPreview( $action ) ) {
984 $siteargs = "&smaxage=0&maxage=0";
985 $usercss = $wgRequest->getText('wpTextbox1');
986 } else {
987 $usercss = '@import "' .
988 self::makeUrl($this->userpage . '/'.$this->skinname.'.css',
989 'action=raw&ctype=text/css') . '";' ."\n";
990 }
991
992 $siteargs .= '&ts=' . $wgUser->mTouched;
993 }
994
995 if( $wgContLang->isRTL() && in_array( 'rtl', $this->cssfiles ) ) {
996 global $wgStyleVersion;
997 $sitecss .= "@import \"$wgStylePath/$this->stylename/rtl.css?$wgStyleVersion\";\n";
998 }
999
1000 # If we use the site's dynamic CSS, throw that in, too
1001 if ( $wgUseSiteCss ) {
1002 $query = "usemsgcache=yes&action=raw&ctype=text/css&smaxage=$wgSquidMaxage";
1003 $skinquery = '';
1004 if (($us = $wgRequest->getVal('useskin', '')) !== '')
1005 $skinquery = "&useskin=$us";
1006 $sitecss .= '@import "' . self::makeNSUrl( 'Common.css', $query, NS_MEDIAWIKI) . '";' . "\n";
1007 $sitecss .= '@import "' . self::makeNSUrl( ucfirst( $this->skinname ) . '.css', $query, NS_MEDIAWIKI ) . '";' . "\n";
1008 $sitecss .= '@import "' . self::makeUrl( '-', "action=raw&gen=css$siteargs$skinquery" ) . '";' . "\n";
1009 if( $wgOut->isPrintable()) $sitecss .= '@import "' . self::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI) . '";' . "\n";
1010 else $sitecss .= '@import "' . self::makeNSUrl( 'Print.css', $query, NS_MEDIAWIKI) . '" print;' . "\n";
1011 }
1012
1013 # If we use any dynamic CSS, make a little CDATA block out of it.
1014
1015 if ( !empty($sitecss) || !empty($usercss) ) {
1016 $this->usercss = "/*<![CDATA[*/\n" . $sitecss . $usercss . '/*]]>*/';
1017 }
1018 wfProfileOut( __METHOD__ );
1019 }
1020
1021 /**
1022 * @private
1023 */
1024 function setupUserJs( $allowUserJs ) {
1025 wfProfileIn( __METHOD__ );
1026
1027 global $wgRequest, $wgJsMimeType;
1028 $action = $wgRequest->getText('action');
1029
1030 if( $allowUserJs && $this->loggedin ) {
1031 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
1032 # XXX: additional security check/prompt?
1033 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
1034 } else {
1035 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType);
1036 }
1037 }
1038 wfProfileOut( __METHOD__ );
1039 }
1040
1041 /**
1042 * Code for extensions to hook into to provide per-page CSS, see
1043 * extensions/PageCSS/PageCSS.php for an implementation of this.
1044 *
1045 * @private
1046 */
1047 function setupPageCss() {
1048 wfProfileIn( __METHOD__ );
1049 $out = false;
1050 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1051
1052 wfProfileOut( __METHOD__ );
1053 return $out;
1054 }
1055
1056 /**
1057 * returns css with user-specific options
1058 */
1059 public function getUserStylesheet() {
1060 wfProfileIn( __METHOD__ );
1061
1062 $s = "/* generated user stylesheet */\n";
1063 $s .= $this->reallyDoGetUserStyles();
1064 wfProfileOut( __METHOD__ );
1065 return $s;
1066 }
1067
1068 /**
1069 * Returns the print stylesheet for this skin. In all default skins this
1070 * is just commonPrint.css, but third-party skins may want to modify it.
1071 *
1072 * @return string
1073 */
1074 protected function getPrintCss() {
1075 global $wgStylePath;
1076 return $wgStylePath . "/common/commonPrint.css";
1077 }
1078
1079 /**
1080 * This returns MediaWiki:Common.js and MediaWiki:[Skinname].js concate-
1081 * nated together. For some bizarre reason, it does *not* return any
1082 * custom user JS from subpages. Huh?
1083 *
1084 * There's absolutely no reason to have separate Monobook/Common JSes.
1085 * Any JS that cares can just check the skin variable generated at the
1086 * top. For now Monobook.js will be maintained, but it should be consi-
1087 * dered deprecated.
1088 *
1089 * @return string
1090 */
1091 public function getUserJs() {
1092 wfProfileIn( __METHOD__ );
1093
1094 $s = parent::getUserJs();
1095 $s .= "\n\n/* MediaWiki:".ucfirst($this->skinname).".js */\n";
1096
1097 // avoid inclusion of non defined user JavaScript (with custom skins only)
1098 // by checking for default message content
1099 $msgKey = ucfirst($this->skinname).'.js';
1100 $userJS = wfMsgForContent($msgKey);
1101 if ( !wfEmptyMsg( $msgKey, $userJS ) ) {
1102 $s .= $userJS;
1103 }
1104
1105 wfProfileOut( __METHOD__ );
1106 return $s;
1107 }
1108 }
1109
1110 /**
1111 * Generic wrapper for template functions, with interface
1112 * compatible with what we use of PHPTAL 0.7.
1113 * @ingroup Skins
1114 */
1115 class QuickTemplate {
1116 /**
1117 * @public
1118 */
1119 function QuickTemplate() {
1120 $this->data = array();
1121 $this->translator = new MediaWiki_I18N();
1122 }
1123
1124 /**
1125 * @public
1126 */
1127 function set( $name, $value ) {
1128 $this->data[$name] = $value;
1129 }
1130
1131 /**
1132 * @public
1133 */
1134 function setRef($name, &$value) {
1135 $this->data[$name] =& $value;
1136 }
1137
1138 /**
1139 * @public
1140 */
1141 function setTranslator( &$t ) {
1142 $this->translator = &$t;
1143 }
1144
1145 /**
1146 * @public
1147 */
1148 function execute() {
1149 echo "Override this function.";
1150 }
1151
1152
1153 /**
1154 * @private
1155 */
1156 function text( $str ) {
1157 echo htmlspecialchars( $this->data[$str] );
1158 }
1159
1160 /**
1161 * @private
1162 */
1163 function jstext( $str ) {
1164 echo Xml::escapeJsString( $this->data[$str] );
1165 }
1166
1167 /**
1168 * @private
1169 */
1170 function html( $str ) {
1171 echo $this->data[$str];
1172 }
1173
1174 /**
1175 * @private
1176 */
1177 function msg( $str ) {
1178 echo htmlspecialchars( $this->translator->translate( $str ) );
1179 }
1180
1181 /**
1182 * @private
1183 */
1184 function msgHtml( $str ) {
1185 echo $this->translator->translate( $str );
1186 }
1187
1188 /**
1189 * An ugly, ugly hack.
1190 * @private
1191 */
1192 function msgWiki( $str ) {
1193 global $wgParser, $wgTitle, $wgOut;
1194
1195 $text = $this->translator->translate( $str );
1196 $parserOutput = $wgParser->parse( $text, $wgTitle,
1197 $wgOut->parserOptions(), true );
1198 echo $parserOutput->getText();
1199 }
1200
1201 /**
1202 * @private
1203 */
1204 function haveData( $str ) {
1205 return isset( $this->data[$str] );
1206 }
1207
1208 /**
1209 * @private
1210 */
1211 function haveMsg( $str ) {
1212 $msg = $this->translator->translate( $str );
1213 return ($msg != '-') && ($msg != ''); # ????
1214 }
1215 }