/** * Get page configuration settings from a DB row */ public static function getVisibilitySettingsFromRow($row) { if ($row) { # This code should be refactored, now that it's being used more generally. $expiry = Block::decodeExpiry($row->fpc_expiry); # Only apply the settings if they haven't expired if (!$expiry || $expiry < wfTimestampNow()) { $row = null; // expired self::purgeExpiredConfigurations(); } } // Is there a non-expired row? if ($row) { $level = $row->fpc_level; if (!self::isValidRestriction($row->fpc_level)) { $level = ''; // site default; ignore fpc_level } $config = array('override' => $row->fpc_override ? 1 : 0, 'autoreview' => $level, 'expiry' => Block::decodeExpiry($row->fpc_expiry)); # If there are protection levels defined check if this is valid... if (FlaggedRevs::useProtectionLevels()) { $level = self::getProtectionLevel($config); if ($level == 'invalid' || $level == 'none') { // If 'none', make sure expiry is 'infinity' $config = self::getDefaultVisibilitySettings(); // revert to default (none) } } } else { # Return the default config if this page doesn't have its own $config = self::getDefaultVisibilitySettings(); } return $config; }
/** * @return Array: empty or a message key with parameters */ static function getUserBlockErrors($user, $ip) { static $result = null; // Instance cache if (!is_null($result)) { return $result; } $block = self::getGlobalBlockingBlock($ip, $user->isAnon()); if ($block) { global $wgLang; // Check for local whitelisting if (GlobalBlocking::getWhitelistInfo($block->gb_id)) { // Block has been whitelisted. return $result = array(); } if ($user->isAllowed('ipblock-exempt') || $user->isAllowed('globalblock-exempt')) { // User is exempt from IP blocks. return $result = array(); } # Messy B/C until $wgLang->formatExpiry() is well embedded if (Block::decodeExpiry($block->gb_expiry) == 'infinity') { $expiry = wfMsgExt('infiniteblock', 'parseinline'); } else { $expiry = Block::decodeExpiry($block->gb_expiry); $expiry = wfMsgExt('expiringblock', 'parseinline', $wgLang->date($expiry), $wgLang->time($expiry)); } $display_wiki = self::getWikiName($block->gb_by_wiki); $user_display = self::maybeLinkUserpage($block->gb_by_wiki, $block->gb_by); return $result = array('globalblocking-blocked', $user_display, $display_wiki, $block->gb_reason, $expiry, $ip); } return $result = array(); }
/** * Callback function to output a restriction */ function formatRow($row) { global $wgUser, $wgLang, $wgContLang; wfProfileIn(__METHOD__); static $skin = null; if (is_null($skin)) { $skin = $wgUser->getSkin(); } $title = Title::makeTitleSafe($row->page_namespace, $row->page_title); $link = $skin->makeLinkObj($title); $description_items = array(); $protType = wfMsgHtml('restriction-level-' . $row->pr_level); $description_items[] = $protType; if ($row->pr_cascade) { $description_items[] = wfMsg('protect-summary-cascade'); } $expiry_description = ''; $stxt = ''; if ($row->pr_expiry != 'infinity' && strlen($row->pr_expiry)) { $expiry = Block::decodeExpiry($row->pr_expiry); $expiry_description = wfMsgForContent('protect-expiring', $wgLang->timeanddate($expiry)); $description_items[] = $expiry_description; } if (!is_null($size = $row->page_len)) { if ($size == 0) { $stxt = ' <small>' . wfMsgHtml('historyempty') . '</small>'; } else { $stxt = ' <small>' . wfMsgHtml('historysize', $wgLang->formatNum($size)) . '</small>'; } $stxt = $wgContLang->getDirMark() . $stxt; } wfProfileOut(__METHOD__); return '<li>' . wfSpecialList($link . $stxt, implode($description_items, ', ')) . "</li>\n"; }
public function __construct($db = '', $target = '', $proxy = null, $by = null, $expiry = '', $reason = '', $timestamp = '', $autoblock = 0, $options = array(), $id = 0) { $this->mDb = $db; $this->mTarget = $target; $this->mProxy = $proxy; $this->mBy = $by; $this->mExpiry = Block::decodeExpiry($expiry); $this->mTimestamp = wfTimestamp(TS_MW, $timestamp); $this->mReason = $reason; $this->mAutoblock = $autoblock; $this->mOptions = $options; $this->mId = $id; }
public function execute() { $params = $this->extractRequestParams(); $fld_protection = false; if (!is_null($params['prop'])) { $prop = array_flip($params['prop']); $fld_protection = isset($prop['protection']); } $pageSet = $this->getPageSet(); $titles = $pageSet->getGoodTitles(); $result = $this->getResult(); $pageIsRedir = $pageSet->getCustomField('page_is_redirect'); $pageIsNew = $pageSet->getCustomField('page_is_new'); $pageCounter = $pageSet->getCustomField('page_counter'); $pageTouched = $pageSet->getCustomField('page_touched'); $pageLatest = $pageSet->getCustomField('page_latest'); $pageLength = $pageSet->getCustomField('page_len'); if ($fld_protection && count($titles) > 0) { $this->addTables('page_restrictions'); $this->addFields(array('pr_page', 'pr_type', 'pr_level', 'pr_expiry')); $this->addWhereFld('pr_page', array_keys($titles)); $db = $this->getDB(); $res = $this->select(__METHOD__); while ($row = $db->fetchObject($res)) { $protections[$row->pr_page][] = array('type' => $row->pr_type, 'level' => $row->pr_level, 'expiry' => Block::decodeExpiry($row->pr_expiry, TS_ISO_8601)); } $db->freeResult($res); } foreach ($titles as $pageid => $unused) { $pageInfo = array('touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]), 'lastrevid' => intval($pageLatest[$pageid]), 'counter' => intval($pageCounter[$pageid]), 'length' => intval($pageLength[$pageid])); if ($pageIsRedir[$pageid]) { $pageInfo['redirect'] = ''; } if ($pageIsNew[$pageid]) { $pageInfo['new'] = ''; } if ($fld_protection) { if (isset($protections[$pageid])) { $pageInfo['protection'] = $protections[$pageid]; $result->setIndexedTagName($pageInfo['protection'], 'pr'); } else { $pageInfo['protection'] = array(); } } $result->addValue(array('query', 'pages'), $pageid, $pageInfo); } }
/** * Callback function to output a restriction */ function formatRow($row) { global $wgUser, $wgLang; wfProfileIn(__METHOD__); static $skin = null; if (is_null($skin)) { $skin = $wgUser->getSkin(); } $title = Title::makeTitleSafe($row->pt_namespace, $row->pt_title); $link = $skin->link($title); $description_items = array(); $protType = wfMsgHtml('restriction-level-' . $row->pt_create_perm); $description_items[] = $protType; $stxt = ''; if ($row->pt_expiry != 'infinity' && strlen($row->pt_expiry)) { $expiry = Block::decodeExpiry($row->pt_expiry); $expiry_description = wfMsg('protect-expiring', $wgLang->timeanddate($expiry), $wgLang->date($expiry), $wgLang->time($expiry)); $description_items[] = $expiry_description; } wfProfileOut(__METHOD__); return '<li>' . wfSpecialList($link . $stxt, implode($description_items, ', ')) . "</li>\n"; }
/** * Callback function to output a restriction * @param $row object Protected title * @return string Formatted <li> element */ public function formatRow($row) { global $wgUser, $wgLang, $wgContLang; wfProfileIn(__METHOD__); static $skin = null; if (is_null($skin)) { $skin = $wgUser->getSkin(); } $title = Title::makeTitleSafe($row->page_namespace, $row->page_title); $link = $skin->makeLinkObj($title); $description_items = array(); $protType = wfMsgHtml('restriction-level-' . $row->pr_level); $description_items[] = $protType; if ($row->pr_cascade) { $description_items[] = wfMsg('protect-summary-cascade'); } $expiry_description = ''; $stxt = ''; if ($row->pr_expiry != 'infinity' && strlen($row->pr_expiry)) { $expiry = Block::decodeExpiry($row->pr_expiry); $expiry_description = wfMsg('protect-expiring', $wgLang->timeanddate($expiry), $wgLang->date($expiry), $wgLang->time($expiry)); $description_items[] = $expiry_description; } if (!is_null($size = $row->page_len)) { $stxt = $wgContLang->getDirMark() . ' ' . $skin->formatRevisionSize($size); } # Show a link to the change protection form for allowed users otherwise a link to the protection log if ($wgUser->isAllowed('protect')) { $changeProtection = ' (' . $skin->makeKnownLinkObj($title, wfMsgHtml('protect_change'), 'action=unprotect') . ')'; } else { $ltitle = SpecialPage::getTitleFor('Log'); $changeProtection = ' (' . $skin->makeKnownLinkObj($ltitle, wfMsgHtml('protectlogpage'), 'type=protect&page=' . $title->getPrefixedUrl()) . ')'; } wfProfileOut(__METHOD__); return '<li>' . wfSpecialList($link . $stxt, implode($description_items, ', ')) . $changeProtection . "</li>\n"; }
/** * 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__); while ($row = $db->fetchObject($res)) { $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'); } } } } $db->freeResult($res); } // 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__); while ($row = $db->fetchObject($res)) { $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)); } $db->freeResult($res); } // 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__); while ($row = $db->fetchObject($res)) { $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()); } $db->freeResult($res); } 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__); while ($row = $db->fetchObject($res)) { $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()); } $db->freeResult($res); } }
/** * Loads a string into mRestrictions array * @param resource $res restrictions as an SQL result. */ private function loadRestrictionsFromRow($res, $oldFashionedRestrictions = NULL) { $dbr = wfGetDb(DB_SLAVE); $this->mRestrictions['edit'] = array(); $this->mRestrictions['move'] = array(); # Backwards-compatibility: also load the restrictions from the page record (old format). if ($oldFashionedRestrictions == NULL) { $oldFashionedRestrictions = $dbr->selectField('page', 'page_restrictions', array('page_id' => $this->getArticleId()), __METHOD__); } if ($oldFashionedRestrictions != '') { foreach (explode(':', trim($oldFashionedRestrictions)) as $restrict) { $temp = explode('=', trim($restrict)); if (count($temp) == 1) { // old old format should be treated as edit/move restriction $this->mRestrictions["edit"] = explode(',', trim($temp[0])); $this->mRestrictions["move"] = explode(',', trim($temp[0])); } else { $this->mRestrictions[$temp[0]] = explode(',', trim($temp[1])); } } $this->mOldRestrictions = true; $this->mCascadeRestriction = false; $this->mRestrictionsExpiry = Block::decodeExpiry(''); } if ($dbr->numRows($res)) { # Current system - load second to make them override. $now = wfTimestampNow(); $purgeExpired = false; while ($row = $dbr->fetchObject($res)) { # Cycle through all the restrictions. // This code should be refactored, now that it's being used more generally, // But I don't really see any harm in leaving it in Block for now -werdna $expiry = Block::decodeExpiry($row->pr_expiry); // Only apply the restrictions if they haven't expired! if (!$expiry || $expiry > $now) { $this->mRestrictionsExpiry = $expiry; $this->mRestrictions[$row->pr_type] = explode(',', trim($row->pr_level)); $this->mCascadeRestriction |= $row->pr_cascade; } else { // Trigger a lazy purge of expired restrictions $purgeExpired = true; } } if ($purgeExpired) { Title::purgeExpiredRestrictions(); } } $this->mRestrictionsLoaded = true; }
public function loadRestrictions($oldFashionedRestrictions = NULL) { if (!$this->mRestrictionsLoaded) { if ($this->exists()) { $dbr = wfGetDB(DB_SLAVE); $res = $dbr->select('page_restrictions', '*', array('pr_page' => $this->getArticleId()), __METHOD__); $this->loadRestrictionsFromRow($res, $oldFashionedRestrictions); } else { $title_protection = $this->getTitleProtection(); if (is_array($title_protection)) { extract($title_protection); $now = wfTimestampNow(); $expiry = Block::decodeExpiry($pt_expiry); if (!$expiry || $expiry > $now) { // Apply the restrictions $this->mRestrictionsExpiry = $expiry; $this->mRestrictions['create'] = explode(',', trim($pt_create_perm)); } else { // Get rid of the old restrictions Title::purgeExpiredRestrictions(); } } $this->mRestrictionsLoaded = true; } } }
public function execute() { $params = $this->extractRequestParams(); $prop = array_flip($params['prop']); $fld_id = isset($prop['id']); $fld_address = isset($prop['address']); $fld_by = isset($prop['by']); $fld_timestamp = isset($prop['timestamp']); $fld_expiry = isset($prop['expiry']); $fld_reason = isset($prop['reason']); $fld_range = isset($prop['range']); $result = $this->getResult(); $data = array(); $this->addTables('globalblocks'); if ($fld_id) { $this->addFields('gb_id'); } if ($fld_address) { $this->addFields(array('gb_address', 'gb_anon_only')); } if ($fld_by) { $this->addFields(array('gb_by', 'gb_by_wiki')); } if ($fld_timestamp) { $this->addFields('gb_timestamp'); } if ($fld_expiry) { $this->addFields('gb_expiry'); } if ($fld_reason) { $this->addFields('gb_reason'); } if ($fld_range) { $this->addFields(array('gb_range_start', 'gb_range_end')); } $this->addOption('LIMIT', $params['limit'] + 1); $this->addWhereRange('gb_timestamp', $params['dir'], $params['start'], $params['end']); if (isset($params['ids'])) { $this->addWhereFld('gb_id', $params['ids']); } if (isset($params['addresses'])) { $this->addWhereFld('gb_address', $params['addresses']); } if (isset($params['ip'])) { list($ip, $range) = IP::parseCIDR($params['ip']); if ($ip && $range) { # We got a CIDR range if ($range < 16) { $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad'); } $lower = wfBaseConvert($ip, 10, 16, 8, false); $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false); } else { $lower = $upper = IP::toHex($params['ip']); } $prefix = substr($lower, 0, 4); $this->addWhere(array("gb_range_start LIKE '{$prefix}%'", "gb_range_start <= '{$lower}'", "gb_range_end >= '{$upper}'")); } $res = $this->select(__METHOD__); $count = 0; foreach ($res as $row) { if (++$count > $params['limit']) { // We've had enough $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->gb_timestamp)); break; } $block = array(); if ($fld_id) { $block['id'] = $row->gb_id; } if ($fld_address) { $block['address'] = $row->gb_address; if ($row->gb_anon_only) { $block['anononly'] = ''; } } if ($fld_by) { $block['by'] = $row->gb_by; $block['bywiki'] = $row->gb_by_wiki; } if ($fld_timestamp) { $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->gb_timestamp); } if ($fld_expiry) { $block['expiry'] = Block::decodeExpiry($row->gb_expiry, TS_ISO_8601); } if ($fld_reason) { $block['reason'] = $row->gb_reason; } if ($fld_range) { $block['rangestart'] = IP::hexToQuad($row->gb_range_start); $block['rangeend'] = IP::hexToQuad($row->gb_range_end); } $data[] = $block; } $result->setIndexedTagName($data, 'block'); $result->addValue('query', $this->getModuleName(), $data); }
private function run($resultPageSet = null) { $db = $this->getDB(); $params = $this->extractRequestParams(); $this->addTables('protected_titles'); $this->addFields(array('pt_namespace', 'pt_title', 'pt_timestamp')); $prop = array_flip($params['prop']); $this->addFieldsIf('pt_user', isset($prop['user'])); $this->addFieldsIf('pt_reason', isset($prop['comment'])); $this->addFieldsIf('pt_expiry', isset($prop['expiry'])); $this->addFieldsIf('pt_create_perm', isset($prop['level'])); $this->addWhereRange('pt_timestamp', $params['dir'], $params['start'], $params['end']); $this->addWhereFld('pt_namespace', $params['namespace']); $this->addWhereFld('pt_create_perm', $params['level']); if (isset($prop['user'])) { $this->addTables('user'); $this->addFields('user_name'); $this->addJoinConds(array('user' => array('LEFT JOIN', 'user_id=pt_user'))); } $this->addOption('LIMIT', $params['limit'] + 1); $res = $this->select(__METHOD__); $count = 0; $result = $this->getResult(); while ($row = $db->fetchObject($res)) { if (++$count > $params['limit']) { // We've reached the one extra which shows that there are additional pages to be had. Stop here... $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->pt_timestamp)); break; } $title = Title::makeTitle($row->pt_namespace, $row->pt_title); if (is_null($resultPageSet)) { $vals = array(); ApiQueryBase::addTitleInfo($vals, $title); if (isset($prop['timestamp'])) { $vals['timestamp'] = wfTimestamp(TS_ISO_8601, $row->pt_timestamp); } if (isset($prop['user']) && !is_null($row->user_name)) { $vals['user'] = $row->user_name; } if (isset($prop['comment'])) { $vals['comment'] = $row->pt_reason; } if (isset($prop['expiry'])) { $vals['expiry'] = Block::decodeExpiry($row->pt_expiry, TS_ISO_8601); } if (isset($prop['level'])) { $vals['level'] = $row->pt_create_perm; } $fit = $result->addValue(array('query', $this->getModuleName()), null, $vals); if (!$fit) { $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->pt_timestamp)); break; } } else { $titles[] = $title; } } $db->freeResult($res); if (is_null($resultPageSet)) { $result->setIndexedTagName_internal(array('query', $this->getModuleName()), $this->getModulePrefix()); } else { $resultPageSet->populateFromTitles($titles); } }
public function execute() { global $wgUser; $params = $this->extractRequestParams(); if (isset($params['users']) && isset($params['ip'])) { $this->dieUsage('bkusers and bkip cannot be used together', 'usersandip'); } $prop = array_flip($params['prop']); $fld_id = isset($prop['id']); $fld_user = isset($prop['user']); $fld_by = isset($prop['by']); $fld_timestamp = isset($prop['timestamp']); $fld_expiry = isset($prop['expiry']); $fld_reason = isset($prop['reason']); $fld_range = isset($prop['range']); $fld_flags = isset($prop['flags']); $result = $this->getResult(); $pageSet = $this->getPageSet(); $titles = $pageSet->getTitles(); $data = array(); $this->addTables('ipblocks'); if ($fld_id) { $this->addFields('ipb_id'); } if ($fld_user) { $this->addFields(array('ipb_address', 'ipb_user', 'ipb_auto')); } if ($fld_by) { $this->addTables('user'); $this->addFields(array('ipb_by', 'user_name')); $this->addWhere('user_id = ipb_by'); } if ($fld_timestamp) { $this->addFields('ipb_timestamp'); } if ($fld_expiry) { $this->addFields('ipb_expiry'); } if ($fld_reason) { $this->addFields('ipb_reason'); } if ($fld_range) { $this->addFields(array('ipb_range_start', 'ipb_range_end')); } if ($fld_flags) { $this->addFields(array('ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted', 'ipb_allow_usertalk')); } $this->addOption('LIMIT', $params['limit'] + 1); $this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']); if (isset($params['ids'])) { $this->addWhereFld('ipb_id', $params['ids']); } if (isset($params['users'])) { foreach ((array) $params['users'] as $u) { $this->prepareUsername($u); } $this->addWhereFld('ipb_address', $this->usernames); } if (isset($params['ip'])) { list($ip, $range) = IP::parseCIDR($params['ip']); if ($ip && $range) { # We got a CIDR range if ($range < 16) { $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad'); } $lower = wfBaseConvert($ip, 10, 16, 8, false); $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false); } else { $lower = $upper = IP::toHex($params['ip']); } $prefix = substr($lower, 0, 4); $this->addWhere(array("ipb_range_start LIKE '{$prefix}%'", "ipb_range_start <= '{$lower}'", "ipb_range_end >= '{$upper}'")); } if (!$wgUser->isAllowed('suppress')) { $this->addWhereFld('ipb_deleted', 0); } // Purge expired entries on one in every 10 queries if (!mt_rand(0, 10)) { Block::purgeExpired(); } $res = $this->select(__METHOD__); $count = 0; while ($row = $res->fetchObject()) { if (++$count > $params['limit']) { // We've had enough $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp)); break; } $block = array(); if ($fld_id) { $block['id'] = $row->ipb_id; } if ($fld_user && !$row->ipb_auto) { $block['user'] = $row->ipb_address; } if ($fld_by) { $block['by'] = $row->user_name; } if ($fld_timestamp) { $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp); } if ($fld_expiry) { $block['expiry'] = Block::decodeExpiry($row->ipb_expiry, TS_ISO_8601); } if ($fld_reason) { $block['reason'] = $row->ipb_reason; } if ($fld_range) { $block['rangestart'] = IP::hexToQuad($row->ipb_range_start); $block['rangeend'] = IP::hexToQuad($row->ipb_range_end); } if ($fld_flags) { // For clarity, these flags use the same names as their action=block counterparts if ($row->ipb_auto) { $block['automatic'] = ''; } if ($row->ipb_anon_only) { $block['anononly'] = ''; } if ($row->ipb_create_account) { $block['nocreate'] = ''; } if ($row->ipb_enable_autoblock) { $block['autoblock'] = ''; } if ($row->ipb_block_email) { $block['noemail'] = ''; } if ($row->ipb_deleted) { $block['hidden'] = ''; } if ($row->ipb_allow_usertalk) { $block['allowusertalk'] = ''; } } $data[] = $block; } $result->setIndexedTagName($data, 'block'); $result->addValue('query', $this->getModuleName(), $data); }
function formatRow($row) { global $wgLang, $wgUser; ## One-time setup static $sk = null; if (is_null($sk)) { $sk = $wgUser->getSkin(); } ## Setup $timestamp = $row->gb_timestamp; $expiry = $row->gb_expiry; $options = array(); # Messy B/C until $wgLang->formatExpiry() is well embedded if (Block::decodeExpiry($expiry) == 'infinity') { $options[] = wfMsgExt('infiniteblock', 'parseinline'); } else { $expiry = Block::decodeExpiry($expiry); $options[] = wfMsgExt('expiringblock', 'parseinline', $wgLang->date($expiry), $wgLang->time($expiry)); } # Check for whitelisting. $wlinfo = GlobalBlocking::getWhitelistInfo($row->gb_id); if ($wlinfo) { $options[] = wfMsg('globalblocking-list-whitelisted', User::whois($wlinfo['user']), $wlinfo['reason']); } $timestamp = $wgLang->timeanddate(wfTimestamp(TS_MW, $timestamp), true); if ($row->gb_anon_only) { $options[] = wfMsg('globalblocking-list-anononly'); } ## Do afterthoughts (comment, links for admins) $info = array(); if ($wgUser->isAllowed('globalunblock')) { $unblockTitle = SpecialPage::getTitleFor("RemoveGlobalBlock"); $info[] = $sk->link($unblockTitle, wfMsgExt('globalblocking-list-unblock', 'parseinline'), array(), array('address' => $row->gb_address)); } global $wgApplyGlobalBlocks; if ($wgUser->isAllowed('globalblock-whitelist') && $wgApplyGlobalBlocks) { $whitelistTitle = SpecialPage::getTitleFor("GlobalBlockStatus"); $info[] = $sk->link($whitelistTitle, wfMsgExt('globalblocking-list-whitelist', 'parseinline'), array(), array('address' => $row->gb_address)); } if ($wgUser->isAllowed('globalblock')) { $reblockTitle = SpecialPage::getTitleFor('GlobalBlock'); $msg = wfMsgExt('globalblocking-list-modify', 'parseinline'); $info[] = $sk->link($reblockTitle, $msg, array(), array('wpAddress' => $row->gb_address, 'modify' => 1)); } ## Userpage link / Info on originating wiki $display_wiki = GlobalBlocking::getWikiName($row->gb_by_wiki); $user_display = GlobalBlocking::maybeLinkUserpage($row->gb_by_wiki, $row->gb_by); $infoItems = count($info) ? wfMsg('parentheses', $wgLang->pipeList($info)) : ''; ## Put it all together. return Html::rawElement('li', array(), wfMsgExt('globalblocking-list-blockitem', array('parseinline'), $timestamp, $user_display, $display_wiki, $row->gb_address, $wgLang->commaList($options)) . ' ' . $sk->commentBlock($row->gb_reason) . ' ' . $infoItems); }
/** * Callback function to output a restriction * @param $row object Protected title * @return string Formatted <li> element */ public function formatRow($row) { global $wgUser, $wgLang, $wgContLang; wfProfileIn(__METHOD__); static $skin = null; if (is_null($skin)) { $skin = $wgUser->getSkin(); } $title = Title::makeTitleSafe($row->page_namespace, $row->page_title); $link = $skin->link($title); $description_items = array(); $protType = wfMsgHtml('restriction-level-' . $row->pr_level); $description_items[] = $protType; if ($row->pr_cascade) { $description_items[] = wfMsg('protect-summary-cascade'); } $stxt = ''; if ($row->pr_expiry != 'infinity' && strlen($row->pr_expiry)) { $expiry = Block::decodeExpiry($row->pr_expiry); $expiry_description = wfMsg('protect-expiring', $wgLang->timeanddate($expiry), $wgLang->date($expiry), $wgLang->time($expiry)); $description_items[] = htmlspecialchars($expiry_description); } if (!is_null($size = $row->page_len)) { $stxt = $wgContLang->getDirMark() . ' ' . $skin->formatRevisionSize($size); } # Show a link to the change protection form for allowed users otherwise a link to the protection log if ($wgUser->isAllowed('protect')) { $changeProtection = ' (' . $skin->linkKnown($title, wfMsgHtml('protect_change'), array(), array('action' => 'unprotect')) . ')'; } else { $ltitle = SpecialPage::getTitleFor('Log'); $changeProtection = ' (' . $skin->linkKnown($ltitle, wfMsgHtml('protectlogpage'), array(), array('type' => 'protect', 'page' => $title->getPrefixedText())) . ')'; } wfProfileOut(__METHOD__); return Html::rawElement('li', array(), wfSpecialList($link . $stxt, $wgLang->commaList($description_items)) . $changeProtection) . "\n"; }
private function run() { global $wgUser; $params = $this->extractRequestParams(); $prop = array_flip($params['prop']); $fld_id = isset($prop['id']); $fld_user = isset($prop['user']); $fld_by = isset($prop['by']); $fld_timestamp = isset($prop['timestamp']); $fld_expiry = isset($prop['expiry']); $fld_reason = isset($prop['reason']); $fld_range = isset($prop['range']); $fld_flags = isset($prop['flags']); $result = $this->getResult(); $pageSet = $this->getPageSet(); $titles = $pageSet->getTitles(); $data = array(); $this->addTables('ipblocks'); if ($fld_id) { $this->addFields('ipb_id'); } if ($fld_user) { $this->addFields(array('ipb_address', 'ipb_user')); } if ($fld_by) { $this->addTables('user'); $this->addFields(array('ipb_by', 'user_name')); $this->addWhere('user_id = ipb_by'); } if ($fld_timestamp) { $this->addFields('ipb_timestamp'); } if ($fld_expiry) { $this->addFields('ipb_expiry'); } if ($fld_reason) { $this->addFields('ipb_reason'); } if ($fld_range) { $this->addFields(array('ipb_range_start', 'ipb_range_end')); } if ($fld_flags) { $this->addFields(array('ipb_auto', 'ipb_anon_only', 'ipb_create_account', 'ipb_enable_autoblock', 'ipb_block_email', 'ipb_deleted')); } $this->addOption('LIMIT', $params['limit'] + 1); $this->addWhereRange('ipb_timestamp', $params['dir'], $params['start'], $params['end']); if (isset($params['ids'])) { $this->addWhere(array('ipb_id' => $params['ids'])); } if (isset($params['users'])) { $this->addWhere(array('ipb_address' => $params['users'])); } if (!$wgUser->isAllowed('oversight')) { $this->addWhere(array('ipb_deleted' => 0)); } // Purge expired entries on one in every 10 queries if (!mt_rand(0, 10)) { Block::purgeExpired(); } $res = $this->select(__METHOD__); $db = wfGetDB(); $count = 0; while ($row = $db->fetchObject($res)) { if ($count++ == $params['limit']) { // We've had enough $this->setContinueEnumParameter('start', wfTimestamp(TS_ISO_8601, $row->ipb_timestamp)); break; } $block = array(); if ($fld_id) { $block['id'] = $row->ipb_id; } if ($fld_user && !$row->ipb_auto) { $block['user'] = $row->ipb_address; } if ($fld_by) { $block['by'] = $row->user_name; } if ($fld_timestamp) { $block['timestamp'] = wfTimestamp(TS_ISO_8601, $row->ipb_timestamp); } if ($fld_expiry) { $block['expiry'] = Block::decodeExpiry($row->ipb_expiry, TS_ISO_8601); } if ($fld_reason) { $block['reason'] = $row->ipb_reason; } if ($fld_range) { $block['rangestart'] = $this->convertHexIP($row->ipb_range_start); $block['rangeend'] = $this->convertHexIP($row->ipb_range_end); } if ($fld_flags) { // For clarity, these flags use the same names as their action=block counterparts if ($row->ipb_auto) { $block['automatic'] = ''; } if ($row->ipb_anon_only) { $block['anononly'] = ''; } if ($row->ipb_create_account) { $block['nocreate'] = ''; } if ($row->ipb_enable_autoblock) { $block['autoblock'] = ''; } if ($row->ipb_block_email) { $block['noemail'] = ''; } if ($row->ipb_deleted) { $block['hidden'] = ''; } } $data[] = $block; } $result->setIndexedTagName($data, 'block'); $result->addValue('query', $this->getModuleName(), $data); }
public function execute() { global $wgUser; $params = $this->extractRequestParams(); $fld_protection = $fld_talkid = $fld_subjectid = $fld_url = $fld_readable = false; if (!is_null($params['prop'])) { $prop = array_flip($params['prop']); $fld_protection = isset($prop['protection']); $fld_talkid = isset($prop['talkid']); $fld_subjectid = isset($prop['subjectid']); $fld_url = isset($prop['url']); $fld_readable = isset($prop['readable']); } $pageSet = $this->getPageSet(); $titles = $pageSet->getGoodTitles(); $missing = $pageSet->getMissingTitles(); $result = $this->getResult(); $pageRestrictions = $pageSet->getCustomField('page_restrictions'); $pageIsRedir = $pageSet->getCustomField('page_is_redirect'); $pageIsNew = $pageSet->getCustomField('page_is_new'); $pageCounter = $pageSet->getCustomField('page_counter'); $pageTouched = $pageSet->getCustomField('page_touched'); $pageLatest = $pageSet->getCustomField('page_latest'); $pageLength = $pageSet->getCustomField('page_len'); $db = $this->getDB(); if ($fld_protection && count($titles)) { $this->addTables('page_restrictions'); $this->addFields(array('pr_page', 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade')); $this->addWhereFld('pr_page', array_keys($titles)); $res = $this->select(__METHOD__); while ($row = $db->fetchObject($res)) { $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'] = ''; } $protections[$row->pr_page][] = $a; # Also check old restrictions if ($pageRestrictions[$row->pr_page]) { foreach (explode(':', trim($pageRestrictions[$pageid])) 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; } $protections[$row->pr_page][] = array('type' => 'edit', 'level' => $restriction, 'expiry' => 'infinity'); $protections[$row->pr_page][] = array('type' => 'move', 'level' => $restriction, 'expiry' => 'infinity'); } else { $restriction = trim($temp[1]); if ($restriction == '') { continue; } $protections[$row->pr_page][] = array('type' => $temp[0], 'level' => $restriction, 'expiry' => 'infinity'); } } } } $db->freeResult($res); $imageIds = array(); foreach ($titles as $id => $title) { if ($title->getNamespace() == NS_FILE) { $imageIds[] = $id; } } // To avoid code duplication $cascadeTypes = array(array('prefix' => 'tl', 'table' => 'templatelinks', 'ns' => 'tl_namespace', 'title' => 'tl_title', 'ids' => array_diff(array_keys($titles), $imageIds)), array('prefix' => 'il', 'table' => 'imagelinks', 'ns' => NS_FILE, 'title' => 'il_to', 'ids' => $imageIds)); foreach ($cascadeTypes as $type) { if (count($type['ids']) != 0) { $this->resetQueryParams(); $this->addTables(array('page_restrictions', $type['table'])); $this->addTables('page', 'page_source'); $this->addTables('page', 'page_target'); $this->addFields(array('pr_type', 'pr_level', 'pr_expiry', 'page_target.page_id AS page_target_id', 'page_source.page_namespace AS page_source_namespace', 'page_source.page_title AS page_source_title')); $this->addWhere(array("{$type['prefix']}_from = pr_page", 'page_target.page_namespace = ' . $type['ns'], 'page_target.page_title = ' . $type['title'], 'page_source.page_id = pr_page')); $this->addWhereFld('pr_cascade', 1); $this->addWhereFld('page_target.page_id', $type['ids']); $res = $this->select(__METHOD__); while ($row = $db->fetchObject($res)) { $source = Title::makeTitle($row->page_source_namespace, $row->page_source_title); $a = array('type' => $row->pr_type, 'level' => $row->pr_level, 'expiry' => Block::decodeExpiry($row->pr_expiry, TS_ISO_8601), 'source' => $source->getPrefixedText()); $protections[$row->page_target_id][] = $a; } $db->freeResult($res); } } } // We don't need to check for pt stuff if there are no nonexistent titles if ($fld_protection && count($missing)) { $this->resetQueryParams(); // Construct a custom WHERE clause that matches all titles in $missing $lb = new LinkBatch($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__); $prottitles = array(); while ($row = $db->fetchObject($res)) { $prottitles[$row->pt_namespace][$row->pt_title][] = array('type' => 'create', 'level' => $row->pt_create_perm, 'expiry' => Block::decodeExpiry($row->pt_expiry, TS_ISO_8601)); } $db->freeResult($res); $images = array(); $others = array(); foreach ($missing as $title) { if ($title->getNamespace() == NS_FILE) { $images[] = $title->getDBKey(); } else { $others[] = $title; } } if (count($others) != 0) { $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__); while ($row = $db->fetchObject($res)) { $source = Title::makeTitle($row->page_namespace, $row->page_title); $a = array('type' => $row->pr_type, 'level' => $row->pr_level, 'expiry' => Block::decodeExpiry($row->pr_expiry, TS_ISO_8601), 'source' => $source->getPrefixedText()); $prottitles[$row->tl_namespace][$row->tl_title][] = $a; } $db->freeResult($res); } if (count($images) != 0) { $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__); while ($row = $db->fetchObject($res)) { $source = Title::makeTitle($row->page_namespace, $row->page_title); $a = array('type' => $row->pr_type, 'level' => $row->pr_level, 'expiry' => Block::decodeExpiry($row->pr_expiry, TS_ISO_8601), 'source' => $source->getPrefixedText()); $prottitles[NS_FILE][$row->il_to][] = $a; } $db->freeResult($res); } } // Run the talkid/subjectid query if ($fld_talkid || $fld_subjectid) { $talktitles = $subjecttitles = $talkids = $subjectids = array(); $everything = array_merge($titles, $missing); foreach ($everything as $t) { if (MWNamespace::isTalk($t->getNamespace())) { if ($fld_subjectid) { $subjecttitles[] = $t->getSubjectPage(); } } else { if ($fld_talkid) { $talktitles[] = $t->getTalkPage(); } } } if (count($talktitles) || count($subjecttitles)) { // Construct a custom WHERE clause that matches // all titles in $talktitles and $subjecttitles $lb = new LinkBatch(array_merge($talktitles, $subjecttitles)); $this->resetQueryParams(); $this->addTables('page'); $this->addFields(array('page_title', 'page_namespace', 'page_id')); $this->addWhere($lb->constructSet('page', $db)); $res = $this->select(__METHOD__); while ($row = $db->fetchObject($res)) { if (MWNamespace::isTalk($row->page_namespace)) { $talkids[MWNamespace::getSubject($row->page_namespace)][$row->page_title] = $row->page_id; } else { $subjectids[MWNamespace::getTalk($row->page_namespace)][$row->page_title] = $row->page_id; } } } } foreach ($titles as $pageid => $title) { $pageInfo = array('touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]), 'lastrevid' => intval($pageLatest[$pageid]), 'counter' => intval($pageCounter[$pageid]), 'length' => intval($pageLength[$pageid])); if ($pageIsRedir[$pageid]) { $pageInfo['redirect'] = ''; } if ($pageIsNew[$pageid]) { $pageInfo['new'] = ''; } if (!is_null($params['token'])) { $tokenFunctions = $this->getTokenFunctions(); $pageInfo['starttimestamp'] = wfTimestamp(TS_ISO_8601, time()); foreach ($params['token'] as $t) { $val = call_user_func($tokenFunctions[$t], $pageid, $title); if ($val === false) { $this->setWarning("Action '{$t}' is not allowed for the current user"); } else { $pageInfo[$t . 'token'] = $val; } } } if ($fld_protection) { $pageInfo['protection'] = array(); if (isset($protections[$pageid])) { $pageInfo['protection'] = $protections[$pageid]; $result->setIndexedTagName($pageInfo['protection'], 'pr'); } } if ($fld_talkid && isset($talkids[$title->getNamespace()][$title->getDBKey()])) { $pageInfo['talkid'] = $talkids[$title->getNamespace()][$title->getDBKey()]; } if ($fld_subjectid && isset($subjectids[$title->getNamespace()][$title->getDBKey()])) { $pageInfo['subjectid'] = $subjectids[$title->getNamespace()][$title->getDBKey()]; } if ($fld_url) { $pageInfo['fullurl'] = $title->getFullURL(); $pageInfo['editurl'] = $title->getFullURL('action=edit'); } if ($fld_readable) { if ($title->userCanRead()) { $pageInfo['readable'] = ''; } } $result->addValue(array('query', 'pages'), $pageid, $pageInfo); } // Get properties for missing titles if requested if (!is_null($params['token']) || $fld_protection || $fld_talkid || $fld_subjectid || $fld_url || $fld_readable) { $res =& $result->getData(); foreach ($missing as $pageid => $title) { if (!is_null($params['token'])) { $tokenFunctions = $this->getTokenFunctions(); $res['query']['pages'][$pageid]['starttimestamp'] = wfTimestamp(TS_ISO_8601, time()); foreach ($params['token'] as $t) { $val = call_user_func($tokenFunctions[$t], $pageid, $title); if ($val === false) { $this->setWarning("Action '{$t}' is not allowed for the current user"); } else { $res['query']['pages'][$pageid][$t . 'token'] = $val; } } } if ($fld_protection) { // Apparently the XML formatting code doesn't like array(null) // This is painful to fix, so we'll just work around it if (isset($prottitles[$title->getNamespace()][$title->getDBkey()])) { $res['query']['pages'][$pageid]['protection'] = $prottitles[$title->getNamespace()][$title->getDBkey()]; } else { $res['query']['pages'][$pageid]['protection'] = array(); } $result->setIndexedTagName($res['query']['pages'][$pageid]['protection'], 'pr'); } if ($fld_talkid && isset($talkids[$title->getNamespace()][$title->getDBKey()])) { $res['query']['pages'][$pageid]['talkid'] = $talkids[$title->getNamespace()][$title->getDBKey()]; } if ($fld_subjectid && isset($subjectids[$title->getNamespace()][$title->getDBKey()])) { $res['query']['pages'][$pageid]['subjectid'] = $subjectids[$title->getNamespace()][$title->getDBKey()]; } if ($fld_url) { $res['query']['pages'][$pageid]['fullurl'] = $title->getFullURL(); $res['query']['pages'][$pageid]['editurl'] = $title->getFullURL('action=edit'); } if ($fld_readable) { if ($title->userCanRead()) { $res['query']['pages'][$pageid]['readable'] = ''; } } } } }
/** * Convert a DB-encoded expiry into a real string that humans can read. * * @param $encoded_expiry String: Database encoded expiry time * @return String */ public static function formatExpiry($encoded_expiry) { static $msg = null; if (is_null($msg)) { $msg = array(); $keys = array('infiniteblock', 'expiringblock'); foreach ($keys as $key) { $msg[$key] = wfMsgHtml($key); } } $expiry = Block::decodeExpiry($encoded_expiry); if ($expiry == 'infinity') { $expirystr = $msg['infiniteblock']; } else { global $wgLang; $expiretimestr = $wgLang->timeanddate($expiry, true); $expirystr = wfMsgReplaceArgs($msg['expiringblock'], array($expiretimestr)); } return $expirystr; }
/** * Fetch a row of user data needed for migration. * * @param $wikiID String * @return Array|bool */ protected function localUserData($wikiID) { $lb = wfGetLB($wikiID); $db = $lb->getConnection(DB_SLAVE, array(), $wikiID); $fields = array('user_id', 'user_email', 'user_email_authenticated', 'user_password', 'user_editcount'); $conds = array('user_name' => $this->mName); $row = $db->selectRow('user', $fields, $conds, __METHOD__); if (!$row) { # Row missing from slave, try the master instead $lb->reuseConnection($db); $db = $lb->getConnection(DB_MASTER, array(), $wikiID); $row = $db->selectRow('user', $fields, $conds, __METHOD__); } if (!$row) { $lb->reuseConnection($db); return false; } /** @var $row object */ $data = array('wiki' => $wikiID, 'id' => $row->user_id, 'email' => $row->user_email, 'emailAuthenticated' => wfTimestampOrNull(TS_MW, $row->user_email_authenticated), 'password' => $row->user_password, 'editCount' => $row->user_editcount, 'groups' => array(), 'blocked' => false); // Edit count field may not be initialized... if (is_null($row->user_editcount)) { $data['editCount'] = $db->selectField('revision', 'COUNT(*)', array('rev_user' => $data['id']), __METHOD__); } // And we have to fetch groups separately, sigh... $result = $db->select('user_groups', array('ug_group'), array('ug_user' => $data['id']), __METHOD__); foreach ($result as $row) { $data['groups'][] = $row->ug_group; } $result->free(); // And while we're in here, look for user blocks :D $result = $db->select('ipblocks', array('ipb_expiry', 'ipb_reason'), array('ipb_user' => $data['id']), __METHOD__); foreach ($result as $row) { if (Block::decodeExpiry($row->ipb_expiry) > wfTimestampNow()) { $data['block-expiry'] = $row->ipb_expiry; $data['block-reason'] = $row->ipb_reason; $data['blocked'] = true; } } $result->free(); $lb->reuseConnection($db); return $data; }
public function execute() { global $wgUser; $params = $this->extractRequestParams(); $fld_protection = false; if (!is_null($params['prop'])) { $prop = array_flip($params['prop']); $fld_protection = isset($prop['protection']); } if (!is_null($params['token'])) { $token = $params['token']; $tok_edit = $this->getTokenFlag($token, 'edit'); $tok_delete = $this->getTokenFlag($token, 'delete'); $tok_protect = $this->getTokenFlag($token, 'protect'); $tok_move = $this->getTokenFlag($token, 'move'); } else { // Fix E_NOTICEs about unset variables $token = $tok_edit = $tok_delete = $tok_protect = $tok_move = null; } $pageSet = $this->getPageSet(); $titles = $pageSet->getGoodTitles(); $missing = $pageSet->getMissingTitles(); $result = $this->getResult(); $pageRestrictions = $pageSet->getCustomField('page_restrictions'); $pageIsRedir = $pageSet->getCustomField('page_is_redirect'); $pageIsNew = $pageSet->getCustomField('page_is_new'); $pageCounter = $pageSet->getCustomField('page_counter'); $pageTouched = $pageSet->getCustomField('page_touched'); $pageLatest = $pageSet->getCustomField('page_latest'); $pageLength = $pageSet->getCustomField('page_len'); $db = $this->getDB(); if ($fld_protection && !empty($titles)) { $this->addTables('page_restrictions'); $this->addFields(array('pr_page', 'pr_type', 'pr_level', 'pr_expiry', 'pr_cascade')); $this->addWhereFld('pr_page', array_keys($titles)); $res = $this->select(__METHOD__); while ($row = $db->fetchObject($res)) { $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'] = ''; } $protections[$row->pr_page][] = $a; } $db->freeResult($res); } // We don't need to check for pt stuff if there are no nonexistent titles if ($fld_protection && !empty($missing)) { $this->resetQueryParams(); // Construct a custom WHERE clause that matches all titles in $missing $lb = new LinkBatch($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__); $prottitles = array(); while ($row = $db->fetchObject($res)) { $prottitles[$row->pt_namespace][$row->pt_title] = array('type' => 'create', 'level' => $row->pt_create_perm, 'expiry' => Block::decodeExpiry($row->pt_expiry, TS_ISO_8601)); } $db->freeResult($res); } foreach ($titles as $pageid => $title) { $pageInfo = array('touched' => wfTimestamp(TS_ISO_8601, $pageTouched[$pageid]), 'lastrevid' => intval($pageLatest[$pageid]), 'counter' => intval($pageCounter[$pageid]), 'length' => intval($pageLength[$pageid])); if ($pageIsRedir[$pageid]) { $pageInfo['redirect'] = ''; } if ($pageIsNew[$pageid]) { $pageInfo['new'] = ''; } if (!is_null($token)) { // Currently all tokens are generated the same way, but it might change if ($tok_edit) { $pageInfo['edittoken'] = $wgUser->editToken(); } if ($tok_delete) { $pageInfo['deletetoken'] = $wgUser->editToken(); } if ($tok_protect) { $pageInfo['protecttoken'] = $wgUser->editToken(); } if ($tok_move) { $pageInfo['movetoken'] = $wgUser->editToken(); } } if ($fld_protection) { if (isset($protections[$pageid])) { $pageInfo['protection'] = $protections[$pageid]; $result->setIndexedTagName($pageInfo['protection'], 'pr'); } else { # Also check old restrictions if ($pageRestrictions[$pageid]) { foreach (explode(':', trim($pageRestrictions[$pageid])) as $restrict) { $temp = explode('=', trim($restrict)); if (count($temp) == 1) { // old old format should be treated as edit/move restriction $restriction = trim($temp[0]); $pageInfo['protection'][] = array('type' => 'edit', 'level' => $restriction, 'expiry' => 'infinity'); $pageInfo['protection'][] = array('type' => 'move', 'level' => $restriction, 'expiry' => 'infinity'); } else { $restriction = trim($temp[1]); $pageInfo['protection'][] = array('type' => $temp[0], 'level' => $restriction, 'expiry' => 'infinity'); } } $result->setIndexedTagName($pageInfo['protection'], 'pr'); } else { $pageInfo['protection'] = array(); } } } $result->addValue(array('query', 'pages'), $pageid, $pageInfo); } // Get edit/protect tokens and protection data for missing titles if requested // Delete and move tokens are N/A for missing titles anyway if ($tok_edit || $tok_protect || $fld_protection) { $res =& $result->getData(); foreach ($missing as $pageid => $title) { if ($tok_edit) { $res['query']['pages'][$pageid]['edittoken'] = $wgUser->editToken(); } if ($tok_protect) { $res['query']['pages'][$pageid]['protecttoken'] = $wgUser->editToken(); } if ($fld_protection) { // Apparently the XML formatting code doesn't like array(null) // This is painful to fix, so we'll just work around it if (isset($prottitles[$title->getNamespace()][$title->getDBkey()])) { $res['query']['pages'][$pageid]['protection'][] = $prottitles[$title->getNamespace()][$title->getDBkey()]; } else { $res['query']['pages'][$pageid]['protection'] = array(); } $result->setIndexedTagName($res['query']['pages'][$pageid]['protection'], 'pr'); } } } }