I know there's no second parameter to WikiPage::newFromID(), but this will change soon.
This follows-up I098dd36619fff3610be6894037220d3472b809d5.
Change-Id: Ic28b7e05db51e55a5f49fed70c042ba11e4d97fe
/**
* @param $params array
- * @return Title
+ * @param $load bool|string Whether load the object's state from the database:
+ * - false: don't load (if the pageid is given, it will still be loaded)
+ * - 'fromdb': load from a slave database
+ * - 'fromdbmaster': load from the master database
+ * @return WikiPage
*/
- public function getTitleOrPageId( $params ) {
+ public function getTitleOrPageId( $params, $load = false ) {
$this->requireOnlyOneParameter( $params, 'title', 'pageid' );
- $titleObj = null;
+ $pageObj = null;
if ( isset( $params['title'] ) ) {
$titleObj = Title::newFromText( $params['title'] );
if ( !$titleObj ) {
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
}
+ $pageObj = WikiPage::factory( $titleObj );
+ if ( $load !== false ) {
+ $pageObj->loadPageData( $load );
+ }
} elseif ( isset( $params['pageid'] ) ) {
- $titleObj = Title::newFromID( $params['pageid'] );
- if ( !$titleObj ) {
+ if ( $load === false ) {
+ $load = 'fromdb';
+ }
+ $pageObj = WikiPage::newFromID( $params['pageid'], $load );
+ if ( !$pageObj ) {
$this->dieUsageMsg( array( 'nosuchpageid', $params['pageid'] ) );
}
}
- return $titleObj;
+
+ return $pageObj;
}
/**
public function execute() {
$params = $this->extractRequestParams();
- $titleObj = $this->getTitleOrPageId( $params );
- $pageObj = WikiPage::factory( $titleObj );
- $pageObj->loadPageData( 'fromdbmaster' );
+ $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
if ( !$pageObj->exists() ) {
$this->dieUsageMsg( 'notanarticle' );
}
+ $titleObj = $pageObj->getTitle();
$reason = ( isset( $params['reason'] ) ? $params['reason'] : null );
$user = $this->getUser();
$this->dieUsageMsg( 'missingtext' );
}
- $titleObj = $this->getTitleOrPageId( $params );
+ $pageObj = $this->getTitleOrPageId( $params );
+ $titleObj = $pageObj->getTitle();
if ( $titleObj->isExternal() ) {
$this->dieUsageMsg( array( 'invalidtitle', $params['title'] ) );
}
global $wgRestrictionLevels;
$params = $this->extractRequestParams();
- $titleObj = $this->getTitleOrPageId( $params );
- $pageObj = WikiPage::factory( $titleObj );
+ $pageObj = $this->getTitleOrPageId( $params, 'fromdbmaster' );
+ $titleObj = $pageObj->getTitle();
$errors = $titleObj->getUserPermissionsErrors( 'protect', $this->getUser() );
if ( $errors ) {
if ( !is_null( $this->params['continue'] ) ) {
$this->parseContinueParam();
} else {
- $this->rootTitle = $this->getTitleOrPageId( $this->params );
+ $this->rootTitle = $this->getTitleOrPageId( $this->params )->getTitle();
}
// only image titles are allowed for the root in imageinfo mode
private function run( $resultPageSet = null ) {
$params = $this->extractRequestParams();
- $categoryTitle = $this->getTitleOrPageId( $params );
+ $categoryTitle = $this->getTitleOrPageId( $params )->getTitle();
if ( $categoryTitle->getNamespace() != NS_CATEGORY ) {
$this->dieUsage( 'The category name you entered is not valid', 'invalidcategory' );
}