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