*/
const PARAM_ALL = 17;
+ /**
+ * (int[]) When PARAM_TYPE is 'namespace', include these as additional possible values.
+ * @since 1.29
+ */
+ const PARAM_EXTRA_NAMESPACES = 18;
+
/**@}*/
const ALL_DEFAULT_STRING = '*';
return $pageObj;
}
+ /**
+ * Get a Title object from a title or pageid param, if possible.
+ * Can die, if no param is set or if the title or page id is not valid.
+ *
+ * @since 1.29
+ * @param array $params
+ * @return Title
+ */
+ public function getTitleFromTitleOrPageId( $params ) {
+ $this->requireOnlyOneParameter( $params, 'title', 'pageid' );
+
+ $titleObj = null;
+ if ( isset( $params['title'] ) ) {
+ $titleObj = Title::newFromText( $params['title'] );
+ if ( !$titleObj || $titleObj->isExternal() ) {
+ $this->dieWithError( [ 'apierror-invalidtitle', wfEscapeWikiText( $params['title'] ) ] );
+ }
+ return $titleObj;
+ } elseif ( isset( $params['pageid'] ) ) {
+ $titleObj = Title::newFromID( $params['pageid'] );
+ if ( !$titleObj ) {
+ $this->dieWithError( [ 'apierror-nosuchpageid', $params['pageid'] ] );
+ }
+ }
+
+ return $titleObj;
+ }
+
/**
* Return true if we're to watch the page, false if not, null if no change.
* @param string $watchlist Valid values: 'watch', 'unwatch', 'preferences', 'nochange'
// Some classes may decide to change parameter names
$encParamName = $this->encodeParamName( $paramName );
+ // Shorthand
if ( !is_array( $paramSettings ) ) {
- $default = $paramSettings;
- $multi = false;
- $type = gettype( $paramSettings );
- $dupes = false;
- $deprecated = false;
- $required = false;
- $allowAll = false;
- } else {
- $default = isset( $paramSettings[self::PARAM_DFLT] )
- ? $paramSettings[self::PARAM_DFLT]
- : null;
- $multi = isset( $paramSettings[self::PARAM_ISMULTI] )
- ? $paramSettings[self::PARAM_ISMULTI]
- : false;
- $type = isset( $paramSettings[self::PARAM_TYPE] )
- ? $paramSettings[self::PARAM_TYPE]
- : null;
- $dupes = isset( $paramSettings[self::PARAM_ALLOW_DUPLICATES] )
- ? $paramSettings[self::PARAM_ALLOW_DUPLICATES]
- : false;
- $deprecated = isset( $paramSettings[self::PARAM_DEPRECATED] )
- ? $paramSettings[self::PARAM_DEPRECATED]
- : false;
- $required = isset( $paramSettings[self::PARAM_REQUIRED] )
- ? $paramSettings[self::PARAM_REQUIRED]
- : false;
- $allowAll = isset( $paramSettings[self::PARAM_ALL] )
- ? $paramSettings[self::PARAM_ALL]
- : false;
-
- // When type is not given, and no choices, the type is the same as $default
- if ( !isset( $type ) ) {
- if ( isset( $default ) ) {
- $type = gettype( $default );
- } else {
- $type = 'NULL'; // allow everything
- }
+ $paramSettings = [
+ self::PARAM_DFLT => $paramSettings,
+ ];
+ }
+
+ $default = isset( $paramSettings[self::PARAM_DFLT] )
+ ? $paramSettings[self::PARAM_DFLT]
+ : null;
+ $multi = isset( $paramSettings[self::PARAM_ISMULTI] )
+ ? $paramSettings[self::PARAM_ISMULTI]
+ : false;
+ $type = isset( $paramSettings[self::PARAM_TYPE] )
+ ? $paramSettings[self::PARAM_TYPE]
+ : null;
+ $dupes = isset( $paramSettings[self::PARAM_ALLOW_DUPLICATES] )
+ ? $paramSettings[self::PARAM_ALLOW_DUPLICATES]
+ : false;
+ $deprecated = isset( $paramSettings[self::PARAM_DEPRECATED] )
+ ? $paramSettings[self::PARAM_DEPRECATED]
+ : false;
+ $required = isset( $paramSettings[self::PARAM_REQUIRED] )
+ ? $paramSettings[self::PARAM_REQUIRED]
+ : false;
+ $allowAll = isset( $paramSettings[self::PARAM_ALL] )
+ ? $paramSettings[self::PARAM_ALL]
+ : false;
+
+ // When type is not given, and no choices, the type is the same as $default
+ if ( !isset( $type ) ) {
+ if ( isset( $default ) ) {
+ $type = gettype( $default );
+ } else {
+ $type = 'NULL'; // allow everything
}
}
if ( isset( $value ) && $type == 'namespace' ) {
$type = MWNamespace::getValidNamespaces();
+ if ( isset( $paramSettings[self::PARAM_EXTRA_NAMESPACES] ) &&
+ is_array( $paramSettings[self::PARAM_EXTRA_NAMESPACES] )
+ ) {
+ $type = array_merge( $type, $paramSettings[self::PARAM_EXTRA_NAMESPACES] );
+ }
// By default, namespace parameters allow ALL_DEFAULT_STRING to be used to specify
// all namespaces.
$allowAll = true;
$titles = $pageSet->getGoodAndMissingTitles();
$map = $pageSet->getGoodAndMissingTitlesByNamespace();
+ // Add in special pages, they can theoretically have backlinks too.
+ // (although currently they only do for prop=redirects)
+ foreach ( $pageSet->getSpecialTitles() as $id => $title ) {
+ $titles[] = $title;
+ $map[$title->getNamespace()][$title->getDBkey()] = $id;
+ }
+
// Determine our fields to query on
$p = $settings['prefix'];
$hasNS = !isset( $settings['to_namespace'] );
$this->addFieldsIf( 'page_namespace', $miser_ns !== null );
if ( $hasNS ) {
- $lb = new LinkBatch( $titles );
- $this->addWhere( $lb->constructSet( $p, $db ) );
+ // Can't use LinkBatch because it throws away Special titles.
+ // And we already have the needed data structure anyway.
+ $this->addWhere( $db->makeWhereFrom2d( $map, $bl_namespace, $bl_title ) );
} else {
$where = [];
foreach ( $titles as $t ) {