Anomie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/209304
Change subject: ApiPageSet: Indicate why a title was invalid
......................................................................
ApiPageSet: Indicate why a title was invalid
May as well.
Bug: T98198
Change-Id: Ib17088a9685c48d7db647896ecd59aced7911374
---
M includes/api/ApiImageRotate.php
M includes/api/ApiPageSet.php
M includes/api/ApiQuery.php
M includes/api/ApiSetNotificationTimestamp.php
4 files changed, 32 insertions(+), 17 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core
refs/changes/04/209304/1
diff --git a/includes/api/ApiImageRotate.php b/includes/api/ApiImageRotate.php
index 865d39f..c8390b6 100644
--- a/includes/api/ApiImageRotate.php
+++ b/includes/api/ApiImageRotate.php
@@ -60,7 +60,7 @@
$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' );
diff --git a/includes/api/ApiPageSet.php b/includes/api/ApiPageSet.php
index e6f218d..5efe788 100644
--- a/includes/api/ApiPageSet.php
+++ b/includes/api/ApiPageSet.php
@@ -58,7 +58,7 @@
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 @@
/**
* 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 @@
*
* @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 @@
) {
$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,16 +1090,20 @@
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;
diff --git a/includes/api/ApiQuery.php b/includes/api/ApiQuery.php
index bfe3205..304d0f0 100644
--- a/includes/api/ApiQuery.php
+++ b/includes/api/ApiQuery.php
@@ -407,8 +407,8 @@
$pages[$fakeId] = $vals;
}
// Report any invalid titles
- foreach ( $pageSet->getInvalidTitles() as $fakeId => $title ) {
- $pages[$fakeId] = array( 'title' => $title, 'invalid'
=> true );
+ foreach ( $pageSet->getInvalidTitlesAndReasons() as $fakeId =>
$data ) {
+ $pages[$fakeId] = $data + array( 'invalid' => true );
}
// Report any missing page ids
foreach ( $pageSet->getMissingPageIDs() as $pageid ) {
diff --git a/includes/api/ApiSetNotificationTimestamp.php
b/includes/api/ApiSetNotificationTimestamp.php
index 86a3f6a..fa6fabf 100644
--- a/includes/api/ApiSetNotificationTimestamp.php
+++ b/includes/api/ApiSetNotificationTimestamp.php
@@ -112,9 +112,7 @@
: wfTimestamp( TS_ISO_8601, $timestamp );
} else {
// First, log the invalid titles
- foreach ( $pageSet->getInvalidTitles() as $title ) {
- $r = array();
- $r['title'] = $title;
+ foreach ( $pageSet->getInvalidTitlesAndReasons() as $r
) {
$r['invalid'] = true;
$result[] = $r;
}
--
To view, visit https://gerrit.wikimedia.org/r/209304
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib17088a9685c48d7db647896ecd59aced7911374
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Anomie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits