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