7295a03446ab5906d2c7eadd197183fb06cf6095
[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
92 /**
93 * Setup the base parameters...
94 * Child classes should override this to set the name,
95 * style subdirectory, and template filler callback.
96 *
97 * @param $out OutputPage
98 */
99 function initPage( OutputPage $out ) {
100 parent::initPage( $out );
101 $this->skinname = 'monobook';
102 $this->stylename = 'monobook';
103 $this->template = 'QuickTemplate';
104 }
105
106 /**
107 * Add specific styles for this skin
108 *
109 * @param $out OutputPage
110 */
111 function setupSkinUserCss( OutputPage $out ){
112 $out->addStyle( 'common/shared.css', 'screen' );
113 $out->addStyle( 'common/commonPrint.css', 'print' );
114 }
115
116 /**
117 * Create the template engine object; we feed it a bunch of data
118 * and eventually it spits out some HTML. Should have interface
119 * roughly equivalent to PHPTAL 0.7.
120 *
121 * @param $callback string (or file)
122 * @param $repository string: subdirectory where we keep template files
123 * @param $cache_dir string
124 * @return object
125 * @private
126 */
127 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
128 return new $classname();
129 }
130
131 /**
132 * initialize various variables and generate the template
133 *
134 * @param $out OutputPage
135 */
136 function outputPage( OutputPage $out ) {
137 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang;
138 global $wgScript, $wgStylePath, $wgContLanguageCode;
139 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
140 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
141 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
142 global $wgMaxCredits, $wgShowCreditsIfMax;
143 global $wgPageShowWatchingUsers;
144 global $wgUseTrackbacks, $wgUseSiteJs;
145 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
146
147 wfProfileIn( __METHOD__ );
148
149 $oldid = $wgRequest->getVal( 'oldid' );
150 $diff = $wgRequest->getVal( 'diff' );
151
152 wfProfileIn( __METHOD__."-init" );
153 $this->initPage( $out );
154
155 $this->setMembers();
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
171 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
172 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
173 } else {
174 # This won't be used in the standard skins, but we define it to preserve the interface
175 # To save time, we check for existence
176 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
177 }
178
179 $this->userjs = $this->userjsprev = false;
180 $this->setupUserCss( $out );
181 $this->setupUserJs( $out->isUserJsAllowed() );
182 $this->titletxt = $this->mTitle->getPrefixedText();
183 wfProfileOut( __METHOD__."-stuff" );
184
185 wfProfileIn( __METHOD__."-stuff2" );
186 $tpl->set( 'title', $out->getPageTitle() );
187 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
188 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
189 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
190 $tpl->set( 'skinnameclass', ( "skin-" . Sanitizer::escapeClass( $this->getSkinName ( ) ) ) );
191
192 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
193 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
194 $this->mTitle->getNsText();
195
196 $tpl->set( 'nscanonical', $nsname );
197 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
198 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
199 $tpl->set( 'titletext', $this->mTitle->getText() );
200 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
201 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
202
203 $tpl->set( 'isarticle', $out->isArticle() );
204
205 $tpl->setRef( "thispage", $this->thispage );
206 $subpagestr = $this->subPageSubtitle();
207 $tpl->set(
208 'subtitle', !empty($subpagestr)?
209 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle():
210 $out->getSubtitle()
211 );
212 $undelete = $this->getUndeleteLink();
213 $tpl->set(
214 "undelete", !empty($undelete)?
215 '<span class="subpages">'.$undelete.'</span>':
216 ''
217 );
218
219 $tpl->set( 'catlinks', $this->getCategories());
220 if( $out->isSyndicated() ) {
221 $feeds = array();
222 foreach( $out->getSyndicationLinks() as $format => $link ) {
223 $feeds[$format] = array(
224 'text' => wfMsg( "feed-$format" ),
225 'href' => $link );
226 }
227 $tpl->setRef( 'feeds', $feeds );
228 } else {
229 $tpl->set( 'feeds', false );
230 }
231 if ($wgUseTrackbacks && $out->isArticleRelated()) {
232 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
233 } else {
234 $tpl->set( 'trackbackhtml', null );
235 }
236
237 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
238 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
239 $tpl->setRef( 'mimetype', $wgMimeType );
240 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
241 $tpl->setRef( 'charset', $wgOutputEncoding );
242 $tpl->set( 'headlinks', $out->getHeadLinks() );
243 $tpl->set( 'headscripts', $out->getScript() );
244 $tpl->set( 'csslinks', $out->buildCssLinks() );
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->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
251 $tpl->setRef( 'loggedin', $this->loggedin );
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->setRef( 'usercss', $this->usercss);
278 $tpl->setRef( 'userjs', $this->userjs);
279 $tpl->setRef( 'userjsprev', $this->userjsprev);
280 if( $wgUseSiteJs ) {
281 $jsCache = $this->loggedin ? '&smaxage=0' : '';
282 $tpl->set( 'jsvarurl',
283 self::makeUrl('-',
284 "action=raw$jsCache&gen=js&useskin=" .
285 urlencode( $this->getSkinName() ) ) );
286 } else {
287 $tpl->set('jsvarurl', false);
288 }
289 $newtalks = $wgUser->getNewMessageLinks();
290
291 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
292 $usertitle = $this->mUser->getUserPage();
293 $usertalktitle = $usertitle->getTalkPage();
294 if( !$usertalktitle->equals( $this->mTitle ) ) {
295 $ntl = wfMsg( 'youhavenewmessages',
296 $this->makeKnownLinkObj(
297 $usertalktitle,
298 wfMsgHtml( 'newmessageslink' ),
299 'redirect=no'
300 ),
301 $this->makeKnownLinkObj(
302 $usertalktitle,
303 wfMsgHtml( 'newmessagesdifflink' ),
304 'diff=cur'
305 )
306 );
307 # Disable Cache
308 $out->setSquidMaxage(0);
309 }
310 } else if (count($newtalks)) {
311 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
312 $msgs = array();
313 foreach ($newtalks as $newtalk) {
314 $msgs[] = Xml::element("a",
315 array('href' => $newtalk["link"]), $newtalk["wiki"]);
316 }
317 $parts = implode($sep, $msgs);
318 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
319 $out->setSquidMaxage(0);
320 } else {
321 $ntl = '';
322 }
323 wfProfileOut( __METHOD__."-stuff2" );
324
325 wfProfileIn( __METHOD__."-stuff3" );
326 $tpl->setRef( 'newtalk', $ntl );
327 $tpl->setRef( 'skin', $this );
328 $tpl->set( 'logo', $this->logoText() );
329 if ( $out->isArticle() and (!isset( $oldid ) or isset( $diff )) and
330 $wgArticle and 0 != $wgArticle->getID() )
331 {
332 if ( !$wgDisableCounters ) {
333 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
334 if ( $viewcount ) {
335 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
336 } else {
337 $tpl->set('viewcount', false);
338 }
339 } else {
340 $tpl->set('viewcount', false);
341 }
342
343 if ($wgPageShowWatchingUsers) {
344 $dbr = wfGetDB( DB_SLAVE );
345 $watchlist = $dbr->tableName( 'watchlist' );
346 $sql = "SELECT COUNT(*) AS n FROM $watchlist
347 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
348 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
349 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
350 $x = $dbr->fetchObject( $res );
351 $numberofwatchingusers = $x->n;
352 if ($numberofwatchingusers > 0) {
353 $tpl->set('numberofwatchingusers',
354 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
355 $wgLang->formatNum($numberofwatchingusers))
356 );
357 } else {
358 $tpl->set('numberofwatchingusers', false);
359 }
360 } else {
361 $tpl->set('numberofwatchingusers', false);
362 }
363
364 $tpl->set('copyright',$this->getCopyright());
365
366 $this->credits = false;
367
368 if( $wgMaxCredits != 0 ){
369 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
370 } else {
371 $tpl->set( 'lastmod', $this->lastModified() );
372 }
373
374 $tpl->setRef( 'credits', $this->credits );
375
376 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
377 $tpl->set('copyright', $this->getCopyright());
378 $tpl->set('viewcount', false);
379 $tpl->set('lastmod', false);
380 $tpl->set('credits', false);
381 $tpl->set('numberofwatchingusers', false);
382 } else {
383 $tpl->set('copyright', false);
384 $tpl->set('viewcount', false);
385 $tpl->set('lastmod', false);
386 $tpl->set('credits', false);
387 $tpl->set('numberofwatchingusers', false);
388 }
389 wfProfileOut( __METHOD__."-stuff3" );
390
391 wfProfileIn( __METHOD__."-stuff4" );
392 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
393 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
394 $tpl->set( 'disclaimer', $this->disclaimerLink() );
395 $tpl->set( 'privacy', $this->privacyLink() );
396 $tpl->set( 'about', $this->aboutLink() );
397
398 $tpl->setRef( 'debug', $out->mDebugtext );
399 $tpl->set( 'reporttime', wfReportTime() );
400 $tpl->set( 'sitenotice', wfGetSiteNotice() );
401 $tpl->set( 'bottomscripts', $this->bottomScripts() );
402
403 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
404 $out->mBodytext .= $printfooter ;
405 $tpl->setRef( 'bodytext', $out->mBodytext );
406
407 # Language links
408 $language_urls = array();
409
410 if ( !$wgHideInterlanguageLinks ) {
411 foreach( $out->getLanguageLinks() as $l ) {
412 $tmp = explode( ':', $l, 2 );
413 $class = 'interwiki-' . $tmp[0];
414 unset($tmp);
415 $nt = Title::newFromText( $l );
416 if ( $nt ) {
417 $language_urls[] = array(
418 'href' => $nt->getFullURL(),
419 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != ''
420 ? $wgContLang->getLanguageName( $nt->getInterwiki() )
421 : $l ),
422 'class' => $class,
423 'title' => ( $wgLang->getLanguageNameLocalized( $nt->getInterwiki() ) != ''
424 ? $wgLang->getLanguageNameLocalized( $nt->getInterwiki() )
425 : $l )
426 );
427 }
428 }
429 }
430 if(count($language_urls)) {
431 $tpl->setRef( 'language_urls', $language_urls);
432 } else {
433 $tpl->set('language_urls', false);
434 }
435 wfProfileOut( __METHOD__."-stuff4" );
436
437 wfProfileIn( __METHOD__."-stuff5" );
438 # Personal toolbar
439 $tpl->set('personal_urls', $this->buildPersonalUrls());
440 $content_actions = $this->buildContentActionUrls();
441 $tpl->setRef('content_actions', $content_actions);
442
443 // XXX: attach this from javascript, same with section editing
444 if($this->iseditable && $wgUser->getOption("editondblclick") )
445 {
446 $encEditUrl = Xml::escapeJsString( $this->mTitle->getLocalUrl( $this->editUrlOptions() ) );
447 $tpl->set('body_ondblclick', 'document.location = "' . $encEditUrl . '";');
448 } else {
449 $tpl->set('body_ondblclick', false);
450 }
451 $tpl->set( 'body_onload', false );
452 $tpl->set( 'sidebar', $this->buildSidebar() );
453 $tpl->set( 'nav_urls', $this->buildNavUrls() );
454
455 // original version by hansm
456 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
457 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
458 }
459
460 // allow extensions adding stuff after the page content.
461 // See Skin::afterContentHook() for further documentation.
462 $tpl->set ('dataAfterContent', $this->afterContentHook());
463 wfProfileOut( __METHOD__."-stuff5" );
464
465 // execute template
466 wfProfileIn( __METHOD__."-execute" );
467 $res = $tpl->execute();
468 wfProfileOut( __METHOD__."-execute" );
469
470 // result may be an error
471 $this->printOrError( $res );
472 wfProfileOut( __METHOD__ );
473 }
474
475 /**
476 * Output the string, or print error message if it's
477 * an error object of the appropriate type.
478 * For the base class, assume strings all around.
479 *
480 * @param mixed $str
481 * @private
482 */
483 function printOrError( $str ) {
484 echo $str;
485 }
486
487 /**
488 * build array of urls for personal toolbar
489 * @return array
490 * @private
491 */
492 function buildPersonalUrls() {
493 global $wgTitle, $wgRequest;
494
495 $pageurl = $wgTitle->getLocalURL();
496 wfProfileIn( __METHOD__ );
497
498 /* set up the default links for the personal toolbar */
499 $personal_urls = array();
500 if ($this->loggedin) {
501 $personal_urls['userpage'] = array(
502 'text' => $this->username,
503 'href' => &$this->userpageUrlDetails['href'],
504 'class' => $this->userpageUrlDetails['exists']?false:'new',
505 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
506 );
507 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
508 $personal_urls['mytalk'] = array(
509 'text' => wfMsg('mytalk'),
510 'href' => &$usertalkUrlDetails['href'],
511 'class' => $usertalkUrlDetails['exists']?false:'new',
512 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
513 );
514 $href = self::makeSpecialUrl( 'Preferences' );
515 $personal_urls['preferences'] = array(
516 'text' => wfMsg( 'mypreferences' ),
517 'href' => $href,
518 'active' => ( $href == $pageurl )
519 );
520 $href = self::makeSpecialUrl( 'Watchlist' );
521 $personal_urls['watchlist'] = array(
522 'text' => wfMsg( 'mywatchlist' ),
523 'href' => $href,
524 'active' => ( $href == $pageurl )
525 );
526
527 # We need to do an explicit check for Special:Contributions, as we
528 # have to match both the title, and the target (which could come
529 # from request values or be specified in "sub page" form. The plot
530 # thickens, because $wgTitle is altered for special pages, so doesn't
531 # contain the original alias-with-subpage.
532 $title = Title::newFromText( $wgRequest->getText( 'title' ) );
533 if( $title instanceof Title && $title->getNamespace() == NS_SPECIAL ) {
534 list( $spName, $spPar ) =
535 SpecialPage::resolveAliasWithSubpage( $title->getText() );
536 $active = $spName == 'Contributions'
537 && ( ( $spPar && $spPar == $this->username )
538 || $wgRequest->getText( 'target' ) == $this->username );
539 } else {
540 $active = false;
541 }
542
543 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
544 $personal_urls['mycontris'] = array(
545 'text' => wfMsg( 'mycontris' ),
546 'href' => $href,
547 'active' => $active
548 );
549 $personal_urls['logout'] = array(
550 'text' => wfMsg( 'userlogout' ),
551 'href' => self::makeSpecialUrl( 'Userlogout',
552 $wgTitle->isSpecial( 'Preferences' ) ? '' : "returnto={$this->thisurl}"
553 ),
554 'active' => false
555 );
556 } else {
557 global $wgUser;
558 $loginlink = $wgUser->isAllowed( 'createaccount' )
559 ? 'nav-login-createaccount'
560 : 'login';
561 if( $this->showIPinHeader() ) {
562 $href = &$this->userpageUrlDetails['href'];
563 $personal_urls['anonuserpage'] = array(
564 'text' => $this->username,
565 'href' => $href,
566 'class' => $this->userpageUrlDetails['exists']?false:'new',
567 'active' => ( $pageurl == $href )
568 );
569 $usertalkUrlDetails = $this->makeTalkUrlDetails($this->userpage);
570 $href = &$usertalkUrlDetails['href'];
571 $personal_urls['anontalk'] = array(
572 'text' => wfMsg('anontalk'),
573 'href' => $href,
574 'class' => $usertalkUrlDetails['exists']?false:'new',
575 'active' => ( $pageurl == $href )
576 );
577 $personal_urls['anonlogin'] = array(
578 'text' => wfMsg( $loginlink ),
579 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
580 'active' => $wgTitle->isSpecial( 'Userlogin' )
581 );
582 } else {
583
584 $personal_urls['login'] = array(
585 'text' => wfMsg( $loginlink ),
586 'href' => self::makeSpecialUrl( 'Userlogin', 'returnto=' . $this->thisurl ),
587 'active' => $wgTitle->isSpecial( 'Userlogin' )
588 );
589 }
590 }
591
592 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$wgTitle ) );
593 wfProfileOut( __METHOD__ );
594 return $personal_urls;
595 }
596
597 function tabAction( $title, $message, $selected, $query='', $checkEdit=false ) {
598 $classes = array();
599 if( $selected ) {
600 $classes[] = 'selected';
601 }
602 if( $checkEdit && !$title->isKnown() ) {
603 $classes[] = 'new';
604 $query = 'action=edit&redlink=1';
605 }
606
607 $text = wfMsg( $message );
608 if ( wfEmptyMsg( $message, $text ) ) {
609 global $wgContLang;
610 $text = $wgContLang->getFormattedNsText( MWNamespace::getSubject( $title->getNamespace() ) );
611 }
612
613 $result = array();
614 if( !wfRunHooks('SkinTemplateTabAction', array(&$this,
615 $title, $message, $selected, $checkEdit,
616 &$classes, &$query, &$text, &$result)) ) {
617 return $result;
618 }
619
620 return array(
621 'class' => implode( ' ', $classes ),
622 'text' => $text,
623 'href' => $title->getLocalUrl( $query ) );
624 }
625
626 function makeTalkUrlDetails( $name, $urlaction = '' ) {
627 $title = Title::newFromText( $name );
628 if( !is_object($title) ) {
629 throw new MWException( __METHOD__." given invalid pagename $name" );
630 }
631 $title = $title->getTalkPage();
632 self::checkTitle( $title, $name );
633 return array(
634 'href' => $title->getLocalURL( $urlaction ),
635 'exists' => $title->getArticleID() != 0 ? true : false
636 );
637 }
638
639 function makeArticleUrlDetails( $name, $urlaction = '' ) {
640 $title = Title::newFromText( $name );
641 $title= $title->getSubjectPage();
642 self::checkTitle( $title, $name );
643 return array(
644 'href' => $title->getLocalURL( $urlaction ),
645 'exists' => $title->getArticleID() != 0 ? true : false
646 );
647 }
648
649 /**
650 * an array of edit links by default used for the tabs
651 * @return array
652 * @private
653 */
654 function buildContentActionUrls() {
655 global $wgContLang, $wgLang, $wgOut;
656 wfProfileIn( __METHOD__ );
657
658 global $wgUser, $wgRequest;
659 $action = $wgRequest->getText( 'action' );
660 $section = $wgRequest->getText( 'section' );
661 $content_actions = array();
662
663 $prevent_active_tabs = false ;
664 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this , &$prevent_active_tabs ) ) ;
665
666 if( $this->iscontent ) {
667 $subjpage = $this->mTitle->getSubjectPage();
668 $talkpage = $this->mTitle->getTalkPage();
669
670 $nskey = $this->mTitle->getNamespaceKey();
671 $content_actions[$nskey] = $this->tabAction(
672 $subjpage,
673 $nskey,
674 !$this->mTitle->isTalkPage() && !$prevent_active_tabs,
675 '', true);
676
677 $content_actions['talk'] = $this->tabAction(
678 $talkpage,
679 'talk',
680 $this->mTitle->isTalkPage() && !$prevent_active_tabs,
681 '',
682 true);
683
684 wfProfileIn( __METHOD__."-edit" );
685 if ( $this->mTitle->quickUserCan( 'edit' ) && ( $this->mTitle->exists() || $this->mTitle->quickUserCan( 'create' ) ) ) {
686 $istalk = $this->mTitle->isTalkPage();
687 $istalkclass = $istalk?' istalk':'';
688 $content_actions['edit'] = array(
689 'class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '').$istalkclass,
690 'text' => $this->mTitle->exists()
691 ? wfMsg( 'edit' )
692 : wfMsg( 'create' ),
693 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
694 );
695
696 if ( $istalk || $wgOut->showNewSectionLink() ) {
697 $content_actions['addsection'] = array(
698 'class' => $section == 'new'?'selected':false,
699 'text' => wfMsg('addsection'),
700 'href' => $this->mTitle->getLocalUrl( 'action=edit&section=new' )
701 );
702 }
703 } elseif ( $this->mTitle->isKnown() ) {
704 $content_actions['viewsource'] = array(
705 'class' => ($action == 'edit') ? 'selected' : false,
706 'text' => wfMsg('viewsource'),
707 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
708 );
709 }
710 wfProfileOut( __METHOD__."-edit" );
711
712 wfProfileIn( __METHOD__."-live" );
713 if ( $this->mTitle->exists() ) {
714
715 $content_actions['history'] = array(
716 'class' => ($action == 'history') ? 'selected' : false,
717 'text' => wfMsg('history_short'),
718 'href' => $this->mTitle->getLocalUrl( 'action=history')
719 );
720
721 if( $wgUser->isAllowed('delete') ) {
722 $content_actions['delete'] = array(
723 'class' => ($action == 'delete') ? 'selected' : false,
724 'text' => wfMsg('delete'),
725 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
726 );
727 }
728 if ( $this->mTitle->quickUserCan( 'move' ) ) {
729 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
730 $content_actions['move'] = array(
731 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
732 'text' => wfMsg('move'),
733 'href' => $moveTitle->getLocalUrl()
734 );
735 }
736
737 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
738 if( !$this->mTitle->isProtected() ){
739 $content_actions['protect'] = array(
740 'class' => ($action == 'protect') ? 'selected' : false,
741 'text' => wfMsg('protect'),
742 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
743 );
744
745 } else {
746 $content_actions['unprotect'] = array(
747 'class' => ($action == 'unprotect') ? 'selected' : false,
748 'text' => wfMsg('unprotect'),
749 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
750 );
751 }
752 }
753 } else {
754 //article doesn't exist or is deleted
755 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
756 if( $n = $this->mTitle->isDeleted() ) {
757 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
758 $content_actions['undelete'] = array(
759 'class' => false,
760 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
761 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
762 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
763 );
764 }
765 }
766
767 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
768 if( !$this->mTitle->getRestrictions( 'create' ) ) {
769 $content_actions['protect'] = array(
770 'class' => ($action == 'protect') ? 'selected' : false,
771 'text' => wfMsg('protect'),
772 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
773 );
774
775 } else {
776 $content_actions['unprotect'] = array(
777 'class' => ($action == 'unprotect') ? 'selected' : false,
778 'text' => wfMsg('unprotect'),
779 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
780 );
781 }
782 }
783 }
784
785 wfProfileOut( __METHOD__."-live" );
786
787 if( $this->loggedin ) {
788 if( !$this->mTitle->userIsWatching()) {
789 $content_actions['watch'] = array(
790 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
791 'text' => wfMsg('watch'),
792 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
793 );
794 } else {
795 $content_actions['unwatch'] = array(
796 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
797 'text' => wfMsg('unwatch'),
798 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
799 );
800 }
801 }
802
803
804 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
805 } else {
806 /* show special page tab */
807
808 $content_actions[$this->mTitle->getNamespaceKey()] = array(
809 'class' => 'selected',
810 'text' => wfMsg('nstab-special'),
811 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
812 );
813
814 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
815 }
816
817 /* show links to different language variants */
818 global $wgDisableLangConversion;
819 $variants = $wgContLang->getVariants();
820 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
821 $preferred = $wgContLang->getPreferredVariant();
822 $vcount=0;
823 foreach( $variants as $code ) {
824 $varname = $wgContLang->getVariantname( $code );
825 if( $varname == 'disable' )
826 continue;
827 $selected = ( $code == $preferred )? 'selected' : false;
828 $content_actions['varlang-' . $vcount] = array(
829 'class' => $selected,
830 'text' => $varname,
831 'href' => $this->mTitle->getLocalURL('',$code)
832 );
833 $vcount ++;
834 }
835 }
836
837 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
838
839 wfProfileOut( __METHOD__ );
840 return $content_actions;
841 }
842
843
844
845 /**
846 * build array of common navigation links
847 * @return array
848 * @private
849 */
850 function buildNavUrls() {
851 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
852 global $wgEnableUploads, $wgUploadNavigationUrl;
853
854 wfProfileIn( __METHOD__ );
855
856 $action = $wgRequest->getText( 'action' );
857
858 $nav_urls = array();
859 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
860 if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
861 if ($wgUploadNavigationUrl) {
862 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
863 } else {
864 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
865 }
866 } else {
867 if ($wgUploadNavigationUrl)
868 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
869 else
870 $nav_urls['upload'] = false;
871 }
872 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
873
874 // default permalink to being off, will override it as required below.
875 $nav_urls['permalink'] = false;
876
877 // A print stylesheet is attached to all pages, but nobody ever
878 // figures that out. :) Add a link...
879 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
880 $nav_urls['print'] = array(
881 'text' => wfMsg( 'printableversion' ),
882 'href' => $wgRequest->appendQuery( 'printable=yes' )
883 );
884
885 // Also add a "permalink" while we're at it
886 if ( $this->mRevisionId ) {
887 global $wgScript;
888 $nav_urls['permalink'] = array(
889 'text' => wfMsg( 'permalink' ),
890 'href' => "{$wgScript}?oldid={$this->mRevisionId}"
891 );
892 }
893
894 // Copy in case this undocumented, shady hook tries to mess with internals
895 $revid = $this->mRevisionId;
896 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
897 }
898
899 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
900 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
901 $nav_urls['whatlinkshere'] = array(
902 'href' => $wlhTitle->getLocalUrl()
903 );
904 if( $this->mTitle->getArticleId() ) {
905 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
906 $nav_urls['recentchangeslinked'] = array(
907 'href' => $rclTitle->getLocalUrl()
908 );
909 } else {
910 $nav_urls['recentchangeslinked'] = false;
911 }
912 if ($wgUseTrackbacks)
913 $nav_urls['trackbacklink'] = array(
914 'href' => $wgTitle->trackbackURL()
915 );
916 }
917
918 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
919 $id = User::idFromName($this->mTitle->getText());
920 $ip = User::isIP($this->mTitle->getText());
921 } else {
922 $id = 0;
923 $ip = false;
924 }
925
926 if($id || $ip) { # both anons and non-anons have contribs list
927 $nav_urls['contributions'] = array(
928 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
929 );
930
931 if( $id ) {
932 $logPage = SpecialPage::getTitleFor( 'Log' );
933 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
934 . $this->mTitle->getPartialUrl() ) );
935 } else {
936 $nav_urls['log'] = false;
937 }
938
939 if ( $wgUser->isAllowed( 'block' ) ) {
940 $nav_urls['blockip'] = array(
941 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
942 );
943 } else {
944 $nav_urls['blockip'] = false;
945 }
946 } else {
947 $nav_urls['contributions'] = false;
948 $nav_urls['log'] = false;
949 $nav_urls['blockip'] = false;
950 }
951 $nav_urls['emailuser'] = false;
952 if( $this->showEmailUser( $id ) ) {
953 $nav_urls['emailuser'] = array(
954 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
955 );
956 }
957 wfProfileOut( __METHOD__ );
958 return $nav_urls;
959 }
960
961 /**
962 * Generate strings used for xml 'id' names
963 * @return string
964 * @private
965 */
966 function getNameSpaceKey() {
967 return $this->mTitle->getNamespaceKey();
968 }
969
970 /**
971 * @private
972 */
973 function setupUserJs( $allowUserJs ) {
974 wfProfileIn( __METHOD__ );
975
976 global $wgRequest, $wgJsMimeType;
977 $action = $wgRequest->getText('action');
978
979 if( $allowUserJs && $this->loggedin ) {
980 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
981 # XXX: additional security check/prompt?
982 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
983 } else {
984 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType);
985 }
986 }
987 wfProfileOut( __METHOD__ );
988 }
989
990 /**
991 * Code for extensions to hook into to provide per-page CSS, see
992 * extensions/PageCSS/PageCSS.php for an implementation of this.
993 *
994 * @private
995 */
996 function setupPageCss() {
997 wfProfileIn( __METHOD__ );
998 $out = false;
999 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1000 wfProfileOut( __METHOD__ );
1001 return $out;
1002 }
1003 }
1004
1005 /**
1006 * Generic wrapper for template functions, with interface
1007 * compatible with what we use of PHPTAL 0.7.
1008 * @ingroup Skins
1009 */
1010 class QuickTemplate {
1011 /**
1012 * @public
1013 */
1014 function QuickTemplate() {
1015 $this->data = array();
1016 $this->translator = new MediaWiki_I18N();
1017 }
1018
1019 /**
1020 * @public
1021 */
1022 function set( $name, $value ) {
1023 $this->data[$name] = $value;
1024 }
1025
1026 /**
1027 * @public
1028 */
1029 function setRef($name, &$value) {
1030 $this->data[$name] =& $value;
1031 }
1032
1033 /**
1034 * @public
1035 */
1036 function setTranslator( &$t ) {
1037 $this->translator = &$t;
1038 }
1039
1040 /**
1041 * @public
1042 */
1043 function execute() {
1044 echo "Override this function.";
1045 }
1046
1047
1048 /**
1049 * @private
1050 */
1051 function text( $str ) {
1052 echo htmlspecialchars( $this->data[$str] );
1053 }
1054
1055 /**
1056 * @private
1057 */
1058 function jstext( $str ) {
1059 echo Xml::escapeJsString( $this->data[$str] );
1060 }
1061
1062 /**
1063 * @private
1064 */
1065 function html( $str ) {
1066 echo $this->data[$str];
1067 }
1068
1069 /**
1070 * @private
1071 */
1072 function msg( $str ) {
1073 echo htmlspecialchars( $this->translator->translate( $str ) );
1074 }
1075
1076 /**
1077 * @private
1078 */
1079 function msgHtml( $str ) {
1080 echo $this->translator->translate( $str );
1081 }
1082
1083 /**
1084 * An ugly, ugly hack.
1085 * @private
1086 */
1087 function msgWiki( $str ) {
1088 global $wgParser, $wgTitle, $wgOut;
1089
1090 $text = $this->translator->translate( $str );
1091 $parserOutput = $wgParser->parse( $text, $wgTitle,
1092 $wgOut->parserOptions(), true );
1093 echo $parserOutput->getText();
1094 }
1095
1096 /**
1097 * @private
1098 */
1099 function haveData( $str ) {
1100 return isset( $this->data[$str] );
1101 }
1102
1103 /**
1104 * @private
1105 */
1106 function haveMsg( $str ) {
1107 $msg = $this->translator->translate( $str );
1108 return ($msg != '-') && ($msg != ''); # ????
1109 }
1110 }