| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
module.exports = function () { |
| 6 |
const |
| 7 |
ms = require( 'mobile.startup' ), |
| 8 |
PageHTMLParser = ms.PageHTMLParser, |
| 9 |
permissions = mw.config.get( 'wgMinervaPermissions' ) || {}, |
| 10 |
notifyOnPageReload = ms.notifyOnPageReload, |
| 11 |
time = ms.time, |
| 12 |
preInit = require( './preInit.js' ), |
| 13 |
mobileRedirect = require( './mobileRedirect.js' ), |
| 14 |
search = require( './search.js' ), |
| 15 |
references = require( './references.js' ), |
| 16 |
TitleUtil = require( './TitleUtil.js' ), |
| 17 |
issues = require( './page-issues/index.js' ), |
| 18 |
Toolbar = require( './Toolbar.js' ), |
| 19 |
ToggleList = require( '../../includes/Skins/ToggleList/ToggleList.js' ), |
| 20 |
TabScroll = require( './TabScroll.js' ), |
| 21 |
router = require( 'mediawiki.router' ), |
| 22 |
ctaDrawers = require( './ctaDrawers.js' ), |
| 23 |
drawers = require( './drawers.js' ), |
| 24 |
desktopMMV = mw.loader.getState( 'mmv.bootstrap' ), |
| 25 |
overlayManager = ms.getOverlayManager(), |
| 26 |
currentPage = ms.currentPage(), |
| 27 |
currentPageHTMLParser = ms.currentPageHTMLParser(), |
| 28 |
api = new mw.Api(), |
| 29 |
namespaceIDs = mw.config.get( 'wgNamespaceIds' ); |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
function onClickImage( ev ) { |
| 38 |
|
| 39 |
if ( ev.altKey || ev.ctrlKey || ev.shiftKey || ev.metaKey ) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
const el = ev.target.closest( PageHTMLParser.THUMB_SELECTOR ); |
| 44 |
if ( !el ) { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
const thumb = currentPageHTMLParser.getThumbnail( $( el ) ); |
| 49 |
if ( !thumb ) { |
| 50 |
return; |
| 51 |
} |
| 52 |
|
| 53 |
ev.preventDefault(); |
| 54 |
routeThumbnail( thumb ); |
| 55 |
} |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
function routeThumbnail( thumbnail ) { |
| 62 |
router.navigate( '#/media/' + encodeURIComponent( thumbnail.getFileName() ) ); |
| 63 |
} |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
function initMediaViewer( container ) { |
| 73 |
|
| 74 |
if ( container instanceof HTMLElement ) { |
| 75 |
container.addEventListener( 'click', onClickImage ); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
function initButton() { |
| 86 |
|
| 87 |
|
| 88 |
const $primaryBtn = $( '.language-selector' ); |
| 89 |
|
| 90 |
if ( $primaryBtn.length ) { |
| 91 |
|
| 92 |
$primaryBtn.on( 'click', ( ev ) => { |
| 93 |
ev.preventDefault(); |
| 94 |
|
| 95 |
if ( $primaryBtn.attr( 'href' ) || $primaryBtn.find( 'a' ).length ) { |
| 96 |
router.navigate( '/languages' ); |
| 97 |
} else { |
| 98 |
mw.notify( mw.msg( 'mobile-frontend-languages-not-available' ), { |
| 99 |
tag: 'languages-not-available' |
| 100 |
} ); |
| 101 |
} |
| 102 |
} ); |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
function makeMediaViewerOverlayIfNeeded( title ) { |
| 117 |
if ( mw.loader.getState( 'mmv.bootstrap' ) === 'ready' ) { |
| 118 |
|
| 119 |
|
| 120 |
return; |
| 121 |
} |
| 122 |
try { |
| 123 |
title = decodeURIComponent( title ); |
| 124 |
} catch ( e ) { |
| 125 |
|
| 126 |
return; |
| 127 |
} |
| 128 |
|
| 129 |
return ms.mediaViewer.overlay( { |
| 130 |
api, |
| 131 |
thumbnails: currentPageHTMLParser.getThumbnails(), |
| 132 |
title |
| 133 |
} ); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
overlayManager.add( /^\/media\/(.+)$/, makeMediaViewerOverlayIfNeeded ); |
| 138 |
overlayManager.add( /^\/languages$/, () => ms.languages.languageOverlay() ); |
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
overlayManager.add( /^\/languages\/all$/, () => ms.languages.languageInfoOverlay( api, true ) ); |
| 144 |
overlayManager.add( /^\/languages\/all\/no-suggestions$/, () => ms.languages.languageInfoOverlay( api, false ) ); |
| 145 |
|
| 146 |
|
| 147 |
$( () => { |
| 148 |
initButton(); |
| 149 |
} ); |
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
function initHistoryLink( $lastModifiedLink ) { |
| 162 |
const ts = $lastModifiedLink.data( 'timestamp' ); |
| 163 |
if ( ts ) { |
| 164 |
const username = $lastModifiedLink.data( 'user-name' ) || false; |
| 165 |
const gender = $lastModifiedLink.data( 'user-gender' ); |
| 166 |
const delta = time.getTimeAgoDelta( parseInt( ts, 10 ) ); |
| 167 |
if ( time.isRecent( delta ) ) { |
| 168 |
const $bar = $lastModifiedLink.closest( '.last-modified-bar' ); |
| 169 |
$bar.addClass( 'active' ); |
| 170 |
} |
| 171 |
|
| 172 |
const $msg = $( '<span>' ) |
| 173 |
|
| 174 |
.attr( 'class', $lastModifiedLink.attr( 'class' ) ) |
| 175 |
.html( |
| 176 |
time.getLastModifiedMessage( ts, username, gender, |
| 177 |
|
| 178 |
$lastModifiedLink.attr( 'href' ) |
| 179 |
) |
| 180 |
); |
| 181 |
$lastModifiedLink.replaceWith( $msg ); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
function amcHistoryClickHandler( ev ) { |
| 190 |
const self = this; |
| 191 |
const amcOutreach = ms.amcOutreach; |
| 192 |
const amcCampaign = amcOutreach.loadCampaign(); |
| 193 |
const onDismiss = function () { |
| 194 |
notifyOnPageReload( mw.msg( 'mobile-frontend-amc-outreach-dismissed-message' ) ); |
| 195 |
window.location = self.href; |
| 196 |
}; |
| 197 |
const drawer = amcCampaign.showIfEligible( amcOutreach.ACTIONS.onHistoryLink, onDismiss, currentPage.title, 'action=history' ); |
| 198 |
|
| 199 |
if ( drawer ) { |
| 200 |
ev.preventDefault(); |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
ev.stopPropagation(); |
| 205 |
|
| 206 |
drawers.displayDrawer( drawer, {} ); |
| 207 |
drawers.lockScroll(); |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
function initAmcHistoryLink( $lastModifiedLink ) { |
| 217 |
$lastModifiedLink.one( 'click', amcHistoryClickHandler ); |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
function initModifiedInfo() { |
| 230 |
|
| 231 |
$( '.modified-enhancement' ).each( ( _i, el ) => { |
| 232 |
initHistoryLink( $( el ) ); |
| 233 |
} ); |
| 234 |
Array.prototype.forEach.call( document.querySelectorAll( '.mw-diff-timestamp' ), ( tsNode ) => { |
| 235 |
const ts = tsNode.dataset.timestamp; |
| 236 |
if ( ts ) { |
| 237 |
const ago = time.getTimeAgoDelta( |
| 238 |
parseInt( |
| 239 |
( new Date( ts ) ).getTime() / 1000, |
| 240 |
10 |
| 241 |
) |
| 242 |
); |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
tsNode.textContent = mw.msg( |
| 251 |
`skin-minerva-time-ago-${ ago.unit }`, |
| 252 |
mw.language.convertNumber( ago.value ) |
| 253 |
); |
| 254 |
} |
| 255 |
} ); |
| 256 |
} |
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
|
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
function initRegistrationDate( $tagline ) { |
| 269 |
const ts = $tagline.data( 'userpage-registration-date' ); |
| 270 |
|
| 271 |
if ( ts ) { |
| 272 |
const msg = time.getRegistrationMessage( ts, $tagline.data( 'userpage-gender' ) ); |
| 273 |
$tagline.text( msg ); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
function initRegistrationInfo() { |
| 287 |
|
| 288 |
$( '#tagline-userpage' ).each( ( _i, el ) => { |
| 289 |
initRegistrationDate( $( el ) ); |
| 290 |
} ); |
| 291 |
} |
| 292 |
|
| 293 |
|
| 294 |
|
| 295 |
|
| 296 |
|
| 297 |
|
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
function isUserUri( url ) { |
| 313 |
const title = TitleUtil.newFromUri( url ); |
| 314 |
const namespace = title ? title.getNamespaceId() : undefined; |
| 315 |
return namespace === namespaceIDs.user; |
| 316 |
} |
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
function initUserRedLinks( $redLinks ) { |
| 324 |
$redLinks.filter( |
| 325 |
|
| 326 |
( _, element ) => isUserUri( element.href ) |
| 327 |
).each( ( _, element ) => { |
| 328 |
const uri = new mw.Uri( element.href ); |
| 329 |
if ( uri.query.action !== 'edit' ) { |
| 330 |
|
| 331 |
return; |
| 332 |
} |
| 333 |
|
| 334 |
|
| 335 |
delete uri.query.action; |
| 336 |
|
| 337 |
|
| 338 |
element.href = uri.toString(); |
| 339 |
} ); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
function setupEcho() { |
| 346 |
const echoBtn = document.querySelector( '.minerva-notifications .mw-echo-notification-badge-nojs' ); |
| 347 |
if ( echoBtn ) { |
| 348 |
echoBtn.addEventListener( 'click', ( ev ) => { |
| 349 |
router.navigate( '#/notifications' ); |
| 350 |
|
| 351 |
|
| 352 |
ev.preventDefault(); |
| 353 |
|
| 354 |
|
| 355 |
echoBtn.dataset.counterNum = 0; |
| 356 |
echoBtn.dataset.counterText = mw.msg( 'echo-badge-count', |
| 357 |
mw.language.convertNumber( 0 ) |
| 358 |
); |
| 359 |
|
| 360 |
} ); |
| 361 |
} |
| 362 |
} |
| 363 |
|
| 364 |
$( () => { |
| 365 |
|
| 366 |
const $watch = $( '#page-actions-watch' ); |
| 367 |
const toolbarElement = document.querySelector( Toolbar.selector ); |
| 368 |
const userMenu = document.querySelector( '.minerva-user-menu' ); |
| 369 |
const navigationDrawer = document.querySelector( '.navigation-drawer' ); |
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
$( document.body ).addClass( 'minerva-animations-ready' ); |
| 378 |
|
| 379 |
|
| 380 |
$( '.mw-mf-page-center__mask' ).on( 'click', ( ev ) => { |
| 381 |
const path = router.getPath(); |
| 382 |
|
| 383 |
|
| 384 |
if ( !path ) { |
| 385 |
ev.preventDefault(); |
| 386 |
} |
| 387 |
} ); |
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
preInit(); |
| 392 |
|
| 393 |
references(); |
| 394 |
|
| 395 |
search(); |
| 396 |
|
| 397 |
mobileRedirect( ms.amcOutreach, currentPage ); |
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
initModifiedInfo(); |
| 402 |
initRegistrationInfo(); |
| 403 |
|
| 404 |
initAmcHistoryLink( $( '.last-modified-bar__text a' ) ); |
| 405 |
|
| 406 |
if ( toolbarElement ) { |
| 407 |
Toolbar.bind( window, toolbarElement ); |
| 408 |
|
| 409 |
Toolbar.render( window, toolbarElement ); |
| 410 |
} |
| 411 |
if ( userMenu ) { |
| 412 |
ToggleList.bind( window, userMenu ); |
| 413 |
} |
| 414 |
if ( navigationDrawer ) { |
| 415 |
ToggleList.bind( window, navigationDrawer ); |
| 416 |
const navigationDrawerMask = navigationDrawer.querySelector( '.main-menu-mask' ); |
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
navigationDrawerMask.removeAttribute( 'for' ); |
| 421 |
} |
| 422 |
TabScroll.initTabsScrollPosition(); |
| 423 |
|
| 424 |
|
| 425 |
if ( |
| 426 |
!currentPage.isMissing && |
| 427 |
!currentPage.titleObj.isTalkPage() |
| 428 |
) { |
| 429 |
issues.init( overlayManager, currentPageHTMLParser ); |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
mw.hook( 'wikipage.content' ).add( ( $container ) => { |
| 436 |
|
| 437 |
if ( desktopMMV === null || desktopMMV === 'registered' ) { |
| 438 |
initMediaViewer( $container[ 0 ] ); |
| 439 |
} |
| 440 |
|
| 441 |
|
| 442 |
const $toctitle = $container.find( '.toctitle' ); |
| 443 |
$( '<span>' ).addClass( 'toc-title-icon' ).prependTo( $toctitle ); |
| 444 |
$( '<span>' ).addClass( 'toc-title-state-icon' ).appendTo( $toctitle ); |
| 445 |
|
| 446 |
|
| 447 |
const $redLinks = currentPageHTMLParser.getRedLinks(); |
| 448 |
ctaDrawers.initRedlinksCta( |
| 449 |
$redLinks.filter( |
| 450 |
|
| 451 |
( _, element ) => !isUserUri( element.href ) |
| 452 |
) |
| 453 |
); |
| 454 |
initUserRedLinks( $redLinks ); |
| 455 |
} ); |
| 456 |
|
| 457 |
|
| 458 |
if ( permissions.watchable && !permissions.watch ) { |
| 459 |
ctaDrawers.initWatchstarCta( $watch ); |
| 460 |
} |
| 461 |
|
| 462 |
|
| 463 |
const echoState = mw.loader.getState( 'ext.echo.mobile' ); |
| 464 |
|
| 465 |
if ( echoState !== null && echoState !== 'registered' ) { |
| 466 |
setupEcho(); |
| 467 |
} |
| 468 |
} ); |
| 469 |
}; |