+ if ( $this->fld_protection ) {
+ $pageInfo['protection'] = array();
+ if ( isset( $this->protections[$title->getNamespace()][$title->getDBkey()] ) ) {
+ $pageInfo['protection'] =
+ $this->protections[$title->getNamespace()][$title->getDBkey()];
+ }
+ $this->getResult()->setIndexedTagName( $pageInfo['protection'], 'pr' );
+ }
+
+ if ( $this->fld_watched && isset( $this->watched[$title->getNamespace()][$title->getDBkey()] ) ) {
+ $pageInfo['watched'] = '';
+ }
+
+ if ( $this->fld_talkid && isset( $this->talkids[$title->getNamespace()][$title->getDBkey()] ) ) {
+ $pageInfo['talkid'] = $this->talkids[$title->getNamespace()][$title->getDBkey()];
+ }
+
+ if ( $this->fld_subjectid && isset( $this->subjectids[$title->getNamespace()][$title->getDBkey()] ) ) {
+ $pageInfo['subjectid'] = $this->subjectids[$title->getNamespace()][$title->getDBkey()];
+ }
+
+ if ( $this->fld_url ) {
+ $pageInfo['fullurl'] = $title->getFullURL();
+ $pageInfo['editurl'] = $title->getFullURL( 'action=edit' );
+ }
+ if ( $this->fld_readable && $title->userCanRead() ) {
+ $pageInfo['readable'] = '';
+ }
+
+ if ( $this->fld_preload ) {
+ if ( $title->exists() ) {
+ $pageInfo['preload'] = '';
+ } else {
+ $text = null;
+ wfRunHooks( 'EditFormPreloadText', array( &$text, &$title ) );
+
+ $pageInfo['preload'] = $text;
+ }
+ }
+
+ if ( $this->fld_displaytitle ) {
+ if ( isset( $this->displaytitles[$title->getArticleId()] ) ) {
+ $pageInfo['displaytitle'] = $this->displaytitles[$title->getArticleId()];
+ } else {
+ $pageInfo['displaytitle'] = $title->getPrefixedText();
+ }
+ }
+
+ return $pageInfo;
+ }
+
+ /**
+ * Get information about protections and put it in $protections
+ */
+ private function getProtectionInfo() {
+ $this->protections = array();
+ $db = $this->getDB();
+
+ // Get normal protections for existing titles
+ if ( count( $this->titles ) ) {
+ $this->resetQueryParams();
+ $this->addTables( array( 'page_restrictions', 'page' ) );
+ $this->addWhere( 'page_id=pr_page' );
+ $this->addFields( array( 'pr_page', 'pr_type', 'pr_level',
+ 'pr_expiry', 'pr_cascade', 'page_namespace',
+ 'page_title' ) );
+ $this->addWhereFld( 'pr_page', array_keys( $this->titles ) );
+
+ $res = $this->select( __METHOD__ );
+ foreach ( $res as $row ) {
+ $a = array(
+ 'type' => $row->pr_type,
+ 'level' => $row->pr_level,
+ 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 )
+ );
+ if ( $row->pr_cascade ) {
+ $a['cascade'] = '';
+ }
+ $this->protections[$row->page_namespace][$row->page_title][] = $a;
+
+ // Also check old restrictions
+ if ( $this->pageRestrictions[$row->pr_page] ) {
+ $restrictions = explode( ':', trim( $this->pageRestrictions[$row->pr_page] ) );
+ foreach ( $restrictions as $restrict ) {
+ $temp = explode( '=', trim( $restrict ) );
+ if ( count( $temp ) == 1 ) {
+ // old old format should be treated as edit/move restriction
+ $restriction = trim( $temp[0] );
+
+ if ( $restriction == '' ) {
+ continue;
+ }
+ $this->protections[$row->page_namespace][$row->page_title][] = array(
+ 'type' => 'edit',
+ 'level' => $restriction,
+ 'expiry' => 'infinity',
+ );
+ $this->protections[$row->page_namespace][$row->page_title][] = array(
+ 'type' => 'move',
+ 'level' => $restriction,
+ 'expiry' => 'infinity',
+ );
+ } else {
+ $restriction = trim( $temp[1] );
+ if ( $restriction == '' ) {
+ continue;
+ }
+ $this->protections[$row->page_namespace][$row->page_title][] = array(
+ 'type' => $temp[0],
+ 'level' => $restriction,
+ 'expiry' => 'infinity',
+ );
+ }
+ }
+ }
+ }
+ }
+
+ // Get protections for missing titles
+ if ( count( $this->missing ) ) {
+ $this->resetQueryParams();
+ $lb = new LinkBatch( $this->missing );
+ $this->addTables( 'protected_titles' );
+ $this->addFields( array( 'pt_title', 'pt_namespace', 'pt_create_perm', 'pt_expiry' ) );
+ $this->addWhere( $lb->constructSet( 'pt', $db ) );
+ $res = $this->select( __METHOD__ );
+ foreach ( $res as $row ) {
+ $this->protections[$row->pt_namespace][$row->pt_title][] = array(
+ 'type' => 'create',
+ 'level' => $row->pt_create_perm,
+ 'expiry' => Block::decodeExpiry( $row->pt_expiry, TS_ISO_8601 )
+ );
+ }
+ }
+
+ // Cascading protections
+ $images = $others = array();
+ foreach ( $this->everything as $title ) {
+ if ( $title->getNamespace() == NS_FILE ) {
+ $images[] = $title->getDBkey();
+ } else {
+ $others[] = $title;
+ }
+ }
+
+ if ( count( $others ) ) {
+ // Non-images: check templatelinks
+ $lb = new LinkBatch( $others );
+ $this->resetQueryParams();
+ $this->addTables( array( 'page_restrictions', 'page', 'templatelinks' ) );
+ $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
+ 'page_title', 'page_namespace',
+ 'tl_title', 'tl_namespace' ) );
+ $this->addWhere( $lb->constructSet( 'tl', $db ) );
+ $this->addWhere( 'pr_page = page_id' );
+ $this->addWhere( 'pr_page = tl_from' );
+ $this->addWhereFld( 'pr_cascade', 1 );
+
+ $res = $this->select( __METHOD__ );
+ foreach ( $res as $row ) {
+ $source = Title::makeTitle( $row->page_namespace, $row->page_title );
+ $this->protections[$row->tl_namespace][$row->tl_title][] = array(
+ 'type' => $row->pr_type,
+ 'level' => $row->pr_level,
+ 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ),
+ 'source' => $source->getPrefixedText()
+ );
+ }
+ }
+
+ if ( count( $images ) ) {
+ // Images: check imagelinks
+ $this->resetQueryParams();
+ $this->addTables( array( 'page_restrictions', 'page', 'imagelinks' ) );
+ $this->addFields( array( 'pr_type', 'pr_level', 'pr_expiry',
+ 'page_title', 'page_namespace', 'il_to' ) );
+ $this->addWhere( 'pr_page = page_id' );
+ $this->addWhere( 'pr_page = il_from' );
+ $this->addWhereFld( 'pr_cascade', 1 );
+ $this->addWhereFld( 'il_to', $images );
+
+ $res = $this->select( __METHOD__ );
+ foreach ( $res as $row ) {
+ $source = Title::makeTitle( $row->page_namespace, $row->page_title );
+ $this->protections[NS_FILE][$row->il_to][] = array(
+ 'type' => $row->pr_type,
+ 'level' => $row->pr_level,
+ 'expiry' => Block::decodeExpiry( $row->pr_expiry, TS_ISO_8601 ),
+ 'source' => $source->getPrefixedText()
+ );
+ }
+ }
+ }
+
+ /**
+ * Get talk page IDs (if requested) and subject page IDs (if requested)
+ * and put them in $talkids and $subjectids
+ */
+ private function getTSIDs() {
+ $getTitles = $this->talkids = $this->subjectids = array();
+
+ foreach ( $this->everything as $t ) {
+ if ( MWNamespace::isTalk( $t->getNamespace() ) ) {
+ if ( $this->fld_subjectid ) {
+ $getTitles[] = $t->getSubjectPage();
+ }
+ } elseif ( $this->fld_talkid ) {
+ $getTitles[] = $t->getTalkPage();
+ }
+ }
+ if ( !count( $getTitles ) ) {
+ return;
+ }
+
+ $db = $this->getDB();
+
+ // Construct a custom WHERE clause that matches
+ // all titles in $getTitles
+ $lb = new LinkBatch( $getTitles );
+ $this->resetQueryParams();
+ $this->addTables( 'page' );
+ $this->addFields( array( 'page_title', 'page_namespace', 'page_id' ) );
+ $this->addWhere( $lb->constructSet( 'page', $db ) );
+ $res = $this->select( __METHOD__ );
+ foreach ( $res as $row ) {
+ if ( MWNamespace::isTalk( $row->page_namespace ) ) {
+ $this->talkids[MWNamespace::getSubject( $row->page_namespace )][$row->page_title] =
+ intval( $row->page_id );
+ } else {
+ $this->subjectids[MWNamespace::getTalk( $row->page_namespace )][$row->page_title] =
+ intval( $row->page_id );
+ }
+ }
+ }
+
+ private function getDisplayTitle() {
+ $this->displaytitles = array();
+
+ $pageIds = array_keys( $this->titles );
+
+ if ( !count( $pageIds ) ) {
+ return;
+ }
+
+ $this->resetQueryParams();
+ $this->addTables( 'page_props' );
+ $this->addFields( array( 'pp_page', 'pp_value' ) );
+ $this->addWhereFld( 'pp_page', $pageIds );
+ $this->addWhereFld( 'pp_propname', 'displaytitle' );
+ $res = $this->select( __METHOD__ );
+
+ foreach ( $res as $row ) {
+ $this->displaytitles[$row->pp_page] = $row->pp_value;
+ }
+ }
+
+ /**
+ * Get information about watched status and put it in $this->watched
+ */
+ private function getWatchedInfo() {
+ global $wgUser;
+
+ if ( $wgUser->isAnon() || count( $this->everything ) == 0 ) {
+ return;
+ }
+
+ $this->watched = array();
+ $db = $this->getDB();
+
+ $lb = new LinkBatch( $this->everything );
+
+ $this->resetQueryParams();
+ $this->addTables( array( 'watchlist' ) );
+ $this->addFields( array( 'wl_title', 'wl_namespace' ) );
+ $this->addWhere( array(
+ $lb->constructSet( 'wl', $db ),
+ 'wl_user' => $wgUser->getID()
+ ) );
+
+ $res = $this->select( __METHOD__ );
+
+ foreach ( $res as $row ) {
+ $this->watched[$row->wl_namespace][$row->wl_title] = true;
+ }
+ }
+
+ public function getCacheMode( $params ) {
+ $publicProps = array(
+ 'protection',
+ 'talkid',
+ 'subjectid',
+ 'url',
+ 'preload',
+ 'displaytitle',