*/
class ApiPageSet extends ApiQueryBase {
- private $mAllPages; // [ns][dbkey] => page_id or 0 when missing
- private $mTitles, $mGoodTitles, $mMissingTitles, $mMissingPageIDs, $mRedirectTitles;
+ private $mAllPages; // [ns][dbkey] => page_id or negative when missing
+ private $mTitles, $mGoodTitles, $mMissingTitles, $mInvalidTitles;
+ private $mMissingPageIDs, $mRedirectTitles;
private $mNormalizedTitles, $mInterwikiTitles;
private $mResolveRedirects, $mPendingRedirectIDs;
private $mGoodRevIDs, $mMissingRevIDs;
$this->mTitles = array();
$this->mGoodTitles = array ();
$this->mMissingTitles = array ();
+ $this->mInvalidTitles = array ();
$this->mMissingPageIDs = array ();
$this->mRedirectTitles = array ();
$this->mNormalizedTitles = array ();
}
/**
- * Returns an array [ns][dbkey] => page_id for all requested titles
- * page_id is a unique negative number in case title was not found
+ * Returns an array [ns][dbkey] => page_id for all requested titles.
+ * page_id is a unique negative number in case title was not found.
+ * Invalid titles will also have negative page IDs and will be in namespace 0
*/
public function getAllTitlesByNamespace() {
return $this->mAllPages;
public function getMissingTitles() {
return $this->mMissingTitles;
}
+
+ /**
+ * Titles that were deemed invalid by Title::newFromText()
+ * The array's index will be unique and negative for each item
+ * @return array of strings (not Title objects)
+ */
+ public function getInvalidTitles() {
+ return $this->mInvalidTitles;
+ }
/**
* Page IDs that were not found in the database
$titleObj = is_string($title) ? Title :: newFromText($title) : $title;
if (!$titleObj)
- $this->dieUsage("bad title", 'invalidtitle');
-
+ {
+ # 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
+ }
$iw = $titleObj->getInterwiki();
if (!empty($iw)) {
// This title is an interwiki link.
/**
* Appends an element for each page in the current pageSet with the most general
- * information (id, title), plus any title normalizations and missing title/pageids/revids.
+ * information (id, title), plus any title normalizations and missing or invalid title/pageids/revids.
*/
private function outputGeneralPageInfo() {
$vals['missing'] = '';
$pages[$fakeId] = $vals;
}
-
+ // Report any invalid titles
+ foreach ($pageSet->getInvalidTitles() as $fakeId => $title)
+ $pages[$fakeId] = array('title' => $title, 'invalid' => '');
// Report any missing page ids
foreach ($pageSet->getMissingPageIDs() as $pageid) {
$pages[$pageid] = array (