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