MediaWiki  1.27.4
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 
60  public static function newFromID( $id ) {
61  $t = Title::newFromID( $id );
62  # @todo FIXME: Doesn't inherit right
63  return $t == null ? null : new self( $t );
64  # return $t == null ? null : new static( $t ); // PHP 5.3
65  }
66 
71  public function setFile( $file ) {
72  $this->mPage->setFile( $file );
73  $this->displayImg = $file;
74  $this->fileLoaded = true;
75  }
76 
77  protected function loadFile() {
78  if ( $this->fileLoaded ) {
79  return;
80  }
81  $this->fileLoaded = true;
82 
83  $this->displayImg = $img = false;
84 
85  Hooks::run( 'ImagePageFindFile', [ $this, &$img, &$this->displayImg ] );
86  if ( !$img ) { // not set by hook?
87  $img = wfFindFile( $this->getTitle() );
88  if ( !$img ) {
89  $img = wfLocalFile( $this->getTitle() );
90  }
91  }
92  $this->mPage->setFile( $img );
93  if ( !$this->displayImg ) { // not set by hook?
94  $this->displayImg = $img;
95  }
96  $this->repo = $img->getRepo();
97  }
98 
103  public function render() {
104  $this->getContext()->getOutput()->setArticleBodyOnly( true );
105  parent::view();
106  }
107 
108  public function view() {
110 
111  $out = $this->getContext()->getOutput();
112  $request = $this->getContext()->getRequest();
113  $diff = $request->getVal( 'diff' );
114  $diffOnly = $request->getBool(
115  'diffonly',
116  $this->getContext()->getUser()->getOption( 'diffonly' )
117  );
118 
119  if ( $this->getTitle()->getNamespace() != NS_FILE || ( $diff !== null && $diffOnly ) ) {
120  parent::view();
121  return;
122  }
123 
124  $this->loadFile();
125 
126  if ( $this->getTitle()->getNamespace() == NS_FILE && $this->mPage->getFile()->getRedirected() ) {
127  if ( $this->getTitle()->getDBkey() == $this->mPage->getFile()->getName() || $diff !== null ) {
128  // mTitle is the same as the redirect target so ask Article
129  // to perform the redirect for us.
130  $request->setVal( 'diffonly', 'true' );
131  parent::view();
132  return;
133  } else {
134  // mTitle is not the same as the redirect target so it is
135  // probably the redirect page itself. Fake the redirect symbol
136  $out->setPageTitle( $this->getTitle()->getPrefixedText() );
137  $out->addHTML( $this->viewRedirect(
138  Title::makeTitle( NS_FILE, $this->mPage->getFile()->getName() ),
139  /* $appendSubtitle */ true,
140  /* $forceKnown */ true )
141  );
142  $this->mPage->doViewUpdates( $this->getContext()->getUser(), $this->getOldID() );
143  return;
144  }
145  }
146 
147  if ( $wgShowEXIF && $this->displayImg->exists() ) {
148  // @todo FIXME: Bad interface, see note on MediaHandler::formatMetadata().
149  $formattedMetadata = $this->displayImg->formatMetadata( $this->getContext() );
150  $showmeta = $formattedMetadata !== false;
151  } else {
152  $showmeta = false;
153  }
154 
155  if ( !$diff && $this->displayImg->exists() ) {
156  $out->addHTML( $this->showTOC( $showmeta ) );
157  }
158 
159  if ( !$diff ) {
160  $this->openShowImage();
161  }
162 
163  # No need to display noarticletext, we use our own message, output in openShowImage()
164  if ( $this->mPage->getId() ) {
165  # NS_FILE is in the user language, but this section (the actual wikitext)
166  # should be in page content language
167  $pageLang = $this->getTitle()->getPageViewLanguage();
168  $out->addHTML( Xml::openElement( 'div', [ 'id' => 'mw-imagepage-content',
169  'lang' => $pageLang->getHtmlCode(), 'dir' => $pageLang->getDir(),
170  'class' => 'mw-content-' . $pageLang->getDir() ] ) );
171 
172  parent::view();
173 
174  $out->addHTML( Xml::closeElement( 'div' ) );
175  } else {
176  # Just need to set the right headers
177  $out->setArticleFlag( true );
178  $out->setPageTitle( $this->getTitle()->getPrefixedText() );
179  $this->mPage->doViewUpdates( $this->getContext()->getUser(), $this->getOldID() );
180  }
181 
182  # Show shared description, if needed
183  if ( $this->mExtraDescription ) {
184  $fol = $this->getContext()->msg( 'shareddescriptionfollows' );
185  if ( !$fol->isDisabled() ) {
186  $out->addWikiText( $fol->plain() );
187  }
188  $out->addHTML( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
189  }
190 
191  $this->closeShowImage();
192  $this->imageHistory();
193  // TODO: Cleanup the following
194 
195  $out->addHTML( Xml::element( 'h2',
196  [ 'id' => 'filelinks' ],
197  $this->getContext()->msg( 'imagelinks' )->text() ) . "\n" );
198  $this->imageDupes();
199  # @todo FIXME: For some freaky reason, we can't redirect to foreign images.
200  # Yet we return metadata about the target. Definitely an issue in the FileRepo
201  $this->imageLinks();
202 
203  # Allow extensions to add something after the image links
204  $html = '';
205  Hooks::run( 'ImagePageAfterImageLinks', [ $this, &$html ] );
206  if ( $html ) {
207  $out->addHTML( $html );
208  }
209 
210  if ( $showmeta ) {
211  $out->addHTML( Xml::element(
212  'h2',
213  [ 'id' => 'metadata' ],
214  $this->getContext()->msg( 'metadata' )->text() ) . "\n" );
215  $out->addWikiText( $this->makeMetadataTable( $formattedMetadata ) );
216  $out->addModules( [ 'mediawiki.action.view.metadata' ] );
217  }
218 
219  // Add remote Filepage.css
220  if ( !$this->repo->isLocal() ) {
221  $css = $this->repo->getDescriptionStylesheetUrl();
222  if ( $css ) {
223  $out->addStyle( $css );
224  }
225  }
226  // always show the local local Filepage.css, bug 29277
227  $out->addModuleStyles( 'filepage' );
228 
229  // Add MediaWiki styles for a file page
230  $out->addModuleStyles( 'mediawiki.action.view.filepage' );
231  }
232 
236  public function getDisplayedFile() {
237  $this->loadFile();
238  return $this->displayImg;
239  }
240 
247  protected function showTOC( $metadata ) {
248  $r = [
249  '<li><a href="#file">' . $this->getContext()->msg( 'file-anchor-link' )->escaped() . '</a></li>',
250  '<li><a href="#filehistory">' . $this->getContext()->msg( 'filehist' )->escaped() . '</a></li>',
251  '<li><a href="#filelinks">' . $this->getContext()->msg( 'imagelinks' )->escaped() . '</a></li>',
252  ];
253 
254  Hooks::run( 'ImagePageShowTOC', [ $this, &$r ] );
255 
256  if ( $metadata ) {
257  $r[] = '<li><a href="#metadata">' .
258  $this->getContext()->msg( 'metadata' )->escaped() .
259  '</a></li>';
260  }
261 
262  return '<ul id="filetoc">' . implode( "\n", $r ) . '</ul>';
263  }
264 
273  protected function makeMetadataTable( $metadata ) {
274  $r = "<div class=\"mw-imagepage-section-metadata\">";
275  $r .= $this->getContext()->msg( 'metadata-help' )->plain();
276  $r .= "<table id=\"mw_metadata\" class=\"mw_metadata\">\n";
277  foreach ( $metadata as $type => $stuff ) {
278  foreach ( $stuff as $v ) {
279  # @todo FIXME: Why is this using escapeId for a class?!
280  $class = Sanitizer::escapeId( $v['id'] );
281  if ( $type == 'collapsed' ) {
282  // Handled by mediawiki.action.view.metadata module.
283  $class .= ' collapsable';
284  }
285  $r .= "<tr class=\"$class\">\n";
286  $r .= "<th>{$v['name']}</th>\n";
287  $r .= "<td>{$v['value']}</td>\n</tr>";
288  }
289  }
290  $r .= "</table>\n</div>\n";
291  return $r;
292  }
293 
301  public function getContentObject() {
302  $this->loadFile();
303  if ( $this->mPage->getFile() && !$this->mPage->getFile()->isLocal() && 0 == $this->getId() ) {
304  return null;
305  }
306  return parent::getContentObject();
307  }
308 
309  protected function openShowImage() {
311 
312  $this->loadFile();
313  $out = $this->getContext()->getOutput();
314  $user = $this->getContext()->getUser();
315  $lang = $this->getContext()->getLanguage();
316  $dirmark = $lang->getDirMarkEntity();
317  $request = $this->getContext()->getRequest();
318 
319  $max = $this->getImageLimitsFromOption( $user, 'imagesize' );
320  $maxWidth = $max[0];
321  $maxHeight = $max[1];
322 
323  if ( $this->displayImg->exists() ) {
324  # image
325  $page = $request->getIntOrNull( 'page' );
326  if ( is_null( $page ) ) {
327  $params = [];
328  $page = 1;
329  } else {
330  $params = [ 'page' => $page ];
331  }
332 
333  $renderLang = $request->getVal( 'lang' );
334  if ( !is_null( $renderLang ) ) {
335  $handler = $this->displayImg->getHandler();
336  if ( $handler && $handler->validateParam( 'lang', $renderLang ) ) {
337  $params['lang'] = $renderLang;
338  } else {
339  $renderLang = null;
340  }
341  }
342 
343  $width_orig = $this->displayImg->getWidth( $page );
344  $width = $width_orig;
345  $height_orig = $this->displayImg->getHeight( $page );
346  $height = $height_orig;
347 
348  $filename = wfEscapeWikiText( $this->displayImg->getName() );
349  $linktext = $filename;
350 
351  // Use of &$this in hooks triggers warnings in PHP 7.1
352  $imagePage = $this;
353 
354  Hooks::run( 'ImageOpenShowImageInlineBefore', [ &$imagePage, &$out ] );
355 
356  if ( $this->displayImg->allowInlineDisplay() ) {
357  # image
358  # "Download high res version" link below the image
359  # $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
360  # Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
361  # We'll show a thumbnail of this image
362  if ( $width > $maxWidth || $height > $maxHeight || $this->displayImg->isVectorized() ) {
363  list( $width, $height ) = $this->getDisplayWidthHeight(
364  $maxWidth, $maxHeight, $width, $height
365  );
366  $linktext = $this->getContext()->msg( 'show-big-image' )->escaped();
367 
368  $thumbSizes = $this->getThumbSizes( $width_orig, $height_orig );
369  # Generate thumbnails or thumbnail links as needed...
370  $otherSizes = [];
371  foreach ( $thumbSizes as $size ) {
372  // We include a thumbnail size in the list, if it is
373  // less than or equal to the original size of the image
374  // asset ($width_orig/$height_orig). We also exclude
375  // the current thumbnail's size ($width/$height)
376  // since that is added to the message separately, so
377  // it can be denoted as the current size being shown.
378  // Vectorized images are limited by $wgSVGMaxSize big,
379  // so all thumbs less than or equal that are shown.
380  if ( ( ( $size[0] <= $width_orig && $size[1] <= $height_orig )
381  || ( $this->displayImg->isVectorized()
382  && max( $size[0], $size[1] ) <= $wgSVGMaxSize )
383  )
384  && $size[0] != $width && $size[1] != $height
385  ) {
386  $sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] );
387  if ( $sizeLink ) {
388  $otherSizes[] = $sizeLink;
389  }
390  }
391  }
392  $otherSizes = array_unique( $otherSizes );
393 
394  $sizeLinkBigImagePreview = $this->makeSizeLink( $params, $width, $height );
395  $msgsmall = $this->getThumbPrevText( $params, $sizeLinkBigImagePreview );
396  if ( count( $otherSizes ) ) {
397  $msgsmall .= ' ' .
399  'span',
400  [ 'class' => 'mw-filepage-other-resolutions' ],
401  $this->getContext()->msg( 'show-big-image-other' )
402  ->rawParams( $lang->pipeList( $otherSizes ) )
403  ->params( count( $otherSizes ) )
404  ->parse()
405  );
406  }
407  } elseif ( $width == 0 && $height == 0 ) {
408  # Some sort of audio file that doesn't have dimensions
409  # Don't output a no hi res message for such a file
410  $msgsmall = '';
411  } else {
412  # Image is small enough to show full size on image page
413  $msgsmall = $this->getContext()->msg( 'file-nohires' )->parse();
414  }
415 
416  $params['width'] = $width;
417  $params['height'] = $height;
418  $thumbnail = $this->displayImg->transform( $params );
419  Linker::processResponsiveImages( $this->displayImg, $thumbnail, $params );
420 
421  $anchorclose = Html::rawElement(
422  'div',
423  [ 'class' => 'mw-filepage-resolutioninfo' ],
424  $msgsmall
425  );
426 
427  $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
428  if ( $isMulti ) {
429  $out->addModules( 'mediawiki.page.image.pagination' );
430  $out->addHTML( '<table class="multipageimage"><tr><td>' );
431  }
432 
433  if ( $thumbnail ) {
434  $options = [
435  'alt' => $this->displayImg->getTitle()->getPrefixedText(),
436  'file-link' => true,
437  ];
438  $out->addHTML( '<div class="fullImageLink" id="file">' .
439  $thumbnail->toHtml( $options ) .
440  $anchorclose . "</div>\n" );
441  }
442 
443  if ( $isMulti ) {
444  $count = $this->displayImg->pageCount();
445 
446  if ( $page > 1 ) {
447  $label = $out->parse( $this->getContext()->msg( 'imgmultipageprev' )->text(), false );
448  // on the client side, this link is generated in ajaxifyPageNavigation()
449  // in the mediawiki.page.image.pagination module
451  $this->getTitle(),
452  $label,
453  [],
454  [ 'page' => $page - 1 ]
455  );
456  $thumb1 = Linker::makeThumbLinkObj(
457  $this->getTitle(),
458  $this->displayImg,
459  $link,
460  $label,
461  'none',
462  [ 'page' => $page - 1 ]
463  );
464  } else {
465  $thumb1 = '';
466  }
467 
468  if ( $page < $count ) {
469  $label = $this->getContext()->msg( 'imgmultipagenext' )->text();
471  $this->getTitle(),
472  $label,
473  [],
474  [ 'page' => $page + 1 ]
475  );
476  $thumb2 = Linker::makeThumbLinkObj(
477  $this->getTitle(),
478  $this->displayImg,
479  $link,
480  $label,
481  'none',
482  [ 'page' => $page + 1 ]
483  );
484  } else {
485  $thumb2 = '';
486  }
487 
489 
490  $formParams = [
491  'name' => 'pageselector',
492  'action' => $wgScript,
493  ];
494  $options = [];
495  for ( $i = 1; $i <= $count; $i++ ) {
496  $options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page );
497  }
498  $select = Xml::tags( 'select',
499  [ 'id' => 'pageselector', 'name' => 'page' ],
500  implode( "\n", $options ) );
501 
502  $out->addHTML(
503  '</td><td><div class="multipageimagenavbox">' .
504  Xml::openElement( 'form', $formParams ) .
505  Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
506  $this->getContext()->msg( 'imgmultigoto' )->rawParams( $select )->parse() .
507  Xml::submitButton( $this->getContext()->msg( 'imgmultigo' )->text() ) .
508  Xml::closeElement( 'form' ) .
509  "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
510  );
511  }
512  } elseif ( $this->displayImg->isSafeFile() ) {
513  # if direct link is allowed but it's not a renderable image, show an icon.
514  $icon = $this->displayImg->iconThumb();
515 
516  $out->addHTML( '<div class="fullImageLink" id="file">' .
517  $icon->toHtml( [ 'file-link' => true ] ) .
518  "</div>\n" );
519  }
520 
521  $longDesc = $this->getContext()->msg( 'parentheses', $this->displayImg->getLongDesc() )->text();
522 
523  $handler = $this->displayImg->getHandler();
524 
525  // If this is a filetype with potential issues, warn the user.
526  if ( $handler ) {
527  $warningConfig = $handler->getWarningConfig( $this->displayImg );
528 
529  if ( $warningConfig !== null ) {
530  // The warning will be displayed via CSS and JavaScript.
531  // We just need to tell the client side what message to use.
532  $output = $this->getContext()->getOutput();
533  $output->addJsConfigVars( 'wgFileWarning', $warningConfig );
534  $output->addModules( $warningConfig['module'] );
535  $output->addModules( 'mediawiki.filewarning' );
536  }
537  }
538 
539  $medialink = "[[Media:$filename|$linktext]]";
540 
541  if ( !$this->displayImg->isSafeFile() ) {
542  $warning = $this->getContext()->msg( 'mediawarning' )->plain();
543  // dirmark is needed here to separate the file name, which
544  // most likely ends in Latin characters, from the description,
545  // which may begin with the file type. In RTL environment
546  // this will get messy.
547  // The dirmark, however, must not be immediately adjacent
548  // to the filename, because it can get copied with it.
549  // See bug 25277.
550  // @codingStandardsIgnoreStart Ignore long line
551  $out->addWikiText( <<<EOT
552 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
553 <div class="mediaWarning">$warning</div>
554 EOT
555  );
556  // @codingStandardsIgnoreEnd
557  } else {
558  $out->addWikiText( <<<EOT
559 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
560 </div>
561 EOT
562  );
563  }
564 
565  $renderLangOptions = $this->displayImg->getAvailableLanguages();
566  if ( count( $renderLangOptions ) >= 1 ) {
567  $currentLanguage = $renderLang;
568  $defaultLang = $this->displayImg->getDefaultRenderLanguage();
569  if ( is_null( $currentLanguage ) ) {
570  $currentLanguage = $defaultLang;
571  }
572  $out->addHTML( $this->doRenderLangOpt( $renderLangOptions, $currentLanguage, $defaultLang ) );
573  }
574 
575  // Add cannot animate thumbnail warning
576  if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
577  // Include the extension so wiki admins can
578  // customize it on a per file-type basis
579  // (aka say things like use format X instead).
580  // additionally have a specific message for
581  // file-no-thumb-animation-gif
582  $ext = $this->displayImg->getExtension();
583  $noAnimMesg = wfMessageFallback(
584  'file-no-thumb-animation-' . $ext,
585  'file-no-thumb-animation'
586  )->plain();
587 
588  $out->addWikiText( <<<EOT
589 <div class="mw-noanimatethumb">{$noAnimMesg}</div>
590 EOT
591  );
592  }
593 
594  if ( !$this->displayImg->isLocal() ) {
595  $this->printSharedImageText();
596  }
597  } else {
598  # Image does not exist
599  if ( !$this->getId() ) {
600  # No article exists either
601  # Show deletion log to be consistent with normal articles
603  $out,
604  [ 'delete', 'move' ],
605  $this->getTitle()->getPrefixedText(),
606  '',
607  [ 'lim' => 10,
608  'conds' => [ "log_action != 'revision'" ],
609  'showIfEmpty' => false,
610  'msgKey' => [ 'moveddeleted-notice' ]
611  ]
612  );
613  }
614 
615  if ( $wgEnableUploads && $user->isAllowed( 'upload' ) ) {
616  // Only show an upload link if the user can upload
617  $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
618  $nofile = [
619  'filepage-nofile-link',
620  $uploadTitle->getFullURL( [ 'wpDestFile' => $this->mPage->getFile()->getName() ] )
621  ];
622  } else {
623  $nofile = 'filepage-nofile';
624  }
625  // Note, if there is an image description page, but
626  // no image, then this setRobotPolicy is overridden
627  // by Article::View().
628  $out->setRobotPolicy( 'noindex,nofollow' );
629  $out->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
630  if ( !$this->getId() && $wgSend404Code ) {
631  // If there is no image, no shared image, and no description page,
632  // output a 404, to be consistent with Article::showMissingArticle.
633  $request->response()->statusHeader( 404 );
634  }
635  }
636  $out->setFileVersion( $this->displayImg );
637  }
638 
646  private function getThumbPrevText( $params, $sizeLinkBigImagePreview ) {
647  if ( $sizeLinkBigImagePreview ) {
648  // Show a different message of preview is different format from original.
649  $previewTypeDiffers = false;
650  $origExt = $thumbExt = $this->displayImg->getExtension();
651  if ( $this->displayImg->getHandler() ) {
652  $origMime = $this->displayImg->getMimeType();
653  $typeParams = $params;
654  $this->displayImg->getHandler()->normaliseParams( $this->displayImg, $typeParams );
655  list( $thumbExt, $thumbMime ) = $this->displayImg->getHandler()->getThumbType(
656  $origExt, $origMime, $typeParams );
657  if ( $thumbMime !== $origMime ) {
658  $previewTypeDiffers = true;
659  }
660  }
661  if ( $previewTypeDiffers ) {
662  return $this->getContext()->msg( 'show-big-image-preview-differ' )->
663  rawParams( $sizeLinkBigImagePreview )->
664  params( strtoupper( $origExt ) )->
665  params( strtoupper( $thumbExt ) )->
666  parse();
667  } else {
668  return $this->getContext()->msg( 'show-big-image-preview' )->
669  rawParams( $sizeLinkBigImagePreview )->
670  parse();
671  }
672  } else {
673  return '';
674  }
675  }
676 
684  private function makeSizeLink( $params, $width, $height ) {
685  $params['width'] = $width;
686  $params['height'] = $height;
687  $thumbnail = $this->displayImg->transform( $params );
688  if ( $thumbnail && !$thumbnail->isError() ) {
689  return Html::rawElement( 'a', [
690  'href' => $thumbnail->getUrl(),
691  'class' => 'mw-thumbnail-link'
692  ], $this->getContext()->msg( 'show-big-image-size' )->numParams(
693  $thumbnail->getWidth(), $thumbnail->getHeight()
694  )->parse() );
695  } else {
696  return '';
697  }
698  }
699 
703  protected function printSharedImageText() {
704  $out = $this->getContext()->getOutput();
705  $this->loadFile();
706 
707  $descUrl = $this->mPage->getFile()->getDescriptionUrl();
708  $descText = $this->mPage->getFile()->getDescriptionText( $this->getContext()->getLanguage() );
709 
710  /* Add canonical to head if there is no local page for this shared file */
711  if ( $descUrl && $this->mPage->getId() == 0 ) {
712  $out->setCanonicalUrl( $descUrl );
713  }
714 
715  $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
716  $repo = $this->mPage->getFile()->getRepo()->getDisplayName();
717 
718  if ( $descUrl &&
719  $descText &&
720  $this->getContext()->msg( 'sharedupload-desc-here' )->plain() !== '-'
721  ) {
722  $out->wrapWikiMsg( $wrap, [ 'sharedupload-desc-here', $repo, $descUrl ] );
723  } elseif ( $descUrl &&
724  $this->getContext()->msg( 'sharedupload-desc-there' )->plain() !== '-'
725  ) {
726  $out->wrapWikiMsg( $wrap, [ 'sharedupload-desc-there', $repo, $descUrl ] );
727  } else {
728  $out->wrapWikiMsg( $wrap, [ 'sharedupload', $repo ], ''/*BACKCOMPAT*/ );
729  }
730 
731  if ( $descText ) {
732  $this->mExtraDescription = $descText;
733  }
734  }
735 
736  public function getUploadUrl() {
737  $this->loadFile();
738  $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
739  return $uploadTitle->getFullURL( [
740  'wpDestFile' => $this->mPage->getFile()->getName(),
741  'wpForReUpload' => 1
742  ] );
743  }
744 
749  protected function uploadLinksBox() {
751 
752  if ( !$wgEnableUploads ) {
753  return;
754  }
755 
756  $this->loadFile();
757  if ( !$this->mPage->getFile()->isLocal() ) {
758  return;
759  }
760 
761  $out = $this->getContext()->getOutput();
762  $out->addHTML( "<ul>\n" );
763 
764  # "Upload a new version of this file" link
765  $canUpload = $this->getTitle()->quickUserCan( 'upload', $this->getContext()->getUser() );
766  if ( $canUpload && UploadBase::userCanReUpload(
767  $this->getContext()->getUser(),
768  $this->mPage->getFile() )
769  ) {
770  $ulink = Linker::makeExternalLink(
771  $this->getUploadUrl(),
772  $this->getContext()->msg( 'uploadnewversion-linktext' )->text()
773  );
774  $out->addHTML( "<li id=\"mw-imagepage-reupload-link\">"
775  . "<div class=\"plainlinks\">{$ulink}</div></li>\n" );
776  } else {
777  $out->addHTML( "<li id=\"mw-imagepage-upload-disallowed\">"
778  . $this->getContext()->msg( 'upload-disallowed-here' )->escaped() . "</li>\n" );
779  }
780 
781  $out->addHTML( "</ul>\n" );
782  }
783 
787  protected function closeShowImage() {
788  }
789 
794  protected function imageHistory() {
795  $this->loadFile();
796  $out = $this->getContext()->getOutput();
797  $pager = new ImageHistoryPseudoPager( $this );
798  $out->addHTML( $pager->getBody() );
799  $out->preventClickjacking( $pager->getPreventClickjacking() );
800 
801  $this->mPage->getFile()->resetHistory(); // free db resources
802 
803  # Exist check because we don't want to show this on pages where an image
804  # doesn't exist along with the noimage message, that would suck. -ævar
805  if ( $this->mPage->getFile()->exists() ) {
806  $this->uploadLinksBox();
807  }
808  }
809 
815  protected function queryImageLinks( $target, $limit ) {
816  $dbr = wfGetDB( DB_SLAVE );
817 
818  return $dbr->select(
819  [ 'imagelinks', 'page' ],
820  [ 'page_namespace', 'page_title', 'il_to' ],
821  [ 'il_to' => $target, 'il_from = page_id' ],
822  __METHOD__,
823  [ 'LIMIT' => $limit + 1, 'ORDER BY' => 'il_from', ]
824  );
825  }
826 
827  protected function imageLinks() {
828  $limit = 100;
829 
830  $out = $this->getContext()->getOutput();
831 
832  $rows = [];
833  $redirects = [];
834  foreach ( $this->getTitle()->getRedirectsHere( NS_FILE ) as $redir ) {
835  $redirects[$redir->getDBkey()] = [];
836  $rows[] = (object)[
837  'page_namespace' => NS_FILE,
838  'page_title' => $redir->getDBkey(),
839  ];
840  }
841 
842  $res = $this->queryImageLinks( $this->getTitle()->getDBkey(), $limit + 1 );
843  foreach ( $res as $row ) {
844  $rows[] = $row;
845  }
846  $count = count( $rows );
847 
848  $hasMore = $count > $limit;
849  if ( !$hasMore && count( $redirects ) ) {
850  $res = $this->queryImageLinks( array_keys( $redirects ),
851  $limit - count( $rows ) + 1 );
852  foreach ( $res as $row ) {
853  $redirects[$row->il_to][] = $row;
854  $count++;
855  }
856  $hasMore = ( $res->numRows() + count( $rows ) ) > $limit;
857  }
858 
859  if ( $count == 0 ) {
860  $out->wrapWikiMsg(
861  Html::rawElement( 'div',
862  [ 'id' => 'mw-imagepage-nolinkstoimage' ], "\n$1\n" ),
863  'nolinkstoimage'
864  );
865  return;
866  }
867 
868  $out->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
869  if ( !$hasMore ) {
870  $out->addWikiMsg( 'linkstoimage', $count );
871  } else {
872  // More links than the limit. Add a link to [[Special:Whatlinkshere]]
873  $out->addWikiMsg( 'linkstoimage-more',
874  $this->getContext()->getLanguage()->formatNum( $limit ),
875  $this->getTitle()->getPrefixedDBkey()
876  );
877  }
878 
879  $out->addHTML(
880  Html::openElement( 'ul',
881  [ 'class' => 'mw-imagepage-linkstoimage' ] ) . "\n"
882  );
883  $count = 0;
884 
885  // Sort the list by namespace:title
886  usort( $rows, [ $this, 'compare' ] );
887 
888  // Create links for every element
889  $currentCount = 0;
890  foreach ( $rows as $element ) {
891  $currentCount++;
892  if ( $currentCount > $limit ) {
893  break;
894  }
895 
896  $query = [];
897  # Add a redirect=no to make redirect pages reachable
898  if ( isset( $redirects[$element->page_title] ) ) {
899  $query['redirect'] = 'no';
900  }
902  Title::makeTitle( $element->page_namespace, $element->page_title ),
903  null, [], $query
904  );
905  if ( !isset( $redirects[$element->page_title] ) ) {
906  # No redirects
907  $liContents = $link;
908  } elseif ( count( $redirects[$element->page_title] ) === 0 ) {
909  # Redirect without usages
910  $liContents = $this->getContext()->msg( 'linkstoimage-redirect' )
911  ->rawParams( $link, '' )
912  ->parse();
913  } else {
914  # Redirect with usages
915  $li = '';
916  foreach ( $redirects[$element->page_title] as $row ) {
917  $currentCount++;
918  if ( $currentCount > $limit ) {
919  break;
920  }
921 
922  $link2 = Linker::linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
923  $li .= Html::rawElement(
924  'li',
925  [ 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
926  $link2
927  ) . "\n";
928  }
929 
931  'ul',
932  [ 'class' => 'mw-imagepage-redirectstofile' ],
933  $li
934  ) . "\n";
935  $liContents = $this->getContext()->msg( 'linkstoimage-redirect' )->rawParams(
936  $link, $ul )->parse();
937  }
938  $out->addHTML( Html::rawElement(
939  'li',
940  [ 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
941  $liContents
942  ) . "\n"
943  );
944 
945  };
946  $out->addHTML( Html::closeElement( 'ul' ) . "\n" );
947  $res->free();
948 
949  // Add a links to [[Special:Whatlinkshere]]
950  if ( $count > $limit ) {
951  $out->addWikiMsg( 'morelinkstoimage', $this->getTitle()->getPrefixedDBkey() );
952  }
953  $out->addHTML( Html::closeElement( 'div' ) . "\n" );
954  }
955 
956  protected function imageDupes() {
957  $this->loadFile();
958  $out = $this->getContext()->getOutput();
959 
960  $dupes = $this->mPage->getDuplicates();
961  if ( count( $dupes ) == 0 ) {
962  return;
963  }
964 
965  $out->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
966  $out->addWikiMsg( 'duplicatesoffile',
967  $this->getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->getTitle()->getDBkey()
968  );
969  $out->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
970 
974  foreach ( $dupes as $file ) {
975  $fromSrc = '';
976  if ( $file->isLocal() ) {
977  $link = Linker::linkKnown( $file->getTitle() );
978  } else {
979  $link = Linker::makeExternalLink( $file->getDescriptionUrl(),
980  $file->getTitle()->getPrefixedText() );
981  $fromSrc = $this->getContext()->msg(
982  'shared-repo-from',
983  $file->getRepo()->getDisplayName()
984  )->text();
985  }
986  $out->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
987  }
988  $out->addHTML( "</ul></div>\n" );
989  }
990 
994  public function delete() {
995  $file = $this->mPage->getFile();
996  if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
997  // Standard article deletion
998  parent::delete();
999  return;
1000  }
1001 
1002  $deleter = new FileDeleteForm( $file );
1003  $deleter->execute();
1004  }
1005 
1011  function showError( $description ) {
1012  $out = $this->getContext()->getOutput();
1013  $out->setPageTitle( $this->getContext()->msg( 'internalerror' ) );
1014  $out->setRobotPolicy( 'noindex,nofollow' );
1015  $out->setArticleRelated( false );
1016  $out->enableClientCache( false );
1017  $out->addWikiText( $description );
1018  }
1019 
1028  protected function compare( $a, $b ) {
1029  if ( $a->page_namespace == $b->page_namespace ) {
1030  return strcmp( $a->page_title, $b->page_title );
1031  } else {
1032  return $a->page_namespace - $b->page_namespace;
1033  }
1034  }
1035 
1044  public function getImageLimitsFromOption( $user, $optionName ) {
1046 
1047  $option = $user->getIntOption( $optionName );
1048  if ( !isset( $wgImageLimits[$option] ) ) {
1049  $option = User::getDefaultOption( $optionName );
1050  }
1051 
1052  // The user offset might still be incorrect, specially if
1053  // $wgImageLimits got changed (see bug #8858).
1054  if ( !isset( $wgImageLimits[$option] ) ) {
1055  // Default to the first offset in $wgImageLimits
1056  $option = 0;
1057  }
1058 
1059  return isset( $wgImageLimits[$option] )
1060  ? $wgImageLimits[$option]
1061  : [ 800, 600 ]; // if nothing is set, fallback to a hardcoded default
1062  }
1063 
1072  protected function doRenderLangOpt( array $langChoices, $curLang, $defaultLang ) {
1073  global $wgScript;
1074  sort( $langChoices );
1075  $curLang = wfBCP47( $curLang );
1076  $defaultLang = wfBCP47( $defaultLang );
1077  $opts = '';
1078  $haveCurrentLang = false;
1079  $haveDefaultLang = false;
1080 
1081  // We make a list of all the language choices in the file.
1082  // Additionally if the default language to render this file
1083  // is not included as being in this file (for example, in svgs
1084  // usually the fallback content is the english content) also
1085  // include a choice for that. Last of all, if we're viewing
1086  // the file in a language not on the list, add it as a choice.
1087  foreach ( $langChoices as $lang ) {
1088  $code = wfBCP47( $lang );
1089  $name = Language::fetchLanguageName( $code, $this->getContext()->getLanguage()->getCode() );
1090  if ( $name !== '' ) {
1091  $display = $this->getContext()->msg( 'img-lang-opt', $code, $name )->text();
1092  } else {
1093  $display = $code;
1094  }
1095  $opts .= "\n" . Xml::option( $display, $code, $curLang === $code );
1096  if ( $curLang === $code ) {
1097  $haveCurrentLang = true;
1098  }
1099  if ( $defaultLang === $code ) {
1100  $haveDefaultLang = true;
1101  }
1102  }
1103  if ( !$haveDefaultLang ) {
1104  // Its hard to know if the content is really in the default language, or
1105  // if its just unmarked content that could be in any language.
1106  $opts = Xml::option(
1107  $this->getContext()->msg( 'img-lang-default' )->text(),
1108  $defaultLang,
1109  $defaultLang === $curLang
1110  ) . $opts;
1111  }
1112  if ( !$haveCurrentLang && $defaultLang !== $curLang ) {
1113  $name = Language::fetchLanguageName( $curLang, $this->getContext()->getLanguage()->getCode() );
1114  if ( $name !== '' ) {
1115  $display = $this->getContext()->msg( 'img-lang-opt', $curLang, $name )->text();
1116  } else {
1117  $display = $curLang;
1118  }
1119  $opts = Xml::option( $display, $curLang, true ) . $opts;
1120  }
1121 
1122  $select = Html::rawElement(
1123  'select',
1124  [ 'id' => 'mw-imglangselector', 'name' => 'lang' ],
1125  $opts
1126  );
1127  $submit = Xml::submitButton( $this->getContext()->msg( 'img-lang-go' )->text() );
1128 
1129  $formContents = $this->getContext()->msg( 'img-lang-info' )
1130  ->rawParams( $select, $submit )
1131  ->parse();
1132  $formContents .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() );
1133 
1134  $langSelectLine = Html::rawElement( 'div', [ 'id' => 'mw-imglangselector-line' ],
1135  Html::rawElement( 'form', [ 'action' => $wgScript ], $formContents )
1136  );
1137  return $langSelectLine;
1138  }
1139 
1154  protected function getDisplayWidthHeight( $maxWidth, $maxHeight, $width, $height ) {
1155  if ( !$maxWidth || !$maxHeight ) {
1156  // should never happen
1157  throw new MWException( 'Using a choice from $wgImageLimits that is 0x0' );
1158  }
1159 
1160  if ( !$width || !$height ) {
1161  return [ 0, 0 ];
1162  }
1163 
1164  # Calculate the thumbnail size.
1165  if ( $width <= $maxWidth && $height <= $maxHeight ) {
1166  // Vectorized image, do nothing.
1167  } elseif ( $width / $height >= $maxWidth / $maxHeight ) {
1168  # The limiting factor is the width, not the height.
1169  $height = round( $height * $maxWidth / $width );
1170  $width = $maxWidth;
1171  # Note that $height <= $maxHeight now.
1172  } else {
1173  $newwidth = floor( $width * $maxHeight / $height );
1174  $height = round( $height * $newwidth / $width );
1175  $width = $newwidth;
1176  # Note that $height <= $maxHeight now, but might not be identical
1177  # because of rounding.
1178  }
1179  return [ $width, $height ];
1180  }
1181 
1190  protected function getThumbSizes( $origWidth, $origHeight ) {
1192  if ( $this->displayImg->getRepo()->canTransformVia404() ) {
1193  $thumbSizes = $wgImageLimits;
1194  // Also include the full sized resolution in the list, so
1195  // that users know they can get it. This will link to the
1196  // original file asset if mustRender() === false. In the case
1197  // that we mustRender, some users have indicated that they would
1198  // find it useful to have the full size image in the rendered
1199  // image format.
1200  $thumbSizes[] = [ $origWidth, $origHeight ];
1201  } else {
1202  # Creating thumb links triggers thumbnail generation.
1203  # Just generate the thumb for the current users prefs.
1204  $thumbSizes = [
1205  $this->getImageLimitsFromOption( $this->getContext()->getUser(), 'thumbsize' )
1206  ];
1207  if ( !$this->displayImg->mustRender() ) {
1208  // We can safely include a link to the "full-size" preview,
1209  // without actually rendering.
1210  $thumbSizes[] = [ $origWidth, $origHeight ];
1211  }
1212  }
1213  return $thumbSizes;
1214  }
1215 
1220  public function getFile() {
1221  return $this->mPage->getFile();
1222  }
1223 
1228  public function isLocal() {
1229  return $this->mPage->isLocal();
1230  }
1231 
1236  public function getDuplicates() {
1237  return $this->mPage->getDuplicates();
1238  }
1239 
1244  public function getForeignCategories() {
1245  $this->mPage->getForeignCategories();
1246  }
1247 
1248 }
viewRedirect($target, $appendSubtitle=true, $forceKnown=false)
Return the HTML for the top of a redirect page.
Definition: Article.php:1554
static newFromID($id, $flags=0)
Create a new Title from an article ID.
Definition: Title.php:417
static closeElement($element)
Returns "".
Definition: Html.php:306
$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:1802
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:766
static processResponsiveImages($file, $thumb, $hp)
Process responsive images: add 1.5x and 2x subimages to the thumbnail, where applicable.
Definition: Linker.php:878
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:1422
$wgScript
The URL path to index.php.
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
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:815
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:75
showTOC($metadata)
Create the TOC.
Definition: ImagePage.php:247
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:210
if(!isset($args[0])) $lang
static hidden($name, $value, array $attribs=[])
Convenience function to produce an input element with type=hidden.
Definition: Html.php:759
getUploadUrl()
Definition: ImagePage.php:736
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...
Represents a title within MediaWiki.
Definition: Title.php:34
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:703
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:794
uploadLinksBox()
Print out the various links at the bottom of the image page, e.g.
Definition: ImagePage.php:749
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:1244
the value to return A Title object or null for latest to be modified or replaced by the hook handler or if authentication is not possible after cache objects are set for highlighting & $link
Definition: hooks.txt:2585
getThumbSizes($origWidth, $origHeight)
Get alternative thumbnail sizes.
Definition: ImagePage.php:1190
$wgEnableUploads
Uploads have to be specially set up to be secure.
getContext()
Gets the context this Article is executed in.
Definition: Article.php:2059
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:1011
static openElement($element, $attribs=[])
Identical to rawElement(), but has no third parameter and omits the end tag (and the self-closing '/'...
Definition: Html.php:248
$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.
static newFromID($id)
Constructor from a page id.
Definition: ImagePage.php:60
$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:1008
$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:166
$params
File $displayImg
Definition: ImagePage.php:30
const DB_SLAVE
Definition: Defines.php:47
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:916
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:76
addModules($modules)
render()
Handler for action=render Include body text only; none of the image extras.
Definition: ImagePage.php:103
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:766
compare($a, $b)
Callback for usort() to do link sorts by (namespace, title) Function copied from Title::compare() ...
Definition: ImagePage.php:1028
static fetchLanguageName($code, $inLanguage=null, $include= 'all')
Definition: Language.php:886
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:1132
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:1008
static makeExternalLink($url, $text, $escape=true, $linktype= '', $attribs=[], $title=null)
Make an external link.
Definition: Linker.php:1052
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:2422
getId()
Call to WikiPage function for backwards compatibility.
Definition: Article.php:2304
getDisplayWidthHeight($maxWidth, $maxHeight, $width, $height)
Get the width and height to display image at.
Definition: ImagePage.php:1154
getOldID()
Definition: Article.php:253
setFile($file)
Definition: ImagePage.php:71
getDisplayName()
Get the human-readable name of the repo.
Definition: FileRepo.php:1761
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:1008
bool $mExtraDescription
Definition: ImagePage.php:39
getDisplayedFile()
Definition: ImagePage.php:236
makeSizeLink($params, $width, $height)
Creates an thumbnail of specified size and returns an HTML link to it.
Definition: ImagePage.php:684
$count
addJsConfigVars($keys, $value=null)
Add one or more variables to be set in mw.config in JavaScript.
doRenderLangOpt(array $langChoices, $curLang, $defaultLang)
Output a drop-down box for language options for the file.
Definition: ImagePage.php:1072
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:766
getThumbPrevText($params, $sizeLinkBigImagePreview)
Make the text under the image to say what size preview.
Definition: ImagePage.php:646
getUser($audience=Revision::FOR_PUBLIC, User $user=null)
Call to WikiPage function for backwards compatibility.
Definition: Article.php:2401
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:726
static getDefaultOption($opt)
Get a given default option value.
Definition: User.php:1545
$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:1044
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:2342
makeMetadataTable($metadata)
Make a table with metadata to be shown in the output page.
Definition: ImagePage.php:273
getContentObject()
Overloading Article's getContentObject method.
Definition: ImagePage.php:301
static & makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
Definition: Title.php:524
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:2342
closeShowImage()
For overloading.
Definition: ImagePage.php:787
openShowImage()
Definition: ImagePage.php:309
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:314