Page MenuHomePhabricator

Make DynamicPageList_(wikimedia) use page images as the image in gallery mode for pages that are not in the File namespace
Closed, ResolvedPublic

Description

This task is a more advanced task. It is recommended you have already done at least two (maybe more) tasks involving PHP coding of MediaWiki extensions that involved submitting code to gerrit. As this is meant as a more challenging task, some of the details are not as spelled out as some of the less challenging tasks. If things are confusing, don't hesitate to ask for clarification on irc.

The DynamicPageList_(Wikimedia) extension (also known as the "intersection" extension) https://www.mediawiki.org/wiki/Extension:DynamicPageList_(Wikimedia) has an option mode=gallery which allows showing a gallery of images that match the query. Currently this only really works with files in the file namespace. Your task is to have it use the page image (from the PageImages extension https://www.mediawiki.org/wiki/Extension:PageImages ) for pages that are not file pages. Currently it just displays an empty space for pages not in the file namespace.

Broadly speaking you have to do two things: Modify the SQL query so that the database returns the "free page image" and the "non-free page image". Second, you have to modify the display code so that for pages that are not File pages, first it will use the free page image if available, then it will fallback to the non-free image, and last it will just use the page in question if no page image is available.

Prerequisites:

  • You have done several MediaWiki PHP coding related tasks, and are looking for a more complex PHP coding task
  • You have already setup MediaWiki locally
  • You have a basic knowledge of SQL and know what a LEFT JOIN is (e.g. You understand what the query SELECT page_namespace, page_title, p1.pp_value AS 'image' FROM page left join page_props p1 on p1.pp_page = page_id and p1.pp_propname = 'page_image_free' where page_id = 1931416; means. If not, there are several sql tutorials online)

It is recommended you skim through https://www.mediawiki.org/wiki/Manual:Page_props_table and https://www.mediawiki.org/wiki/Manual:Database_access#Database_Abstraction_Layer to give you background as to how MediaWiki makes SQL queries, if you are not already familiar with this. However that page goes in a lot of detail, so don't worry if you don't understand all of it.

To do this, you need to modify two parts of the dynamic page list extension:

Where the SQL is generated (around line 441-ish of intersection/includes/DynamicPageListHooks.php ), provided you are in gallery mode, and the PageImages extension is loaded, you would have to add page_props to the $tables. You should use an alias so the key to the array is the alias name, and the value is page_props. You then need to add a join to $join for page_props. it should be a LEFT JOIN and the two ON conditions should be pp_propname = PageImages::PROP_NAME and page_id = pp_page (adding appropriate table aliases). You should then do the same thing with a different alias but for PageImages::PROP_NAME_FREE. You then have to add <alias>.pp_value to $fields (Probably also giving this an alias for clarify). Doing these modifications show change the query so that the database returns a column containing the "free" page image and a column containing the "non-free" page image

Once the query is modified, we now have to make use of the modified query. Now you must adjust the gallery building code to use the alternative images for pages that are not in the file namespace. You then have to find the code that calls $gallery->add. Instead of the current code, if $title->getNamespace() !== NS_FILE you have to get the field from the page_prop (trying first the free version, and then not free version if free is null), create a title from it (use Title::makeTitleSafe), and add that instead of the current title. However if you are not adding the current title, you also have to make sure the link goes to the right place, so you have to provide the fourth argument to $gallery->add as a link to the original title, e.g. $title->getLinkURL()

Once all this is done, test the code on your local wiki to make sure it all works. Make a commit with an appropriate commit message, and upload to gerrit.

Event Timeline

Change 560871 had a related patch set uploaded (by BrandonXLF; owner: BrandonXLF):
[mediawiki/extensions/intersection@master] Use page image when in gallery mode

https://gerrit.wikimedia.org/r/560871

Change 560871 merged by jenkins-bot:
[mediawiki/extensions/intersection@master] Use page image when in gallery mode

https://gerrit.wikimedia.org/r/560871