$result = array();
- self::addValues( $result, $pageSet->getInvalidTitles(), 'invalid', 'title' );
+ self::addValues( $result, $pageSet->getInvalidTitlesAndReasons(), 'invalid' );
self::addValues( $result, $pageSet->getSpecialTitles(), 'special', 'title' );
self::addValues( $result, $pageSet->getMissingPageIDs(), 'missing', 'pageid' );
self::addValues( $result, $pageSet->getMissingRevisionIDs(), 'missing', 'revid' );
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();
/**
* 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;
}
*
* @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()
) {
$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' );
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() ) {