76 if ( !is_string( $pageName ) ) {
77 throw new \MWException(
'$pageName must be a string' );
85 $pageName = Validator::cleanUp( $pageName );
92 'converttitles' =>
true,
94 'titles' => $pageName,
106 $ret = $this->http->get( $url, [], __METHOD__ );
108 if ( $ret ===
false ) {
109 wfDebugLog(
"MediaWikiSite",
"call to external site failed: $url" );
115 if ( !is_array( $data ) ) {
116 wfDebugLog(
"MediaWikiSite",
"call to <$url> returned bad json: " . $ret );
120 $page = static::extractPageRecord( $data, $pageName );
122 if ( isset( $page[
'missing'] ) ) {
123 wfDebugLog(
"MediaWikiSite",
"call to <$url> returned a marker for a missing page title! "
128 if ( isset( $page[
'invalid'] ) ) {
129 wfDebugLog(
"MediaWikiSite",
"call to <$url> returned a marker for an invalid page title! "
134 if ( !isset( $page[
'title'] ) ) {
135 wfDebugLog(
"MediaWikiSite",
"call to <$url> did not return a page title! " . $ret );
139 return $page[
'title'];
154 if ( isset( $externalData[
'query'][
'pages'] ) ) {
155 $pages = array_values( $externalData[
'query'][
'pages'] );
156 if ( count( $pages ) === 1 ) {
163 if ( !is_array( $externalData ) || !isset( $externalData[
'query'] ) ) {
168 'normalized' =>
'from',
169 'converted' =>
'from',
170 'redirects' =>
'from',
173 foreach ( $structs as $listId => $fieldId ) {
175 if ( !isset( $externalData[
'query'][$listId] ) ) {
179 $collectedHits = array_filter(
180 array_values( $externalData[
'query'][$listId] ),
181 function ( $a ) use ( $fieldId, $pageTitle ) {
182 return $a[$fieldId] === $pageTitle;
187 if ( $fieldId ===
'from' && is_array( $collectedHits ) ) {
188 switch ( count( $collectedHits ) ) {
192 $pageTitle = $collectedHits[0][
'to'];
197 } elseif ( $fieldId ===
'title' && is_array( $collectedHits ) ) {
200 switch ( count( $collectedHits ) ) {
204 return array_shift( $collectedHits );