(bug 10347) Add subtitle message for protected pages
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 if ( ! defined( 'MEDIAWIKI' ) )
3 die( 1 );
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
19
20 /**
21 * Wrapper object for MediaWiki's localization functions,
22 * to be passed to the template engine.
23 *
24 * @private
25 * @ingroup Skins
26 */
27 class MediaWiki_I18N {
28 var $_context = array();
29
30 function set($varName, $value) {
31 $this->_context[$varName] = $value;
32 }
33
34 function translate($value) {
35 wfProfileIn( __METHOD__ );
36
37 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
38 $value = preg_replace( '/^string:/', '', $value );
39
40 $value = wfMsg( $value );
41 // interpolate variables
42 $m = array();
43 while (preg_match('/\$([0-9]*?)/sm', $value, $m)) {
44 list($src, $var) = $m;
45 wfSuppressWarnings();
46 $varValue = $this->_context[$var];
47 wfRestoreWarnings();
48 $value = str_replace($src, $varValue, $value);
49 }
50 wfProfileOut( __METHOD__ );
51 return $value;
52 }
53 }
54
55 /**
56 * Template-filler skin base class
57 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
58 * Based on Brion's smarty skin
59 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
60 *
61 * @todo Needs some serious refactoring into functions that correspond
62 * to the computations individual esi snippets need. Most importantly no body
63 * parsing for most of those of course.
64 *
65 * @ingroup Skins
66 */
67 class SkinTemplate extends Skin {
68 /**#@+
69 * @private
70 */
71
72 /**
73 * Name of our skin, set in initPage()
74 * It probably need to be all lower case.
75 */
76 var $skinname;
77
78 /**
79 * Stylesheets set to use
80 * Sub directory in ./skins/ where various stylesheets are located
81 */
82 var $stylename;
83
84 /**
85 * For QuickTemplate, the name of the subclass which
86 * will actually fill the template.
87 */
88 var $template;
89
90 /**#@-*/
91
92 /**
93 * Setup the base parameters...
94 * Child classes should override this to set the name,
95 * style subdirectory, and template filler callback.
96 *
97 * @param $out OutputPage
98 */
99 function initPage( OutputPage $out ) {
100 parent::initPage( $out );
101 $this->skinname = 'monobook';
102 $this->stylename = 'monobook';
103 $this->template = 'QuickTemplate';
104 }
105
106 /**
107 * Add specific styles for this skin
108 *
109 * @param $out OutputPage
110 */
111 function setupSkinUserCss( OutputPage $out ){
112 $out->addStyle( 'common/shared.css', 'screen' );
113 $out->addStyle( 'common/commonPrint.css', 'print' );
114 }
115
116 /**
117 * Create the template engine object; we feed it a bunch of data
118 * and eventually it spits out some HTML. Should have interface
119 * roughly equivalent to PHPTAL 0.7.
120 *
121 * @param $callback string (or file)
122 * @param $repository string: subdirectory where we keep template files
123 * @param $cache_dir string
124 * @return object
125 * @private
126 */
127 function setupTemplate( $classname, $repository=false, $cache_dir=false ) {
128 return new $classname();
129 }
130
131 /**
132 * initialize various variables and generate the template
133 *
134 * @param $out OutputPage
135 */
136 function outputPage( OutputPage $out ) {
137 global $wgTitle, $wgArticle, $wgUser, $wgLang, $wgContLang;
138 global $wgScript, $wgStylePath, $wgContLanguageCode;
139 global $wgMimeType, $wgJsMimeType, $wgOutputEncoding, $wgRequest;
140 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces;
141 global $wgDisableCounters, $wgLogo, $action, $wgFeedClasses, $wgHideInterlanguageLinks;
142 global $wgMaxCredits, $wgShowCreditsIfMax;
143 global $wgPageShowWatchingUsers;
144 global $wgUseTrackbacks, $wgUseSiteJs;
145 global $wgArticlePath, $wgScriptPath, $wgServer, $wgLang, $wgCanonicalNamespaceNames;
146
147 wfProfileIn( __METHOD__ );
148
149 $oldid = $wgRequest->getVal( 'oldid' );
150 $diff = $wgRequest->getVal( 'diff' );
151
152 wfProfileIn( __METHOD__."-init" );
153 $this->initPage( $out );
154
155 $this->setMembers();
156 $tpl = $this->setupTemplate( $this->template, 'skins' );
157
158 #if ( $wgUseDatabaseMessages ) { // uncomment this to fall back to GetText
159 $tpl->setTranslator(new MediaWiki_I18N());
160 #}
161 wfProfileOut( __METHOD__."-init" );
162
163 wfProfileIn( __METHOD__."-stuff" );
164 $this->thispage = $this->mTitle->getPrefixedDbKey();
165 $this->thisurl = $this->mTitle->getPrefixedURL();
166 $this->loggedin = $wgUser->isLoggedIn();
167 $this->iscontent = ($this->mTitle->getNamespace() != NS_SPECIAL );
168 $this->iseditable = ($this->iscontent and !($action == 'edit' or $action == 'submit'));
169 $this->username = $wgUser->getName();
170
171 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
172 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
173 } else {
174 # This won't be used in the standard skins, but we define it to preserve the interface
175 # To save time, we check for existence
176 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
177 }
178
179 $this->userjs = $this->userjsprev = false;
180 $this->setupUserCss( $out );
181 $this->setupUserJs( $out->isUserJsAllowed() );
182 $this->titletxt = $this->mTitle->getPrefixedText();
183 wfProfileOut( __METHOD__."-stuff" );
184
185 wfProfileIn( __METHOD__."-stuff2" );
186 $tpl->set( 'title', $out->getPageTitle() );
187 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
188 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
189 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
190 $tpl->set( 'skinnameclass', ( "skin-" . Sanitizer::escapeClass( $this->getSkinName ( ) ) ) );
191
192 $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
193 $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
194 $this->mTitle->getNsText();
195
196 $tpl->set( 'nscanonical', $nsname );
197 $tpl->set( 'nsnumber', $this->mTitle->getNamespace() );
198 $tpl->set( 'titleprefixeddbkey', $this->mTitle->getPrefixedDBKey() );
199 $tpl->set( 'titletext', $this->mTitle->getText() );
200 $tpl->set( 'articleid', $this->mTitle->getArticleId() );
201 $tpl->set( 'currevisionid', isset( $wgArticle ) ? $wgArticle->getLatest() : 0 );
202
203 $tpl->set( 'isarticle', $out->isArticle() );
204
205 $tpl->setRef( "thispage", $this->thispage );
206
207 $undelete = $this->getUndeleteLink();
208 $tpl->set(
209 "undelete", !empty($undelete)?
210 '<span class="subpages">'.$undelete.'</span>':
211 ''
212 );
213
214 $tpl->set( 'catlinks', $this->getCategories());
215 if( $out->isSyndicated() ) {
216 $feeds = array();
217 foreach( $out->getSyndicationLinks() as $format => $link ) {
218 $feeds[$format] = array(
219 'text' => wfMsg( "feed-$format" ),
220 'href' => $link );
221 }
222 $tpl->setRef( 'feeds', $feeds );
223 } else {
224 $tpl->set( 'feeds', false );
225 }
226 if ($wgUseTrackbacks && $out->isArticleRelated()) {
227 $tpl->set( 'trackbackhtml', $wgTitle->trackbackRDF() );
228 } else {
229 $tpl->set( 'trackbackhtml', null );
230 }
231
232 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
233 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
234 $tpl->setRef( 'mimetype', $wgMimeType );
235 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
236 $tpl->setRef( 'charset', $wgOutputEncoding );
237 $tpl->set( 'headlinks', $out->getHeadLinks() );
238 $tpl->set( 'headscripts', $out->getScript() );
239 $tpl->set( 'csslinks', $out->buildCssLinks() );
240 $tpl->setRef( 'wgScript', $wgScript );
241 $tpl->setRef( 'skinname', $this->skinname );
242 $tpl->set( 'skinclass', get_class( $this ) );
243 $tpl->setRef( 'stylename', $this->stylename );
244 $tpl->set( 'printable', $wgRequest->getBool( 'printable' ) );
245 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
246 $tpl->setRef( 'loggedin', $this->loggedin );
247 $tpl->set('notspecialpage', $this->mTitle->getNamespace() != NS_SPECIAL);
248 /* XXX currently unused, might get useful later
249 $tpl->set( "editable", ($this->mTitle->getNamespace() != NS_SPECIAL ) );
250 $tpl->set( "exists", $this->mTitle->getArticleID() != 0 );
251 $tpl->set( "watch", $this->mTitle->userIsWatching() ? "unwatch" : "watch" );
252 $tpl->set( "protect", count($this->mTitle->isProtected()) ? "unprotect" : "protect" );
253 $tpl->set( "helppage", wfMsg('helppage'));
254 */
255 $tpl->set( 'searchaction', $this->escapeSearchLink() );
256 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
257 $tpl->setRef( 'stylepath', $wgStylePath );
258 $tpl->setRef( 'articlepath', $wgArticlePath );
259 $tpl->setRef( 'scriptpath', $wgScriptPath );
260 $tpl->setRef( 'serverurl', $wgServer );
261 $tpl->setRef( 'logopath', $wgLogo );
262 $tpl->setRef( "lang", $wgContLanguageCode );
263 $tpl->set( 'dir', $wgContLang->isRTL() ? "rtl" : "ltr" );
264 $tpl->set( 'rtl', $wgContLang->isRTL() );
265 $tpl->set( 'langname', $wgContLang->getLanguageName( $wgContLanguageCode ) );
266 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
267 $tpl->set( 'username', $wgUser->isAnon() ? NULL : $this->username );
268 $tpl->setRef( 'userpage', $this->userpage);
269 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href']);
270 $tpl->set( 'userlang', $wgLang->getCode() );
271 $tpl->set( 'pagecss', $this->setupPageCss() );
272 $tpl->setRef( 'usercss', $this->usercss);
273 $tpl->setRef( 'userjs', $this->userjs);
274 $tpl->setRef( 'userjsprev', $this->userjsprev);
275 if( $wgUseSiteJs ) {
276 $jsCache = $this->loggedin ? '&smaxage=0' : '';
277 $tpl->set( 'jsvarurl',
278 self::makeUrl('-',
279 "action=raw$jsCache&gen=js&useskin=" .
280 urlencode( $this->getSkinName() ) ) );
281 } else {
282 $tpl->set('jsvarurl', false);
283 }
284 $newtalks = $wgUser->getNewMessageLinks();
285
286 if (count($newtalks) == 1 && $newtalks[0]["wiki"] === wfWikiID() ) {
287 $usertitle = $this->mUser->getUserPage();
288 $usertalktitle = $usertitle->getTalkPage();
289 if( !$usertalktitle->equals( $this->mTitle ) ) {
290 $ntl = wfMsg( 'youhavenewmessages',
291 $this->makeKnownLinkObj(
292 $usertalktitle,
293 wfMsgHtml( 'newmessageslink' ),
294 'redirect=no'
295 ),
296 $this->makeKnownLinkObj(
297 $usertalktitle,
298 wfMsgHtml( 'newmessagesdifflink' ),
299 'diff=cur'
300 )
301 );
302 # Disable Cache
303 $out->setSquidMaxage(0);
304 }
305 } else if (count($newtalks)) {
306 $sep = str_replace("_", " ", wfMsgHtml("newtalkseparator"));
307 $msgs = array();
308 foreach ($newtalks as $newtalk) {
309 $msgs[] = wfElement("a",
310 array('href' => $newtalk["link"]), $newtalk["wiki"]);
311 }
312 $parts = implode($sep, $msgs);
313 $ntl = wfMsgHtml('youhavenewmessagesmulti', $parts);
314 $out->setSquidMaxage(0);
315 } else {
316 $ntl = '';
317 }
318 wfProfileOut( __METHOD__."-stuff2" );
319
320 wfProfileIn( __METHOD__."-stuff3" );
321 $tpl->setRef( 'newtalk', $ntl );
322 $tpl->setRef( 'skin', $this );
323 $tpl->set( 'logo', $this->logoText() );
324 if ( $out->isArticle() and (!isset( $oldid ) or isset( $diff )) and
325 $wgArticle and 0 != $wgArticle->getID() )
326 {
327 if ( !$wgDisableCounters ) {
328 $viewcount = $wgLang->formatNum( $wgArticle->getCount() );
329 if ( $viewcount ) {
330 $tpl->set('viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
331 } else {
332 $tpl->set('viewcount', false);
333 }
334 } else {
335 $tpl->set('viewcount', false);
336 }
337
338 if ($wgPageShowWatchingUsers) {
339 $dbr = wfGetDB( DB_SLAVE );
340 $watchlist = $dbr->tableName( 'watchlist' );
341 $sql = "SELECT COUNT(*) AS n FROM $watchlist
342 WHERE wl_title='" . $dbr->strencode($this->mTitle->getDBkey()) .
343 "' AND wl_namespace=" . $this->mTitle->getNamespace() ;
344 $res = $dbr->query( $sql, 'SkinTemplate::outputPage');
345 $x = $dbr->fetchObject( $res );
346 $numberofwatchingusers = $x->n;
347 if ($numberofwatchingusers > 0) {
348 $tpl->set('numberofwatchingusers',
349 wfMsgExt('number_of_watching_users_pageview', array('parseinline'),
350 $wgLang->formatNum($numberofwatchingusers))
351 );
352 } else {
353 $tpl->set('numberofwatchingusers', false);
354 }
355 } else {
356 $tpl->set('numberofwatchingusers', false);
357 }
358
359 $tpl->set('copyright',$this->getCopyright());
360
361 $this->credits = false;
362
363 if( $wgMaxCredits != 0 ){
364 $this->credits = Credits::getCredits( $wgArticle, $wgMaxCredits, $wgShowCreditsIfMax );
365 } else {
366 $tpl->set( 'lastmod', $this->lastModified() );
367 }
368
369 $tpl->setRef( 'credits', $this->credits );
370
371 } elseif ( isset( $oldid ) && !isset( $diff ) ) {
372 $tpl->set('copyright', $this->getCopyright());
373 $tpl->set('viewcount', false);
374 $tpl->set('lastmod', false);
375 $tpl->set('credits', false);
376 $tpl->set('numberofwatchingusers', false);
377 } else {
378 $tpl->set('copyright', false);
379 $tpl->set('viewcount', false);
380 $tpl->set('lastmod', false);
381 $tpl->set('credits', false);
382 $tpl->set('numberofwatchingusers', false);
383 }
384 wfProfileOut( __METHOD__."-stuff3" );
385
386 wfProfileIn( __METHOD__."-stuff4" );
387 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
388 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
389 $tpl->set( 'disclaimer', $this->disclaimerLink() );
390 $tpl->set( 'privacy', $this->privacyLink() );
391 $tpl->set( 'about', $this->aboutLink() );
392
393 $tpl->setRef( 'debug', $out->mDebugtext );
394 $tpl->set( 'reporttime', wfReportTime() );
395 $tpl->set( 'sitenotice', wfGetSiteNotice() );
396 $tpl->set( 'bottomscripts', $this->bottomScripts() );
397
398 $printfooter = "<div class=\"printfooter\">\n" . $this->printSource() . "</div>\n";
399 $out->mBodytext .= $printfooter ;
400 $tpl->setRef( 'bodytext', $out->mBodytext );
401
402 # Language links
403 $language_urls = array();
404
405 if ( !$wgHideInterlanguageLinks ) {
406 foreach( $out->getLanguageLinks() as $l ) {
407 $tmp = explode( ':', $l, 2 );
408 $class = 'interwiki-' . $tmp[0];
409 unset($tmp);
410 $nt = Title::newFromText( $l );
411 if ( $nt ) {
412 $language_urls[] = array(
413 'href' => $nt->getFullURL(),
414 'text' => $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
415 $wgContLang->getLanguageName( $nt->getInterwiki()) : $l,
416 'class' => $class
417 );
418 }
419 }
420 }
421 if(count($language_urls)) {
422 $tpl->setRef( 'language_urls', $language_urls);
423 } else {
424 $tpl->set('language_urls', false);
425 }
426 wfProfileOut( __METHOD__."-stuff4" );
427
428 wfProfileIn( __METHOD__."-stuff5" );
429 # Personal toolbar
430 $tpl->set('personal_urls', $this->buildPersonalUrls());
431 $content_actions = $this->buildContentActionUrls();
432 $tpl->setRef('content_actions', $content_actions);
433
434 $subpagestr = $this->subPageSubtitle();
435 $tpl->set(
436 'subtitle', !empty($subpagestr) ?
437 '<span class="subpages">'.$subpagestr.'</span>'.$out->getSubtitle() : $out->getSubtitle()
438 );
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', 'view' );
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 # Give notice if this page is locked for others
702 if( ($action == 'view' || $action == 'purge') && $this->mTitle->isProtected( 'edit' ) ) {
703 $wgOut->appendSubtitle( "<span class='plainlinks'>" .
704 wfMsgExt('protected-sub-allowed',array('parse'),$this->mTitle->getFullUrl('action=protect')) .
705 "</span>"
706 );
707 }
708 } elseif ( $this->mTitle->exists() || $this->mTitle->isAlwaysKnown() ) {
709 $content_actions['viewsource'] = array(
710 'class' => ($action == 'edit') ? 'selected' : false,
711 'text' => wfMsg('viewsource'),
712 'href' => $this->mTitle->getLocalUrl( $this->editUrlOptions() )
713 );
714 # Give notice if this page is locked
715 if( ($action == 'view' || $action == 'purge') && $this->mTitle->isProtected( 'edit' ) ) {
716 $wgOut->appendSubtitle( "<span class='plainlinks'>" .
717 wfMsgExt('protected-sub-disallowed',array('parseinline'),$this->mTitle->getFullUrl('action=protect')) .
718 "</span>"
719 );
720 }
721 }
722 wfProfileOut( __METHOD__."-edit" );
723
724 wfProfileIn( __METHOD__."-live" );
725 if ( $this->mTitle->exists() ) {
726
727 $content_actions['history'] = array(
728 'class' => ($action == 'history') ? 'selected' : false,
729 'text' => wfMsg('history_short'),
730 'href' => $this->mTitle->getLocalUrl( 'action=history')
731 );
732
733 if( $wgUser->isAllowed('delete') ) {
734 $content_actions['delete'] = array(
735 'class' => ($action == 'delete') ? 'selected' : false,
736 'text' => wfMsg('delete'),
737 'href' => $this->mTitle->getLocalUrl( 'action=delete' )
738 );
739 }
740 if ( $this->mTitle->quickUserCan( 'move' ) ) {
741 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $this->thispage );
742 $content_actions['move'] = array(
743 'class' => $this->mTitle->isSpecial( 'Movepage' ) ? 'selected' : false,
744 'text' => wfMsg('move'),
745 'href' => $moveTitle->getLocalUrl()
746 );
747 }
748
749 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
750 if( !$this->mTitle->isProtected() ){
751 $content_actions['protect'] = array(
752 'class' => ($action == 'protect') ? 'selected' : false,
753 'text' => wfMsg('protect'),
754 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
755 );
756
757 } else {
758 $content_actions['unprotect'] = array(
759 'class' => ($action == 'unprotect') ? 'selected' : false,
760 'text' => wfMsg('unprotect'),
761 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
762 );
763 }
764 }
765 } else {
766 //article doesn't exist or is deleted
767 if( $wgUser->isAllowed( 'deletedhistory' ) && $wgUser->isAllowed( 'undelete' ) ) {
768 if( $n = $this->mTitle->isDeleted() ) {
769 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
770 $content_actions['undelete'] = array(
771 'class' => false,
772 'text' => wfMsgExt( 'undelete_short', array( 'parsemag' ), $wgLang->formatNum($n) ),
773 'href' => $undelTitle->getLocalUrl( 'target=' . urlencode( $this->thispage ) )
774 #'href' => self::makeSpecialUrl( "Undelete/$this->thispage" )
775 );
776 }
777 }
778
779 if ( $this->mTitle->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
780 if( !$this->mTitle->getRestrictions( 'create' ) ) {
781 $content_actions['protect'] = array(
782 'class' => ($action == 'protect') ? 'selected' : false,
783 'text' => wfMsg('protect'),
784 'href' => $this->mTitle->getLocalUrl( 'action=protect' )
785 );
786
787 } else {
788 $content_actions['unprotect'] = array(
789 'class' => ($action == 'unprotect') ? 'selected' : false,
790 'text' => wfMsg('unprotect'),
791 'href' => $this->mTitle->getLocalUrl( 'action=unprotect' )
792 );
793 }
794 }
795 }
796
797 wfProfileOut( __METHOD__."-live" );
798
799 if( $this->loggedin ) {
800 if( !$this->mTitle->userIsWatching()) {
801 $content_actions['watch'] = array(
802 'class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false,
803 'text' => wfMsg('watch'),
804 'href' => $this->mTitle->getLocalUrl( 'action=watch' )
805 );
806 } else {
807 $content_actions['unwatch'] = array(
808 'class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false,
809 'text' => wfMsg('unwatch'),
810 'href' => $this->mTitle->getLocalUrl( 'action=unwatch' )
811 );
812 }
813 }
814
815
816 wfRunHooks( 'SkinTemplateTabs', array( &$this , &$content_actions ) ) ;
817 } else {
818 /* show special page tab */
819
820 $content_actions[$this->mTitle->getNamespaceKey()] = array(
821 'class' => 'selected',
822 'text' => wfMsg('nstab-special'),
823 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
824 );
825
826 wfRunHooks( 'SkinTemplateBuildContentActionUrlsAfterSpecialPage', array( &$this, &$content_actions ) );
827 }
828
829 /* show links to different language variants */
830 global $wgDisableLangConversion;
831 $variants = $wgContLang->getVariants();
832 if( !$wgDisableLangConversion && sizeof( $variants ) > 1 ) {
833 $preferred = $wgContLang->getPreferredVariant();
834 $vcount=0;
835 foreach( $variants as $code ) {
836 $varname = $wgContLang->getVariantname( $code );
837 if( $varname == 'disable' )
838 continue;
839 $selected = ( $code == $preferred )? 'selected' : false;
840 $content_actions['varlang-' . $vcount] = array(
841 'class' => $selected,
842 'text' => $varname,
843 'href' => $this->mTitle->getLocalURL('',$code)
844 );
845 $vcount ++;
846 }
847 }
848
849 wfRunHooks( 'SkinTemplateContentActions', array( &$content_actions ) );
850
851 wfProfileOut( __METHOD__ );
852 return $content_actions;
853 }
854
855
856
857 /**
858 * build array of common navigation links
859 * @return array
860 * @private
861 */
862 function buildNavUrls() {
863 global $wgUseTrackbacks, $wgTitle, $wgUser, $wgRequest;
864 global $wgEnableUploads, $wgUploadNavigationUrl;
865
866 wfProfileIn( __METHOD__ );
867
868 $action = $wgRequest->getText( 'action' );
869
870 $nav_urls = array();
871 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
872 if( $wgEnableUploads && $wgUser->isAllowed( 'upload' ) ) {
873 if ($wgUploadNavigationUrl) {
874 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
875 } else {
876 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
877 }
878 } else {
879 if ($wgUploadNavigationUrl)
880 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
881 else
882 $nav_urls['upload'] = false;
883 }
884 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
885
886 // default permalink to being off, will override it as required below.
887 $nav_urls['permalink'] = false;
888
889 // A print stylesheet is attached to all pages, but nobody ever
890 // figures that out. :) Add a link...
891 if( $this->iscontent && ($action == '' || $action == 'view' || $action == 'purge' ) ) {
892 $nav_urls['print'] = array(
893 'text' => wfMsg( 'printableversion' ),
894 'href' => $wgRequest->appendQuery( 'printable=yes' )
895 );
896
897 // Also add a "permalink" while we're at it
898 if ( $this->mRevisionId ) {
899 $nav_urls['permalink'] = array(
900 'text' => wfMsg( 'permalink' ),
901 'href' => $wgTitle->getLocalURL( "oldid=$this->mRevisionId" )
902 );
903 }
904
905 // Copy in case this undocumented, shady hook tries to mess with internals
906 $revid = $this->mRevisionId;
907 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink', array( &$this, &$nav_urls, &$revid, &$revid ) );
908 }
909
910 if( $this->mTitle->getNamespace() != NS_SPECIAL ) {
911 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
912 $nav_urls['whatlinkshere'] = array(
913 'href' => $wlhTitle->getLocalUrl()
914 );
915 if( $this->mTitle->getArticleId() ) {
916 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
917 $nav_urls['recentchangeslinked'] = array(
918 'href' => $rclTitle->getLocalUrl()
919 );
920 } else {
921 $nav_urls['recentchangeslinked'] = false;
922 }
923 if ($wgUseTrackbacks)
924 $nav_urls['trackbacklink'] = array(
925 'href' => $wgTitle->trackbackURL()
926 );
927 }
928
929 if( $this->mTitle->getNamespace() == NS_USER || $this->mTitle->getNamespace() == NS_USER_TALK ) {
930 $id = User::idFromName($this->mTitle->getText());
931 $ip = User::isIP($this->mTitle->getText());
932 } else {
933 $id = 0;
934 $ip = false;
935 }
936
937 if($id || $ip) { # both anons and non-anons have contribs list
938 $nav_urls['contributions'] = array(
939 'href' => self::makeSpecialUrlSubpage( 'Contributions', $this->mTitle->getText() )
940 );
941
942 if( $id ) {
943 $logPage = SpecialPage::getTitleFor( 'Log' );
944 $nav_urls['log'] = array( 'href' => $logPage->getLocalUrl( 'user='
945 . $this->mTitle->getPartialUrl() ) );
946 } else {
947 $nav_urls['log'] = false;
948 }
949
950 if ( $wgUser->isAllowed( 'block' ) ) {
951 $nav_urls['blockip'] = array(
952 'href' => self::makeSpecialUrlSubpage( 'Blockip', $this->mTitle->getText() )
953 );
954 } else {
955 $nav_urls['blockip'] = false;
956 }
957 } else {
958 $nav_urls['contributions'] = false;
959 $nav_urls['log'] = false;
960 $nav_urls['blockip'] = false;
961 }
962 $nav_urls['emailuser'] = false;
963 if( $this->showEmailUser( $id ) ) {
964 $nav_urls['emailuser'] = array(
965 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $this->mTitle->getText() )
966 );
967 }
968 wfProfileOut( __METHOD__ );
969 return $nav_urls;
970 }
971
972 /**
973 * Generate strings used for xml 'id' names
974 * @return string
975 * @private
976 */
977 function getNameSpaceKey() {
978 return $this->mTitle->getNamespaceKey();
979 }
980
981 /**
982 * @private
983 */
984 function setupUserJs( $allowUserJs ) {
985 wfProfileIn( __METHOD__ );
986
987 global $wgRequest, $wgJsMimeType;
988 $action = $wgRequest->getText('action');
989
990 if( $allowUserJs && $this->loggedin ) {
991 if( $this->mTitle->isJsSubpage() and $this->userCanPreview( $action ) ) {
992 # XXX: additional security check/prompt?
993 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText('wpTextbox1') . ' /*]]>*/';
994 } else {
995 $this->userjs = self::makeUrl($this->userpage.'/'.$this->skinname.'.js', 'action=raw&ctype='.$wgJsMimeType);
996 }
997 }
998 wfProfileOut( __METHOD__ );
999 }
1000
1001 /**
1002 * Code for extensions to hook into to provide per-page CSS, see
1003 * extensions/PageCSS/PageCSS.php for an implementation of this.
1004 *
1005 * @private
1006 */
1007 function setupPageCss() {
1008 wfProfileIn( __METHOD__ );
1009 $out = false;
1010 wfRunHooks( 'SkinTemplateSetupPageCss', array( &$out ) );
1011 wfProfileOut( __METHOD__ );
1012 return $out;
1013 }
1014 }
1015
1016 /**
1017 * Generic wrapper for template functions, with interface
1018 * compatible with what we use of PHPTAL 0.7.
1019 * @ingroup Skins
1020 */
1021 class QuickTemplate {
1022 /**
1023 * @public
1024 */
1025 function QuickTemplate() {
1026 $this->data = array();
1027 $this->translator = new MediaWiki_I18N();
1028 }
1029
1030 /**
1031 * @public
1032 */
1033 function set( $name, $value ) {
1034 $this->data[$name] = $value;
1035 }
1036
1037 /**
1038 * @public
1039 */
1040 function setRef($name, &$value) {
1041 $this->data[$name] =& $value;
1042 }
1043
1044 /**
1045 * @public
1046 */
1047 function setTranslator( &$t ) {
1048 $this->translator = &$t;
1049 }
1050
1051 /**
1052 * @public
1053 */
1054 function execute() {
1055 echo "Override this function.";
1056 }
1057
1058
1059 /**
1060 * @private
1061 */
1062 function text( $str ) {
1063 echo htmlspecialchars( $this->data[$str] );
1064 }
1065
1066 /**
1067 * @private
1068 */
1069 function jstext( $str ) {
1070 echo Xml::escapeJsString( $this->data[$str] );
1071 }
1072
1073 /**
1074 * @private
1075 */
1076 function html( $str ) {
1077 echo $this->data[$str];
1078 }
1079
1080 /**
1081 * @private
1082 */
1083 function msg( $str ) {
1084 echo htmlspecialchars( $this->translator->translate( $str ) );
1085 }
1086
1087 /**
1088 * @private
1089 */
1090 function msgHtml( $str ) {
1091 echo $this->translator->translate( $str );
1092 }
1093
1094 /**
1095 * An ugly, ugly hack.
1096 * @private
1097 */
1098 function msgWiki( $str ) {
1099 global $wgParser, $wgTitle, $wgOut;
1100
1101 $text = $this->translator->translate( $str );
1102 $parserOutput = $wgParser->parse( $text, $wgTitle,
1103 $wgOut->parserOptions(), true );
1104 echo $parserOutput->getText();
1105 }
1106
1107 /**
1108 * @private
1109 */
1110 function haveData( $str ) {
1111 return isset( $this->data[$str] );
1112 }
1113
1114 /**
1115 * @private
1116 */
1117 function haveMsg( $str ) {
1118 $msg = $this->translator->translate( $str );
1119 return ($msg != '-') && ($msg != ''); # ????
1120 }
1121 }