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