From: Brian Wolff Date: Sun, 19 Aug 2012 16:21:47 +0000 (-0300) Subject: (bug 27111) Make cascading foreign repo's fetch description properly X-Git-Tag: 1.31.0-rc.0~22617 X-Git-Url: http://git.cyclocoop.org/%24action?a=commitdiff_plain;h=ca13fde652e1a1a05c835219af7b014509a1c88f;p=lhc%2Fweb%2Fwiklou.git (bug 27111) Make cascading foreign repo's fetch description properly This changes action=render on file pages to include the shared image description (if it exists). The reasons for this are two fold: *Logically, most users would consider the shared description part of the content of the page, and not part of the site chrome, so it should be on action=render *Foreign file repos use action=render to get image descriptions. if you use say en.wikipedia.org as your file repo, commons images get cascasively included, but all their descriptions end up being the noarticletext message, which is bad. This makes the shared image descriptions work. Some notes on the implementation: * on action=render the div containing the shared description doesn't have the id that the one on normal page view has. This is to prevent duplicate ids in the cascading repo scenario. I added a class so people can identify them if they want, and this allows people to easily identify the "outermost" shared description as it would be the only one with the id. * This doesn't include the "shareddescriptionfollows" message (which is disabled by default) that would normally separate the local from the non-local description. I wasn't sure, but thought that would be considered part of the site chrome. Patchset 2/3: trailing space/spelling mistake Patchset 4: rebase Change-Id: I18bdf29de62526d699740607b5015da4b01fd43d --- diff --git a/RELEASE-NOTES-1.20 b/RELEASE-NOTES-1.20 index c9bf279df6..cb67f24690 100644 --- a/RELEASE-NOTES-1.20 +++ b/RELEASE-NOTES-1.20 @@ -219,6 +219,7 @@ upgrade PHP if you have not done so prior to upgrading MediaWiki. PCRE is compiled without support for unicode properties. * (bug 30390) Suggested file name on Special:Upload should not contain illegal characters. +* (bug 27111) Cascading foreign file repos now fetch shared descriptions properly === API changes in 1.20 === * (bug 34316) Add ability to retrieve maximum upload size from MediaWiki API. diff --git a/includes/ImagePage.php b/includes/ImagePage.php index da9d1ec5a3..fdc2061480 100644 --- a/includes/ImagePage.php +++ b/includes/ImagePage.php @@ -94,10 +94,47 @@ class ImagePage extends Article { /** * Handler for action=render * Include body text only; none of the image extras + * However, also include the shared description text + * so that cascading ForeignAPIRepo's work. + * + * @note This uses a div with the class "mw-shared-image-desc" + * as opposed to the id "mw-shared-image-desc" since the text + * from here may be cascadingly transcluded to other shared + * repos, and we want all ids to be unique. On normal + * view, the outermost shared description will still have + * the id. + * + * This also differs from normal view in that "shareddescriptionfollows" + * message is not shown. I was not sure if it was appropriate to + * add that message here. */ public function render() { - $this->getContext()->getOutput()->setArticleBodyOnly( true ); - parent::view(); + $out = $this->getContext()->getOutput(); + $this->loadFile(); + + $descText = $this->mPage->getFile()->getDescriptionText(); + + $out->setArticleBodyOnly( true ); + + if ( !$descText ) { + // If no description text, just do standard action=render + parent::view(); + } else { + if ( $this->mPage->getID() !== 0 ) { + // Local description exists. We need to output both + parent::view(); + $out->addHTML( '
' . $descText . "
\n" ); + } else { + // We don't want to output both a "noarticletext" message and the shared + // description, so don't call parent::view(). + $out->addHTML( '
' . $descText . "
\n" ); + // Since we did not call parent::view(), have to call some methods it + // normally takes care of. (Not that it matters much since skin not displayed) + $out->setArticleFlag( true ); + $out->setPageTitle( $this->getTitle()->getPrefixedText() ); + $this->mPage->doViewUpdates( $this->getContext()->getUser() ); + } + } } public function view() { @@ -172,7 +209,7 @@ class ImagePage extends Article { if ( !$fol->isDisabled() ) { $out->addWikiText( $fol->plain() ); } - $out->addHTML( '
' . $this->mExtraDescription . "
\n" ); + $out->addHTML( '
' . $this->mExtraDescription . "
\n" ); } $this->closeShowImage();