7use UtfNormal\Validator;
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 );
Apache License January http
wfDebugLog( $logGroup, $text, $dest='all', array $context=[])
Send a line to a supplementary debug log file, if configured, or main debug log if not.
wfAppendQuery( $url, $query)
Append a query string to an existing URL, which may or may not already have query string parameters a...
Various HTTP related functions.
Service for normalizing a page name using a MediaWiki api.
static extractPageRecord( $externalData, $pageTitle)
Get normalization record for a given page title from an API response.
__construct(Http $http=null)
normalizePageName( $pageName, $apiUrl)
Returns the normalized form of the given page title, using the normalization rules of the given site.
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses & $ret