Liangent has uploaded a new change for review. https://gerrit.wikimedia.org/r/74977
Change subject: Fix API error message when titlePartToKey / keyPartToTitle are used ...................................................................... Fix API error message when titlePartToKey / keyPartToTitle are used Change-Id: I0c83142b44e74cfda1cbc548eebfcfbfce8e7b19 --- M includes/api/ApiQueryBase.php 1 file changed, 14 insertions(+), 6 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core refs/changes/77/74977/1 diff --git a/includes/api/ApiQueryBase.php b/includes/api/ApiQueryBase.php index 8668e04..9fd2455 100644 --- a/includes/api/ApiQueryBase.php +++ b/includes/api/ApiQueryBase.php @@ -408,16 +408,20 @@ /** * Convert a title to a DB key * @param string $title Page title with spaces + * @param string $rawTitle Page title to display in error messages, defaults to $title * @return string Page title with underscores */ - public function titleToKey( $title ) { + public function titleToKey( $title, $rawTitle = null ) { // Don't throw an error if we got an empty string if ( trim( $title ) == '' ) { return ''; } $t = Title::newFromText( $title ); if ( !$t ) { - $this->dieUsageMsg( array( 'invalidtitle', $title ) ); + if ( $rawTitle === null ) { + $rawTitle = $title; + } + $this->dieUsageMsg( array( 'invalidtitle', $rawTitle ) ); } return $t->getPrefixedDBkey(); } @@ -425,9 +429,10 @@ /** * The inverse of titleToKey() * @param string $key Page title with underscores + * @param string $rawKey Page title to display in error messages, defaults to $key * @return string Page title with spaces */ - public function keyToTitle( $key ) { + public function keyToTitle( $key, $rawKey = null ) { // Don't throw an error if we got an empty string if ( trim( $key ) == '' ) { return ''; @@ -435,7 +440,10 @@ $t = Title::newFromDBkey( $key ); // This really shouldn't happen but we gotta check anyway if ( !$t ) { - $this->dieUsageMsg( array( 'invalidtitle', $key ) ); + if ( $rawKey === null ) { + $rawKey = $key; + } + $this->dieUsageMsg( array( 'invalidtitle', $rawKey ) ); } return $t->getPrefixedText(); } @@ -446,7 +454,7 @@ * @return string Title part with underscores */ public function titlePartToKey( $titlePart ) { - return substr( $this->titleToKey( $titlePart . 'x' ), 0, - 1 ); + return substr( $this->titleToKey( $titlePart . 'x', $titlePart ), 0, - 1 ); } /** @@ -455,7 +463,7 @@ * @return string Key part with underscores */ public function keyPartToTitle( $keyPart ) { - return substr( $this->keyToTitle( $keyPart . 'x' ), 0, - 1 ); + return substr( $this->keyToTitle( $keyPart . 'x', $keyPart ), 0, - 1 ); } /** -- To view, visit https://gerrit.wikimedia.org/r/74977 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I0c83142b44e74cfda1cbc548eebfcfbfce8e7b19 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Liangent <liang...@gmail.com> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits