7use UtfNormal\Validator;
73 if ( !is_string( $pageName ) ) {
74 throw new \MWException(
'$pageName must be a string' );
82 $pageName = Validator::cleanUp( $pageName );
89 'converttitles' =>
true,
91 'titles' => $pageName,
103 $ret = $this->
http->get( $url, [], __METHOD__ );
105 if (
$ret ===
false ) {
106 wfDebugLog(
"MediaWikiSite",
"call to external site failed: $url" );
112 if ( !is_array( $data ) ) {
113 wfDebugLog(
"MediaWikiSite",
"call to <$url> returned bad json: " .
$ret );
117 $page = static::extractPageRecord( $data, $pageName );
119 if ( isset( $page[
'missing'] ) ) {
120 wfDebugLog(
"MediaWikiSite",
"call to <$url> returned a marker for a missing page title! "
125 if ( isset( $page[
'invalid'] ) ) {
126 wfDebugLog(
"MediaWikiSite",
"call to <$url> returned a marker for an invalid page title! "
131 if ( !isset( $page[
'title'] ) ) {
132 wfDebugLog(
"MediaWikiSite",
"call to <$url> did not return a page title! " .
$ret );
136 return $page[
'title'];
151 if ( isset( $externalData[
'query'][
'pages'] ) ) {
152 $pages = array_values( $externalData[
'query'][
'pages'] );
153 if ( count( $pages ) === 1 ) {
160 if ( !is_array( $externalData ) || !isset( $externalData[
'query'] ) ) {
165 'normalized' =>
'from',
166 'converted' =>
'from',
167 'redirects' =>
'from',
170 foreach ( $structs as $listId => $fieldId ) {
172 if ( !isset( $externalData[
'query'][$listId] ) ) {
176 $collectedHits = array_filter(
177 array_values( $externalData[
'query'][$listId] ),
178 function ( $a ) use ( $fieldId, $pageTitle ) {
179 return $a[$fieldId] === $pageTitle;
184 if ( $fieldId ===
'from' && is_array( $collectedHits ) ) {
185 switch ( count( $collectedHits ) ) {
189 $pageTitle = $collectedHits[0][
'to'];
194 } elseif ( $fieldId ===
'title' && is_array( $collectedHits ) ) {
197 switch ( count( $collectedHits ) ) {
201 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