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