r70658 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r70657‎ | r70658 | r70659 >
Date:01:14, 8 August 2010
Author:soxred93
Status:resolved (Comments)
Tags:
Comment:
(bug 24330) Add &redirect parameter to ?action=edit
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiEditPage.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiEditPage.php
@@ -57,7 +57,38 @@
5858 if ( !$titleObj || $titleObj->isExternal() ) {
5959 $this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
6060 }
 61+
 62+ if( $params['redirect'] ) {
 63+ if( $titleObj->isRedirect() ) {
 64+ $oldTitle = $titleObj;
 65+
 66+ $titles = Title::newFromRedirectArray( Revision::newFromTitle( $oldTitle )->getText( Revision::FOR_THIS_USER ) );
 67+ //array_shift( $titles );
 68+
 69+ $this->getResult()->addValue( null, 'foo', $titles );
 70+
 71+
 72+ $redirValues = array();
 73+ foreach ( $titles as $id => $newTitle ) {
 74+
 75+ if( !isset( $titles[ $id - 1 ] ) ) {
 76+ $titles[ $id - 1 ] = $oldTitle;
 77+ }
 78+
 79+ $redirValues[] = array(
 80+ 'from' => $titles[ $id - 1 ]->getPrefixedText(),
 81+ 'to' => $newTitle->getPrefixedText()
 82+ );
 83+
 84+ $titleObj = $newTitle;
 85+ }
 86+
 87+ $this->getResult()->setIndexedTagName( $redirValues, 'r' );
 88+ $this->getResult()->addValue( null, 'redirects', $redirValues );
6189
 90+ }
 91+ }
 92+
6293 // Some functions depend on $wgTitle == $ep->mTitle
6394 global $wgTitle;
6495 $wgTitle = $titleObj;
@@ -428,6 +459,10 @@
429460 'undoafter' => array(
430461 ApiBase::PARAM_TYPE => 'integer'
431462 ),
 463+ 'redirect' => array(
 464+ ApiBase::PARAM_TYPE => 'boolean',
 465+ ApiBase::PARAM_DFLT => false,
 466+ ),
432467 );
433468 }
434469
@@ -462,6 +497,7 @@
463498 'appendtext' => "Add this text to the end of the page. Overrides {$p}text",
464499 'undo' => "Undo this revision. Overrides {$p}text, {$p}prependtext and {$p}appendtext",
465500 'undoafter' => 'Undo all revisions from undo to this one. If not set, just undo one revision',
 501+ 'redirect' => 'Automatically resolve redirects',
466502 );
467503 }
468504
Index: trunk/phase3/RELEASE-NOTES
@@ -331,7 +331,8 @@
332332 * (bug 24677) axto= parameters added to allcategories, allimages, alllinks, allmessages,
333333 allpages, and allusers
334334 * (bug 24236) Add add, remove, add-self, remove-self tags to meta=siteinfo&siprop=usergroups
335 -* (bug 24484) Add prop=pageprops module
 335+* (bug 24484) Add prop=pageprops module
 336+* (bug 24330) Add &redirect parameter to ?action=edit
336337
337338 === Languages updated in 1.17 ===
338339

Follow-up revisions

RevisionCommit summaryAuthorDate
r70703Followup to r70658: Code styling, use ApiPageSet to fix redirects.soxred9315:03, 8 August 2010

Comments

#Comment by Catrope (talk | contribs)   11:17, 8 August 2010
+		if( $params['redirect'] ) {
+			if( $titleObj->isRedirect() ) {
[...]
+			}
+		}

Might as well use if ( $params['redirect'] && $titleObj->isRedirect() ) then: it's equivalent to the above because && is lazy, and it's shorter.

+				$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 );

Instead of duplicating functionality from ApiPageSet, it's better to use ApiPageSet directly:

$pageSet = new ApiPageSet( $this->getQuery(), true ); // Or true, true to also do variant conversion of titles
$pageSet->populateFromTitles( array( $title ) );
foreach ( $pageSet->getRedirectTitles() as $from => $to ) {
    $redirs[] = array( 'from' => $from, 'to' => $to );
}
#Comment by X! (talk | contribs)   16:29, 9 August 2010

Fixed.

#Comment by Duplicatebug (talk | contribs)   17:20, 26 March 2011
+			'redirect' => array(
+				ApiBase::PARAM_TYPE => 'boolean',
+				ApiBase::PARAM_DFLT => false,
+			),

it is easy to use:

+			'redirect' => false,

Or change from 'boolean' to 'bool' because that is used more often inside the api. Thanks

#Comment by Duplicatebug (talk | contribs)   19:31, 2 April 2011

You are using 'boolean', because ApiBase::getParameterFromSettings is using 'boolean' and not 'bool' like action=paraminfo outputted. It is possible to get this the same? Thanks.

#Comment by Duplicatebug (talk | contribs)   19:50, 2 July 2011

all the same after r89538

Status & tagging log