(bug 27111) Make cascading foreign repo's fetch description properly
authorBrian Wolff <bawolff+wn@gmail.com>
Sun, 19 Aug 2012 16:21:47 +0000 (13:21 -0300)
committerBrian Wolff <bawolff+wn@gmail.com>
Thu, 23 Aug 2012 18:44:23 +0000 (15:44 -0300)
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

RELEASE-NOTES-1.20
includes/ImagePage.php

index c9bf279..cb67f24 100644 (file)
@@ -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.
index da9d1ec..fdc2061 100644 (file)
@@ -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( '<div class="mw-shared-image-desc">' . $descText . "</div>\n" );
+                       } else {
+                               // We don't want to output both a "noarticletext" message and the shared
+                               // description, so don't call parent::view().
+                               $out->addHTML( '<div class="mw-shared-image-desc">' . $descText . "</div>\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( '<div id="shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
+                       $out->addHTML( '<div id="shared-image-desc" class="mw-shared-image-desc">' . $this->mExtraDescription . "</div>\n" );
                }
 
                $this->closeShowImage();