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