MediaWiki  1.28.2
ImagePage.php
Go to the documentation of this file.
1 <?php
28 class ImagePage extends Article {
30  private $displayImg;
31 
33  private $repo;
34 
36  private $fileLoaded;
37 
39  protected $mExtraDescription = false;
40 
44  protected $mPage;
45 
50  protected function newPage( Title $title ) {
51  // Overload mPage with a file-specific page
52  return new WikiFilePage( $title );
53  }
54 
59  public function setFile( $file ) {
60  $this->mPage->setFile( $file );
61  $this->displayImg = $file;
62  $this->fileLoaded = true;
63  }
64 
65  protected function loadFile() {
66  if ( $this->fileLoaded ) {
67  return;
68  }
69  $this->fileLoaded = true;
70 
71  $this->displayImg = $img = false;
72  Hooks::run( 'ImagePageFindFile', [ $this, &$img, &$this->displayImg ] );
73  if ( !$img ) { // not set by hook?
74  $img = wfFindFile( $this->getTitle() );
75  if ( !$img ) {
76  $img = wfLocalFile( $this->getTitle() );
77  }
78  }
79  $this->mPage->setFile( $img );
80  if ( !$this->displayImg ) { // not set by hook?
81  $this->displayImg = $img;
82  }
83  $this->repo = $img->getRepo();
84  }
85 
90  public function render() {
91  $this->getContext()->getOutput()->setArticleBodyOnly( true );
92  parent::view();
93  }
94 
95  public function view() {
97 
98  $out = $this->getContext()->getOutput();
99  $request = $this->getContext()->getRequest();
100  $diff = $request->getVal( 'diff' );
101  $diffOnly = $request->getBool(
102  'diffonly',
103  $this->getContext()->getUser()->getOption( 'diffonly' )
104  );
105 
106  if ( $this->getTitle()->getNamespace() != NS_FILE || ( $diff !== null && $diffOnly ) ) {
107  parent::view();
108  return;
109  }
110 
111  $this->loadFile();
112 
113  if ( $this->getTitle()->getNamespace() == NS_FILE && $this->mPage->getFile()->getRedirected() ) {
114  if ( $this->getTitle()->getDBkey() == $this->mPage->getFile()->getName() || $diff !== null ) {
115  // mTitle is the same as the redirect target so ask Article
116  // to perform the redirect for us.
117  $request->setVal( 'diffonly', 'true' );
118  parent::view();
119  return;
120  } else {
121  // mTitle is not the same as the redirect target so it is
122  // probably the redirect page itself. Fake the redirect symbol
123  $out->setPageTitle( $this->getTitle()->getPrefixedText() );
124  $out->addHTML( $this->viewRedirect(
125  Title::makeTitle( NS_FILE, $this->mPage->getFile()->getName() ),
126  /* $appendSubtitle */ true,
127  /* $forceKnown */ true )
128  );
129  $this->mPage->doViewUpdates( $this->getContext()->getUser(), $this->getOldID() );
130  return;
131  }
132  }
133 
134  if ( $wgShowEXIF && $this->displayImg->exists() ) {
135  // @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
136  $formattedMetadata = $this->displayImg->formatMetadata( $this->getContext() );
137  $showmeta = $formattedMetadata !== false;
138  } else {
139  $showmeta = false;
140  }
141 
142  if ( !$diff && $this->displayImg->exists() ) {
143  $out->addHTML( $this->showTOC( $showmeta ) );
144  }
145 
146  if ( !$diff ) {
147  $this->openShowImage();
148  }
149 
150  # No need to display noarticletext, we use our own message, output in openShowImage()
151  if ( $this->mPage->getId() ) {
152  # NS_FILE is in the user language, but this section (the actual wikitext)
153  # should be in page content language
154  $pageLang = $this->getTitle()->getPageViewLanguage();
155  $out->addHTML( Xml::openElement( 'div', [ 'id' => 'mw-imagepage-content',
156  'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
157  'class' => 'mw-content-' . $pageLang->getDir() ] ) );
158 
159  parent::view();
160 
161  $out->addHTML( Xml::closeElement( 'div' ) );
162  } else {
163  # Just need to set the right headers
164  $out->setArticleFlag( true );
165  $out->setPageTitle( $this->getTitle()->getPrefixedText() );
166  $this->mPage->doViewUpdates( $this->getContext()->getUser(), $this->getOldID() );
167  }
168 
169  # Show shared description, if needed
170  if ( $this->mExtraDescription ) {
171  $fol = $this->getContext()->msg( 'shareddescriptionfollows' );
172  if ( !$fol->isDisabled() ) {
173  $out->addWikiText( $fol->plain() );
174  }
175  $out->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
176  }
177 
178  $this->closeShowImage();
179  $this->imageHistory();
180  // TODO: Cleanup the following
181 
182  $out->addHTML( Xml::element( 'h2',
183  [ 'id' => 'filelinks' ],
184  $this->getContext()->msg( 'imagelinks' )->text() ) . "\n" );
185  $this->imageDupes();
186  # @todo FIXME: For some freaky reason, we can't redirect to foreign images.
187  # Yet we return metadata about the target. Definitely an issue in the FileRepo
188  $this->imageLinks();
189 
190  # Allow extensions to add something after the image links
191  $html = '';
192  Hooks::run( 'ImagePageAfterImageLinks', [ $this, &$html ] );
193  if ( $html ) {
194  $out->addHTML( $html );
195  }
196 
197  if ( $showmeta ) {
198  $out->addHTML( Xml::element(
199  'h2',
200  [ 'id' => 'metadata' ],
201  $this->getContext()->msg( 'metadata' )->text() ) . "\n" );
202  $out->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
203  $out->addModules( [ 'mediawiki.action.view.metadata' ] );
204  }
205 
206  // Add remote Filepage.css
207  if ( !$this->repo->isLocal() ) {
208  $css = $this->repo->getDescriptionStylesheetUrl();
209  if ( $css ) {
210  $out->addStyle( $css );
211  }
212  }
213 
214  $out->addModuleStyles( [
215  'filepage', // always show the local local Filepage.css, bug 29277
216  'mediawiki.action.view.filepage', // Add MediaWiki styles for a file page
217  ] );
218 
219  }
220 
224  public function getDisplayedFile() {
225  $this->loadFile();
226  return $this->displayImg;
227  }
228 
235  protected function showTOC( $metadata ) {
236  $r = [
237  '<li><a href="#file">' . $this->getContext()->msg( 'file-anchor-link' )->escaped() . '</a></li>',
238  '<li><a href="#filehistory">' . $this->getContext()->msg( 'filehist' )->escaped() . '</a></li>',
239  '<li><a href="#filelinks">' . $this->getContext()->msg( 'imagelinks' )->escaped() . '</a></li>',
240  ];
241 
242  Hooks::run( 'ImagePageShowTOC', [ $this, &$r ] );
243 
244  if ( $metadata ) {
245  $r[] = '<li><a href="#metadata">' .
246  $this->getContext()->msg( 'metadata' )->escaped() .
247  '</a></li>';
248  }
249 
250  return '<ul id="filetoc">' . implode( "\n", $r ) . '</ul>';
251  }
252 
261  protected function makeMetadataTable( $metadata ) {
262  $r = "<div class=\"mw-imagepage-section-metadata\">";
263  $r .= $this->getContext()->msg( 'metadata-help' )->plain();
264  $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
265  foreach ( $metadata as $type => $stuff ) {
266  foreach ( $stuff as $v ) {
267  # @todo FIXME: Why is this using escapeId for a class?!
268  $class = Sanitizer::escapeId( $v['id'] );
269  if ( $type == 'collapsed' ) {
270  // Handled by mediawiki.action.view.metadata module.
271  $class .= ' collapsable';
272  }
273  $r .= "<tr class=\"$class\">\n";
274  $r .= "<th>{$v['name']}</th>\n";
275  $r .= "<td>{$v['value']}</td>\n</tr>";
276  }
277  }
278  $r .= "</table>\n</div>\n";
279  return $r;
280  }
281 
289  public function getContentObject() {
290  $this->loadFile();
291  if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->getId() ) {
292  return null;
293  }
294  return parent::getContentObject();
295  }
296 
297  protected function openShowImage() {
299 
300  $this->loadFile();
301  $out = $this->getContext()->getOutput();
302  $user = $this->getContext()->getUser();
303  $lang = $this->getContext()->getLanguage();
304  $dirmark = $lang->getDirMarkEntity();
305  $request = $this->getContext()->getRequest();
306 
307  $max = $this->getImageLimitsFromOption( $user, 'imagesize' );
308  $maxWidth = $max[0];
309  $maxHeight = $max[1];
310 
311  if ( $this->displayImg->exists() ) {
312  # image
313  $page = $request->getIntOrNull( 'page' );
314  if ( is_null( $page ) ) {
315  $params = [];
316  $page = 1;
317  } else {
318  $params = [ 'page' => $page ];
319  }
320 
321  $renderLang = $request->getVal( 'lang' );
322  if ( !is_null( $renderLang ) ) {
323  $handler = $this->displayImg->getHandler();
324  if ( $handler && $handler->validateParam( 'lang', $renderLang ) ) {
325  $params['lang'] = $renderLang;
326  } else {
327  $renderLang = null;
328  }
329  }
330 
331  $width_orig = $this->displayImg->getWidth( $page );
332  $width = $width_orig;
333  $height_orig = $this->displayImg->getHeight( $page );
334  $height = $height_orig;
335 
336  $filename = wfEscapeWikiText( $this->displayImg->getName() );
337  $linktext = $filename;
338 
339  // Avoid PHP 7.1 warning from passing $this by reference
340  $imagePage = $this;
341 
342  Hooks::run( 'ImageOpenShowImageInlineBefore', [ &$imagePage, &$out ] );
343 
344  if ( $this->displayImg->allowInlineDisplay() ) {
345  # image
346  # "Download high res version" link below the image
347  # $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
348  # Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
349  # We'll show a thumbnail of this image
350  if ( $width > $maxWidth || $height > $maxHeight || $this->displayImg->isVectorized() ) {
351  list( $width, $height ) = $this->getDisplayWidthHeight(
352  $maxWidth, $maxHeight, $width, $height
353  );
354  $linktext = $this->getContext()->msg( 'show-big-image' )->escaped();
355 
356  $thumbSizes = $this->getThumbSizes( $width_orig, $height_orig );
357  # Generate thumbnails or thumbnail links as needed...
358  $otherSizes = [];
359  foreach ( $thumbSizes as $size ) {
360  // We include a thumbnail size in the list, if it is
361  // less than or equal to the original size of the image
362  // asset ($width_orig/$height_orig). We also exclude
363  // the current thumbnail's size ($width/$height)
364  // since that is added to the message separately, so
365  // it can be denoted as the current size being shown.
366  // Vectorized images are limited by $wgSVGMaxSize big,
367  // so all thumbs less than or equal that are shown.
368  if ( ( ( $size[0] <= $width_orig && $size[1] <= $height_orig )
369  || ( $this->displayImg->isVectorized()
370  && max( $size[0], $size[1] ) <= $wgSVGMaxSize )
371  )
372  && $size[0] != $width && $size[1] != $height
373  ) {
374  $sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] );
375  if ( $sizeLink ) {
376  $otherSizes[] = $sizeLink;
377  }
378  }
379  }
380  $otherSizes = array_unique( $otherSizes );
381 
382  $sizeLinkBigImagePreview = $this->makeSizeLink( $params, $width, $height );
383  $msgsmall = $this->getThumbPrevText( $params, $sizeLinkBigImagePreview );
384  if ( count( $otherSizes ) ) {
385  $msgsmall .= ' ' .
387  'span',
388  [ 'class' => 'mw-filepage-other-resolutions' ],
389  $this->getContext()->msg( 'show-big-image-other' )
390  ->rawParams( $lang->pipeList( $otherSizes ) )
391  ->params( count( $otherSizes ) )
392  ->parse()
393  );
394  }
395  } elseif ( $width == 0 && $height == 0 ) {
396  # Some sort of audio file that doesn't have dimensions
397  # Don't output a no hi res message for such a file
398  $msgsmall = '';
399  } else {
400  # Image is small enough to show full size on image page
401  $msgsmall = $this->getContext()->msg( 'file-nohires' )->parse();
402  }
403 
404  $params['width'] = $width;
405  $params['height'] = $height;
406  $thumbnail = $this->displayImg->transform( $params );
407  Linker::processResponsiveImages( $this->displayImg, $thumbnail, $params );
408 
409  $anchorclose = Html::rawElement(
410  'div',
411  [ 'class' => 'mw-filepage-resolutioninfo' ],
412  $msgsmall
413  );
414 
415  $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
416  if ( $isMulti ) {
417  $out->addModules( 'mediawiki.page.image.pagination' );
418  $out->addHTML( '<table class="multipageimage"><tr><td>' );
419  }
420 
421  if ( $thumbnail ) {
422  $options = [
423  'alt' => $this->displayImg->getTitle()->getPrefixedText(),
424  'file-link' => true,
425  ];
426  $out->addHTML( '<div class="fullImageLink" id="file">' .
427  $thumbnail->toHtml( $options ) .
428  $anchorclose . "</div>\n" );
429  }
430 
431  if ( $isMulti ) {
432  $count = $this->displayImg->pageCount();
433 
434  if ( $page > 1 ) {
435  $label = $out->parse( $this->getContext()->msg( 'imgmultipageprev' )->text(), false );
436  // on the client side, this link is generated in ajaxifyPageNavigation()
437  // in the mediawiki.page.image.pagination module
439  $this->getTitle(),
440  $label,
441  [],
442  [ 'page' => $page - 1 ]
443  );
444  $thumb1 = Linker::makeThumbLinkObj(
445  $this->getTitle(),
446  $this->displayImg,
447  $link,
448  $label,
449  'none',
450  [ 'page' => $page - 1 ]
451  );
452  } else {
453  $thumb1 = '';
454  }
455 
456  if ( $page < $count ) {
457  $label = $this->getContext()->msg( 'imgmultipagenext' )->text();
459  $this->getTitle(),
460  $label,
461  [],
462  [ 'page' => $page + 1 ]
463  );
464  $thumb2 = Linker::makeThumbLinkObj(
465  $this->getTitle(),
466  $this->displayImg,
467  $link,
468  $label,
469  'none',
470  [ 'page' => $page + 1 ]
471  );
472  } else {
473  $thumb2 = '';
474  }
475 
477 
478  $formParams = [
479  'name' => 'pageselector',
480  'action' => $wgScript,
481  ];
482  $options = [];
483  for ( $i = 1; $i <= $count; $i++ ) {
484  $options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page );
485  }
486  $select = Xml::tags( 'select',
487  [ 'id' => 'pageselector', 'name' => 'page' ],
488  implode( "\n", $options ) );
489 
490  $out->addHTML(
491  '</td><td><div class="multipageimagenavbox">' .
492  Xml::openElement( 'form', $formParams ) .
493  Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
494  $this->getContext()->msg( 'imgmultigoto' )->rawParams( $select )->parse() .
495  Xml::submitButton( $this->getContext()->msg( 'imgmultigo' )->text() ) .
496  Xml::closeElement( 'form' ) .
497  "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
498  );
499  }
500  } elseif ( $this->displayImg->isSafeFile() ) {
501  # if direct link is allowed but it's not a renderable image, show an icon.
502  $icon = $this->displayImg->iconThumb();
503 
504  $out->addHTML( '<div class="fullImageLink" id="file">' .
505  $icon->toHtml( [ 'file-link' => true ] ) .
506  "</div>\n" );
507  }
508 
509  $longDesc = $this->getContext()->msg( 'parentheses', $this->displayImg->getLongDesc() )->text();
510 
511  $handler = $this->displayImg->getHandler();
512 
513  // If this is a filetype with potential issues, warn the user.
514  if ( $handler ) {
515  $warningConfig = $handler->getWarningConfig( $this->displayImg );
516 
517  if ( $warningConfig !== null ) {
518  // The warning will be displayed via CSS and JavaScript.
519  // We just need to tell the client side what message to use.
520  $output = $this->getContext()->getOutput();
521  $output->addJsConfigVars( 'wgFileWarning', $warningConfig );
522  $output->addModules( $warningConfig['module'] );
523  $output->addModules( 'mediawiki.filewarning' );
524  }
525  }
526 
527  $medialink = "[[Media:$filename|$linktext]]";
528 
529  if ( !$this->displayImg->isSafeFile() ) {
530  $warning = $this->getContext()->msg( 'mediawarning' )->plain();
531  // dirmark is needed here to separate the file name, which
532  // most likely ends in Latin characters, from the description,
533  // which may begin with the file type. In RTL environment
534  // this will get messy.
535  // The dirmark, however, must not be immediately adjacent
536  // to the filename, because it can get copied with it.
537  // See bug 25277.
538  // @codingStandardsIgnoreStart Ignore long line
539  $out->addWikiText( <<<EOT
540 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
541 <div class="mediaWarning">$warning</div>
542 EOT
543  );
544  // @codingStandardsIgnoreEnd
545  } else {
546  $out->addWikiText( <<<EOT
547 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
548 </div>
549 EOT
550  );
551  }
552 
553  $renderLangOptions = $this->displayImg->getAvailableLanguages();
554  if ( count( $renderLangOptions ) >= 1 ) {
555  $currentLanguage = $renderLang;
556  $defaultLang = $this->displayImg->getDefaultRenderLanguage();
557  if ( is_null( $currentLanguage ) ) {
558  $currentLanguage = $defaultLang;
559  }
560  $out->addHTML( $this->doRenderLangOpt( $renderLangOptions, $currentLanguage, $defaultLang ) );
561  }
562 
563  // Add cannot animate thumbnail warning
564  if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
565  // Include the extension so wiki admins can
566  // customize it on a per file-type basis
567  // (aka say things like use format X instead).
568  // additionally have a specific message for
569  // file-no-thumb-animation-gif
570  $ext = $this->displayImg->getExtension();
571  $noAnimMesg = wfMessageFallback(
572  'file-no-thumb-animation-' . $ext,
573  'file-no-thumb-animation'
574  )->plain();
575 
576  $out->addWikiText( <<<EOT
577 <div class="mw-noanimatethumb">{$noAnimMesg}</div>
578 EOT
579  );
580  }
581 
582  if ( !$this->displayImg->isLocal() ) {
583  $this->printSharedImageText();
584  }
585  } else {
586  # Image does not exist
587  if ( !$this->getId() ) {
588  # No article exists either
589  # Show deletion log to be consistent with normal articles
591  $out,
592  [ 'delete', 'move' ],
593  $this->getTitle()->getPrefixedText(),
594  '',
595  [ 'lim' => 10,
596  'conds' => [ "log_action != 'revision'" ],
597  'showIfEmpty' => false,
598  'msgKey' => [ 'moveddeleted-notice' ]
599  ]
600  );
601  }
602 
603  if ( $wgEnableUploads && $user->isAllowed( 'upload' ) ) {
604  // Only show an upload link if the user can upload
605  $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
606  $nofile = [
607  'filepage-nofile-link',
608  $uploadTitle->getFullURL( [ 'wpDestFile' => $this->mPage->getFile()->getName() ] )
609  ];
610  } else {
611  $nofile = 'filepage-nofile';
612  }
613  // Note, if there is an image description page, but
614  // no image, then this setRobotPolicy is overridden
615  // by Article::View().
616  $out->setRobotPolicy( 'noindex,nofollow' );
617  $out->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
618  if ( !$this->getId() && $wgSend404Code ) {
619  // If there is no image, no shared image, and no description page,
620  // output a 404, to be consistent with Article::showMissingArticle.
621  $request->response()->statusHeader( 404 );
622  }
623  }
624  $out->setFileVersion( $this->displayImg );
625  }
626 
634  private function getThumbPrevText( $params, $sizeLinkBigImagePreview ) {
635  if ( $sizeLinkBigImagePreview ) {
636  // Show a different message of preview is different format from original.
637  $previewTypeDiffers = false;
638  $origExt = $thumbExt = $this->displayImg->getExtension();
639  if ( $this->displayImg->getHandler() ) {
640  $origMime = $this->displayImg->getMimeType();
641  $typeParams = $params;
642  $this->displayImg->getHandler()->normaliseParams( $this->displayImg, $typeParams );
643  list( $thumbExt, $thumbMime ) = $this->displayImg->getHandler()->getThumbType(
644  $origExt, $origMime, $typeParams );
645  if ( $thumbMime !== $origMime ) {
646  $previewTypeDiffers = true;
647  }
648  }
649  if ( $previewTypeDiffers ) {
650  return $this->getContext()->msg( 'show-big-image-preview-differ' )->
651  rawParams( $sizeLinkBigImagePreview )->
652  params( strtoupper( $origExt ) )->
653  params( strtoupper( $thumbExt ) )->
654  parse();
655  } else {
656  return $this->getContext()->msg( 'show-big-image-preview' )->
657  rawParams( $sizeLinkBigImagePreview )->
658  parse();
659  }
660  } else {
661  return '';
662  }
663  }
664 
672  private function makeSizeLink( $params, $width, $height ) {
673  $params['width'] = $width;
674  $params['height'] = $height;
675  $thumbnail = $this->displayImg->transform( $params );
676  if ( $thumbnail && !$thumbnail->isError() ) {
677  return Html::rawElement( 'a', [
678  'href' => $thumbnail->getUrl(),
679  'class' => 'mw-thumbnail-link'
680  ], $this->getContext()->msg( 'show-big-image-size' )->numParams(
681  $thumbnail->getWidth(), $thumbnail->getHeight()
682  )->parse() );
683  } else {
684  return '';
685  }
686  }
687 
691  protected function printSharedImageText() {
692  $out = $this->getContext()->getOutput();
693  $this->loadFile();
694 
695  $descUrl = $this->mPage->getFile()->getDescriptionUrl();
696  $descText = $this->mPage->getFile()->getDescriptionText( $this->getContext()->getLanguage() );
697 
698  /* Add canonical to head if there is no local page for this shared file */
699  if ( $descUrl && $this->mPage->getId() == 0 ) {
700  $out->setCanonicalUrl( $descUrl );
701  }
702 
703  $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
704  $repo = $this->mPage->getFile()->getRepo()->getDisplayName();
705 
706  if ( $descUrl &&
707  $descText &&
708  $this->getContext()->msg( 'sharedupload-desc-here' )->plain() !== '-'
709  ) {
710  $out->wrapWikiMsg( $wrap, [ 'sharedupload-desc-here', $repo, $descUrl ] );
711  } elseif ( $descUrl &&
712  $this->getContext()->msg( 'sharedupload-desc-there' )->plain() !== '-'
713  ) {
714  $out->wrapWikiMsg( $wrap, [ 'sharedupload-desc-there', $repo, $descUrl ] );
715  } else {
716  $out->wrapWikiMsg( $wrap, [ 'sharedupload', $repo ], ''/*BACKCOMPAT*/ );
717  }
718 
719  if ( $descText ) {
720  $this->mExtraDescription = $descText;
721  }
722  }
723 
724  public function getUploadUrl() {
725  $this->loadFile();
726  $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
727  return $uploadTitle->getFullURL( [
728  'wpDestFile' => $this->mPage->getFile()->getName(),
729  'wpForReUpload' => 1
730  ] );
731  }
732 
737  protected function uploadLinksBox() {
739 
740  if ( !$wgEnableUploads ) {
741  return;
742  }
743 
744  $this->loadFile();
745  if ( !$this->mPage->getFile()->isLocal() ) {
746  return;
747  }
748 
749  $out = $this->getContext()->getOutput();
750  $out->addHTML( "<ul>\n" );
751 
752  # "Upload a new version of this file" link
753  $canUpload = $this->getTitle()->quickUserCan( 'upload', $this->getContext()->getUser() );
754  if ( $canUpload && UploadBase::userCanReUpload(
755  $this->getContext()->getUser(),
756  $this->mPage->getFile() )
757  ) {
758  $ulink = Linker::makeExternalLink(
759  $this->getUploadUrl(),
760  $this->getContext()->msg( 'uploadnewversion-linktext' )->text()
761  );
762  $out->addHTML( "<li id=\"mw-imagepage-reupload-link\">"
763  . "<div class=\"plainlinks\">{$ulink}</div></li>\n" );
764  } else {
765  $out->addHTML( "<li id=\"mw-imagepage-upload-disallowed\">"
766  . $this->getContext()->msg( 'upload-disallowed-here' )->escaped() . "</li>\n" );
767  }
768 
769  $out->addHTML( "</ul>\n" );
770  }
771 
775  protected function closeShowImage() {
776  }
777 
782  protected function imageHistory() {
783  $this->loadFile();
784  $out = $this->getContext()->getOutput();
785  $pager = new ImageHistoryPseudoPager( $this );
786  $out->addHTML( $pager->getBody() );
787  $out->preventClickjacking( $pager->getPreventClickjacking() );
788 
789  $this->mPage->getFile()->resetHistory(); // free db resources
790 
791  # Exist check because we don't want to show this on pages where an image
792  # doesn't exist along with the noimage message, that would suck. -ævar
793  if ( $this->mPage->getFile()->exists() ) {
794  $this->uploadLinksBox();
795  }
796  }
797 
803  protected function queryImageLinks( $target, $limit ) {
804  $dbr = wfGetDB( DB_REPLICA );
805 
806  return $dbr->select(
807  [ 'imagelinks', 'page' ],
808  [ 'page_namespace', 'page_title', 'il_to' ],
809  [ 'il_to' => $target, 'il_from = page_id' ],
810  __METHOD__,
811  [ 'LIMIT' => $limit + 1, 'ORDER BY' => 'il_from', ]
812  );
813  }
814 
815  protected function imageLinks() {
816  $limit = 100;
817 
818  $out = $this->getContext()->getOutput();
819 
820  $rows = [];
821  $redirects = [];
822  foreach ( $this->getTitle()->getRedirectsHere( NS_FILE ) as $redir ) {
823  $redirects[$redir->getDBkey()] = [];
824  $rows[] = (object)[
825  'page_namespace' => NS_FILE,
826  'page_title' => $redir->getDBkey(),
827  ];
828  }
829 
830  $res = $this->queryImageLinks( $this->getTitle()->getDBkey(), $limit + 1 );
831  foreach ( $res as $row ) {
832  $rows[] = $row;
833  }
834  $count = count( $rows );
835 
836  $hasMore = $count > $limit;
837  if ( !$hasMore && count( $redirects ) ) {
838  $res = $this->queryImageLinks( array_keys( $redirects ),
839  $limit - count( $rows ) + 1 );
840  foreach ( $res as $row ) {
841  $redirects[$row->il_to][] = $row;
842  $count++;
843  }
844  $hasMore = ( $res->numRows() + count( $rows ) ) > $limit;
845  }
846 
847  if ( $count == 0 ) {
848  $out->wrapWikiMsg(
849  Html::rawElement( 'div',
850  [ 'id' => 'mw-imagepage-nolinkstoimage' ], "\n$1\n" ),
851  'nolinkstoimage'
852  );
853  return;
854  }
855 
856  $out->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
857  if ( !$hasMore ) {
858  $out->addWikiMsg( 'linkstoimage', $count );
859  } else {
860  // More links than the limit. Add a link to [[Special:Whatlinkshere]]
861  $out->addWikiMsg( 'linkstoimage-more',
862  $this->getContext()->getLanguage()->formatNum( $limit ),
863  $this->getTitle()->getPrefixedDBkey()
864  );
865  }
866 
867  $out->addHTML(
868  Html::openElement( 'ul',
869  [ 'class' => 'mw-imagepage-linkstoimage' ] ) . "\n"
870  );
871  $count = 0;
872 
873  // Sort the list by namespace:title
874  usort( $rows, [ $this, 'compare' ] );
875 
876  // Create links for every element
877  $currentCount = 0;
878  foreach ( $rows as $element ) {
879  $currentCount++;
880  if ( $currentCount > $limit ) {
881  break;
882  }
883 
884  $query = [];
885  # Add a redirect=no to make redirect pages reachable
886  if ( isset( $redirects[$element->page_title] ) ) {
887  $query['redirect'] = 'no';
888  }
890  Title::makeTitle( $element->page_namespace, $element->page_title ),
891  null, [], $query
892  );
893  if ( !isset( $redirects[$element->page_title] ) ) {
894  # No redirects
895  $liContents = $link;
896  } elseif ( count( $redirects[$element->page_title] ) === 0 ) {
897  # Redirect without usages
898  $liContents = $this->getContext()->msg( 'linkstoimage-redirect' )
899  ->rawParams( $link, '' )
900  ->parse();
901  } else {
902  # Redirect with usages
903  $li = '';
904  foreach ( $redirects[$element->page_title] as $row ) {
905  $currentCount++;
906  if ( $currentCount > $limit ) {
907  break;
908  }
909 
910  $link2 = Linker::linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
911  $li .= Html::rawElement(
912  'li',
913  [ 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
914  $link2
915  ) . "\n";
916  }
917 
919  'ul',
920  [ 'class' => 'mw-imagepage-redirectstofile' ],
921  $li
922  ) . "\n";
923  $liContents = $this->getContext()->msg( 'linkstoimage-redirect' )->rawParams(
924  $link, $ul )->parse();
925  }
926  $out->addHTML( Html::rawElement(
927  'li',
928  [ 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
929  $liContents
930  ) . "\n"
931  );
932 
933  };
934  $out->addHTML( Html::closeElement( 'ul' ) . "\n" );
935  $res->free();
936 
937  // Add a links to [[Special:Whatlinkshere]]
938  if ( $count > $limit ) {
939  $out->addWikiMsg( 'morelinkstoimage', $this->getTitle()->getPrefixedDBkey() );
940  }
941  $out->addHTML( Html::closeElement( 'div' ) . "\n" );
942  }
943 
944  protected function imageDupes() {
945  $this->loadFile();
946  $out = $this->getContext()->getOutput();
947 
948  $dupes = $this->mPage->getDuplicates();
949  if ( count( $dupes ) == 0 ) {
950  return;
951  }
952 
953  $out->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
954  $out->addWikiMsg( 'duplicatesoffile',
955  $this->getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->getTitle()->getDBkey()
956  );
957  $out->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
958 
962  foreach ( $dupes as $file ) {
963  $fromSrc = '';
964  if ( $file->isLocal() ) {
965  $link = Linker::linkKnown( $file->getTitle() );
966  } else {
967  $link = Linker::makeExternalLink( $file->getDescriptionUrl(),
968  $file->getTitle()->getPrefixedText() );
969  $fromSrc = $this->getContext()->msg(
970  'shared-repo-from',
971  $file->getRepo()->getDisplayName()
972  )->text();
973  }
974  $out->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
975  }
976  $out->addHTML( "</ul></div>\n" );
977  }
978 
982  public function delete() {
983  $file = $this->mPage->getFile();
984  if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
985  // Standard article deletion
986  parent::delete();
987  return;
988  }
989 
990  $deleter = new FileDeleteForm( $file );
991  $deleter->execute();
992  }
993 
999  function showError( $description ) {
1000  $out = $this->getContext()->getOutput();
1001  $out->setPageTitle( $this->getContext()->msg( 'internalerror' ) );
1002  $out->setRobotPolicy( 'noindex,nofollow' );
1003  $out->setArticleRelated( false );
1004  $out->enableClientCache( false );
1005  $out->addWikiText( $description );
1006  }
1007 
1016  protected function compare( $a, $b ) {
1017  if ( $a->page_namespace == $b->page_namespace ) {
1018  return strcmp( $a->page_title, $b->page_title );
1019  } else {
1020  return $a->page_namespace - $b->page_namespace;
1021  }
1022  }
1023 
1032  public function getImageLimitsFromOption( $user, $optionName ) {
1034 
1035  $option = $user->getIntOption( $optionName );
1036  if ( !isset( $wgImageLimits[$option] ) ) {
1037  $option = User::getDefaultOption( $optionName );
1038  }
1039 
1040  // The user offset might still be incorrect, specially if
1041  // $wgImageLimits got changed (see bug #8858).
1042  if ( !isset( $wgImageLimits[$option] ) ) {
1043  // Default to the first offset in $wgImageLimits
1044  $option = 0;
1045  }
1046 
1047  return isset( $wgImageLimits[$option] )
1048  ? $wgImageLimits[$option]
1049  : [ 800, 600 ]; // if nothing is set, fallback to a hardcoded default
1050  }
1051 
1060  protected function doRenderLangOpt( array $langChoices, $curLang, $defaultLang ) {
1061  global $wgScript;
1062  sort( $langChoices );
1063  $curLang = wfBCP47( $curLang );
1064  $defaultLang = wfBCP47( $defaultLang );
1065  $opts = '';
1066  $haveCurrentLang = false;
1067  $haveDefaultLang = false;
1068 
1069  // We make a list of all the language choices in the file.
1070  // Additionally if the default language to render this file
1071  // is not included as being in this file (for example, in svgs
1072  // usually the fallback content is the english content) also
1073  // include a choice for that. Last of all, if we're viewing
1074  // the file in a language not on the list, add it as a choice.
1075  foreach ( $langChoices as $lang ) {
1076  $code = wfBCP47( $lang );
1077  $name = Language::fetchLanguageName( $code, $this->getContext()->getLanguage()->getCode() );
1078  if ( $name !== '' ) {
1079  $display = $this->getContext()->msg( 'img-lang-opt', $code, $name )->text();
1080  } else {
1081  $display = $code;
1082  }
1083  $opts .= "\n" . Xml::option( $display, $code, $curLang === $code );
1084  if ( $curLang === $code ) {
1085  $haveCurrentLang = true;
1086  }
1087  if ( $defaultLang === $code ) {
1088  $haveDefaultLang = true;
1089  }
1090  }
1091  if ( !$haveDefaultLang ) {
1092  // Its hard to know if the content is really in the default language, or
1093  // if its just unmarked content that could be in any language.
1094  $opts = Xml::option(
1095  $this->getContext()->msg( 'img-lang-default' )->text(),
1096  $defaultLang,
1097  $defaultLang === $curLang
1098  ) . $opts;
1099  }
1100  if ( !$haveCurrentLang && $defaultLang !== $curLang ) {
1101  $name = Language::fetchLanguageName( $curLang, $this->getContext()->getLanguage()->getCode() );
1102  if ( $name !== '' ) {
1103  $display = $this->getContext()->msg( 'img-lang-opt', $curLang, $name )->text();
1104  } else {
1105  $display = $curLang;
1106  }
1107  $opts = Xml::option( $display, $curLang, true ) . $opts;
1108  }
1109 
1110  $select = Html::rawElement(
1111  'select',
1112  [ 'id' => 'mw-imglangselector', 'name' => 'lang' ],
1113  $opts
1114  );
1115  $submit = Xml::submitButton( $this->getContext()->msg( 'img-lang-go' )->text() );
1116 
1117  $formContents = $this->getContext()->msg( 'img-lang-info' )
1118  ->rawParams( $select, $submit )
1119  ->parse();
1120  $formContents .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() );
1121 
1122  $langSelectLine = Html::rawElement( 'div', [ 'id' => 'mw-imglangselector-line' ],
1123  Html::rawElement( 'form', [ 'action' => $wgScript ], $formContents )
1124  );
1125  return $langSelectLine;
1126  }
1127 
1142  protected function getDisplayWidthHeight( $maxWidth, $maxHeight, $width, $height ) {
1143  if ( !$maxWidth || !$maxHeight ) {
1144  // should never happen
1145  throw new MWException( 'Using a choice from $wgImageLimits that is 0x0' );
1146  }
1147 
1148  if ( !$width || !$height ) {
1149  return [ 0, 0 ];
1150  }
1151 
1152  # Calculate the thumbnail size.
1153  if ( $width <= $maxWidth && $height <= $maxHeight ) {
1154  // Vectorized image, do nothing.
1155  } elseif ( $width / $height >= $maxWidth / $maxHeight ) {
1156  # The limiting factor is the width, not the height.
1157  $height = round( $height * $maxWidth / $width );
1158  $width = $maxWidth;
1159  # Note that $height <= $maxHeight now.
1160  } else {
1161  $newwidth = floor( $width * $maxHeight / $height );
1162  $height = round( $height * $newwidth / $width );
1163  $width = $newwidth;
1164  # Note that $height <= $maxHeight now, but might not be identical
1165  # because of rounding.
1166  }
1167  return [ $width, $height ];
1168  }
1169 
1178  protected function getThumbSizes( $origWidth, $origHeight ) {
1180  if ( $this->displayImg->getRepo()->canTransformVia404() ) {
1181  $thumbSizes = $wgImageLimits;
1182  // Also include the full sized resolution in the list, so
1183  // that users know they can get it. This will link to the
1184  // original file asset if mustRender() === false. In the case
1185  // that we mustRender, some users have indicated that they would
1186  // find it useful to have the full size image in the rendered
1187  // image format.
1188  $thumbSizes[] = [ $origWidth, $origHeight ];
1189  } else {
1190  # Creating thumb links triggers thumbnail generation.
1191  # Just generate the thumb for the current users prefs.
1192  $thumbSizes = [
1193  $this->getImageLimitsFromOption( $this->getContext()->getUser(), 'thumbsize' )
1194  ];
1195  if ( !$this->displayImg->mustRender() ) {
1196  // We can safely include a link to the "full-size" preview,
1197  // without actually rendering.
1198  $thumbSizes[] = [ $origWidth, $origHeight ];
1199  }
1200  }
1201  return $thumbSizes;
1202  }
1203 
1208  public function getFile() {
1209  return $this->mPage->getFile();
1210  }
1211 
1216  public function isLocal() {
1217  return $this->mPage->isLocal();
1218  }
1219 
1224  public function getDuplicates() {
1225  return $this->mPage->getDuplicates();
1226  }
1227 
1232  public function getForeignCategories() {
1233  $this->mPage->getForeignCategories();
1234  }
1235 
1236 }
viewRedirect($target, $appendSubtitle=true, $forceKnown=false)
Return the HTML for the top of a redirect page.
Definition: Article.php:1530
static closeElement($element)
Returns "".
Definition: Html.php:305
$article view()
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return an< a > element with HTML attributes $attribs and contents $html will be returned If you return $ret will be returned and may include noclasses & $html
Definition: hooks.txt:1940
deferred txt A few of the database updates required by various functions here can be deferred until after the result page is displayed to the user For updating the view updating the linked to tables after a etc PHP does not yet have any way to tell the server to actually return and disconnect while still running these but it might have such a feature in the future We handle these by creating a deferred update object and putting those objects on a global list
Definition: deferred.txt:11
wfGetDB($db, $groups=[], $wiki=false)
Get a Database object.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition: hooks.txt:806
static processResponsiveImages($file, $thumb, $hp)
Process responsive images: add 1.5x and 2x subimages to the thumbnail, where applicable.
Definition: Linker.php:746
bool $fileLoaded
Definition: ImagePage.php:36
the array() calling protocol came about after MediaWiki 1.4rc1.
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
Definition: hooks.txt:1559
either a plain
Definition: hooks.txt:1991
$wgScript
The URL path to index.php.
static element($element, $attribs=null, $contents= '', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
queryImageLinks($target, $limit)
Definition: ImagePage.php:803
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name If you don't need a full Title object...
Definition: SpecialPage.php:82
showTOC($metadata)
Create the TOC.
Definition: ImagePage.php:235
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:209
if(!isset($args[0])) $lang
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:758
getUploadUrl()
Definition: ImagePage.php:724
Class for viewing MediaWiki article and history.
Definition: Article.php:34
Class for viewing MediaWiki file description pages.
Definition: ImagePage.php:28
FileRepo $repo
Definition: ImagePage.php:33
wfMessageFallback()
This function accepts multiple message keys and returns a message instance for the first message whic...
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
printSharedImageText()
Show a notice that the file is from a shared repository.
Definition: ImagePage.php:691
wfLocalFile($title)
Get an object referring to a locally registered file.
imageHistory()
If the page we've just displayed is in the "Image" namespace, we follow it with an upload history of ...
Definition: ImagePage.php:782
uploadLinksBox()
Print out the various links at the bottom of the image page, e.g.
Definition: ImagePage.php:737
globals will be eliminated from MediaWiki replaced by an application object which would be passed to constructors Whether that would be an convenient solution remains to be but certainly PHP makes such object oriented programming models easier than they were in previous versions For the time being MediaWiki programmers will have to work in an environment with some global context At the time of globals were initialised on startup by MediaWiki of these were configuration which are documented in DefaultSettings php There is no comprehensive documentation for the remaining however some of the most important ones are listed below They are typically initialised either in index php or in Setup php For a description of the see design txt $wgTitle Title object created from the request URL $wgOut OutputPage object for HTTP response $wgUser User object for the user associated with the current request $wgLang Language object selected by user preferences $wgContLang Language object associated with the wiki being viewed $wgParser Parser object Parser extensions register their hooks here $wgRequest WebRequest object
Definition: globals.txt:25
static submitButton($value, $attribs=[])
Convenience function to build an HTML submit button When $wgUseMediaWikiUIEverywhere is true it will ...
Definition: Xml.php:460
static userCanReUpload(User $user, File $img)
Check if a user is the last uploader.
static showLogExtract(&$out, $types=[], $page= '', $user= '', $param=[])
Show log extract.
getForeignCategories()
Definition: ImagePage.php:1232
getThumbSizes($origWidth, $origHeight)
Get alternative thumbnail sizes.
Definition: ImagePage.php:1178
usually copyright or history_copyright This message must be in HTML not wikitext & $link
Definition: hooks.txt:2893
$wgEnableUploads
Uploads have to be specially set up to be secure.
getContext()
Gets the context this Article is executed in.
Definition: Article.php:2034
static closeElement($element)
Shortcut to close an XML element.
Definition: Xml.php:118
showError($description)
Display an error with a wikitext description.
Definition: ImagePage.php:999
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:247
$wgShowEXIF
Show Exif data, on by default if available.
wfEscapeWikiText($text)
Escapes the given text so that it may be output using addWikiText() without any linking, formatting, etc.
$css
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context $options
Definition: hooks.txt:1050
$res
Definition: database.txt:21
static option($text, $value=null, $selected=false, $attribs=[])
Convenience function to build an HTML drop-down list item.
Definition: Xml.php:485
static openElement($element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
$wgImageLimits
Limit images on image description pages to a user-selectable limit.
getTitle()
Get the title object of the article.
Definition: Article.php:173
$params
File $displayImg
Definition: ImagePage.php:30
wfBCP47($code)
Get the normalised IETF language tag See unit test for examples.
namespace and then decline to actually register it file or subcat img or subcat $title
Definition: hooks.txt:957
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:255
static run($event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
Definition: Hooks.php:131
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition: design.txt:12
const NS_FILE
Definition: Defines.php:62
addModules($modules)
render()
Handler for action=render Include body text only; none of the image extras.
Definition: ImagePage.php:90
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
Definition: distributors.txt:9
Special handling for file pages.
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable & $code
Definition: hooks.txt:806
compare($a, $b)
Callback for usort() to do link sorts by (namespace, title) Function copied from Title::compare() ...
Definition: ImagePage.php:1016
static fetchLanguageName($code, $inLanguage=null, $include= 'all')
Definition: Language.php:888
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a local account $user
Definition: hooks.txt:246
$wgSVGMaxSize
Don't scale a SVG larger than this.
static escapeId($id, $options=[])
Given a value, escape it so that it can be used in an id attribute and return it. ...
Definition: Sanitizer.php:1170
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object & $output
Definition: hooks.txt:1050
static makeExternalLink($url, $text, $escape=true, $linktype= '', $attribs=[], $title=null)
Make an external link.
Definition: Linker.php:934
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition: injection.txt:35
static tags($element, $attribs=null, $contents)
Same as Xml::element(), but does not escape contents.
Definition: Xml.php:131
error also a ContextSource you ll probably need to make sure the header is varied on $request
Definition: hooks.txt:2577
getId()
Call to WikiPage function for backwards compatibility.
Definition: Article.php:2278
getDisplayWidthHeight($maxWidth, $maxHeight, $width, $height)
Get the width and height to display image at.
Definition: ImagePage.php:1142
getOldID()
Definition: Article.php:260
setFile($file)
Definition: ImagePage.php:59
getDisplayName()
Get the human-readable name of the repo.
Definition: FileRepo.php:1765
newPage(Title $title)
Definition: ImagePage.php:50
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
Definition: hooks.txt:1050
bool $mExtraDescription
Definition: ImagePage.php:39
getDisplayedFile()
Definition: ImagePage.php:224
makeSizeLink($params, $width, $height)
Creates an thumbnail of specified size and returns an HTML link to it.
Definition: ImagePage.php:672
$count
addJsConfigVars($keys, $value=null)
Add one or more variables to be set in mw.config in JavaScript.
const DB_REPLICA
Definition: defines.php:22
doRenderLangOpt(array $langChoices, $curLang, $defaultLang)
Output a drop-down box for language options for the file.
Definition: ImagePage.php:1060
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output modifiable modifiable after all normalizations have been except for the $wgMaxImageArea check set to true or false to override the $wgMaxImageArea check result gives extension the possibility to transform it themselves $handler
Definition: hooks.txt:806
getThumbPrevText($params, $sizeLinkBigImagePreview)
Make the text under the image to say what size preview.
Definition: ImagePage.php:634
getUser($audience=Revision::FOR_PUBLIC, User $user=null)
Call to WikiPage function for backwards compatibility.
Definition: Article.php:2376
WikiFilePage $mPage
Definition: ImagePage.php:44
static makeThumbLinkObj(Title $title, $file, $label= '', $alt, $align= 'right', $params=[], $framed=false, $manualthumb="")
Make HTML for a thumbnail including image, border and caption.
Definition: Linker.php:598
static getDefaultOption($opt)
Get a given default option value.
Definition: User.php:1563
$wgSend404Code
Some web hosts attempt to rewrite all responses with a 404 (not found) status code, mangling or hiding MediaWiki's output.
getImageLimitsFromOption($user, $optionName)
Returns the corresponding $wgImageLimits entry for the selected user option.
Definition: ImagePage.php:1032
File deletion user interface.
wfFindFile($title, $options=[])
Find a file.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached one of or reset my talk my contributions etc etc otherwise the built in rate limiting checks are if enabled allows for interception of redirect as a string mapping parameter names to values & $type
Definition: hooks.txt:2495
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:511
makeMetadataTable($metadata)
Make a table with metadata to be shown in the output page.
Definition: ImagePage.php:261
getContentObject()
Overloading Article's getContentObject method.
Definition: ImagePage.php:289
do that in ParserLimitReportFormat instead use this to modify the parameters of the image and a DIV can begin in one section and end in another Make sure your code can handle that case gracefully See the EditSectionClearerLink extension for an example zero but section is usually empty its values are the globals values before the output is cached $page
Definition: hooks.txt:2495
closeShowImage()
For overloading.
Definition: ImagePage.php:775
openShowImage()
Definition: ImagePage.php:297
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:304