From 9f025aeb1d0e374a737735e943906a56734bc3ba Mon Sep 17 00:00:00 2001 From: X! Date: Sun, 8 Aug 2010 01:14:48 +0000 Subject: [PATCH] (bug 24330) Add &redirect parameter to ?action=edit --- RELEASE-NOTES | 3 ++- includes/api/ApiEditPage.php | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 2579818ad7..319c3c275f 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -331,7 +331,8 @@ it from source control: http://www.mediawiki.org/wiki/Download_from_SVN * (bug 24677) axto= parameters added to allcategories, allimages, alllinks, allmessages, allpages, and allusers * (bug 24236) Add add, remove, add-self, remove-self tags to meta=siteinfo&siprop=usergroups -* (bug 24484) Add prop=pageprops module +* (bug 24484) Add prop=pageprops module +* (bug 24330) Add &redirect parameter to ?action=edit === Languages updated in 1.17 === diff --git a/includes/api/ApiEditPage.php b/includes/api/ApiEditPage.php index 159d1cc40b..1c165b6450 100644 --- a/includes/api/ApiEditPage.php +++ b/includes/api/ApiEditPage.php @@ -57,6 +57,37 @@ class ApiEditPage extends ApiBase { if ( !$titleObj || $titleObj->isExternal() ) { $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) ); } + + if( $params['redirect'] ) { + if( $titleObj->isRedirect() ) { + $oldTitle = $titleObj; + + $titles = Title::newFromRedirectArray( Revision::newFromTitle( $oldTitle )->getText( Revision::FOR_THIS_USER ) ); + //array_shift( $titles ); + + $this->getResult()->addValue( null, 'foo', $titles ); + + + $redirValues = array(); + foreach ( $titles as $id => $newTitle ) { + + if( !isset( $titles[ $id - 1 ] ) ) { + $titles[ $id - 1 ] = $oldTitle; + } + + $redirValues[] = array( + 'from' => $titles[ $id - 1 ]->getPrefixedText(), + 'to' => $newTitle->getPrefixedText() + ); + + $titleObj = $newTitle; + } + + $this->getResult()->setIndexedTagName( $redirValues, 'r' ); + $this->getResult()->addValue( null, 'redirects', $redirValues ); + + } + } // Some functions depend on $wgTitle == $ep->mTitle global $wgTitle; @@ -428,6 +459,10 @@ class ApiEditPage extends ApiBase { 'undoafter' => array( ApiBase::PARAM_TYPE => 'integer' ), + 'redirect' => array( + ApiBase::PARAM_TYPE => 'boolean', + ApiBase::PARAM_DFLT => false, + ), ); } @@ -462,6 +497,7 @@ class ApiEditPage extends ApiBase { 'appendtext' => "Add this text to the end of the page. Overrides {$p}text", 'undo' => "Undo this revision. Overrides {$p}text, {$p}prependtext and {$p}appendtext", 'undoafter' => 'Undo all revisions from undo to this one. If not set, just undo one revision', + 'redirect' => 'Automatically resolve redirects', ); } -- 2.20.1