From f66b26e0a6bfe96555a60a61be935d7442a4572d Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Fri, 17 Jun 2011 15:57:00 +0000 Subject: [PATCH] * (bug 25133) allow redirects also for action=parse&pageid --- RELEASE-NOTES-1.19 | 5 ++-- includes/api/ApiParse.php | 61 ++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 28 deletions(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 80f87df0c9..2c078b2244 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -95,7 +95,7 @@ production. * (bug 29332) Warn if user requests mediawiki-announce subscription but does not enter an e-mail address. * (bug 25375) Add canonical namespaces to JavaScript "wgNamespaceIds" -* The class JpegOrTiffHandler was renamed ExifBitmapHandler. +* The class JpegOrTiffHandler was renamed ExifBitmapHandler. === API changes in 1.19 === * BREAKING CHANGE: action=watch now requires POST and token. @@ -105,7 +105,7 @@ production. * (bug 28578) API's parse module should not silently override invalid title inputs * (bug 20699) API watchlist should list log-events -* (bug 29070) Add token to action=watch API +* (bug 29070) Add token to action=watch API * (bug 29221) Expose oldrevid in watchlist output * (bug 29267) always give the servername for meta=siteinfo&siprop=dbrepllag * (bug 28897) rvparse doesn’t seem to work with rvsection @@ -116,6 +116,7 @@ production. * (bug 21346) Make deleted images searchable by hash (disabled in Miser Mode) * (bug 27595) sha1 search of list=filearchive does not work * (bug 26763) Make RSS/Atom of user contributions more visible +* (bug 25133) allow redirects also for action=parse&pageid === Languages updated in 1.19 === diff --git a/includes/api/ApiParse.php b/includes/api/ApiParse.php index 198083da72..dfc2602b91 100644 --- a/includes/api/ApiParse.php +++ b/includes/api/ApiParse.php @@ -110,35 +110,44 @@ class ApiParse extends ApiBase { $p_result = $wgParser->parse( $this->text, $titleObj, $popts ); } } else { // Not $oldid - if ( !is_null ( $pageid ) ) { - $titleObj = Title::newFromID( $pageid ); - - if ( !$titleObj ) { - $this->dieUsageMsg( array( 'nosuchpageid', $pageid ) ); + if ( $params['redirects'] ) { + $reqParams = array( + 'action' => 'query', + 'redirects' => '', + ); + if ( !is_null ( $pageid ) ) { + $reqParams['pageids'] = $pageid; + } else { // $page + $reqParams['titles'] = $page; } - } else { // $page - if ( $params['redirects'] ) { - $req = new FauxRequest( array( - 'action' => 'query', - 'redirects' => '', - 'titles' => $page - ) ); - $main = new ApiMain( $req ); - $main->execute(); - $data = $main->getResultData(); - $redirValues = isset( $data['query']['redirects'] ) - ? $data['query']['redirects'] : array(); - $to = $page; - foreach ( (array)$redirValues as $r ) { - $to = $r['to']; - } - } else { - $to = $page; + $req = new FauxRequest( $reqParams ); + $main = new ApiMain( $req ); + $main->execute(); + $data = $main->getResultData(); + $redirValues = isset( $data['query']['redirects'] ) + ? $data['query']['redirects'] + : array(); + $to = $page; + foreach ( (array)$redirValues as $r ) { + $to = $r['to']; } $titleObj = Title::newFromText( $to ); - if ( !$titleObj || !$titleObj->exists() ) { - $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' ); + } else { + if ( !is_null ( $pageid ) ) { + $reqParams['pageids'] = $pageid; + $titleObj = Title::newFromID( $pageid ); + } else { // $page + $to = $page; + $titleObj = Title::newFromText( $to ); + } + } + if ( !is_null ( $pageid ) ) { + if ( !$titleObj ) { + // Still throw nosuchpageid error if pageid was provided + $this->dieUsageMsg( array( 'nosuchpageid', $pageid ) ); } + } elseif ( !$titleObj || !$titleObj->exists() ) { + $this->dieUsage( "The page you specified doesn't exist", 'missingtitle' ); } $wgTitle = $titleObj; @@ -515,7 +524,7 @@ class ApiParse extends ApiBase { return array( 'text' => 'Wikitext to parse', 'summary' => 'Summary to parse', - 'redirects' => "If the {$p}page parameter is set to a redirect, resolve it", + 'redirects' => "If the {$p}page or the {$p}pageid parameter is set to a redirect, resolve it", 'title' => 'Title of page the text belongs to', 'page' => "Parse the content of this page. Cannot be used together with {$p}text and {$p}title", 'pageid' => "Parse the content of this page. Overrides {$p}page", -- 2.20.1