From: Erik Bernhardson Date: Tue, 3 Feb 2015 06:08:12 +0000 (-0800) Subject: Allow override of page disply within CategoryViewer X-Git-Tag: 1.31.0-rc.0~12336 X-Git-Url: https://git.cyclocoop.org/%7B%24www_url%7Dadmin/compta/exercices/bilan.php?a=commitdiff_plain;h=8bf4496869181fd40f0284fade2ffaa5f234b39f;p=lhc%2Fweb%2Fwiklou.git Allow override of page disply within CategoryViewer Patch adds two hook which are described in hooks.txt. This is being used to allow Flow to offer two links instead of just one that are relevant to the page that was categorized. The default output without these hooks is: Topic:Soiasdf90f09 This patch allows flow to provide context as to where this topic came from, by replacing that with: Topic:Soiasdf90f09 on Talk:Help (Note that the names of pages within the Topic namespace will also become more friendly soonish, but outside the scope of this patch). Bug: T87793 Related-Flow-Change: Ia4f2953bcd807ba3990e762a2efcaab428c40147 Change-Id: I182e6e35fcc3a2a298e928e088579bdb22e145ff --- diff --git a/RELEASE-NOTES-1.25 b/RELEASE-NOTES-1.25 index 67a32ec3a0..df13daab30 100644 --- a/RELEASE-NOTES-1.25 +++ b/RELEASE-NOTES-1.25 @@ -103,6 +103,8 @@ production. dynamically-compiled Mustache templates (currently uses lightncandy library). * Clickable anchors for each section heading in the content are now generated and appear in the gutter on hovering over the heading. +* Added 'CategoryViewer::doCategoryQuery' and 'CategoryViewer::generateLink' hooks + to allow extensions to override how links to pages are rendered within NS_CATEGORY ==== External libraries ==== * MediaWiki now requires certain external libraries to be installed. In the past diff --git a/docs/hooks.txt b/docs/hooks.txt index 78ac2ffdb4..a88803b291 100644 --- a/docs/hooks.txt +++ b/docs/hooks.txt @@ -870,6 +870,20 @@ $wikiPage: WikiPage that was removed 'CategoryPageView': Before viewing a categorypage in CategoryPage::view. $catpage: CategoryPage instance +'CategoryViewer::doCategoryQuery': After querying for pages to be displayed +in a Category page. Gives extensions the opportunity to batch load any +related data about the pages. +$type: The category type. Either 'page', 'file' or 'subcat' +$res: Query result from DatabaseBase::select() + +'CategoryViewer::generateLink': Before generating an output link allow +extensions opportunity to generate a more specific or relevant link. +$type: The category type. Either 'page', 'img' or 'subcat' +$title: Title object for the categorized page +$html: Requested html content of anchor +&$link: Returned value. When set to a non-null value by a hook subscriber +this value will be used as the anchor instead of Linker::link + 'ChangePasswordForm': For extensions that need to add a field to the ChangePassword form via the Preferences form. &$extraFields: An array of arrays that hold fields like would be passed to the diff --git a/includes/CategoryViewer.php b/includes/CategoryViewer.php index 6b86853e51..1e0bf16c9f 100644 --- a/includes/CategoryViewer.php +++ b/includes/CategoryViewer.php @@ -174,19 +174,30 @@ class CategoryViewer extends ContextSource { // Subcategory; strip the 'Category' namespace from the link text. $title = $cat->getTitle(); - $link = Linker::link( $title, htmlspecialchars( $title->getText() ) ); - if ( $title->isRedirect() ) { - // This didn't used to add redirect-in-category, but might - // as well be consistent with the rest of the sections - // on a category page. - $link = '' . $link . ''; - } - $this->children[] = $link; + $this->children[] = $this->generateLink( + 'subcat', + $title, + $title->isRedirect(), + htmlspecialchars( $title->getText() ) + ); $this->children_start_char[] = $this->getSubcategorySortChar( $cat->getTitle(), $sortkey ); } + function generateLink( $type, Title $title, $isRedirect, $html = null ) { + $link = null; + Hooks::run( 'CategoryViewer::generateLink', array( $type, $title, $html, &$link ) ); + if ( $link === null ) { + $link = Linker::link( $title, $html ); + } + if ( $isRedirect ) { + $link = '' . $link . ''; + } + + return $link; + } + /** * Get the character to be used for sorting subcategories. * If there's a link from Category:A to Category:B, the sortkey of the resulting @@ -229,13 +240,7 @@ class CategoryViewer extends ContextSource { $this->gallery->add( $title ); } } else { - $link = Linker::link( $title ); - if ( $isRedirect ) { - // This seems kind of pointless given 'mw-redirect' class, - // but keeping for back-compatibility with user css. - $link = '' . $link . ''; - } - $this->imgsNoGallery[] = $link; + $this->imgsNoGallery[] = $this->generateLink( 'image', $title, $isRedirect ); $this->imgsNoGallery_start_char[] = $wgContLang->convert( $this->collation->getFirstLetter( $sortkey ) ); @@ -252,13 +257,7 @@ class CategoryViewer extends ContextSource { function addPage( $title, $sortkey, $pageLength, $isRedirect = false ) { global $wgContLang; - $link = Linker::link( $title ); - if ( $isRedirect ) { - // This seems kind of pointless given 'mw-redirect' class, - // but keeping for back-compatibility with user css. - $link = '' . $link . ''; - } - $this->articles[] = $link; + $this->articles[] = $this->generateLink( 'page', $title, $isRedirect ); $this->articles_start_char[] = $wgContLang->convert( $this->collation->getFirstLetter( $sortkey ) ); @@ -331,6 +330,8 @@ class CategoryViewer extends ContextSource { ) ); + Hooks::run( 'CategoryViewer::doCategoryQuery', array( $type, $res ) ); + $count = 0; foreach ( $res as $row ) { $title = Title::newFromRow( $row );