(bug 15641) prevent blocked administrators from accessing deleted revisions.
[lhc/web/wiklou.git] / includes / SkinTemplate.php
1 <?php
2 /**
3 * Base class for template-based skins
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 * @file
21 */
22
23 if ( !defined( 'MEDIAWIKI' ) ) {
24 die( 1 );
25 }
26
27 /**
28 * Wrapper object for MediaWiki's localization functions,
29 * to be passed to the template engine.
30 *
31 * @private
32 * @ingroup Skins
33 */
34 class MediaWiki_I18N {
35 var $_context = array();
36
37 function set( $varName, $value ) {
38 $this->_context[$varName] = $value;
39 }
40
41 function translate( $value ) {
42 wfProfileIn( __METHOD__ );
43
44 // Hack for i18n:attributes in PHPTAL 1.0.0 dev version as of 2004-10-23
45 $value = preg_replace( '/^string:/', '', $value );
46
47 $value = wfMsg( $value );
48 // interpolate variables
49 $m = array();
50 while( preg_match( '/\$([0-9]*?)/sm', $value, $m ) ) {
51 list( $src, $var ) = $m;
52 wfSuppressWarnings();
53 $varValue = $this->_context[$var];
54 wfRestoreWarnings();
55 $value = str_replace( $src, $varValue, $value );
56 }
57 wfProfileOut( __METHOD__ );
58 return $value;
59 }
60 }
61
62 /**
63 * Template-filler skin base class
64 * Formerly generic PHPTal (http://phptal.sourceforge.net/) skin
65 * Based on Brion's smarty skin
66 * @copyright Copyright © Gabriel Wicke -- http://www.aulinx.de/
67 *
68 * @todo Needs some serious refactoring into functions that correspond
69 * to the computations individual esi snippets need. Most importantly no body
70 * parsing for most of those of course.
71 *
72 * @ingroup Skins
73 */
74 class SkinTemplate extends Skin {
75 /**#@+
76 * @private
77 */
78
79 /**
80 * Name of our skin, it probably needs to be all lower case. Child classes
81 * should override the default.
82 */
83 var $skinname = 'monobook';
84
85 /**
86 * Stylesheets set to use. Subdirectory in skins/ where various stylesheets
87 * are located. Child classes should override the default.
88 */
89 var $stylename = 'monobook';
90
91 /**
92 * For QuickTemplate, the name of the subclass which will actually fill the
93 * template. Child classes should override the default.
94 */
95 var $template = 'QuickTemplate';
96
97 /**
98 * Whether this skin use OutputPage::headElement() to generate the <head>
99 * tag
100 */
101 var $useHeadElement = false;
102
103 /**#@-*/
104
105 /**
106 * Add specific styles for this skin
107 *
108 * @param $out OutputPage
109 */
110 function setupSkinUserCss( OutputPage $out ) {
111 $out->addModuleStyles( array( 'mediawiki.legacy.shared', 'mediawiki.legacy.commonPrint' ) );
112 }
113
114 /**
115 * Create the template engine object; we feed it a bunch of data
116 * and eventually it spits out some HTML. Should have interface
117 * roughly equivalent to PHPTAL 0.7.
118 *
119 * @param $classname String
120 * @param $repository string: subdirectory where we keep template files
121 * @param $cache_dir string
122 * @return QuickTemplate
123 * @private
124 */
125 function setupTemplate( $classname, $repository = false, $cache_dir = false ) {
126 return new $classname();
127 }
128
129 /**
130 * initialize various variables and generate the template
131 *
132 * @param $out OutputPage
133 */
134 function outputPage( OutputPage $out ) {
135 global $wgUser, $wgLang, $wgContLang;
136 global $wgScript, $wgStylePath;
137 global $wgMimeType, $wgJsMimeType, $wgRequest;
138 global $wgXhtmlDefaultNamespace, $wgXhtmlNamespaces, $wgHtml5Version;
139 global $wgDisableCounters, $wgLogo, $wgHideInterlanguageLinks;
140 global $wgMaxCredits, $wgShowCreditsIfMax;
141 global $wgPageShowWatchingUsers;
142 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
143 global $wgArticlePath, $wgScriptPath, $wgServer;
144
145 wfProfileIn( __METHOD__ );
146 Profiler::instance()->setTemplated( true );
147
148 wfProfileIn( __METHOD__ . '-init' );
149 $this->initPage( $out );
150
151 $tpl = $this->setupTemplate( $this->template, 'skins' );
152 wfProfileOut( __METHOD__ . '-init' );
153
154 wfProfileIn( __METHOD__ . '-stuff' );
155 $this->thispage = $this->getTitle()->getPrefixedDBkey();
156 $this->userpage = $this->getUser()->getUserPage()->getPrefixedText();
157 $query = array();
158 if ( !$wgRequest->wasPosted() ) {
159 $query = $wgRequest->getValues();
160 unset( $query['title'] );
161 unset( $query['returnto'] );
162 unset( $query['returntoquery'] );
163 }
164 $this->thisquery = wfArrayToCGI( $query );
165 $this->loggedin = $wgUser->isLoggedIn();
166 $this->username = $wgUser->getName();
167
168 if ( $wgUser->isLoggedIn() || $this->showIPinHeader() ) {
169 $this->userpageUrlDetails = self::makeUrlDetails( $this->userpage );
170 } else {
171 # This won't be used in the standard skins, but we define it to preserve the interface
172 # To save time, we check for existence
173 $this->userpageUrlDetails = self::makeKnownUrlDetails( $this->userpage );
174 }
175
176 $this->titletxt = $this->getTitle()->getPrefixedText();
177 wfProfileOut( __METHOD__ . '-stuff' );
178
179 wfProfileIn( __METHOD__ . '-stuff-head' );
180 if ( !$this->useHeadElement ) {
181 $tpl->set( 'pagecss', false );
182 $tpl->set( 'usercss', false );
183
184 $this->userjs = $this->userjsprev = false;
185 # @todo FIXME: This is the only use of OutputPage::isUserJsAllowed() anywhere; can we
186 # get rid of it? For that matter, why is any of this here at all?
187 $this->setupUserJs( $out->isUserJsAllowed() );
188 $tpl->setRef( 'userjs', $this->userjs );
189 $tpl->setRef( 'userjsprev', $this->userjsprev );
190
191 if( $wgUseSiteJs ) {
192 $jsCache = $this->loggedin ? '&smaxage=0' : '';
193 $tpl->set( 'jsvarurl',
194 self::makeUrl( '-',
195 "action=raw$jsCache&gen=js&useskin=" .
196 urlencode( $this->getSkinName() ) ) );
197 } else {
198 $tpl->set( 'jsvarurl', false );
199 }
200
201 $tpl->setRef( 'xhtmldefaultnamespace', $wgXhtmlDefaultNamespace );
202 $tpl->set( 'xhtmlnamespaces', $wgXhtmlNamespaces );
203 $tpl->set( 'html5version', $wgHtml5Version );
204 $tpl->set( 'headlinks', $out->getHeadLinks() );
205 $tpl->set( 'csslinks', $out->buildCssLinks() );
206
207 if( $wgUseTrackbacks && $out->isArticleRelated() ) {
208 $tpl->set( 'trackbackhtml', $out->getTitle()->trackbackRDF() );
209 } else {
210 $tpl->set( 'trackbackhtml', null );
211 }
212
213 $tpl->set( 'pageclass', $this->getPageClasses( $this->getTitle() ) );
214 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
215 }
216 wfProfileOut( __METHOD__ . '-stuff-head' );
217
218 wfProfileIn( __METHOD__ . '-stuff2' );
219 $tpl->set( 'title', $out->getPageTitle() );
220 $tpl->set( 'pagetitle', $out->getHTMLTitle() );
221 $tpl->set( 'displaytitle', $out->mPageLinkTitle );
222
223 $tpl->set( 'titleprefixeddbkey', $this->getTitle()->getPrefixedDBKey() );
224 $tpl->set( 'titletext', $this->getTitle()->getText() );
225 $tpl->set( 'articleid', $this->getTitle()->getArticleId() );
226
227 $tpl->set( 'isarticle', $out->isArticle() );
228
229 $tpl->setRef( 'thispage', $this->thispage );
230 $subpagestr = $this->subPageSubtitle();
231 $tpl->set(
232 'subtitle', !empty( $subpagestr ) ?
233 '<span class="subpages">' . $subpagestr . '</span>' . $out->getSubtitle() :
234 $out->getSubtitle()
235 );
236 $undelete = $this->getUndeleteLink();
237 $tpl->set(
238 'undelete', !empty( $undelete ) ?
239 '<span class="subpages">' . $undelete . '</span>' :
240 ''
241 );
242
243 $tpl->set( 'catlinks', $this->getCategories() );
244 if( $out->isSyndicated() ) {
245 $feeds = array();
246 foreach( $out->getSyndicationLinks() as $format => $link ) {
247 $feeds[$format] = array(
248 'text' => wfMsg( "feed-$format" ),
249 'href' => $link
250 );
251 }
252 $tpl->setRef( 'feeds', $feeds );
253 } else {
254 $tpl->set( 'feeds', false );
255 }
256
257 $tpl->setRef( 'mimetype', $wgMimeType );
258 $tpl->setRef( 'jsmimetype', $wgJsMimeType );
259 $tpl->set( 'charset', 'UTF-8' );
260 $tpl->setRef( 'wgScript', $wgScript );
261 $tpl->setRef( 'skinname', $this->skinname );
262 $tpl->set( 'skinclass', get_class( $this ) );
263 $tpl->setRef( 'stylename', $this->stylename );
264 $tpl->set( 'printable', $out->isPrintable() );
265 $tpl->set( 'handheld', $wgRequest->getBool( 'handheld' ) );
266 $tpl->setRef( 'loggedin', $this->loggedin );
267 $tpl->set( 'notspecialpage', $this->getTitle()->getNamespace() != NS_SPECIAL );
268 /* XXX currently unused, might get useful later
269 $tpl->set( 'editable', ( $this->getTitle()->getNamespace() != NS_SPECIAL ) );
270 $tpl->set( 'exists', $this->getTitle()->getArticleID() != 0 );
271 $tpl->set( 'watch', $this->getTitle()->userIsWatching() ? 'unwatch' : 'watch' );
272 $tpl->set( 'protect', count( $this->getTitle()->isProtected() ) ? 'unprotect' : 'protect' );
273 $tpl->set( 'helppage', wfMsg( 'helppage' ) );
274 */
275 $tpl->set( 'searchaction', $this->escapeSearchLink() );
276 $tpl->set( 'searchtitle', SpecialPage::getTitleFor( 'Search' )->getPrefixedDBKey() );
277 $tpl->set( 'search', trim( $wgRequest->getVal( 'search' ) ) );
278 $tpl->setRef( 'stylepath', $wgStylePath );
279 $tpl->setRef( 'articlepath', $wgArticlePath );
280 $tpl->setRef( 'scriptpath', $wgScriptPath );
281 $tpl->setRef( 'serverurl', $wgServer );
282 $tpl->setRef( 'logopath', $wgLogo );
283
284 $contentlang = $wgContLang->getCode();
285 $contentdir = $wgContLang->getDir();
286 $userlang = $wgLang->getCode();
287 $userdir = $wgLang->getDir();
288
289 $tpl->set( 'lang', $userlang );
290 $tpl->set( 'dir', $userdir );
291 $tpl->set( 'rtl', $wgLang->isRTL() );
292
293 $tpl->set( 'capitalizeallnouns', $wgLang->capitalizeAllNouns() ? ' capitalize-all-nouns' : '' );
294 $tpl->set( 'showjumplinks', $wgUser->getOption( 'showjumplinks' ) );
295 $tpl->set( 'username', $wgUser->isAnon() ? null : $this->username );
296 $tpl->setRef( 'userpage', $this->userpage );
297 $tpl->setRef( 'userpageurl', $this->userpageUrlDetails['href'] );
298 $tpl->set( 'userlang', $userlang );
299
300 // Users can have their language set differently than the
301 // content of the wiki. For these users, tell the web browser
302 // that interface elements are in a different language.
303 $tpl->set( 'userlangattributes', '' );
304 $tpl->set( 'specialpageattributes', '' ); # obsolete
305
306 if ( $userlang !== $contentlang || $userdir !== $contentdir ) {
307 $attrs = " lang='$userlang' dir='$userdir'";
308 $tpl->set( 'userlangattributes', $attrs );
309 }
310
311 wfProfileOut( __METHOD__ . '-stuff2' );
312
313 wfProfileIn( __METHOD__ . '-stuff3' );
314 $tpl->set( 'newtalk', $this->getNewtalks() );
315 $tpl->setRef( 'skin', $this );
316 $tpl->set( 'logo', $this->logoText() );
317
318 $tpl->set( 'copyright', false );
319 $tpl->set( 'viewcount', false );
320 $tpl->set( 'lastmod', false );
321 $tpl->set( 'credits', false );
322 $tpl->set( 'numberofwatchingusers', false );
323 if ( $out->isArticle() && $this->getTitle()->exists() ) {
324 if ( $this->isRevisionCurrent() ) {
325 $article = new Article( $this->getTitle(), 0 );
326 if ( !$wgDisableCounters ) {
327 $viewcount = $wgLang->formatNum( $article->getCount() );
328 if ( $viewcount ) {
329 $tpl->set( 'viewcount', wfMsgExt( 'viewcount', array( 'parseinline' ), $viewcount ) );
330 }
331 }
332
333 if( $wgPageShowWatchingUsers ) {
334 $dbr = wfGetDB( DB_SLAVE );
335 $num = $dbr->selectField( 'watchlist', 'COUNT(*)',
336 array( 'wl_title' => $this->getTitle()->getDBkey(), 'wl_namespace' => $this->getTitle()->getNamespace() ),
337 __METHOD__
338 );
339 if( $num > 0 ) {
340 $tpl->set( 'numberofwatchingusers',
341 wfMsgExt( 'number_of_watching_users_pageview', array( 'parseinline' ),
342 $wgLang->formatNum( $num ) )
343 );
344 }
345 }
346
347 if ( $wgMaxCredits != 0 ) {
348 $tpl->set( 'credits', Action::factory( 'credits', $article )->getCredits( $wgMaxCredits, $wgShowCreditsIfMax ) );
349 } else {
350 $tpl->set( 'lastmod', $this->lastModified( $article ) );
351 }
352 }
353 $tpl->set( 'copyright', $this->getCopyright() );
354 }
355 wfProfileOut( __METHOD__ . '-stuff3' );
356
357 wfProfileIn( __METHOD__ . '-stuff4' );
358 $tpl->set( 'copyrightico', $this->getCopyrightIcon() );
359 $tpl->set( 'poweredbyico', $this->getPoweredBy() );
360 $tpl->set( 'disclaimer', $this->disclaimerLink() );
361 $tpl->set( 'privacy', $this->privacyLink() );
362 $tpl->set( 'about', $this->aboutLink() );
363
364 $tpl->set( 'footerlinks', array(
365 'info' => array(
366 'lastmod',
367 'viewcount',
368 'numberofwatchingusers',
369 'credits',
370 'copyright',
371 ),
372 'places' => array(
373 'privacy',
374 'about',
375 'disclaimer',
376 ),
377 ) );
378
379 global $wgFooterIcons;
380 $tpl->set( 'footericons', $wgFooterIcons );
381 foreach ( $tpl->data['footericons'] as $footerIconsKey => &$footerIconsBlock ) {
382 if ( count( $footerIconsBlock ) > 0 ) {
383 foreach ( $footerIconsBlock as &$footerIcon ) {
384 if ( isset( $footerIcon['src'] ) ) {
385 if ( !isset( $footerIcon['width'] ) ) {
386 $footerIcon['width'] = 88;
387 }
388 if ( !isset( $footerIcon['height'] ) ) {
389 $footerIcon['height'] = 31;
390 }
391 }
392 }
393 } else {
394 unset( $tpl->data['footericons'][$footerIconsKey] );
395 }
396 }
397
398 if ( $wgDebugComments ) {
399 $tpl->setRef( 'debug', $out->mDebugtext );
400 } else {
401 $tpl->set( 'debug', '' );
402 }
403
404 $tpl->set( 'reporttime', wfReportTime() );
405 $tpl->set( 'sitenotice', $this->getSiteNotice() );
406 $tpl->set( 'bottomscripts', $this->bottomScripts() );
407 $tpl->set( 'printfooter', $this->printSource() );
408
409 # Add a <div class="mw-content-ltr/rtl"> around the body text
410 # not for special pages or file pages AND only when viewing AND if the page exists
411 # (or is in MW namespace, because that has default content)
412 if( !in_array( $this->getTitle()->getNamespace(), array( NS_SPECIAL, NS_FILE ) ) &&
413 $wgRequest->getVal( 'action', 'view' ) == 'view' &&
414 ( $this->getTitle()->exists() || $this->getTitle()->getNamespace() == NS_MEDIAWIKI ) ) {
415 $pageLang = $this->getTitle()->getPageLanguage();
416 $realBodyAttribs = array( 'lang' => $pageLang->getCode(), 'dir' => $pageLang->getDir(),
417 'class' => 'mw-content-'.$pageLang->getDir() );
418 $out->mBodytext = Html::rawElement( 'div', $realBodyAttribs, $out->mBodytext );
419 }
420
421 $tpl->setRef( 'bodytext', $out->mBodytext );
422
423 # Language links
424 $language_urls = array();
425
426 if ( !$wgHideInterlanguageLinks ) {
427 foreach( $out->getLanguageLinks() as $l ) {
428 $tmp = explode( ':', $l, 2 );
429 $class = 'interwiki-' . $tmp[0];
430 unset( $tmp );
431 $nt = Title::newFromText( $l );
432 if ( $nt ) {
433 $language_urls[] = array(
434 'href' => $nt->getFullURL(),
435 'text' => ( $wgContLang->getLanguageName( $nt->getInterwiki() ) != '' ?
436 $wgContLang->getLanguageName( $nt->getInterwiki() ) : $l ),
437 'title' => $nt->getText(),
438 'class' => $class
439 );
440 }
441 }
442 }
443 if( count( $language_urls ) ) {
444 $tpl->setRef( 'language_urls', $language_urls );
445 } else {
446 $tpl->set( 'language_urls', false );
447 }
448 wfProfileOut( __METHOD__ . '-stuff4' );
449
450 wfProfileIn( __METHOD__ . '-stuff5' );
451 # Personal toolbar
452 $tpl->set( 'personal_urls', $this->buildPersonalUrls( $out ) );
453 $content_navigation = $this->buildContentNavigationUrls( $out );
454 $content_actions = $this->buildContentActionUrls( $content_navigation );
455 $tpl->setRef( 'content_navigation', $content_navigation );
456 $tpl->setRef( 'content_actions', $content_actions );
457
458 $tpl->set( 'sidebar', $this->buildSidebar() );
459 $tpl->set( 'nav_urls', $this->buildNavUrls( $out ) );
460
461 // Set the head scripts near the end, in case the above actions resulted in added scripts
462 if ( $this->useHeadElement ) {
463 $tpl->set( 'headelement', $out->headElement( $this ) );
464 } else {
465 $tpl->set( 'headscripts', $out->getScript() );
466 }
467
468 $tpl->set( 'debughtml', $this->generateDebugHTML() );
469
470 // original version by hansm
471 if( !wfRunHooks( 'SkinTemplateOutputPageBeforeExec', array( &$this, &$tpl ) ) ) {
472 wfDebug( __METHOD__ . ": Hook SkinTemplateOutputPageBeforeExec broke outputPage execution!\n" );
473 }
474
475 // allow extensions adding stuff after the page content.
476 // See Skin::afterContentHook() for further documentation.
477 $tpl->set( 'dataAfterContent', $this->afterContentHook() );
478 wfProfileOut( __METHOD__ . '-stuff5' );
479
480 // execute template
481 wfProfileIn( __METHOD__ . '-execute' );
482 $res = $tpl->execute();
483 wfProfileOut( __METHOD__ . '-execute' );
484
485 // result may be an error
486 $this->printOrError( $res );
487 wfProfileOut( __METHOD__ );
488 }
489
490 /**
491 * Output the string, or print error message if it's
492 * an error object of the appropriate type.
493 * For the base class, assume strings all around.
494 *
495 * @param $str Mixed
496 * @private
497 */
498 function printOrError( $str ) {
499 echo $str;
500 }
501
502 /**
503 * Output a boolean indiciating if buildPersonalUrls should output separate
504 * login and create account links or output a combined link
505 * By default we simply return a global config setting that affects most skins
506 * This is setup as a method so that like with $wgLogo and getLogo() a skin
507 * can override this setting and always output one or the other if it has
508 * a reason it can't output one of the two modes.
509 */
510 function useCombinedLoginLink() {
511 global $wgUseCombinedLoginLink;
512 return $wgUseCombinedLoginLink;
513 }
514
515 /**
516 * build array of urls for personal toolbar
517 * @return array
518 */
519 protected function buildPersonalUrls( OutputPage $out ) {
520 global $wgRequest;
521
522 $title = $out->getTitle();
523 $pageurl = $title->getLocalURL();
524 wfProfileIn( __METHOD__ );
525
526 /* set up the default links for the personal toolbar */
527 $personal_urls = array();
528
529 $page = $wgRequest->getVal( 'returnto', $this->thispage );
530 $query = $wgRequest->getVal( 'returntoquery', $this->thisquery );
531 $a = array( 'returnto' => $page );
532 if( $query != '' ) {
533 $a['returntoquery'] = $query;
534 }
535 $returnto = wfArrayToCGI( $a );
536 if( $this->loggedin ) {
537 $personal_urls['userpage'] = array(
538 'text' => $this->username,
539 'href' => &$this->userpageUrlDetails['href'],
540 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
541 'active' => ( $this->userpageUrlDetails['href'] == $pageurl )
542 );
543 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
544 $personal_urls['mytalk'] = array(
545 'text' => wfMsg( 'mytalk' ),
546 'href' => &$usertalkUrlDetails['href'],
547 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
548 'active' => ( $usertalkUrlDetails['href'] == $pageurl )
549 );
550 $href = self::makeSpecialUrl( 'Preferences' );
551 $personal_urls['preferences'] = array(
552 'text' => wfMsg( 'mypreferences' ),
553 'href' => $href,
554 'active' => ( $href == $pageurl )
555 );
556 $href = self::makeSpecialUrl( 'Watchlist' );
557 $personal_urls['watchlist'] = array(
558 'text' => wfMsg( 'mywatchlist' ),
559 'href' => $href,
560 'active' => ( $href == $pageurl )
561 );
562
563 # We need to do an explicit check for Special:Contributions, as we
564 # have to match both the title, and the target (which could come
565 # from request values or be specified in "sub page" form. The plot
566 # thickens, because $wgTitle is altered for special pages, so doesn't
567 # contain the original alias-with-subpage.
568 $origTitle = Title::newFromText( $wgRequest->getText( 'title' ) );
569 if( $origTitle instanceof Title && $origTitle->getNamespace() == NS_SPECIAL ) {
570 list( $spName, $spPar ) = SpecialPageFactory::resolveAlias( $origTitle->getText() );
571 $active = $spName == 'Contributions'
572 && ( ( $spPar && $spPar == $this->username )
573 || $wgRequest->getText( 'target' ) == $this->username );
574 } else {
575 $active = false;
576 }
577
578 $href = self::makeSpecialUrlSubpage( 'Contributions', $this->username );
579 $personal_urls['mycontris'] = array(
580 'text' => wfMsg( 'mycontris' ),
581 'href' => $href,
582 'active' => $active
583 );
584 $personal_urls['logout'] = array(
585 'text' => wfMsg( 'userlogout' ),
586 'href' => self::makeSpecialUrl( 'Userlogout',
587 // userlogout link must always contain an & character, otherwise we might not be able
588 // to detect a buggy precaching proxy (bug 17790)
589 $title->isSpecial( 'Preferences' ) ? 'noreturnto' : $returnto
590 ),
591 'active' => false
592 );
593 } else {
594 global $wgUser;
595 $useCombinedLoginLink = $this->useCombinedLoginLink();
596 $loginlink = $wgUser->isAllowed( 'createaccount' ) && $useCombinedLoginLink
597 ? 'nav-login-createaccount'
598 : 'login';
599 $is_signup = $wgRequest->getText('type') == "signup";
600
601 # anonlogin & login are the same
602 $login_url = array(
603 'text' => wfMsg( $loginlink ),
604 'href' => self::makeSpecialUrl( 'Userlogin', $returnto ),
605 'active' => $title->isSpecial( 'Userlogin' ) && ( $loginlink == "nav-login-createaccount" || !$is_signup )
606 );
607 if ( $wgUser->isAllowed( 'createaccount' ) && !$useCombinedLoginLink ) {
608 $createaccount_url = array(
609 'text' => wfMsg( 'createaccount' ),
610 'href' => self::makeSpecialUrl( 'Userlogin', "$returnto&type=signup" ),
611 'active' => $title->isSpecial( 'Userlogin' ) && $is_signup
612 );
613 }
614 global $wgServer, $wgSecureLogin;
615 if( substr( $wgServer, 0, 5 ) === 'http:' && $wgSecureLogin ) {
616 $title = SpecialPage::getTitleFor( 'Userlogin' );
617 $https_url = preg_replace( '/^http:/', 'https:', $title->getFullURL() );
618 $login_url['href'] = $https_url;
619 # @todo FIXME: Class depends on skin
620 $login_url['class'] = 'link-https';
621 if ( isset($createaccount_url) ) {
622 $https_url = preg_replace( '/^http:/', 'https:',
623 $title->getFullURL("type=signup") );
624 $createaccount_url['href'] = $https_url;
625 # @todo FIXME: Class depends on skin
626 $createaccount_url['class'] = 'link-https';
627 }
628 }
629
630
631 if( $this->showIPinHeader() ) {
632 $href = &$this->userpageUrlDetails['href'];
633 $personal_urls['anonuserpage'] = array(
634 'text' => $this->username,
635 'href' => $href,
636 'class' => $this->userpageUrlDetails['exists'] ? false : 'new',
637 'active' => ( $pageurl == $href )
638 );
639 $usertalkUrlDetails = $this->makeTalkUrlDetails( $this->userpage );
640 $href = &$usertalkUrlDetails['href'];
641 $personal_urls['anontalk'] = array(
642 'text' => wfMsg( 'anontalk' ),
643 'href' => $href,
644 'class' => $usertalkUrlDetails['exists'] ? false : 'new',
645 'active' => ( $pageurl == $href )
646 );
647 $personal_urls['anonlogin'] = $login_url;
648 } else {
649 $personal_urls['login'] = $login_url;
650 }
651 if ( isset($createaccount_url) ) {
652 $personal_urls['createaccount'] = $createaccount_url;
653 }
654 }
655
656 wfRunHooks( 'PersonalUrls', array( &$personal_urls, &$title ) );
657 wfProfileOut( __METHOD__ );
658 return $personal_urls;
659 }
660
661 /**
662 * TODO document
663 * @param $title Title
664 * @param $message String message key
665 * @param $selected Bool
666 * @param $query String
667 * @param $checkEdit Bool
668 * @return array
669 */
670 function tabAction( $title, $message, $selected, $query = '', $checkEdit = false ) {
671 $classes = array();
672 if( $selected ) {
673 $classes[] = 'selected';
674 }
675 if( $checkEdit && !$title->isKnown() ) {
676 $classes[] = 'new';
677 $query = 'action=edit&redlink=1';
678 }
679
680 // wfMessageFallback will nicely accept $message as an array of fallbacks
681 // or just a single key
682 $msg = wfMessageFallback( $message );
683 if ( is_array($message) ) {
684 // for hook compatibility just keep the last message name
685 $message = end($message);
686 }
687 if ( $msg->exists() ) {
688 $text = $msg->text();
689 } else {
690 global $wgContLang;
691 $text = $wgContLang->getFormattedNsText(
692 MWNamespace::getSubject( $title->getNamespace() ) );
693 }
694
695 $result = array();
696 if( !wfRunHooks( 'SkinTemplateTabAction', array( &$this,
697 $title, $message, $selected, $checkEdit,
698 &$classes, &$query, &$text, &$result ) ) ) {
699 return $result;
700 }
701
702 return array(
703 'class' => implode( ' ', $classes ),
704 'text' => $text,
705 'href' => $title->getLocalUrl( $query ),
706 'primary' => true );
707 }
708
709 function makeTalkUrlDetails( $name, $urlaction = '' ) {
710 $title = Title::newFromText( $name );
711 if( !is_object( $title ) ) {
712 throw new MWException( __METHOD__ . " given invalid pagename $name" );
713 }
714 $title = $title->getTalkPage();
715 self::checkTitle( $title, $name );
716 return array(
717 'href' => $title->getLocalURL( $urlaction ),
718 'exists' => $title->getArticleID() != 0,
719 );
720 }
721
722 function makeArticleUrlDetails( $name, $urlaction = '' ) {
723 $title = Title::newFromText( $name );
724 $title= $title->getSubjectPage();
725 self::checkTitle( $title, $name );
726 return array(
727 'href' => $title->getLocalURL( $urlaction ),
728 'exists' => $title->getArticleID() != 0,
729 );
730 }
731
732 /**
733 * a structured array of links usually used for the tabs in a skin
734 *
735 * There are 4 standard sections
736 * namespaces: Used for namespace tabs like special, page, and talk namespaces
737 * views: Used for primary page views like read, edit, history
738 * actions: Used for most extra page actions like deletion, protection, etc...
739 * variants: Used to list the language variants for the page
740 *
741 * Each section's value is a key/value array of links for that section.
742 * The links themseves have these common keys:
743 * - class: The css classes to apply to the tab
744 * - text: The text to display on the tab
745 * - href: The href for the tab to point to
746 * - rel: An optional rel= for the tab's link
747 * - redundant: If true the tab will be dropped in skins using content_actions
748 * this is useful for tabs like "Read" which only have meaning in skins that
749 * take special meaning from the grouped structure of content_navigation
750 *
751 * Views also have an extra key which can be used:
752 * - primary: If this is not true skins like vector may try to hide the tab
753 * when the user has limited space in their browser window
754 *
755 * content_navigation using code also expects these ids to be present on the
756 * links, however these are usually automatically generated by SkinTemplate
757 * itself and are not necessary when using a hook. The only things these may
758 * matter to are people modifying content_navigation after it's initial creation:
759 * - id: A "preferred" id, most skins are best off outputting this preferred id for best compatibility
760 * - tooltiponly: This is set to true for some tabs in cases where the system
761 * believes that the accesskey should not be added to the tab.
762 *
763 * @return array
764 */
765 protected function buildContentNavigationUrls( OutputPage $out ) {
766 global $wgContLang, $wgLang, $wgUser, $wgRequest;
767 global $wgDisableLangConversion;
768
769 wfProfileIn( __METHOD__ );
770
771 $title = $this->getRelevantTitle(); // Display tabs for the relevant title rather than always the title itself
772 $onPage = $title->equals($this->getTitle());
773
774 $content_navigation = array(
775 'namespaces' => array(),
776 'views' => array(),
777 'actions' => array(),
778 'variants' => array()
779 );
780
781 // parameters
782 $action = $wgRequest->getVal( 'action', 'view' );
783 $section = $wgRequest->getVal( 'section' );
784
785 $userCanRead = $title->userCanRead();
786 $skname = $this->skinname;
787
788 $preventActiveTabs = false;
789 wfRunHooks( 'SkinTemplatePreventOtherActiveTabs', array( &$this, &$preventActiveTabs ) );
790
791 // Checks if page is some kind of content
792 if( $title->getNamespace() != NS_SPECIAL ) {
793 // Gets page objects for the related namespaces
794 $subjectPage = $title->getSubjectPage();
795 $talkPage = $title->getTalkPage();
796
797 // Determines if this is a talk page
798 $isTalk = $title->isTalkPage();
799
800 // Generates XML IDs from namespace names
801 $subjectId = $title->getNamespaceKey( '' );
802
803 if ( $subjectId == 'main' ) {
804 $talkId = 'talk';
805 } else {
806 $talkId = "{$subjectId}_talk";
807 }
808
809 // Adds namespace links
810 $subjectMsg = array( "nstab-$subjectId" );
811 if ( $subjectPage->isMainPage() ) {
812 array_unshift($subjectMsg, 'mainpage-nstab');
813 }
814 $content_navigation['namespaces'][$subjectId] = $this->tabAction(
815 $subjectPage, $subjectMsg, !$isTalk && !$preventActiveTabs, '', $userCanRead
816 );
817 $content_navigation['namespaces'][$subjectId]['context'] = 'subject';
818 $content_navigation['namespaces'][$talkId] = $this->tabAction(
819 $talkPage, array( "nstab-$talkId", 'talk' ), $isTalk && !$preventActiveTabs, '', $userCanRead
820 );
821 $content_navigation['namespaces'][$talkId]['context'] = 'talk';
822
823 // Adds view view link
824 if ( $title->exists() && $userCanRead ) {
825 $content_navigation['views']['view'] = $this->tabAction(
826 $isTalk ? $talkPage : $subjectPage,
827 array( "$skname-view-view", 'view' ),
828 ( $onPage && ($action == 'view' || $action == 'purge' ) ), '', true
829 );
830 $content_navigation['views']['view']['redundant'] = true; // signal to hide this from simple content_actions
831 }
832
833 wfProfileIn( __METHOD__ . '-edit' );
834
835 // Checks if user can...
836 if (
837 // read and edit the current page
838 $userCanRead && $title->quickUserCan( 'edit' ) &&
839 (
840 // if it exists
841 $title->exists() ||
842 // or they can create one here
843 $title->quickUserCan( 'create' )
844 )
845 ) {
846 // Builds CSS class for talk page links
847 $isTalkClass = $isTalk ? ' istalk' : '';
848
849 // Determines if we're in edit mode
850 $selected = (
851 $onPage &&
852 ( $action == 'edit' || $action == 'submit' ) &&
853 ( $section != 'new' )
854 );
855 $msgKey = $title->exists() || ( $title->getNamespace() == NS_MEDIAWIKI && $title->getDefaultMessageText() !== false ) ?
856 "edit" : "create";
857 $content_navigation['views']['edit'] = array(
858 'class' => ( $selected ? 'selected' : '' ) . $isTalkClass,
859 'text' => wfMessageFallback( "$skname-view-$msgKey", $msgKey )->text(),
860 'href' => $title->getLocalURL( $this->editUrlOptions() ),
861 'primary' => true, // don't collapse this in vector
862 );
863 // Checks if this is a current rev of talk page and we should show a new
864 // section link
865 if ( ( $isTalk && $this->isRevisionCurrent() ) || ( $out->showNewSectionLink() ) ) {
866 // Checks if we should ever show a new section link
867 if ( !$out->forceHideNewSectionLink() ) {
868 // Adds new section link
869 //$content_navigation['actions']['addsection']
870 $content_navigation['views']['addsection'] = array(
871 'class' => $section == 'new' ? 'selected' : false,
872 'text' => wfMessageFallback( "$skname-action-addsection", 'addsection' )->text(),
873 'href' => $title->getLocalURL( 'action=edit&section=new' )
874 );
875 }
876 }
877 // Checks if the page has some kind of viewable content
878 } elseif ( $title->hasSourceText() && $userCanRead ) {
879 // Adds view source view link
880 $content_navigation['views']['viewsource'] = array(
881 'class' => ( $onPage && $action == 'edit' ) ? 'selected' : false,
882 'text' => wfMessageFallback( "$skname-action-viewsource", 'viewsource' )->text(),
883 'href' => $title->getLocalURL( $this->editUrlOptions() ),
884 'primary' => true, // don't collapse this in vector
885 );
886 }
887 wfProfileOut( __METHOD__ . '-edit' );
888
889 wfProfileIn( __METHOD__ . '-live' );
890
891 // Checks if the page exists
892 if ( $title->exists() && $userCanRead ) {
893 // Adds history view link
894 $content_navigation['views']['history'] = array(
895 'class' => ( $onPage && $action == 'history' ) ? 'selected' : false,
896 'text' => wfMessageFallback( "$skname-view-history", 'history_short' )->text(),
897 'href' => $title->getLocalURL( 'action=history' ),
898 'rel' => 'archives',
899 );
900
901 if( $wgUser->isAllowed( 'delete' ) ) {
902 $content_navigation['actions']['delete'] = array(
903 'class' => ( $onPage && $action == 'delete' ) ? 'selected' : false,
904 'text' => wfMessageFallback( "$skname-action-delete", 'delete' )->text(),
905 'href' => $title->getLocalURL( 'action=delete' )
906 );
907 }
908 if ( $title->quickUserCan( 'move' ) ) {
909 $moveTitle = SpecialPage::getTitleFor( 'Movepage', $title->getPrefixedDBkey() );
910 $content_navigation['actions']['move'] = array(
911 'class' => $this->getTitle()->isSpecial( 'Movepage' ) ? 'selected' : false,
912 'text' => wfMessageFallback( "$skname-action-move", 'move' )->text(),
913 'href' => $moveTitle->getLocalURL()
914 );
915 }
916
917 if ( $title->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
918 $mode = !$title->isProtected() ? 'protect' : 'unprotect';
919 $content_navigation['actions'][$mode] = array(
920 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
921 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
922 'href' => $title->getLocalURL( "action=$mode" )
923 );
924 }
925 } else {
926 // article doesn't exist or is deleted
927 if ( $wgUser->isAllowed( 'deletedhistory' ) && !$wgUser->isBlocked() ) {
928 $includeSuppressed = $wgUser->isAllowed( 'suppressrevision' );
929 $n = $title->isDeleted( $includeSuppressed );
930 if( $n ) {
931 $undelTitle = SpecialPage::getTitleFor( 'Undelete' );
932 // If the user can't undelete but can view deleted history show them a "View .. deleted" tab instead
933 $msgKey = $wgUser->isAllowed( 'undelete' ) ? 'undelete' : 'viewdeleted';
934 $content_navigation['actions']['undelete'] = array(
935 'class' => $this->getTitle()->isSpecial( 'Undelete' ) ? 'selected' : false,
936 'text' => wfMessageFallback( "$skname-action-$msgKey", "{$msgKey}_short" )
937 ->params( $wgLang->formatNum( $n ) )->text(),
938 'href' => $undelTitle->getLocalURL( array( 'target' => $title->getPrefixedDBkey() ) )
939 );
940 }
941 }
942
943 if ( $title->getNamespace() !== NS_MEDIAWIKI && $wgUser->isAllowed( 'protect' ) ) {
944 $mode = !$title->getRestrictions( 'create' ) ? 'protect' : 'unprotect';
945 $content_navigation['actions'][$mode] = array(
946 'class' => ( $onPage && $action == $mode ) ? 'selected' : false,
947 'text' => wfMessageFallback( "$skname-action-$mode", $mode )->text(),
948 'href' => $title->getLocalURL( "action=$mode" )
949 );
950 }
951 }
952 wfProfileOut( __METHOD__ . '-live' );
953
954 // Checks if the user is logged in
955 if ( $this->loggedin ) {
956 /**
957 * The following actions use messages which, if made particular to
958 * the any specific skins, would break the Ajax code which makes this
959 * action happen entirely inline. Skin::makeGlobalVariablesScript
960 * defines a set of messages in a javascript object - and these
961 * messages are assumed to be global for all skins. Without making
962 * a change to that procedure these messages will have to remain as
963 * the global versions.
964 */
965 $mode = $title->userIsWatching() ? 'unwatch' : 'watch';
966 $token = WatchAction::getWatchToken( $title, $wgUser, $mode );
967 $content_navigation['actions'][$mode] = array(
968 'class' => $onPage && ( $action == 'watch' || $action == 'unwatch' ) ? 'selected' : false,
969 'text' => wfMsg( $mode ), // uses 'watch' or 'unwatch' message
970 'href' => $title->getLocalURL( array( 'action' => $mode, 'token' => $token ) )
971 );
972 }
973
974 wfRunHooks( 'SkinTemplateNavigation', array( &$this, &$content_navigation ) );
975 } else {
976 // If it's not content, it's got to be a special page
977 $content_navigation['namespaces']['special'] = array(
978 'class' => 'selected',
979 'text' => wfMsg( 'nstab-special' ),
980 'href' => $wgRequest->getRequestURL(), // @bug 2457, 2510
981 'context' => 'subject'
982 );
983
984 wfRunHooks( 'SkinTemplateNavigation::SpecialPage',
985 array( &$this, &$content_navigation ) );
986 }
987
988 // Gets list of language variants
989 $variants = $wgContLang->getVariants();
990 // Checks that language conversion is enabled and variants exist
991 if( !$wgDisableLangConversion && count( $variants ) > 1 ) {
992 // Gets preferred variant
993 $preferred = $wgContLang->getPreferredVariant();
994 // Loops over each variant
995 foreach( $variants as $code ) {
996 // Gets variant name from language code
997 $varname = $wgContLang->getVariantname( $code );
998 // Checks if the variant is marked as disabled
999 if( $varname == 'disable' ) {
1000 // Skips this variant
1001 continue;
1002 }
1003 // Appends variant link
1004 $content_navigation['variants'][] = array(
1005 'class' => ( $code == $preferred ) ? 'selected' : false,
1006 'text' => $varname,
1007 'href' => $title->getLocalURL( '', $code )
1008 );
1009 }
1010 }
1011
1012 // Equiv to SkinTemplateContentActions
1013 wfRunHooks( 'SkinTemplateNavigation::Universal', array( &$this, &$content_navigation ) );
1014
1015 // Setup xml ids and tooltip info
1016 foreach ( $content_navigation as $section => &$links ) {
1017 foreach ( $links as $key => &$link ) {
1018 $xmlID = $key;
1019 if ( isset( $link['context'] ) && $link['context'] == 'subject' ) {
1020 $xmlID = 'ca-nstab-' . $xmlID;
1021 } elseif ( isset( $link['context'] ) && $link['context'] == 'talk' ) {
1022 $xmlID = 'ca-talk';
1023 } elseif ( $section == "variants" ) {
1024 $xmlID = 'ca-varlang-' . $xmlID;
1025 } else {
1026 $xmlID = 'ca-' . $xmlID;
1027 }
1028 $link['id'] = $xmlID;
1029 }
1030 }
1031
1032 # We don't want to give the watch tab an accesskey if the
1033 # page is being edited, because that conflicts with the
1034 # accesskey on the watch checkbox. We also don't want to
1035 # give the edit tab an accesskey, because that's fairly su-
1036 # perfluous and conflicts with an accesskey (Ctrl-E) often
1037 # used for editing in Safari.
1038 if( in_array( $action, array( 'edit', 'submit' ) ) ) {
1039 if ( isset($content_navigation['views']['edit']) ) {
1040 $content_navigation['views']['edit']['tooltiponly'] = true;
1041 }
1042 if ( isset($content_navigation['actions']['watch']) ) {
1043 $content_navigation['actions']['watch']['tooltiponly'] = true;
1044 }
1045 if ( isset($content_navigation['actions']['unwatch']) ) {
1046 $content_navigation['actions']['unwatch']['tooltiponly'] = true;
1047 }
1048 }
1049
1050 wfProfileOut( __METHOD__ );
1051
1052 return $content_navigation;
1053 }
1054
1055 /**
1056 * an array of edit links by default used for the tabs
1057 * @return array
1058 * @private
1059 */
1060 function buildContentActionUrls( $content_navigation ) {
1061
1062 wfProfileIn( __METHOD__ );
1063
1064 // content_actions has been replaced with content_navigation for backwards
1065 // compatibility and also for skins that just want simple tabs content_actions
1066 // is now built by flattening the content_navigation arrays into one
1067
1068 $content_actions = array();
1069
1070 foreach ( $content_navigation as $links ) {
1071
1072 foreach ( $links as $key => $value ) {
1073
1074 if ( isset($value["redundant"]) && $value["redundant"] ) {
1075 // Redundant tabs are dropped from content_actions
1076 continue;
1077 }
1078
1079 // content_actions used to have ids built using the "ca-$key" pattern
1080 // so the xmlID based id is much closer to the actual $key that we want
1081 // for that reason we'll just strip out the ca- if present and use
1082 // the latter potion of the "id" as the $key
1083 if ( isset($value["id"]) && substr($value["id"], 0, 3) == "ca-" ) {
1084 $key = substr($value["id"], 3);
1085 }
1086
1087 if ( isset($content_actions[$key]) ) {
1088 wfDebug( __METHOD__ . ": Found a duplicate key for $key while flattening content_navigation into content_actions." );
1089 continue;
1090 }
1091
1092 $content_actions[$key] = $value;
1093
1094 }
1095
1096 }
1097
1098 wfProfileOut( __METHOD__ );
1099
1100 return $content_actions;
1101 }
1102
1103 /**
1104 * build array of common navigation links
1105 * @return array
1106 * @private
1107 */
1108 protected function buildNavUrls( OutputPage $out ) {
1109 global $wgUseTrackbacks, $wgUser, $wgRequest;
1110 global $wgUploadNavigationUrl;
1111
1112 wfProfileIn( __METHOD__ );
1113
1114 $action = $wgRequest->getVal( 'action', 'view' );
1115
1116 $nav_urls = array();
1117 $nav_urls['mainpage'] = array( 'href' => self::makeMainPageUrl() );
1118 if( $wgUploadNavigationUrl ) {
1119 $nav_urls['upload'] = array( 'href' => $wgUploadNavigationUrl );
1120 } elseif( UploadBase::isEnabled() && UploadBase::isAllowed( $wgUser ) === true ) {
1121 $nav_urls['upload'] = array( 'href' => self::makeSpecialUrl( 'Upload' ) );
1122 } else {
1123 $nav_urls['upload'] = false;
1124 }
1125 $nav_urls['specialpages'] = array( 'href' => self::makeSpecialUrl( 'Specialpages' ) );
1126
1127 // default permalink to being off, will override it as required below.
1128 $nav_urls['permalink'] = false;
1129
1130 // A print stylesheet is attached to all pages, but nobody ever
1131 // figures that out. :) Add a link...
1132 if( $this->getTitle()->getNamespace() != NS_SPECIAL && ( $action == 'view' || $action == 'purge' ) ) {
1133 if ( !$out->isPrintable() ) {
1134 $nav_urls['print'] = array(
1135 'text' => wfMsg( 'printableversion' ),
1136 'href' => $this->getTitle()->getLocalURL(
1137 $wgRequest->appendQueryValue( 'printable', 'yes', true ) )
1138 );
1139 }
1140
1141 // Also add a "permalink" while we're at it
1142 $revid = $this->getRevisionId();
1143 if ( $revid ) {
1144 $nav_urls['permalink'] = array(
1145 'text' => wfMsg( 'permalink' ),
1146 'href' => $out->getTitle()->getLocalURL( "oldid=$revid" )
1147 );
1148 }
1149
1150 // Use the copy of revision ID in case this undocumented, shady hook tries to mess with internals
1151 wfRunHooks( 'SkinTemplateBuildNavUrlsNav_urlsAfterPermalink',
1152 array( &$this, &$nav_urls, &$revid, &$revid ) );
1153 }
1154
1155 if( $this->getTitle()->getNamespace() != NS_SPECIAL ) {
1156 $wlhTitle = SpecialPage::getTitleFor( 'Whatlinkshere', $this->thispage );
1157 $nav_urls['whatlinkshere'] = array(
1158 'href' => $wlhTitle->getLocalUrl()
1159 );
1160 if( $this->getTitle()->getArticleId() ) {
1161 $rclTitle = SpecialPage::getTitleFor( 'Recentchangeslinked', $this->thispage );
1162 $nav_urls['recentchangeslinked'] = array(
1163 'href' => $rclTitle->getLocalUrl()
1164 );
1165 } else {
1166 $nav_urls['recentchangeslinked'] = false;
1167 }
1168 if( $wgUseTrackbacks )
1169 $nav_urls['trackbacklink'] = array(
1170 'href' => $out->getTitle()->trackbackURL()
1171 );
1172 }
1173
1174 $user = $this->getRelevantUser();
1175 if ( $user ) {
1176 $id = $user->getID();
1177 $ip = $user->isAnon();
1178 $rootUser = $user->getName();
1179 } else {
1180 $id = 0;
1181 $ip = false;
1182 $rootUser = null;
1183 }
1184
1185 if( $id || $ip ) { # both anons and non-anons have contribs list
1186 $nav_urls['contributions'] = array(
1187 'href' => self::makeSpecialUrlSubpage( 'Contributions', $rootUser )
1188 );
1189
1190 if( $id ) {
1191 $logPage = SpecialPage::getTitleFor( 'Log' );
1192 $nav_urls['log'] = array(
1193 'href' => $logPage->getLocalUrl(
1194 array(
1195 'user' => $rootUser
1196 )
1197 )
1198 );
1199 } else {
1200 $nav_urls['log'] = false;
1201 }
1202
1203 if ( $wgUser->isAllowed( 'block' ) ) {
1204 $nav_urls['blockip'] = array(
1205 'href' => self::makeSpecialUrlSubpage( 'Block', $rootUser )
1206 );
1207 } else {
1208 $nav_urls['blockip'] = false;
1209 }
1210 } else {
1211 $nav_urls['contributions'] = false;
1212 $nav_urls['log'] = false;
1213 $nav_urls['blockip'] = false;
1214 }
1215 $nav_urls['emailuser'] = false;
1216 if( $this->showEmailUser( $id ) ) {
1217 $nav_urls['emailuser'] = array(
1218 'href' => self::makeSpecialUrlSubpage( 'Emailuser', $rootUser )
1219 );
1220 }
1221 wfProfileOut( __METHOD__ );
1222 return $nav_urls;
1223 }
1224
1225 /**
1226 * Generate strings used for xml 'id' names
1227 * @return string
1228 * @private
1229 */
1230 function getNameSpaceKey() {
1231 return $this->getTitle()->getNamespaceKey();
1232 }
1233
1234 /**
1235 * @private
1236 * @todo FIXME: Why is this duplicated in/from OutputPage::getHeadScripts()??
1237 */
1238 function setupUserJs( $allowUserJs ) {
1239 global $wgRequest, $wgJsMimeType;
1240 wfProfileIn( __METHOD__ );
1241
1242 if( $allowUserJs && $this->loggedin ) {
1243 if( $this->getTitle()->isJsSubpage() and $this->getOutput()->userCanPreview() ) {
1244 # XXX: additional security check/prompt?
1245 $this->userjsprev = '/*<![CDATA[*/ ' . $wgRequest->getText( 'wpTextbox1' ) . ' /*]]>*/';
1246 } else {
1247 $this->userjs = self::makeUrl( $this->userpage . '/' . $this->skinname . '.js', 'action=raw&ctype=' . $wgJsMimeType );
1248 }
1249 }
1250 wfProfileOut( __METHOD__ );
1251 }
1252
1253 public function commonPrintStylesheet() {
1254 return false;
1255 }
1256 }
1257
1258 /**
1259 * Generic wrapper for template functions, with interface
1260 * compatible with what we use of PHPTAL 0.7.
1261 * @ingroup Skins
1262 */
1263 abstract class QuickTemplate {
1264 /**
1265 * Constructor
1266 */
1267 public function QuickTemplate() {
1268 $this->data = array();
1269 $this->translator = new MediaWiki_I18N();
1270 }
1271
1272 /**
1273 * Sets the value $value to $name
1274 * @param $name
1275 * @param $value
1276 */
1277 public function set( $name, $value ) {
1278 $this->data[$name] = $value;
1279 }
1280
1281 /**
1282 * @param $name
1283 * @param $value
1284 */
1285 public function setRef( $name, &$value ) {
1286 $this->data[$name] =& $value;
1287 }
1288
1289 /**
1290 * @param $t
1291 */
1292 public function setTranslator( &$t ) {
1293 $this->translator = &$t;
1294 }
1295
1296 /**
1297 * Main function, used by classes that subclass QuickTemplate
1298 * to show the actual HTML output
1299 */
1300 abstract public function execute();
1301
1302 /**
1303 * @private
1304 */
1305 function text( $str ) {
1306 echo htmlspecialchars( $this->data[$str] );
1307 }
1308
1309 /**
1310 * @private
1311 */
1312 function jstext( $str ) {
1313 echo Xml::escapeJsString( $this->data[$str] );
1314 }
1315
1316 /**
1317 * @private
1318 */
1319 function html( $str ) {
1320 echo $this->data[$str];
1321 }
1322
1323 /**
1324 * @private
1325 */
1326 function msg( $str ) {
1327 echo htmlspecialchars( $this->translator->translate( $str ) );
1328 }
1329
1330 /**
1331 * @private
1332 */
1333 function msgHtml( $str ) {
1334 echo $this->translator->translate( $str );
1335 }
1336
1337 /**
1338 * An ugly, ugly hack.
1339 * @private
1340 */
1341 function msgWiki( $str ) {
1342 global $wgParser, $wgOut;
1343
1344 $text = $this->translator->translate( $str );
1345 $parserOutput = $wgParser->parse( $text, $wgOut->getTitle(),
1346 $wgOut->parserOptions(), true );
1347 echo $parserOutput->getText();
1348 }
1349
1350 /**
1351 * @private
1352 */
1353 function haveData( $str ) {
1354 return isset( $this->data[$str] );
1355 }
1356
1357 /**
1358 * @private
1359 *
1360 * @return bool
1361 */
1362 function haveMsg( $str ) {
1363 $msg = $this->translator->translate( $str );
1364 return ( $msg != '-' ) && ( $msg != '' ); # ????
1365 }
1366
1367 /**
1368 * Get the Skin object related to this object
1369 *
1370 * @return Skin object
1371 */
1372 public function getSkin() {
1373 return $this->data['skin'];
1374 }
1375 }
1376
1377 /**
1378 * New base template for a skin's template extended from QuickTemplate
1379 * this class features helper methods that provide common ways of interacting
1380 * with the data stored in the QuickTemplate
1381 */
1382 abstract class BaseTemplate extends QuickTemplate {
1383
1384 /**
1385 * Create an array of common toolbox items from the data in the quicktemplate
1386 * stored by SkinTemplate.
1387 * The resulting array is built acording to a format intended to be passed
1388 * through makeListItem to generate the html.
1389 */
1390 function getToolbox() {
1391 wfProfileIn( __METHOD__ );
1392
1393 $toolbox = array();
1394 if ( $this->data['notspecialpage'] ) {
1395 $toolbox['whatlinkshere'] = $this->data['nav_urls']['whatlinkshere'];
1396 $toolbox['whatlinkshere']['id'] = 't-whatlinkshere';
1397 if ( $this->data['nav_urls']['recentchangeslinked'] ) {
1398 $toolbox['recentchangeslinked'] = $this->data['nav_urls']['recentchangeslinked'];
1399 $toolbox['recentchangeslinked']['msg'] = 'recentchangeslinked-toolbox';
1400 $toolbox['recentchangeslinked']['id'] = 't-recentchangeslinked';
1401 }
1402 }
1403 if( isset( $this->data['nav_urls']['trackbacklink'] ) && $this->data['nav_urls']['trackbacklink'] ) {
1404 $toolbox['trackbacklink'] = $this->data['nav_urls']['trackbacklink'];
1405 $toolbox['trackbacklink']['id'] = 't-trackbacklink';
1406 }
1407 if ( $this->data['feeds'] ) {
1408 $toolbox['feeds']['id'] = 'feedlinks';
1409 $toolbox['feeds']['links'] = array();
1410 foreach ( $this->data['feeds'] as $key => $feed ) {
1411 $toolbox['feeds']['links'][$key] = $feed;
1412 $toolbox['feeds']['links'][$key]['id'] = "feed-$key";
1413 $toolbox['feeds']['links'][$key]['rel'] = 'alternate';
1414 $toolbox['feeds']['links'][$key]['type'] = "application/{$key}+xml";
1415 $toolbox['feeds']['links'][$key]['class'] = 'feedlink';
1416 }
1417 }
1418 foreach ( array( 'contributions', 'log', 'blockip', 'emailuser', 'upload', 'specialpages' ) as $special ) {
1419 if ( $this->data['nav_urls'][$special] ) {
1420 $toolbox[$special] = $this->data['nav_urls'][$special];
1421 $toolbox[$special]['id'] = "t-$special";
1422 }
1423 }
1424 if ( !empty( $this->data['nav_urls']['print']['href'] ) ) {
1425 $toolbox['print'] = $this->data['nav_urls']['print'];
1426 $toolbox['print']['rel'] = 'alternate';
1427 $toolbox['print']['msg'] = 'printableversion';
1428 }
1429 if( $this->data['nav_urls']['permalink'] ) {
1430 $toolbox['permalink'] = $this->data['nav_urls']['permalink'];
1431 if( $toolbox['permalink']['href'] === '' ) {
1432 unset( $toolbox['permalink']['href'] );
1433 $toolbox['ispermalink']['tooltiponly'] = true;
1434 $toolbox['ispermalink']['id'] = 't-ispermalink';
1435 $toolbox['ispermalink']['msg'] = 'permalink';
1436 } else {
1437 $toolbox['permalink']['id'] = 't-permalink';
1438 }
1439 }
1440 wfRunHooks( 'BaseTemplateToolbox', array( &$this, &$toolbox ) );
1441 wfProfileOut( __METHOD__ );
1442 return $toolbox;
1443 }
1444
1445 /**
1446 * Create an array of personal tools items from the data in the quicktemplate
1447 * stored by SkinTemplate.
1448 * The resulting array is built acording to a format intended to be passed
1449 * through makeListItem to generate the html.
1450 * This is in reality the same list as already stored in personal_urls
1451 * however it is reformatted so that you can just pass the individual items
1452 * to makeListItem instead of hardcoding the element creation boilerplate.
1453 */
1454 function getPersonalTools() {
1455 $personal_tools = array();
1456 foreach( $this->data['personal_urls'] as $key => $ptool ) {
1457 # The class on a personal_urls item is meant to go on the <a> instead
1458 # of the <li> so we have to use a single item "links" array instead
1459 # of using most of the personal_url's keys directly
1460 $personal_tools[$key] = array();
1461 $personal_tools[$key]["links"][] = array();
1462 $personal_tools[$key]["links"][0]["single-id"] = $personal_tools[$key]["id"] = "pt-$key";
1463 if ( isset($ptool["active"]) ) {
1464 $personal_tools[$key]["active"] = $ptool["active"];
1465 }
1466 foreach ( array("href", "class", "text") as $k ) {
1467 if ( isset($ptool[$k]) )
1468 $personal_tools[$key]["links"][0][$k] = $ptool[$k];
1469 }
1470 }
1471 return $personal_tools;
1472 }
1473
1474 /**
1475 * Makes a link, usually used by makeListItem to generate a link for an item
1476 * in a list used in navigation lists, portlets, portals, sidebars, etc...
1477 *
1478 * $key is a string, usually a key from the list you are generating this link from
1479 * $item is an array containing some of a specific set of keys.
1480 * The text of the link will be generated either from the contents of the "text"
1481 * key in the $item array, if a "msg" key is present a message by that name will
1482 * be used, and if neither of those are set the $key will be used as a message name.
1483 * If a "href" key is not present makeLink will just output htmlescaped text.
1484 * The href, id, class, rel, and type keys are used as attributes for the link if present.
1485 * If an "id" or "single-id" (if you don't want the actual id to be output on the link)
1486 * is present it will be used to generate a tooltip and accesskey for the link.
1487 * If you don't want an accesskey, set $item['tooltiponly'] = true;
1488 */
1489 function makeLink( $key, $item ) {
1490 if ( isset( $item['text'] ) ) {
1491 $text = $item['text'];
1492 } else {
1493 $text = $this->translator->translate( isset( $item['msg'] ) ? $item['msg'] : $key );
1494 }
1495
1496 if ( !isset( $item['href'] ) ) {
1497 return htmlspecialchars( $text );
1498 }
1499
1500 $attrs = array();
1501 foreach ( array( 'href', 'id', 'class', 'rel', 'type', 'target') as $attr ) {
1502 if ( isset( $item[$attr] ) ) {
1503 $attrs[$attr] = $item[$attr];
1504 }
1505 }
1506
1507 if ( isset( $item['id'] ) ) {
1508 $item['single-id'] = $item['id'];
1509 }
1510 if ( isset( $item['single-id'] ) ) {
1511 if ( isset( $item['tooltiponly'] ) && $item['tooltiponly'] ) {
1512 $attrs['title'] = $this->skin->titleAttrib( $item['single-id'] );
1513 if ( $attrs['title'] === false ) {
1514 unset( $attrs['title'] );
1515 }
1516 } else {
1517 $attrs = array_merge(
1518 $attrs,
1519 Linker::tooltipAndAccesskeyAttribs( $item['single-id'] )
1520 );
1521 }
1522 }
1523
1524 return Html::element( 'a', $attrs, $text );
1525 }
1526
1527 /**
1528 * Generates a list item for a navigation, portlet, portal, sidebar... etc list
1529 * $key is a string, usually a key from the list you are generating this link from
1530 * $item is an array of list item data containing some of a specific set of keys.
1531 * The "id" and "class" keys will be used as attributes for the list item,
1532 * if "active" contains a value of true a "active" class will also be appended to class.
1533 * If you want something other than a <li> you can pass a tag name such as
1534 * "tag" => "span" in the $options array to change the tag used.
1535 * link/content data for the list item may come in one of two forms
1536 * A "links" key may be used, in which case it should contain an array with
1537 * a list of links to include inside the list item, see makeLink for the format
1538 * of individual links array items.
1539 * Otherwise the relevant keys from the list item $item array will be passed
1540 * to makeLink instead. Note however that "id" and "class" are used by the
1541 * list item directly so they will not be passed to makeLink
1542 * (however the link will still support a tooltip and accesskey from it)
1543 * If you need an id or class on a single link you should include a "links"
1544 * array with just one link item inside of it.
1545 */
1546 function makeListItem( $key, $item, $options = array() ) {
1547 if ( isset( $item['links'] ) ) {
1548 $html = '';
1549 foreach ( $item['links'] as $linkKey => $link ) {
1550 $html .= $this->makeLink( $linkKey, $link );
1551 }
1552 } else {
1553 $link = array();
1554 foreach ( array( 'text', 'msg', 'href', 'rel', 'type', 'tooltiponly', 'target' ) as $k ) {
1555 if ( isset( $item[$k] ) ) {
1556 $link[$k] = $item[$k];
1557 }
1558 }
1559 if ( isset( $item['id'] ) ) {
1560 // The id goes on the <li> not on the <a> for single links
1561 // but makeSidebarLink still needs to know what id to use when
1562 // generating tooltips and accesskeys.
1563 $link['single-id'] = $item['id'];
1564 }
1565 $html = $this->makeLink( $key, $link );
1566 }
1567
1568 $attrs = array();
1569 foreach ( array( 'id', 'class' ) as $attr ) {
1570 if ( isset( $item[$attr] ) ) {
1571 $attrs[$attr] = $item[$attr];
1572 }
1573 }
1574 if ( isset( $item['active'] ) && $item['active'] ) {
1575 if ( !isset( $attrs['class'] ) ) {
1576 $attrs['class'] = '';
1577 }
1578 $attrs['class'] .= ' active';
1579 $attrs['class'] = trim( $attrs['class'] );
1580 }
1581 return Html::rawElement( isset( $options['tag'] ) ? $options['tag'] : 'li', $attrs, $html );
1582 }
1583
1584 function makeSearchInput( $attrs = array() ) {
1585 $realAttrs = array(
1586 'type' => 'search',
1587 'name' => 'search',
1588 'value' => isset( $this->data['search'] ) ? $this->data['search'] : '',
1589 );
1590 $realAttrs = array_merge( $realAttrs, Linker::tooltipAndAccesskeyAttribs( 'search' ), $attrs );
1591 return Html::element( 'input', $realAttrs );
1592 }
1593
1594 function makeSearchButton( $mode, $attrs = array() ) {
1595 switch( $mode ) {
1596 case 'go':
1597 case 'fulltext':
1598 $realAttrs = array(
1599 'type' => 'submit',
1600 'name' => $mode,
1601 'value' => $this->translator->translate(
1602 $mode == 'go' ? 'searcharticle' : 'searchbutton' ),
1603 );
1604 $realAttrs = array_merge(
1605 $realAttrs,
1606 Linker::tooltipAndAccesskeyAttribs( "search-$mode" ),
1607 $attrs
1608 );
1609 return Html::element( 'input', $realAttrs );
1610 case 'image':
1611 $buttonAttrs = array(
1612 'type' => 'submit',
1613 'name' => 'button',
1614 );
1615 $buttonAttrs = array_merge(
1616 $buttonAttrs,
1617 Linker::tooltipAndAccesskeyAttribs( 'search-fulltext' ),
1618 $attrs
1619 );
1620 unset( $buttonAttrs['src'] );
1621 unset( $buttonAttrs['alt'] );
1622 $imgAttrs = array(
1623 'src' => $attrs['src'],
1624 'alt' => isset( $attrs['alt'] )
1625 ? $attrs['alt']
1626 : $this->translator->translate( 'searchbutton' ),
1627 );
1628 return Html::rawElement( 'button', $buttonAttrs, Html::element( 'img', $imgAttrs ) );
1629 default:
1630 throw new MWException( 'Unknown mode passed to BaseTemplate::makeSearchButton' );
1631 }
1632 }
1633
1634 /**
1635 * Returns an array of footerlinks trimmed down to only those footer links that
1636 * are valid.
1637 * If you pass "flat" as an option then the returned array will be a flat array
1638 * of footer icons instead of a key/value array of footerlinks arrays broken
1639 * up into categories.
1640 */
1641 function getFooterLinks( $option = null ) {
1642 $footerlinks = $this->data['footerlinks'];
1643
1644 // Reduce footer links down to only those which are being used
1645 $validFooterLinks = array();
1646 foreach( $footerlinks as $category => $links ) {
1647 $validFooterLinks[$category] = array();
1648 foreach( $links as $link ) {
1649 if( isset( $this->data[$link] ) && $this->data[$link] ) {
1650 $validFooterLinks[$category][] = $link;
1651 }
1652 }
1653 if ( count( $validFooterLinks[$category] ) <= 0 ) {
1654 unset( $validFooterLinks[$category] );
1655 }
1656 }
1657
1658 if ( $option == 'flat' ) {
1659 // fold footerlinks into a single array using a bit of trickery
1660 $validFooterLinks = call_user_func_array(
1661 'array_merge',
1662 array_values( $validFooterLinks )
1663 );
1664 }
1665
1666 return $validFooterLinks;
1667 }
1668
1669 /**
1670 * Returns an array of footer icons filtered down by options relevant to how
1671 * the skin wishes to display them.
1672 * If you pass "icononly" as the option all footer icons which do not have an
1673 * image icon set will be filtered out.
1674 * If you pass "nocopyright" then MediaWiki's copyright icon will not be included
1675 * in the list of footer icons. This is mostly useful for skins which only
1676 * display the text from footericons instead of the images and don't want a
1677 * duplicate copyright statement because footerlinks already rendered one.
1678 */
1679 function getFooterIcons( $option = null ) {
1680 // Generate additional footer icons
1681 $footericons = $this->data['footericons'];
1682
1683 if ( $option == 'icononly' ) {
1684 // Unset any icons which don't have an image
1685 foreach ( $footericons as &$footerIconsBlock ) {
1686 foreach ( $footerIconsBlock as $footerIconKey => $footerIcon ) {
1687 if ( !is_string( $footerIcon ) && !isset( $footerIcon['src'] ) ) {
1688 unset( $footerIconsBlock[$footerIconKey] );
1689 }
1690 }
1691 }
1692 // Redo removal of any empty blocks
1693 foreach ( $footericons as $footerIconsKey => &$footerIconsBlock ) {
1694 if ( count( $footerIconsBlock ) <= 0 ) {
1695 unset( $footericons[$footerIconsKey] );
1696 }
1697 }
1698 } elseif ( $option == 'nocopyright' ) {
1699 unset( $footericons['copyright']['copyright'] );
1700 if ( count( $footericons['copyright'] ) <= 0 ) {
1701 unset( $footericons['copyright'] );
1702 }
1703 }
1704
1705 return $footericons;
1706 }
1707
1708 /**
1709 * Output the basic end-page trail including bottomscripts, reporttime, and
1710 * debug stuff. This should be called right before outputting the closing
1711 * body and html tags.
1712 */
1713 function printTrail() { ?>
1714 <?php $this->html('bottomscripts'); /* JS call to runBodyOnloadHook */ ?>
1715 <?php $this->html('reporttime') ?>
1716 <?php if ( $this->data['debug'] ): ?>
1717 <!-- Debug output:
1718 <?php $this->text( 'debug' ); ?>
1719
1720 -->
1721 <?php endif;
1722 }
1723
1724 }
1725