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