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