aboutsummaryrefslogtreecommitdiffstats
path: root/includes/api/ApiFeedWatchlist.php
diff options
context:
space:
mode:
authorkaligula <winne2i@gmail.com>2013-04-09 20:16:08 +0200
committerkaligula <winne2i@gmail.com>2013-04-09 20:16:08 +0200
commit0d086f32df5c583f09d2f421aa733c2c97673342 (patch)
treebe37903fa723d3142ebb46849d77fedd6d2f6e55 /includes/api/ApiFeedWatchlist.php
parent0f22a50c909662e7a88af2e8603cd7a16d7b7183 (diff)
downloadmediawikicore-0d086f32df5c583f09d2f421aa733c2c97673342.tar.gz
mediawikicore-0d086f32df5c583f09d2f421aa733c2c97673342.zip
Support for linking directly to sections in ApiFeedWatchlist.
It works only if a section name is present in item's comment. Change-Id: I2547c10b01fab2f835fce856f6213386f309f0af
Diffstat (limited to 'includes/api/ApiFeedWatchlist.php')
-rw-r--r--includes/api/ApiFeedWatchlist.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/includes/api/ApiFeedWatchlist.php b/includes/api/ApiFeedWatchlist.php
index fdbdcc33de56..b96ea3714216 100644
--- a/includes/api/ApiFeedWatchlist.php
+++ b/includes/api/ApiFeedWatchlist.php
@@ -33,8 +33,9 @@
*/
class ApiFeedWatchlist extends ApiBase {
- private $linkToDiffs = false;
private $watchlistModule = null;
+ private $linkToDiffs = false;
+ private $linkToSections = false;
/**
* This module uses a custom feed wrapper printer.
@@ -97,6 +98,12 @@ class ApiFeedWatchlist extends ApiBase {
$fauxReqArr['wlprop'] .= '|ids';
}
+ // Support linking directly to sections when possible
+ // (possible only if section name is present in comment)
+ if ( $params['linktosections'] ) {
+ $this->linkToSections = true;
+ }
+
// Check for 'allrev' parameter, and if found, show all revisions to each page on wl.
if ( $params['allrev'] ) {
$fauxReqArr['wlallrev'] = '';
@@ -164,6 +171,18 @@ class ApiFeedWatchlist extends ApiBase {
$titleUrl = $title->getFullURL();
}
$comment = isset( $info['comment'] ) ? $info['comment'] : null;
+
+ // Create an anchor to section.
+ // The anchor won't work for sections that have dupes on page
+ // as there's no way to strip that info from ApiWatchlist (apparently?).
+ // RegExp in the line below is equal to Linker::formatAutocomments().
+ if ( $this->linkToSections && $comment !== null && preg_match( '!(.*)/\*\s*(.*?)\s*\*/(.*)!', $comment, $matches ) ) {
+ global $wgParser;
+ $sectionTitle = $wgParser->stripSectionName( $matches[2] );
+ $sectionTitle = Sanitizer::normalizeSectionNameWhitespace( $sectionTitle );
+ $titleUrl .= Title::newFromText( '#' . $sectionTitle )->getFragmentForURL();
+ }
+
$timestamp = $info['timestamp'];
$user = $info['user'];
@@ -195,6 +214,7 @@ class ApiFeedWatchlist extends ApiBase {
ApiBase::PARAM_MAX => 72,
),
'linktodiffs' => false,
+ 'linktosections' => false,
);
if ( $flags ) {
$wlparams = $this->getWatchlistModule()->getAllowedParams( $flags );
@@ -219,6 +239,7 @@ class ApiFeedWatchlist extends ApiBase {
'feedformat' => 'The format of the feed',
'hours' => 'List pages modified within this many hours from now',
'linktodiffs' => 'Link to change differences instead of article pages',
+ 'linktosections' => 'Link directly to changed sections if possible',
'allrev' => $wldescr['allrev'],
'wlowner' => $wldescr['owner'],
'wltoken' => $wldescr['token'],