X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiPageSet.php;h=d67b18420e23b9d26799d8b5e34b703f04b982fe;hb=df80f1ead5daa993facf934fb32b0d5e10e3d5b9;hp=e6f218d62b4a1c474cf04f7c88f14eb3fbb34fd5;hpb=4f8ff83ecd7166c0ec617c1c3ce4374d464b857c;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php index e6f218d62b..d67b18420e 100644 --- a/includes/api/ApiPageSet.php +++ b/includes/api/ApiPageSet.php @@ -58,7 +58,7 @@ class ApiPageSet extends ApiBase { private $mGoodTitles = array(); private $mMissingPages = array(); // [ns][dbkey] => fake page_id private $mMissingTitles = array(); - private $mInvalidTitles = array(); + private $mInvalidTitles = array(); // [fake_page_id] => array( 'title' => $title, 'invalidreason' => $reason ) private $mMissingPageIDs = array(); private $mRedirectTitles = array(); private $mSpecialTitles = array(); @@ -396,9 +396,22 @@ class ApiPageSet extends ApiBase { /** * Titles that were deemed invalid by Title::newFromText() * The array's index will be unique and negative for each item + * @deprecated since 1.26, use self::getInvalidTitlesAndReasons() * @return string[] Array of strings (not Title objects) */ public function getInvalidTitles() { + wfDeprecated( __METHOD__, '1.26' ); + return array_map( function ( $t ) { + return $t['title']; + }, $this->mInvalidTitles ); + } + + /** + * Titles that were deemed invalid by Title::newFromText() + * The array's index will be unique and negative for each item + * @return array[] Array of arrays with 'title' and 'invalidreason' properties + */ + public function getInvalidTitlesAndReasons() { return $this->mInvalidTitles; } @@ -552,7 +565,7 @@ class ApiPageSet extends ApiBase { * * @param array $invalidChecks List of types of invalid titles to include. * Recognized values are: - * - invalidTitles: Titles from $this->getInvalidTitles() + * - invalidTitles: Titles and reasons from $this->getInvalidTitlesAndReasons() * - special: Titles from $this->getSpecialTitles() * - missingIds: ids from $this->getMissingPageIDs() * - missingRevIds: ids from $this->getMissingRevisionIDs() @@ -566,7 +579,7 @@ class ApiPageSet extends ApiBase { ) { $result = array(); if ( in_array( "invalidTitles", $invalidChecks ) ) { - self::addValues( $result, $this->getInvalidTitles(), 'invalid', 'title' ); + self::addValues( $result, $this->getInvalidTitlesAndReasons(), 'invalid' ); } if ( in_array( "special", $invalidChecks ) ) { self::addValues( $result, $this->getSpecialTitles(), 'special', 'title' ); @@ -1077,17 +1090,21 @@ class ApiPageSet extends ApiBase { foreach ( $titles as $title ) { if ( is_string( $title ) ) { - $titleObj = Title::newFromText( $title, $this->mDefaultNamespace ); + try { + $titleObj = Title::newFromTextThrow( $title, $this->mDefaultNamespace ); + } catch ( MalformedTitleException $ex ) { + // Handle invalid titles gracefully + $this->mAllPages[0][$title] = $this->mFakePageId; + $this->mInvalidTitles[$this->mFakePageId] = array( + 'title' => $title, + 'invalidreason' => $ex->getMessage(), + ); + $this->mFakePageId--; + continue; // There's nothing else we can do + } } else { $titleObj = $title; } - if ( !$titleObj ) { - // Handle invalid titles gracefully - $this->mAllPages[0][$title] = $this->mFakePageId; - $this->mInvalidTitles[$this->mFakePageId] = $title; - $this->mFakePageId--; - continue; // There's nothing else we can do - } $unconvertedTitle = $titleObj->getPrefixedText(); $titleWasConverted = false; if ( $titleObj->isExternal() ) { @@ -1287,8 +1304,8 @@ class ApiPageSet extends ApiBase { ), 'generator' => array( ApiBase::PARAM_TYPE => null, - ApiBase::PARAM_VALUE_LINKS => array(), ApiBase::PARAM_HELP_MSG => 'api-pageset-param-generator', + ApiBase::PARAM_SUBMODULE_PARAM_PREFIX => 'g', ), 'redirects' => array( ApiBase::PARAM_DFLT => false, @@ -1314,10 +1331,8 @@ class ApiPageSet extends ApiBase { if ( !$this->mAllowGenerator ) { unset( $result['generator'] ); } elseif ( $flags & ApiBase::GET_VALUES_FOR_HELP ) { - foreach ( $this->getGenerators() as $g ) { - $result['generator'][ApiBase::PARAM_TYPE][] = $g; - $result['generator'][ApiBase::PARAM_VALUE_LINKS][$g] = "Special:ApiHelp/query+$g"; - } + $result['generator'][ApiBase::PARAM_TYPE] = 'submodule'; + $result['generator'][ApiBase::PARAM_SUBMODULE_MAP] = $this->getGenerators(); } return $result; @@ -1338,13 +1353,14 @@ class ApiPageSet extends ApiBase { $query = $this->getMain()->getModuleManager()->getModule( 'query' ); } $gens = array(); + $prefix = $query->getModulePath() . '+'; $mgr = $query->getModuleManager(); foreach ( $mgr->getNamesWithClasses() as $name => $class ) { if ( is_subclass_of( $class, 'ApiQueryGeneratorBase' ) ) { - $gens[] = $name; + $gens[$name] = $prefix . $name; } } - sort( $gens ); + ksort( $gens ); self::$generators = $gens; }