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