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