本文整理汇总了PHP中Revision::selectTextFields方法的典型用法代码示例。如果您正苦于以下问题:PHP Revision::selectTextFields方法的具体用法?PHP Revision::selectTextFields怎么用?PHP Revision::selectTextFields使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Revision
的用法示例。
在下文中一共展示了Revision::selectTextFields方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populateSearchIndex
/**
* Populates the search index with content from all pages
*/
protected function populateSearchIndex()
{
$res = $this->db->select('page', 'MAX(page_id) AS count');
$s = $this->db->fetchObject($res);
$count = $s->count;
$this->output("Rebuilding index fields for {$count} pages...\n");
$n = 0;
$fields = array_merge(Revision::selectPageFields(), Revision::selectFields(), Revision::selectTextFields());
while ($n < $count) {
if ($n) {
$this->output($n . "\n");
}
$end = $n + self::RTI_CHUNK_SIZE - 1;
$res = $this->db->select(['page', 'revision', 'text'], $fields, ["page_id BETWEEN {$n} AND {$end}", 'page_latest = rev_id', 'rev_text_id = old_id'], __METHOD__);
foreach ($res as $s) {
try {
$title = Title::makeTitle($s->page_namespace, $s->page_title);
$rev = new Revision($s);
$content = $rev->getContent();
$u = new SearchUpdate($s->page_id, $title, $content);
$u->doUpdate();
} catch (MWContentSerializationException $ex) {
$this->output("Failed to deserialize content of revision {$s->rev_id} of page " . "`" . $title->getPrefixedDBkey() . "`!\n");
}
}
$n += self::RTI_CHUNK_SIZE;
}
}
示例2: run
/**
* @param ApiPageSet $resultPageSet
* @return void
*/
protected function run(ApiPageSet $resultPageSet = null)
{
$db = $this->getDB();
$params = $this->extractRequestParams(false);
$result = $this->getResult();
$this->requireMaxOneParameter($params, 'user', 'excludeuser');
// Namespace check is likely to be desired, but can't be done
// efficiently in SQL.
$miser_ns = null;
$needPageTable = false;
if ($params['namespace'] !== null) {
$params['namespace'] = array_unique($params['namespace']);
sort($params['namespace']);
if ($params['namespace'] != MWNamespace::getValidNamespaces()) {
$needPageTable = true;
if ($this->getConfig()->get('MiserMode')) {
$miser_ns = $params['namespace'];
} else {
$this->addWhere(array('page_namespace' => $params['namespace']));
}
}
}
$this->addTables('revision');
if ($resultPageSet === null) {
$this->parseParameters($params);
$this->addTables('page');
$this->addJoinConds(array('page' => array('INNER JOIN', array('rev_page = page_id'))));
$this->addFields(Revision::selectFields());
$this->addFields(Revision::selectPageFields());
// Review this depeneding on the outcome of T113901
$this->addOption('STRAIGHT_JOIN');
} else {
$this->limit = $this->getParameter('limit') ?: 10;
$this->addFields(array('rev_timestamp', 'rev_id'));
if ($params['generatetitles']) {
$this->addFields(array('rev_page'));
}
if ($needPageTable) {
$this->addTables('page');
$this->addJoinConds(array('page' => array('INNER JOIN', array('rev_page = page_id'))));
$this->addFieldsIf(array('page_namespace'), (bool) $miser_ns);
// Review this depeneding on the outcome of T113901
$this->addOption('STRAIGHT_JOIN');
}
}
if ($this->fld_tags) {
$this->addTables('tag_summary');
$this->addJoinConds(array('tag_summary' => array('LEFT JOIN', array('rev_id=ts_rev_id'))));
$this->addFields('ts_tags');
}
if ($this->fetchContent) {
$this->addTables('text');
$this->addJoinConds(array('text' => array('INNER JOIN', array('rev_text_id=old_id'))));
$this->addFields('old_id');
$this->addFields(Revision::selectTextFields());
}
if ($params['user'] !== null) {
$id = User::idFromName($params['user']);
if ($id) {
$this->addWhereFld('rev_user', $id);
} else {
$this->addWhereFld('rev_user_text', $params['user']);
}
} elseif ($params['excludeuser'] !== null) {
$id = User::idFromName($params['excludeuser']);
if ($id) {
$this->addWhere('rev_user != ' . $id);
} else {
$this->addWhere('rev_user_text != ' . $db->addQuotes($params['excludeuser']));
}
}
if ($params['user'] !== null || $params['excludeuser'] !== null) {
// Paranoia: avoid brute force searches (bug 17342)
if (!$this->getUser()->isAllowed('deletedhistory')) {
$bitmask = Revision::DELETED_USER;
} elseif (!$this->getUser()->isAllowedAny('suppressrevision', 'viewsuppressed')) {
$bitmask = Revision::DELETED_USER | Revision::DELETED_RESTRICTED;
} else {
$bitmask = 0;
}
if ($bitmask) {
$this->addWhere($db->bitAnd('rev_deleted', $bitmask) . " != {$bitmask}");
}
}
$dir = $params['dir'];
if ($params['continue'] !== null) {
$op = $dir == 'newer' ? '>' : '<';
$cont = explode('|', $params['continue']);
$this->dieContinueUsageIf(count($cont) != 2);
$ts = $db->addQuotes($db->timestamp($cont[0]));
$rev_id = (int) $cont[1];
$this->dieContinueUsageIf(strval($rev_id) !== $cont[1]);
$this->addWhere("rev_timestamp {$op} {$ts} OR " . "(rev_timestamp = {$ts} AND " . "rev_id {$op}= {$rev_id})");
}
$this->addOption('LIMIT', $this->limit + 1);
$sort = $dir == 'newer' ? '' : ' DESC';
//.........这里部分代码省略.........
示例3: execute
public function execute()
{
$params = $this->extractRequestParams(false);
// If any of those parameters are used, work in 'enumeration' mode.
// Enum mode can only be used when exactly one page is provided.
// Enumerating revisions on multiple pages make it extremely
// difficult to manage continuations and require additional SQL indexes
$enumRevMode = !is_null($params['user']) || !is_null($params['excludeuser']) || !is_null($params['limit']) || !is_null($params['startid']) || !is_null($params['endid']) || $params['dir'] === 'newer' || !is_null($params['start']) || !is_null($params['end']);
$pageSet = $this->getPageSet();
$pageCount = $pageSet->getGoodTitleCount();
$revCount = $pageSet->getRevisionCount();
// Optimization -- nothing to do
if ($revCount === 0 && $pageCount === 0) {
return;
}
if ($revCount > 0 && $enumRevMode) {
$this->dieUsage('The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids');
}
if ($pageCount > 1 && $enumRevMode) {
$this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.', 'multpages');
}
if (!is_null($params['difftotext'])) {
$this->difftotext = $params['difftotext'];
} elseif (!is_null($params['diffto'])) {
if ($params['diffto'] == 'cur') {
$params['diffto'] = 0;
}
if ((!ctype_digit($params['diffto']) || $params['diffto'] < 0) && $params['diffto'] != 'prev' && $params['diffto'] != 'next') {
$this->dieUsage('rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto');
}
// Check whether the revision exists and is readable,
// DifferenceEngine returns a rather ambiguous empty
// string if that's not the case
if ($params['diffto'] != 0) {
$difftoRev = Revision::newFromID($params['diffto']);
if (!$difftoRev) {
$this->dieUsageMsg(array('nosuchrevid', $params['diffto']));
}
if ($difftoRev->isDeleted(Revision::DELETED_TEXT)) {
$this->setWarning("Couldn't diff to r{$difftoRev->getID()}: content is hidden");
$params['diffto'] = null;
}
}
$this->diffto = $params['diffto'];
}
$db = $this->getDB();
$this->addTables('page');
$this->addFields(Revision::selectFields());
$this->addWhere('page_id = rev_page');
$prop = array_flip($params['prop']);
// Optional fields
$this->fld_ids = isset($prop['ids']);
// $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed?
$this->fld_flags = isset($prop['flags']);
$this->fld_timestamp = isset($prop['timestamp']);
$this->fld_comment = isset($prop['comment']);
$this->fld_parsedcomment = isset($prop['parsedcomment']);
$this->fld_size = isset($prop['size']);
$this->fld_sha1 = isset($prop['sha1']);
$this->fld_userid = isset($prop['userid']);
$this->fld_user = isset($prop['user']);
$this->token = $params['token'];
// Possible indexes used
$index = array();
$userMax = $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1;
$botMax = $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2;
$limit = $params['limit'];
if ($limit == 'max') {
$limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
$this->getResult()->setParsedLimit($this->getModuleName(), $limit);
}
if (!is_null($this->token) || $pageCount > 0) {
$this->addFields(Revision::selectPageFields());
}
if (isset($prop['tags'])) {
$this->fld_tags = true;
$this->addTables('tag_summary');
$this->addJoinConds(array('tag_summary' => array('LEFT JOIN', array('rev_id=ts_rev_id'))));
$this->addFields('ts_tags');
}
if (!is_null($params['tag'])) {
$this->addTables('change_tag');
$this->addJoinConds(array('change_tag' => array('INNER JOIN', array('rev_id=ct_rev_id'))));
$this->addWhereFld('ct_tag', $params['tag']);
global $wgOldChangeTagsIndex;
$index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
}
if (isset($prop['content']) || !is_null($this->difftotext)) {
// For each page we will request, the user must have read rights for that page
foreach ($pageSet->getGoodTitles() as $title) {
if (!$title->userCan('read')) {
$this->dieUsage('The current user is not allowed to read ' . $title->getPrefixedText(), 'accessdenied');
}
}
$this->addTables('text');
$this->addWhere('rev_text_id=old_id');
$this->addFields('old_id');
$this->addFields(Revision::selectTextFields());
$this->fld_content = isset($prop['content']);
$this->expandTemplates = $params['expandtemplates'];
//.........这里部分代码省略.........
示例4: run
protected function run(ApiPageSet $resultPageSet = null)
{
$params = $this->extractRequestParams(false);
// If any of those parameters are used, work in 'enumeration' mode.
// Enum mode can only be used when exactly one page is provided.
// Enumerating revisions on multiple pages make it extremely
// difficult to manage continuations and require additional SQL indexes
$enumRevMode = !is_null($params['user']) || !is_null($params['excludeuser']) || !is_null($params['limit']) || !is_null($params['startid']) || !is_null($params['endid']) || $params['dir'] === 'newer' || !is_null($params['start']) || !is_null($params['end']);
$pageSet = $this->getPageSet();
$pageCount = $pageSet->getGoodTitleCount();
$revCount = $pageSet->getRevisionCount();
// Optimization -- nothing to do
if ($revCount === 0 && $pageCount === 0) {
// Nothing to do
return;
}
if ($revCount > 0 && count($pageSet->getLiveRevisionIDs()) === 0) {
// We're in revisions mode but all given revisions are deleted
return;
}
if ($revCount > 0 && $enumRevMode) {
$this->dieUsage('The revids= parameter may not be used with the list options ' . '(limit, startid, endid, dirNewer, start, end).', 'revids');
}
if ($pageCount > 1 && $enumRevMode) {
$this->dieUsage('titles, pageids or a generator was used to supply multiple pages, ' . 'but the limit, startid, endid, dirNewer, user, excludeuser, start ' . 'and end parameters may only be used on a single page.', 'multpages');
}
// In non-enum mode, rvlimit can't be directly used. Use the maximum
// allowed value.
if (!$enumRevMode) {
$this->setParsedLimit = false;
$params['limit'] = 'max';
}
$db = $this->getDB();
$this->addTables(array('revision', 'page'));
$this->addJoinConds(array('page' => array('INNER JOIN', array('page_id = rev_page'))));
if ($resultPageSet === null) {
$this->parseParameters($params);
$this->token = $params['token'];
$this->addFields(Revision::selectFields());
if ($this->token !== null || $pageCount > 0) {
$this->addFields(Revision::selectPageFields());
}
} else {
$this->limit = $this->getParameter('limit') ?: 10;
$this->addFields(array('rev_id', 'rev_page'));
}
if ($this->fld_tags) {
$this->addTables('tag_summary');
$this->addJoinConds(array('tag_summary' => array('LEFT JOIN', array('rev_id=ts_rev_id'))));
$this->addFields('ts_tags');
}
if (!is_null($params['tag'])) {
$this->addTables('change_tag');
$this->addJoinConds(array('change_tag' => array('INNER JOIN', array('rev_id=ct_rev_id'))));
$this->addWhereFld('ct_tag', $params['tag']);
}
if ($this->fetchContent) {
// For each page we will request, the user must have read rights for that page
$user = $this->getUser();
/** @var $title Title */
foreach ($pageSet->getGoodTitles() as $title) {
if (!$title->userCan('read', $user)) {
$this->dieUsage('The current user is not allowed to read ' . $title->getPrefixedText(), 'accessdenied');
}
}
$this->addTables('text');
$this->addJoinConds(array('text' => array('INNER JOIN', array('rev_text_id=old_id'))));
$this->addFields('old_id');
$this->addFields(Revision::selectTextFields());
}
// add user name, if needed
if ($this->fld_user) {
$this->addTables('user');
$this->addJoinConds(array('user' => Revision::userJoinCond()));
$this->addFields(Revision::selectUserFields());
}
if ($enumRevMode) {
// This is mostly to prevent parameter errors (and optimize SQL?)
if (!is_null($params['startid']) && !is_null($params['start'])) {
$this->dieUsage('start and startid cannot be used together', 'badparams');
}
if (!is_null($params['endid']) && !is_null($params['end'])) {
$this->dieUsage('end and endid cannot be used together', 'badparams');
}
if (!is_null($params['user']) && !is_null($params['excludeuser'])) {
$this->dieUsage('user and excludeuser cannot be used together', 'badparams');
}
// Continuing effectively uses startid. But we can't use rvstartid
// directly, because there is no way to tell the client to ''not''
// send rvstart if it sent it in the original query. So instead we
// send the continuation startid as rvcontinue, and ignore both
// rvstart and rvstartid when that is supplied.
if (!is_null($params['continue'])) {
$params['startid'] = $params['continue'];
$params['start'] = null;
}
// This code makes an assumption that sorting by rev_id and rev_timestamp produces
// the same result. This way users may request revisions starting at a given time,
// but to page through results use the rev_id returned after each page.
// Switching to rev_id removes the potential problem of having more than
//.........这里部分代码省略.........
示例5: execute
public function execute()
{
$params = $this->extractRequestParams(false);
// If any of those parameters are used, work in 'enumeration' mode.
// Enum mode can only be used when exactly one page is provided.
// Enumerating revisions on multiple pages make it extremely
// difficult to manage continuations and require additional SQL indexes
$enumRevMode = !is_null($params['user']) || !is_null($params['excludeuser']) || !is_null($params['limit']) || !is_null($params['startid']) || !is_null($params['endid']) || $params['dir'] === 'newer' || !is_null($params['start']) || !is_null($params['end']);
$pageSet = $this->getPageSet();
$pageCount = $pageSet->getGoodTitleCount();
$revCount = $pageSet->getRevisionCount();
// Optimization -- nothing to do
if ($revCount === 0 && $pageCount === 0) {
return;
}
if ($revCount > 0 && $enumRevMode) {
$this->dieUsage('The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids');
}
if ($pageCount > 1 && $enumRevMode) {
$this->dieUsage('titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.', 'multpages');
}
$this->addTables('revision');
$this->addFields(Revision::selectFields());
$this->addTables('page');
$this->addWhere('page_id = rev_page');
$prop = array_flip($params['prop']);
// Optional fields
$this->fld_ids = isset($prop['ids']);
// $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed?
$this->fld_flags = isset($prop['flags']);
$this->fld_timestamp = isset($prop['timestamp']);
$this->fld_comment = isset($prop['comment']);
$this->fld_size = isset($prop['size']);
$this->fld_user = isset($prop['user']);
$this->token = $params['token'];
if (!is_null($this->token) || $pageCount > 0) {
$this->addFields(Revision::selectPageFields());
}
if (isset($prop['content'])) {
// For each page we will request, the user must have read rights for that page
foreach ($pageSet->getGoodTitles() as $title) {
if (!$title->userCanRead()) {
$this->dieUsage('The current user is not allowed to read ' . $title->getPrefixedText(), 'accessdenied');
}
}
$this->addTables('text');
$this->addWhere('rev_text_id=old_id');
$this->addFields('old_id');
$this->addFields(Revision::selectTextFields());
$this->fld_content = true;
$this->expandTemplates = $params['expandtemplates'];
$this->generateXML = $params['generatexml'];
if (isset($params['section'])) {
$this->section = $params['section'];
} else {
$this->section = false;
}
}
$userMax = $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1;
$botMax = $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2;
$limit = $params['limit'];
if ($limit == 'max') {
$limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
$this->getResult()->addValue('limits', $this->getModuleName(), $limit);
}
if ($enumRevMode) {
// This is mostly to prevent parameter errors (and optimize SQL?)
if (!is_null($params['startid']) && !is_null($params['start'])) {
$this->dieUsage('start and startid cannot be used together', 'badparams');
}
if (!is_null($params['endid']) && !is_null($params['end'])) {
$this->dieUsage('end and endid cannot be used together', 'badparams');
}
if (!is_null($params['user']) && !is_null($params['excludeuser'])) {
$this->dieUsage('user and excludeuser cannot be used together', 'badparams');
}
// This code makes an assumption that sorting by rev_id and rev_timestamp produces
// the same result. This way users may request revisions starting at a given time,
// but to page through results use the rev_id returned after each page.
// Switching to rev_id removes the potential problem of having more than
// one row with the same timestamp for the same page.
// The order needs to be the same as start parameter to avoid SQL filesort.
if (is_null($params['startid']) && is_null($params['endid'])) {
$this->addWhereRange('rev_timestamp', $params['dir'], $params['start'], $params['end']);
} else {
$this->addWhereRange('rev_id', $params['dir'], $params['startid'], $params['endid']);
}
// must manually initialize unset limit
if (is_null($limit)) {
$limit = 10;
}
$this->validateLimit('limit', $limit, 1, $userMax, $botMax);
// There is only one ID, use it
$this->addWhereFld('rev_page', current(array_keys($pageSet->getGoodTitles())));
if (!is_null($params['user'])) {
$this->addWhereFld('rev_user_text', $params['user']);
} elseif (!is_null($params['excludeuser'])) {
$this->addWhere('rev_user_text != ' . $this->getDB()->addQuotes($params['excludeuser']));
}
} elseif ($revCount > 0) {
//.........这里部分代码省略.........
示例6: run
protected function run(ApiPageSet $resultPageSet = null)
{
$params = $this->extractRequestParams(false);
// If any of those parameters are used, work in 'enumeration' mode.
// Enum mode can only be used when exactly one page is provided.
// Enumerating revisions on multiple pages make it extremely
// difficult to manage continuations and require additional SQL indexes
$enumRevMode = $params['user'] !== null || $params['excludeuser'] !== null || $params['limit'] !== null || $params['startid'] !== null || $params['endid'] !== null || $params['dir'] === 'newer' || $params['start'] !== null || $params['end'] !== null;
$pageSet = $this->getPageSet();
$pageCount = $pageSet->getGoodTitleCount();
$revCount = $pageSet->getRevisionCount();
// Optimization -- nothing to do
if ($revCount === 0 && $pageCount === 0) {
// Nothing to do
return;
}
if ($revCount > 0 && count($pageSet->getLiveRevisionIDs()) === 0) {
// We're in revisions mode but all given revisions are deleted
return;
}
if ($revCount > 0 && $enumRevMode) {
$this->dieUsage('The revids= parameter may not be used with the list options ' . '(limit, startid, endid, dirNewer, start, end).', 'revids');
}
if ($pageCount > 1 && $enumRevMode) {
$this->dieUsage('titles, pageids or a generator was used to supply multiple pages, ' . 'but the limit, startid, endid, dirNewer, user, excludeuser, start ' . 'and end parameters may only be used on a single page.', 'multpages');
}
// In non-enum mode, rvlimit can't be directly used. Use the maximum
// allowed value.
if (!$enumRevMode) {
$this->setParsedLimit = false;
$params['limit'] = 'max';
}
$db = $this->getDB();
$this->addTables(['revision', 'page']);
$this->addJoinConds(['page' => ['INNER JOIN', ['page_id = rev_page']]]);
if ($resultPageSet === null) {
$this->parseParameters($params);
$this->token = $params['token'];
$this->addFields(Revision::selectFields());
if ($this->token !== null || $pageCount > 0) {
$this->addFields(Revision::selectPageFields());
}
} else {
$this->limit = $this->getParameter('limit') ?: 10;
$this->addFields(['rev_id', 'rev_timestamp', 'rev_page']);
}
if ($this->fld_tags) {
$this->addTables('tag_summary');
$this->addJoinConds(['tag_summary' => ['LEFT JOIN', ['rev_id=ts_rev_id']]]);
$this->addFields('ts_tags');
}
if ($params['tag'] !== null) {
$this->addTables('change_tag');
$this->addJoinConds(['change_tag' => ['INNER JOIN', ['rev_id=ct_rev_id']]]);
$this->addWhereFld('ct_tag', $params['tag']);
}
if ($this->fetchContent) {
// For each page we will request, the user must have read rights for that page
$user = $this->getUser();
/** @var $title Title */
foreach ($pageSet->getGoodTitles() as $title) {
if (!$title->userCan('read', $user)) {
$this->dieUsage('The current user is not allowed to read ' . $title->getPrefixedText(), 'accessdenied');
}
}
$this->addTables('text');
$this->addJoinConds(['text' => ['INNER JOIN', ['rev_text_id=old_id']]]);
$this->addFields('old_id');
$this->addFields(Revision::selectTextFields());
}
// add user name, if needed
if ($this->fld_user) {
$this->addTables('user');
$this->addJoinConds(['user' => Revision::userJoinCond()]);
$this->addFields(Revision::selectUserFields());
}
if ($enumRevMode) {
// Indexes targeted:
// page_timestamp if we don't have rvuser
// page_user_timestamp if we have a logged-in rvuser
// page_timestamp or usertext_timestamp if we have an IP rvuser
// This is mostly to prevent parameter errors (and optimize SQL?)
if ($params['startid'] !== null && $params['start'] !== null) {
$this->dieUsage('start and startid cannot be used together', 'badparams');
}
if ($params['endid'] !== null && $params['end'] !== null) {
$this->dieUsage('end and endid cannot be used together', 'badparams');
}
if ($params['user'] !== null && $params['excludeuser'] !== null) {
$this->dieUsage('user and excludeuser cannot be used together', 'badparams');
}
if ($params['continue'] !== null) {
$cont = explode('|', $params['continue']);
$this->dieContinueUsageIf(count($cont) != 2);
$op = $params['dir'] === 'newer' ? '>' : '<';
$continueTimestamp = $db->addQuotes($db->timestamp($cont[0]));
$continueId = (int) $cont[1];
$this->dieContinueUsageIf($continueId != $cont[1]);
$this->addWhere("rev_timestamp {$op} {$continueTimestamp} OR " . "(rev_timestamp = {$continueTimestamp} AND " . "rev_id {$op}= {$continueId})");
}
//.........这里部分代码省略.........
示例7: execute
public function execute() {
global $wgContLang;
$dbw = TranslationMemoryUpdater::getDatabaseHandle();
if ( $dbw === null ) {
$this->error( "Database file not configured" );
$this->exit();
}
$dbw->setFlag( DBO_TRX ); // HUGE speed improvement
$groups = MessageGroups::singleton()->getGroups();
// TODO: encapsulate list of valid language codes
$languages = Language::getLanguageNames( false );
unset( $languages['en'] );
foreach ( $groups as $id => $group ) {
if ( $group->isMeta() ) {
continue;
}
$this->output( "Processing: {$group->getLabel()} ", $id );
$capitalized = MWNamespace::isCapitalized( $group->getNamespace() );
$ns_text = $wgContLang->getNsText( $group->getNamespace() );
$definitions = $group->load( $group->getSourceLanguage() );
foreach ( $definitions as $key => $definition ) {
// TODO: would be nice to do key normalisation closer to the message groups, to avoid transforming back and forth.
// But how to preserve the original keys...
$key = strtr( $key, ' ', '_' );
$key = $capitalized ? $wgContLang->ucfirst( $key ) : $key;
$dbr = wfGetDB( DB_SLAVE );
$tables = array( 'page', 'revision', 'text' );
// selectFields to stfu Revision class
$vars = array_merge( Revision::selectTextFields(), array( 'page_title' ), Revision::selectFields() );
$conds = array(
'page_latest = rev_id',
'rev_text_id = old_id',
'page_namespace' => $group->getNamespace(),
'page_title ' . $dbr->buildLike( "$key/", $dbr->anyString() )
);
$res = $dbr->select( $tables, $vars, $conds, __METHOD__ );
// Assure that there is at least one translation
if ( $res->numRows() < 1 ) {
continue;
}
$insert = array(
'text' => $definition,
'context' => "$ns_text:$key",
'length' => strlen( $definition ),
'lang' => $group->getSourceLanguage(),
);
$source_id = $dbw->selectField( '`sources`', 'sid', $insert, __METHOD__ );
if ( $source_id === false ) {
$dbw->insert( '`sources`', $insert, __METHOD__ );
$source_id = $dbw->insertId();
}
$this->output( ' ', $id );
foreach ( $res as $row ) {
list( , $code ) = TranslateUtils::figureMessage( $row->page_title );
$revision = new Revision( $row );
$insert = array(
'text' => $revision->getText(),
'lang' => $code,
'time' => wfTimestamp(),
'sid' => $source_id );
// We only do SQlite which doesn't need to know unique indexes
$dbw->replace( '`targets`', null, $insert, __METHOD__ );
}
$this->output( "{$res->numRows()}", $id );
} // each translation>
$dbw->commit();
} // each group>
}
示例8: fetchTranslatorsPortal
public function fetchTranslatorsPortal( $natives ) {
$titles = array();
foreach ( $natives as $code => $_ ) {
$titles[] = Title::capitalize( $code, NS_PORTAL ) . '/translators';
}
$dbr = wfGetDB( DB_SLAVE );
$tables = array( 'page', 'revision', 'text' );
$vars = array_merge( Revision::selectTextFields(), array( 'page_title', 'page_namespace' ), Revision::selectFields() );
$conds = array(
'page_latest = rev_id',
'rev_text_id = old_id',
'page_namespace' => NS_PORTAL,
'page_title' => $titles,
);
$res = $dbr->select( $tables, $vars, $conds, __METHOD__ );
$users = array();
$lb = new LinkBatch;
foreach ( $res as $row ) {
$rev = new Revision( $row );
$text = $rev->getText();
$code = strtolower( preg_replace( '!/translators$!', '', $row->page_title ) );
preg_match_all( '!{{[Uu]ser\|([^}|]+)!', $text, $matches, PREG_SET_ORDER );
foreach ( $matches as $match ) {
$user = Title::capitalize( $match[1], NS_USER );
$lb->add( NS_USER, $user );
$lb->add( NS_USER_TALK, $user );
if ( !isset( $users[$code] ) ) $users[$code] = array();
$users[$code][strtr( $user, '_', ' ' )] = -1;
}
}
$lb->execute();
return $users;
}
示例9: getArticleText
/**
* Fetch an article from this or another local MediaWiki database.
* This is probably *very* fragile, and shouldn't be used perhaps.
*
* @param string $wiki
* @param string $article
* @return string
*/
function getArticleText($wiki, $article)
{
wfDebugLog('SpamBlacklist', "Fetching {$this->getBlacklistType()} blacklist from '{$article}' on '{$wiki}'...\n");
$title = Title::newFromText($article);
// Load all the relevant tables from the correct DB.
// This assumes that old_text is the actual text or
// that the external store system is at least unified.
$row = wfGetDB(DB_SLAVE, array(), $wiki)->selectRow(array('page', 'revision', 'text'), array_merge(Revision::selectFields(), Revision::selectPageFields(), Revision::selectTextFields()), array('page_namespace' => $title->getNamespace(), 'page_title' => $title->getDBkey(), 'rev_id=page_latest', 'old_id=rev_text_id'), __METHOD__);
return $row ? Revision::newFromRow($row)->getText() : false;
}