MediaWiki  1.27.3
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  // Avoid PHP 7.1 warning from passing $this by reference
351  $imagePage = $this;
352 
353  Hooks::run( 'ImageOpenShowImageInlineBefore', [ &$imagePage, &$out ] );
354 
355  if ( $this->displayImg->allowInlineDisplay() ) {
356  # image
357  # "Download high res version" link below the image
358  # $msgsize = $this->getContext()->msg( 'file-info-size', $width_orig, $height_orig,
359  # Linker::formatSize( $this->displayImg->getSize() ), $mime )->escaped();
360  # We'll show a thumbnail of this image
361  if ( $width > $maxWidth || $height > $maxHeight || $this->displayImg->isVectorized() ) {
362  list( $width, $height ) = $this->getDisplayWidthHeight(
363  $maxWidth, $maxHeight, $width, $height
364  );
365  $linktext = $this->getContext()->msg( 'show-big-image' )->escaped();
366 
367  $thumbSizes = $this->getThumbSizes( $width_orig, $height_orig );
368  # Generate thumbnails or thumbnail links as needed...
369  $otherSizes = [];
370  foreach ( $thumbSizes as $size ) {
371  // We include a thumbnail size in the list, if it is
372  // less than or equal to the original size of the image
373  // asset ($width_orig/$height_orig). We also exclude
374  // the current thumbnail's size ($width/$height)
375  // since that is added to the message separately, so
376  // it can be denoted as the current size being shown.
377  // Vectorized images are limited by $wgSVGMaxSize big,
378  // so all thumbs less than or equal that are shown.
379  if ( ( ( $size[0] <= $width_orig && $size[1] <= $height_orig )
380  || ( $this->displayImg->isVectorized()
381  && max( $size[0], $size[1] ) <= $wgSVGMaxSize )
382  )
383  && $size[0] != $width && $size[1] != $height
384  ) {
385  $sizeLink = $this->makeSizeLink( $params, $size[0], $size[1] );
386  if ( $sizeLink ) {
387  $otherSizes[] = $sizeLink;
388  }
389  }
390  }
391  $otherSizes = array_unique( $otherSizes );
392 
393  $sizeLinkBigImagePreview = $this->makeSizeLink( $params, $width, $height );
394  $msgsmall = $this->getThumbPrevText( $params, $sizeLinkBigImagePreview );
395  if ( count( $otherSizes ) ) {
396  $msgsmall .= ' ' .
398  'span',
399  [ 'class' => 'mw-filepage-other-resolutions' ],
400  $this->getContext()->msg( 'show-big-image-other' )
401  ->rawParams( $lang->pipeList( $otherSizes ) )
402  ->params( count( $otherSizes ) )
403  ->parse()
404  );
405  }
406  } elseif ( $width == 0 && $height == 0 ) {
407  # Some sort of audio file that doesn't have dimensions
408  # Don't output a no hi res message for such a file
409  $msgsmall = '';
410  } else {
411  # Image is small enough to show full size on image page
412  $msgsmall = $this->getContext()->msg( 'file-nohires' )->parse();
413  }
414 
415  $params['width'] = $width;
416  $params['height'] = $height;
417  $thumbnail = $this->displayImg->transform( $params );
418  Linker::processResponsiveImages( $this->displayImg, $thumbnail, $params );
419 
420  $anchorclose = Html::rawElement(
421  'div',
422  [ 'class' => 'mw-filepage-resolutioninfo' ],
423  $msgsmall
424  );
425 
426  $isMulti = $this->displayImg->isMultipage() && $this->displayImg->pageCount() > 1;
427  if ( $isMulti ) {
428  $out->addModules( 'mediawiki.page.image.pagination' );
429  $out->addHTML( '<table class="multipageimage"><tr><td>' );
430  }
431 
432  if ( $thumbnail ) {
433  $options = [
434  'alt' => $this->displayImg->getTitle()->getPrefixedText(),
435  'file-link' => true,
436  ];
437  $out->addHTML( '<div class="fullImageLink" id="file">' .
438  $thumbnail->toHtml( $options ) .
439  $anchorclose . "</div>\n" );
440  }
441 
442  if ( $isMulti ) {
443  $count = $this->displayImg->pageCount();
444 
445  if ( $page > 1 ) {
446  $label = $out->parse( $this->getContext()->msg( 'imgmultipageprev' )->text(), false );
447  // on the client side, this link is generated in ajaxifyPageNavigation()
448  // in the mediawiki.page.image.pagination module
450  $this->getTitle(),
451  $label,
452  [],
453  [ 'page' => $page - 1 ]
454  );
455  $thumb1 = Linker::makeThumbLinkObj(
456  $this->getTitle(),
457  $this->displayImg,
458  $link,
459  $label,
460  'none',
461  [ 'page' => $page - 1 ]
462  );
463  } else {
464  $thumb1 = '';
465  }
466 
467  if ( $page < $count ) {
468  $label = $this->getContext()->msg( 'imgmultipagenext' )->text();
470  $this->getTitle(),
471  $label,
472  [],
473  [ 'page' => $page + 1 ]
474  );
475  $thumb2 = Linker::makeThumbLinkObj(
476  $this->getTitle(),
477  $this->displayImg,
478  $link,
479  $label,
480  'none',
481  [ 'page' => $page + 1 ]
482  );
483  } else {
484  $thumb2 = '';
485  }
486 
488 
489  $formParams = [
490  'name' => 'pageselector',
491  'action' => $wgScript,
492  ];
493  $options = [];
494  for ( $i = 1; $i <= $count; $i++ ) {
495  $options[] = Xml::option( $lang->formatNum( $i ), $i, $i == $page );
496  }
497  $select = Xml::tags( 'select',
498  [ 'id' => 'pageselector', 'name' => 'page' ],
499  implode( "\n", $options ) );
500 
501  $out->addHTML(
502  '</td><td><div class="multipageimagenavbox">' .
503  Xml::openElement( 'form', $formParams ) .
504  Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() ) .
505  $this->getContext()->msg( 'imgmultigoto' )->rawParams( $select )->parse() .
506  Xml::submitButton( $this->getContext()->msg( 'imgmultigo' )->text() ) .
507  Xml::closeElement( 'form' ) .
508  "<hr />$thumb1\n$thumb2<br style=\"clear: both\" /></div></td></tr></table>"
509  );
510  }
511  } elseif ( $this->displayImg->isSafeFile() ) {
512  # if direct link is allowed but it's not a renderable image, show an icon.
513  $icon = $this->displayImg->iconThumb();
514 
515  $out->addHTML( '<div class="fullImageLink" id="file">' .
516  $icon->toHtml( [ 'file-link' => true ] ) .
517  "</div>\n" );
518  }
519 
520  $longDesc = $this->getContext()->msg( 'parentheses', $this->displayImg->getLongDesc() )->text();
521 
522  $handler = $this->displayImg->getHandler();
523 
524  // If this is a filetype with potential issues, warn the user.
525  if ( $handler ) {
526  $warningConfig = $handler->getWarningConfig( $this->displayImg );
527 
528  if ( $warningConfig !== null ) {
529  // The warning will be displayed via CSS and JavaScript.
530  // We just need to tell the client side what message to use.
531  $output = $this->getContext()->getOutput();
532  $output->addJsConfigVars( 'wgFileWarning', $warningConfig );
533  $output->addModules( $warningConfig['module'] );
534  $output->addModules( 'mediawiki.filewarning' );
535  }
536  }
537 
538  $medialink = "[[Media:$filename|$linktext]]";
539 
540  if ( !$this->displayImg->isSafeFile() ) {
541  $warning = $this->getContext()->msg( 'mediawarning' )->plain();
542  // dirmark is needed here to separate the file name, which
543  // most likely ends in Latin characters, from the description,
544  // which may begin with the file type. In RTL environment
545  // this will get messy.
546  // The dirmark, however, must not be immediately adjacent
547  // to the filename, because it can get copied with it.
548  // See bug 25277.
549  // @codingStandardsIgnoreStart Ignore long line
550  $out->addWikiText( <<<EOT
551 <div class="fullMedia"><span class="dangerousLink">{$medialink}</span> $dirmark<span class="fileInfo">$longDesc</span></div>
552 <div class="mediaWarning">$warning</div>
553 EOT
554  );
555  // @codingStandardsIgnoreEnd
556  } else {
557  $out->addWikiText( <<<EOT
558 <div class="fullMedia">{$medialink} {$dirmark}<span class="fileInfo">$longDesc</span>
559 </div>
560 EOT
561  );
562  }
563 
564  $renderLangOptions = $this->displayImg->getAvailableLanguages();
565  if ( count( $renderLangOptions ) >= 1 ) {
566  $currentLanguage = $renderLang;
567  $defaultLang = $this->displayImg->getDefaultRenderLanguage();
568  if ( is_null( $currentLanguage ) ) {
569  $currentLanguage = $defaultLang;
570  }
571  $out->addHTML( $this->doRenderLangOpt( $renderLangOptions, $currentLanguage, $defaultLang ) );
572  }
573 
574  // Add cannot animate thumbnail warning
575  if ( !$this->displayImg->canAnimateThumbIfAppropriate() ) {
576  // Include the extension so wiki admins can
577  // customize it on a per file-type basis
578  // (aka say things like use format X instead).
579  // additionally have a specific message for
580  // file-no-thumb-animation-gif
581  $ext = $this->displayImg->getExtension();
582  $noAnimMesg = wfMessageFallback(
583  'file-no-thumb-animation-' . $ext,
584  'file-no-thumb-animation'
585  )->plain();
586 
587  $out->addWikiText( <<<EOT
588 <div class="mw-noanimatethumb">{$noAnimMesg}</div>
589 EOT
590  );
591  }
592 
593  if ( !$this->displayImg->isLocal() ) {
594  $this->printSharedImageText();
595  }
596  } else {
597  # Image does not exist
598  if ( !$this->getId() ) {
599  # No article exists either
600  # Show deletion log to be consistent with normal articles
602  $out,
603  [ 'delete', 'move' ],
604  $this->getTitle()->getPrefixedText(),
605  '',
606  [ 'lim' => 10,
607  'conds' => [ "log_action != 'revision'" ],
608  'showIfEmpty' => false,
609  'msgKey' => [ 'moveddeleted-notice' ]
610  ]
611  );
612  }
613 
614  if ( $wgEnableUploads && $user->isAllowed( 'upload' ) ) {
615  // Only show an upload link if the user can upload
616  $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
617  $nofile = [
618  'filepage-nofile-link',
619  $uploadTitle->getFullURL( [ 'wpDestFile' => $this->mPage->getFile()->getName() ] )
620  ];
621  } else {
622  $nofile = 'filepage-nofile';
623  }
624  // Note, if there is an image description page, but
625  // no image, then this setRobotPolicy is overridden
626  // by Article::View().
627  $out->setRobotPolicy( 'noindex,nofollow' );
628  $out->wrapWikiMsg( "<div id='mw-imagepage-nofile' class='plainlinks'>\n$1\n</div>", $nofile );
629  if ( !$this->getId() && $wgSend404Code ) {
630  // If there is no image, no shared image, and no description page,
631  // output a 404, to be consistent with Article::showMissingArticle.
632  $request->response()->statusHeader( 404 );
633  }
634  }
635  $out->setFileVersion( $this->displayImg );
636  }
637 
645  private function getThumbPrevText( $params, $sizeLinkBigImagePreview ) {
646  if ( $sizeLinkBigImagePreview ) {
647  // Show a different message of preview is different format from original.
648  $previewTypeDiffers = false;
649  $origExt = $thumbExt = $this->displayImg->getExtension();
650  if ( $this->displayImg->getHandler() ) {
651  $origMime = $this->displayImg->getMimeType();
652  $typeParams = $params;
653  $this->displayImg->getHandler()->normaliseParams( $this->displayImg, $typeParams );
654  list( $thumbExt, $thumbMime ) = $this->displayImg->getHandler()->getThumbType(
655  $origExt, $origMime, $typeParams );
656  if ( $thumbMime !== $origMime ) {
657  $previewTypeDiffers = true;
658  }
659  }
660  if ( $previewTypeDiffers ) {
661  return $this->getContext()->msg( 'show-big-image-preview-differ' )->
662  rawParams( $sizeLinkBigImagePreview )->
663  params( strtoupper( $origExt ) )->
664  params( strtoupper( $thumbExt ) )->
665  parse();
666  } else {
667  return $this->getContext()->msg( 'show-big-image-preview' )->
668  rawParams( $sizeLinkBigImagePreview )->
669  parse();
670  }
671  } else {
672  return '';
673  }
674  }
675 
683  private function makeSizeLink( $params, $width, $height ) {
684  $params['width'] = $width;
685  $params['height'] = $height;
686  $thumbnail = $this->displayImg->transform( $params );
687  if ( $thumbnail && !$thumbnail->isError() ) {
688  return Html::rawElement( 'a', [
689  'href' => $thumbnail->getUrl(),
690  'class' => 'mw-thumbnail-link'
691  ], $this->getContext()->msg( 'show-big-image-size' )->numParams(
692  $thumbnail->getWidth(), $thumbnail->getHeight()
693  )->parse() );
694  } else {
695  return '';
696  }
697  }
698 
702  protected function printSharedImageText() {
703  $out = $this->getContext()->getOutput();
704  $this->loadFile();
705 
706  $descUrl = $this->mPage->getFile()->getDescriptionUrl();
707  $descText = $this->mPage->getFile()->getDescriptionText( $this->getContext()->getLanguage() );
708 
709  /* Add canonical to head if there is no local page for this shared file */
710  if ( $descUrl && $this->mPage->getId() == 0 ) {
711  $out->setCanonicalUrl( $descUrl );
712  }
713 
714  $wrap = "<div class=\"sharedUploadNotice\">\n$1\n</div>\n";
715  $repo = $this->mPage->getFile()->getRepo()->getDisplayName();
716 
717  if ( $descUrl &&
718  $descText &&
719  $this->getContext()->msg( 'sharedupload-desc-here' )->plain() !== '-'
720  ) {
721  $out->wrapWikiMsg( $wrap, [ 'sharedupload-desc-here', $repo, $descUrl ] );
722  } elseif ( $descUrl &&
723  $this->getContext()->msg( 'sharedupload-desc-there' )->plain() !== '-'
724  ) {
725  $out->wrapWikiMsg( $wrap, [ 'sharedupload-desc-there', $repo, $descUrl ] );
726  } else {
727  $out->wrapWikiMsg( $wrap, [ 'sharedupload', $repo ], ''/*BACKCOMPAT*/ );
728  }
729 
730  if ( $descText ) {
731  $this->mExtraDescription = $descText;
732  }
733  }
734 
735  public function getUploadUrl() {
736  $this->loadFile();
737  $uploadTitle = SpecialPage::getTitleFor( 'Upload' );
738  return $uploadTitle->getFullURL( [
739  'wpDestFile' => $this->mPage->getFile()->getName(),
740  'wpForReUpload' => 1
741  ] );
742  }
743 
748  protected function uploadLinksBox() {
750 
751  if ( !$wgEnableUploads ) {
752  return;
753  }
754 
755  $this->loadFile();
756  if ( !$this->mPage->getFile()->isLocal() ) {
757  return;
758  }
759 
760  $out = $this->getContext()->getOutput();
761  $out->addHTML( "<ul>\n" );
762 
763  # "Upload a new version of this file" link
764  $canUpload = $this->getTitle()->quickUserCan( 'upload', $this->getContext()->getUser() );
765  if ( $canUpload && UploadBase::userCanReUpload(
766  $this->getContext()->getUser(),
767  $this->mPage->getFile() )
768  ) {
769  $ulink = Linker::makeExternalLink(
770  $this->getUploadUrl(),
771  $this->getContext()->msg( 'uploadnewversion-linktext' )->text()
772  );
773  $out->addHTML( "<li id=\"mw-imagepage-reupload-link\">"
774  . "<div class=\"plainlinks\">{$ulink}</div></li>\n" );
775  } else {
776  $out->addHTML( "<li id=\"mw-imagepage-upload-disallowed\">"
777  . $this->getContext()->msg( 'upload-disallowed-here' )->escaped() . "</li>\n" );
778  }
779 
780  $out->addHTML( "</ul>\n" );
781  }
782 
786  protected function closeShowImage() {
787  }
788 
793  protected function imageHistory() {
794  $this->loadFile();
795  $out = $this->getContext()->getOutput();
796  $pager = new ImageHistoryPseudoPager( $this );
797  $out->addHTML( $pager->getBody() );
798  $out->preventClickjacking( $pager->getPreventClickjacking() );
799 
800  $this->mPage->getFile()->resetHistory(); // free db resources
801 
802  # Exist check because we don't want to show this on pages where an image
803  # doesn't exist along with the noimage message, that would suck. -ævar
804  if ( $this->mPage->getFile()->exists() ) {
805  $this->uploadLinksBox();
806  }
807  }
808 
814  protected function queryImageLinks( $target, $limit ) {
815  $dbr = wfGetDB( DB_SLAVE );
816 
817  return $dbr->select(
818  [ 'imagelinks', 'page' ],
819  [ 'page_namespace', 'page_title', 'il_to' ],
820  [ 'il_to' => $target, 'il_from = page_id' ],
821  __METHOD__,
822  [ 'LIMIT' => $limit + 1, 'ORDER BY' => 'il_from', ]
823  );
824  }
825 
826  protected function imageLinks() {
827  $limit = 100;
828 
829  $out = $this->getContext()->getOutput();
830 
831  $rows = [];
832  $redirects = [];
833  foreach ( $this->getTitle()->getRedirectsHere( NS_FILE ) as $redir ) {
834  $redirects[$redir->getDBkey()] = [];
835  $rows[] = (object)[
836  'page_namespace' => NS_FILE,
837  'page_title' => $redir->getDBkey(),
838  ];
839  }
840 
841  $res = $this->queryImageLinks( $this->getTitle()->getDBkey(), $limit + 1 );
842  foreach ( $res as $row ) {
843  $rows[] = $row;
844  }
845  $count = count( $rows );
846 
847  $hasMore = $count > $limit;
848  if ( !$hasMore && count( $redirects ) ) {
849  $res = $this->queryImageLinks( array_keys( $redirects ),
850  $limit - count( $rows ) + 1 );
851  foreach ( $res as $row ) {
852  $redirects[$row->il_to][] = $row;
853  $count++;
854  }
855  $hasMore = ( $res->numRows() + count( $rows ) ) > $limit;
856  }
857 
858  if ( $count == 0 ) {
859  $out->wrapWikiMsg(
860  Html::rawElement( 'div',
861  [ 'id' => 'mw-imagepage-nolinkstoimage' ], "\n$1\n" ),
862  'nolinkstoimage'
863  );
864  return;
865  }
866 
867  $out->addHTML( "<div id='mw-imagepage-section-linkstoimage'>\n" );
868  if ( !$hasMore ) {
869  $out->addWikiMsg( 'linkstoimage', $count );
870  } else {
871  // More links than the limit. Add a link to [[Special:Whatlinkshere]]
872  $out->addWikiMsg( 'linkstoimage-more',
873  $this->getContext()->getLanguage()->formatNum( $limit ),
874  $this->getTitle()->getPrefixedDBkey()
875  );
876  }
877 
878  $out->addHTML(
879  Html::openElement( 'ul',
880  [ 'class' => 'mw-imagepage-linkstoimage' ] ) . "\n"
881  );
882  $count = 0;
883 
884  // Sort the list by namespace:title
885  usort( $rows, [ $this, 'compare' ] );
886 
887  // Create links for every element
888  $currentCount = 0;
889  foreach ( $rows as $element ) {
890  $currentCount++;
891  if ( $currentCount > $limit ) {
892  break;
893  }
894 
895  $query = [];
896  # Add a redirect=no to make redirect pages reachable
897  if ( isset( $redirects[$element->page_title] ) ) {
898  $query['redirect'] = 'no';
899  }
901  Title::makeTitle( $element->page_namespace, $element->page_title ),
902  null, [], $query
903  );
904  if ( !isset( $redirects[$element->page_title] ) ) {
905  # No redirects
906  $liContents = $link;
907  } elseif ( count( $redirects[$element->page_title] ) === 0 ) {
908  # Redirect without usages
909  $liContents = $this->getContext()->msg( 'linkstoimage-redirect' )
910  ->rawParams( $link, '' )
911  ->parse();
912  } else {
913  # Redirect with usages
914  $li = '';
915  foreach ( $redirects[$element->page_title] as $row ) {
916  $currentCount++;
917  if ( $currentCount > $limit ) {
918  break;
919  }
920 
921  $link2 = Linker::linkKnown( Title::makeTitle( $row->page_namespace, $row->page_title ) );
922  $li .= Html::rawElement(
923  'li',
924  [ 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
925  $link2
926  ) . "\n";
927  }
928 
930  'ul',
931  [ 'class' => 'mw-imagepage-redirectstofile' ],
932  $li
933  ) . "\n";
934  $liContents = $this->getContext()->msg( 'linkstoimage-redirect' )->rawParams(
935  $link, $ul )->parse();
936  }
937  $out->addHTML( Html::rawElement(
938  'li',
939  [ 'class' => 'mw-imagepage-linkstoimage-ns' . $element->page_namespace ],
940  $liContents
941  ) . "\n"
942  );
943 
944  };
945  $out->addHTML( Html::closeElement( 'ul' ) . "\n" );
946  $res->free();
947 
948  // Add a links to [[Special:Whatlinkshere]]
949  if ( $count > $limit ) {
950  $out->addWikiMsg( 'morelinkstoimage', $this->getTitle()->getPrefixedDBkey() );
951  }
952  $out->addHTML( Html::closeElement( 'div' ) . "\n" );
953  }
954 
955  protected function imageDupes() {
956  $this->loadFile();
957  $out = $this->getContext()->getOutput();
958 
959  $dupes = $this->mPage->getDuplicates();
960  if ( count( $dupes ) == 0 ) {
961  return;
962  }
963 
964  $out->addHTML( "<div id='mw-imagepage-section-duplicates'>\n" );
965  $out->addWikiMsg( 'duplicatesoffile',
966  $this->getContext()->getLanguage()->formatNum( count( $dupes ) ), $this->getTitle()->getDBkey()
967  );
968  $out->addHTML( "<ul class='mw-imagepage-duplicates'>\n" );
969 
973  foreach ( $dupes as $file ) {
974  $fromSrc = '';
975  if ( $file->isLocal() ) {
976  $link = Linker::linkKnown( $file->getTitle() );
977  } else {
978  $link = Linker::makeExternalLink( $file->getDescriptionUrl(),
979  $file->getTitle()->getPrefixedText() );
980  $fromSrc = $this->getContext()->msg(
981  'shared-repo-from',
982  $file->getRepo()->getDisplayName()
983  )->text();
984  }
985  $out->addHTML( "<li>{$link} {$fromSrc}</li>\n" );
986  }
987  $out->addHTML( "</ul></div>\n" );
988  }
989 
993  public function delete() {
994  $file = $this->mPage->getFile();
995  if ( !$file->exists() || !$file->isLocal() || $file->getRedirected() ) {
996  // Standard article deletion
997  parent::delete();
998  return;
999  }
1000 
1001  $deleter = new FileDeleteForm( $file );
1002  $deleter->execute();
1003  }
1004 
1010  function showError( $description ) {
1011  $out = $this->getContext()->getOutput();
1012  $out->setPageTitle( $this->getContext()->msg( 'internalerror' ) );
1013  $out->setRobotPolicy( 'noindex,nofollow' );
1014  $out->setArticleRelated( false );
1015  $out->enableClientCache( false );
1016  $out->addWikiText( $description );
1017  }
1018 
1027  protected function compare( $a, $b ) {
1028  if ( $a->page_namespace == $b->page_namespace ) {
1029  return strcmp( $a->page_title, $b->page_title );
1030  } else {
1031  return $a->page_namespace - $b->page_namespace;
1032  }
1033  }
1034 
1043  public function getImageLimitsFromOption( $user, $optionName ) {
1045 
1046  $option = $user->getIntOption( $optionName );
1047  if ( !isset( $wgImageLimits[$option] ) ) {
1048  $option = User::getDefaultOption( $optionName );
1049  }
1050 
1051  // The user offset might still be incorrect, specially if
1052  // $wgImageLimits got changed (see bug #8858).
1053  if ( !isset( $wgImageLimits[$option] ) ) {
1054  // Default to the first offset in $wgImageLimits
1055  $option = 0;
1056  }
1057 
1058  return isset( $wgImageLimits[$option] )
1059  ? $wgImageLimits[$option]
1060  : [ 800, 600 ]; // if nothing is set, fallback to a hardcoded default
1061  }
1062 
1071  protected function doRenderLangOpt( array $langChoices, $curLang, $defaultLang ) {
1072  global $wgScript;
1073  sort( $langChoices );
1074  $curLang = wfBCP47( $curLang );
1075  $defaultLang = wfBCP47( $defaultLang );
1076  $opts = '';
1077  $haveCurrentLang = false;
1078  $haveDefaultLang = false;
1079 
1080  // We make a list of all the language choices in the file.
1081  // Additionally if the default language to render this file
1082  // is not included as being in this file (for example, in svgs
1083  // usually the fallback content is the english content) also
1084  // include a choice for that. Last of all, if we're viewing
1085  // the file in a language not on the list, add it as a choice.
1086  foreach ( $langChoices as $lang ) {
1087  $code = wfBCP47( $lang );
1088  $name = Language::fetchLanguageName( $code, $this->getContext()->getLanguage()->getCode() );
1089  if ( $name !== '' ) {
1090  $display = $this->getContext()->msg( 'img-lang-opt', $code, $name )->text();
1091  } else {
1092  $display = $code;
1093  }
1094  $opts .= "\n" . Xml::option( $display, $code, $curLang === $code );
1095  if ( $curLang === $code ) {
1096  $haveCurrentLang = true;
1097  }
1098  if ( $defaultLang === $code ) {
1099  $haveDefaultLang = true;
1100  }
1101  }
1102  if ( !$haveDefaultLang ) {
1103  // Its hard to know if the content is really in the default language, or
1104  // if its just unmarked content that could be in any language.
1105  $opts = Xml::option(
1106  $this->getContext()->msg( 'img-lang-default' )->text(),
1107  $defaultLang,
1108  $defaultLang === $curLang
1109  ) . $opts;
1110  }
1111  if ( !$haveCurrentLang && $defaultLang !== $curLang ) {
1112  $name = Language::fetchLanguageName( $curLang, $this->getContext()->getLanguage()->getCode() );
1113  if ( $name !== '' ) {
1114  $display = $this->getContext()->msg( 'img-lang-opt', $curLang, $name )->text();
1115  } else {
1116  $display = $curLang;
1117  }
1118  $opts = Xml::option( $display, $curLang, true ) . $opts;
1119  }
1120 
1121  $select = Html::rawElement(
1122  'select',
1123  [ 'id' => 'mw-imglangselector', 'name' => 'lang' ],
1124  $opts
1125  );
1126  $submit = Xml::submitButton( $this->getContext()->msg( 'img-lang-go' )->text() );
1127 
1128  $formContents = $this->getContext()->msg( 'img-lang-info' )
1129  ->rawParams( $select, $submit )
1130  ->parse();
1131  $formContents .= Html::hidden( 'title', $this->getTitle()->getPrefixedDBkey() );
1132 
1133  $langSelectLine = Html::rawElement( 'div', [ 'id' => 'mw-imglangselector-line' ],
1134  Html::rawElement( 'form', [ 'action' => $wgScript ], $formContents )
1135  );
1136  return $langSelectLine;
1137  }
1138 
1153  protected function getDisplayWidthHeight( $maxWidth, $maxHeight, $width, $height ) {
1154  if ( !$maxWidth || !$maxHeight ) {
1155  // should never happen
1156  throw new MWException( 'Using a choice from $wgImageLimits that is 0x0' );
1157  }
1158 
1159  if ( !$width || !$height ) {
1160  return [ 0, 0 ];
1161  }
1162 
1163  # Calculate the thumbnail size.
1164  if ( $width <= $maxWidth && $height <= $maxHeight ) {
1165  // Vectorized image, do nothing.
1166  } elseif ( $width / $height >= $maxWidth / $maxHeight ) {
1167  # The limiting factor is the width, not the height.
1168  $height = round( $height * $maxWidth / $width );
1169  $width = $maxWidth;
1170  # Note that $height <= $maxHeight now.
1171  } else {
1172  $newwidth = floor( $width * $maxHeight / $height );
1173  $height = round( $height * $newwidth / $width );
1174  $width = $newwidth;
1175  # Note that $height <= $maxHeight now, but might not be identical
1176  # because of rounding.
1177  }
1178  return [ $width, $height ];
1179  }
1180 
1189  protected function getThumbSizes( $origWidth, $origHeight ) {
1191  if ( $this->displayImg->getRepo()->canTransformVia404() ) {
1192  $thumbSizes = $wgImageLimits;
1193  // Also include the full sized resolution in the list, so
1194  // that users know they can get it. This will link to the
1195  // original file asset if mustRender() === false. In the case
1196  // that we mustRender, some users have indicated that they would
1197  // find it useful to have the full size image in the rendered
1198  // image format.
1199  $thumbSizes[] = [ $origWidth, $origHeight ];
1200  } else {
1201  # Creating thumb links triggers thumbnail generation.
1202  # Just generate the thumb for the current users prefs.
1203  $thumbSizes = [
1204  $this->getImageLimitsFromOption( $this->getContext()->getUser(), 'thumbsize' )
1205  ];
1206  if ( !$this->displayImg->mustRender() ) {
1207  // We can safely include a link to the "full-size" preview,
1208  // without actually rendering.
1209  $thumbSizes[] = [ $origWidth, $origHeight ];
1210  }
1211  }
1212  return $thumbSizes;
1213  }
1214 
1219  public function getFile() {
1220  return $this->mPage->getFile();
1221  }
1222 
1227  public function isLocal() {
1228  return $this->mPage->isLocal();
1229  }
1230 
1235  public function getDuplicates() {
1236  return $this->mPage->getDuplicates();
1237  }
1238 
1243  public function getForeignCategories() {
1244  $this->mPage->getForeignCategories();
1245  }
1246 
1247 }
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: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:814
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:735
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:702
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:793
uploadLinksBox()
Print out the various links at the bottom of the image page, e.g.
Definition: ImagePage.php:748
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:1243
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:1189
$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:1010
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: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: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: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:766
compare($a, $b)
Callback for usort() to do link sorts by (namespace, title) Function copied from Title::compare() ...
Definition: ImagePage.php:1027
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:2289
getDisplayWidthHeight($maxWidth, $maxHeight, $width, $height)
Get the width and height to display image at.
Definition: ImagePage.php:1153
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:235
makeSizeLink($params, $width, $height)
Creates an thumbnail of specified size and returns an HTML link to it.
Definition: ImagePage.php:683
$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:1071
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:645
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: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:1043
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: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:2342
closeShowImage()
For overloading.
Definition: ImagePage.php:786
openShowImage()
Definition: ImagePage.php:308
Allows to change the fields on the form that will be generated $name
Definition: hooks.txt:314