function formatResult($skin, $result)
 {
     global $wgContLang;
     $fname = 'DoubleRedirectsPage::formatResult';
     $titleA = Title::makeTitle($result->namespace, $result->title);
     if ($result && !isset($result->nsb)) {
         $dbr =& wfGetDB(DB_SLAVE);
         $sql = $this->getSQLText($dbr, $result->namespace, $result->title);
         $res = $dbr->query($sql, $fname);
         if ($res) {
             $result = $dbr->fetchObject($res);
             $dbr->freeResult($res);
         }
     }
     if (!$result) {
         return '';
     }
     $titleB = Title::makeTitle($result->nsb, $result->tb);
     $titleC = Title::makeTitle($result->nsc, $result->tc);
     $linkA = $skin->makeKnownLinkObj($titleA, '', 'redirect=no');
     $edit = $skin->makeBrokenLinkObj($titleA, "(" . wfMsg("qbedit") . ")", 'redirect=no');
     $linkB = $skin->makeKnownLinkObj($titleB, '', 'redirect=no');
     $linkC = $skin->makeKnownLinkObj($titleC);
     $arr = $wgContLang->isRTL() ? '←' : '→';
     return "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}";
 }
 /**
  * Get users with avatar who sign up on the wiki (include founder)
  *
  * @param integer $wikiId
  * @param integer $limit (number of users)
  * @return array $wikiUsers
  */
 protected function getWikiUsers($wikiId = null, $limit = 30)
 {
     global $wgSpecialsDB;
     wfProfileIn(__METHOD__);
     $wikiId = empty($wikiId) ? $this->wg->CityId : $wikiId;
     $memKey = wfSharedMemcKey('userlogin', 'users_with_avatar', $wikiId);
     $wikiUsers = $this->wg->Memc->get($memKey);
     if (!is_array($wikiUsers)) {
         $wikiUsers = array();
         $db = wfGetDB(DB_SLAVE, array(), $wgSpecialsDB);
         $result = $db->select(array('user_login_history'), array('distinct user_id'), array('city_id' => $wikiId), __METHOD__, array('LIMIT' => $limit));
         while ($row = $db->fetchObject($result)) {
             $this->addUserToUserList($row->user_id, $wikiUsers);
         }
         $db->freeResult($result);
         // add founder if not exist
         $founder = WikiFactory::getWikiById($wikiId)->city_founding_user;
         if (!array_key_exists($founder, $wikiUsers)) {
             $this->addUserToUserList($founder, $wikiUsers);
         }
         $this->wg->Memc->set($memKey, $wikiUsers, WikiaResponse::CACHE_STANDARD);
     }
     wfProfileOut(__METHOD__);
     return $wikiUsers;
 }
Example #3
0
function fixAllSwiftSyncData($dry, $limit)
{
    global $wgSwiftSyncDB, $method;
    $dbr = wfGetDB(DB_SLAVE, array(), $wgSwiftSyncDB);
    $res = $dbr->select(['image_sync_done'], ['id, city_id, img_action, img_src, img_dest, img_added, img_sync, img_error'], ['city_id' => 0], $method, ['ORDER BY' => 'id', 'LIMIT' => $limit]);
    $rows = array();
    while ($row = $dbr->fetchObject($res)) {
        $rows[] = $row;
    }
    $dbr->freeResult($res);
    print sprintf("Found %0d rows to fix \n", count($rows));
    foreach ($rows as $row) {
        print "Parsing " . $row->id . ", ";
        $image_path_dir = null;
        if (preg_match('/swift\\-backend\\/(.*)\\/images/', $row->img_dest, $data)) {
            $image_path_dir = $data[1];
        }
        if (empty($image_path_dir)) {
            print " cannot find image_path_dir \n";
            continue;
        }
        $image_path = sprintf("http://images.wikia.com/%s/images", $image_path_dir);
        $serialized_image_path = serialize($image_path);
        print "path: " . $serialized_image_path . ", ";
        $row->city_id = getCityIdByImagePath($serialized_image_path);
        if ($row->city_id > 0) {
            moveRecordToActiveQueue($row, $dry);
        } else {
            print " cannot find city_id \n";
        }
    }
}
 function getSQL()
 {
     $dbr =& wfGetDB(DB_SLAVE);
     list($categorylinks, $page) = $dbr->tableNamesN('categorylinks', 'page');
     $name = $dbr->addQuotes($this->getName());
     return "\n\t\t\tSELECT\n\t\t\t\t{$name} as type,\n\t\t\t\t" . NS_CATEGORY . " as namespace,\n\t\t\t\tcl_to as title,\n\t\t\t\tCOUNT(*) as value\n\t\t\tFROM {$categorylinks}\n\t\t\tLEFT JOIN {$page} ON cl_to = page_title AND page_namespace = " . NS_CATEGORY . "\n\t\t\tWHERE page_title IS NULL\n\t\t\tGROUP BY 1,2,3\n\t\t\t";
 }
 function execute($par)
 {
     $this->setHeaders();
     $this->outputHeader();
     $this->getOutput()->addModuleStyles('mediawiki.special.pagesWithProp');
     $request = $this->getRequest();
     $propname = $request->getVal('propname', $par);
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select('page_props', 'pp_propname', '', __METHOD__, array('DISTINCT', 'ORDER BY' => 'pp_propname'));
     $propnames = array();
     foreach ($res as $row) {
         $propnames[$row->pp_propname] = $row->pp_propname;
     }
     $form = new HTMLForm(array('propname' => array('type' => 'selectorother', 'name' => 'propname', 'options' => $propnames, 'default' => $propname, 'label-message' => 'pageswithprop-prop', 'required' => true)), $this->getContext());
     $form->setMethod('get');
     $form->setSubmitCallback(array($this, 'onSubmit'));
     $form->setWrapperLegendMsg('pageswithprop-legend');
     $form->addHeaderText($this->msg('pageswithprop-text')->parseAsBlock());
     $form->setSubmitTextMsg('pageswithprop-submit');
     $form->prepareForm();
     $form->displayForm(false);
     if ($propname !== '' && $propname !== null) {
         $form->trySubmit();
     }
 }
Example #6
0
 function getSQL()
 {
     global $wgCountCategorizedImagesAsUsed, $wgDBtype;
     $dbr = wfGetDB(DB_SLAVE);
     switch ($wgDBtype) {
         case 'mysql':
             $epoch = 'UNIX_TIMESTAMP(img_timestamp)';
             break;
         case 'oracle':
             $epoch = '((trunc(img_timestamp) - to_date(\'19700101\',\'YYYYMMDD\')) * 86400)';
             break;
         case 'sqlite':
             $epoch = 'img_timestamp';
             break;
         default:
             $epoch = 'EXTRACT(epoch FROM img_timestamp)';
     }
     if ($wgCountCategorizedImagesAsUsed) {
         list($page, $image, $imagelinks, $categorylinks) = $dbr->tableNamesN('page', 'image', 'imagelinks', 'categorylinks');
         return "SELECT 'Unusedimages' as type, 6 as namespace, img_name as title, {$epoch} as value,\n\t\t\t\t\t\timg_user, img_user_text,  img_description\n\t\t\t\t\tFROM ((({$page} AS I LEFT JOIN {$categorylinks} AS L ON I.page_id = L.cl_from)\n\t\t\t\t\t\tLEFT JOIN {$imagelinks} AS P ON I.page_title = P.il_to)\n\t\t\t\t\t\tINNER JOIN {$image} AS G ON I.page_title = G.img_name)\n\t\t\t\t\tWHERE I.page_namespace = " . NS_FILE . " AND L.cl_from IS NULL AND P.il_to IS NULL";
     } else {
         list($image, $imagelinks) = $dbr->tableNamesN('image', 'imagelinks');
         return "SELECT 'Unusedimages' as type, 6 as namespace, img_name as title, {$epoch} as value,\n\t\t\t\timg_user, img_user_text,  img_description\n\t\t\t\tFROM {$image} LEFT JOIN {$imagelinks} ON img_name=il_to WHERE il_to IS NULL ";
     }
 }
 function getSQL()
 {
     $dbr = wfGetDB(DB_SLAVE);
     list($page, $categorylinks) = $dbr->tableNamesN('page', 'categorylinks');
     $ns = NS_IMAGE;
     return "SELECT 'Uncategorizedimages' AS type, page_namespace AS namespace,\r\n\t\t\t\tpage_title AS title, page_title AS value\r\n\t\t\t\tFROM {$page} LEFT JOIN {$categorylinks} ON page_id = cl_from\r\n\t\t\t\tWHERE cl_from IS NULL AND page_namespace = {$ns} AND page_is_redirect = 0";
 }
 function getSQL()
 {
     $dbr = wfGetDB(DB_SLAVE);
     $page = $dbr->tableName('page');
     $sql = "SELECT 'Listredirects' AS type, page_title AS title, page_namespace AS namespace, \n\t\t\t0 AS value FROM {$page} WHERE page_is_redirect = 1";
     return $sql;
 }
function moveToExternal($cluster, $maxID)
{
    $fname = 'moveToExternal';
    $dbw =& wfGetDB(DB_MASTER);
    print "Moving {$maxID} text rows to external storage\n";
    $ext = new ExternalStoreDB();
    for ($id = 1; $id <= $maxID; $id++) {
        if (!($id % REPORTING_INTERVAL)) {
            print "{$id}\n";
            wfWaitForSlaves(5);
        }
        $row = $dbw->selectRow('text', array('old_flags', 'old_text'), array('old_id' => $id, "old_flags NOT LIKE '%external%'"), $fname);
        if (!$row) {
            # Non-existent or already done
            continue;
        }
        # Resolve stubs
        $flags = explode(',', $row->old_flags);
        if (in_array('object', $flags) && substr($row->old_text, 0, strlen(STUB_HEADER)) === STUB_HEADER) {
            resolveStub($id, $row->old_text, $row->old_flags);
            continue;
        }
        $url = $ext->store($cluster, $row->old_text);
        if (!$url) {
            print "Error writing to external storage\n";
            exit;
        }
        if ($row->old_flags === '') {
            $flags = 'external';
        } else {
            $flags = "{$row->old_flags},external";
        }
        $dbw->update('text', array('old_flags' => $flags, 'old_text' => $url), array('old_id' => $id), $fname);
    }
}
 function getSQL()
 {
     $dbr =& wfGetDB(DB_SLAVE);
     extract($dbr->tableNames('categorylinks', 'page'));
     $name = $dbr->addQuotes($this->getName());
     return "\n\t\t\tSELECT\n\t\t\t\t{$name} as type,\n\t\t\t\t" . NS_CATEGORY . " as namespace,\n\t\t\t\tcl_to as title,\n\t\t\t\tCOUNT(*) as value\n\t\t\tFROM {$categorylinks}\n\t\t\tGROUP BY cl_to\n\t\t\t";
 }
 public function execute()
 {
     $this->output("Delete Orphaned Revisions\n");
     $report = $this->hasOption('report');
     $dbw = wfGetDB(DB_MASTER);
     $dbw->begin(__METHOD__);
     list($page, $revision) = $dbw->tableNamesN('page', 'revision');
     # Find all the orphaned revisions
     $this->output("Checking for orphaned revisions...");
     $sql = "SELECT rev_id FROM {$revision} LEFT JOIN {$page} ON rev_page = page_id " . "WHERE page_namespace IS NULL";
     $res = $dbw->query($sql, 'deleteOrphanedRevisions');
     # Stash 'em all up for deletion (if needed)
     $revisions = array();
     foreach ($res as $row) {
         $revisions[] = $row->rev_id;
     }
     $count = count($revisions);
     $this->output("found {$count}.\n");
     # Nothing to do?
     if ($report || $count == 0) {
         $dbw->commit(__METHOD__);
         exit(0);
     }
     # Delete each revision
     $this->output("Deleting...");
     $this->deleteRevs($revisions, $dbw);
     $this->output("done.\n");
     # Close the transaction and call the script to purge unused text records
     $dbw->commit(__METHOD__);
     $this->purgeRedundantText(true);
 }
 function getSQL()
 {
     $dbr =& wfGetDB(DB_SLAVE);
     extract($dbr->tableNames('page', 'pagelinks'));
     $sql = "SELECT 'BrokenRedirects'  AS type,\n\t\t                p1.page_namespace AS namespace,\n\t\t                p1.page_title     AS title,\n\t\t                pl_namespace,\n\t\t                pl_title\n\t\t           FROM {$pagelinks} AS pl\n                   JOIN {$page} p1 ON (p1.page_is_redirect=1 AND pl.pl_from=p1.page_id)\n\t\t      LEFT JOIN {$page} AS p2 ON (pl_namespace=p2.page_namespace AND pl_title=p2.page_title )\n    \t\t                WHERE p2.page_namespace IS NULL";
     return $sql;
 }
Example #13
0
 protected static function fetchRegexData($mode)
 {
     global $wgMemc;
     wfProfileIn(__METHOD__);
     $phrases = array();
     /* first, check if regex string is already stored in memcache */
     $key_clause = $mode == SPAMREGEX_SUMMARY ? 'Summary' : 'Textbox';
     $key = wfSpamRegexCacheKey('spamRegexCore', 'spamRegex', $key_clause);
     $cached = $wgMemc->get($key);
     if (!$cached) {
         /* fetch data from db, concatenate into one string, then fill cache */
         $field = $mode == SPAMREGEX_SUMMARY ? 'spam_summary' : 'spam_textbox';
         $dbr = wfGetDB(DB_SLAVE);
         $res = $dbr->select('spam_regex', 'spam_text', array($field => 1), __METHOD__);
         while ($row = $res->fetchObject()) {
             $concat = $row->spam_text;
             $phrases[] = "/" . $concat . "/i";
         }
         $wgMemc->set($key, $phrases, 0);
         $res->free();
     } else {
         /* take from cache */
         $phrases = $cached;
     }
     wfProfileOut(__METHOD__);
     return $phrases;
 }
 public function execute()
 {
     $params = $this->extractRequestParams();
     $this->requireOnlyOneParameter($params, 'vars', 'rcid', 'logid');
     // "Anti-DoS"
     if (!$this->getUser()->isAllowed('abusefilter-modify')) {
         $this->dieUsageMsg('permissiondenied');
     }
     if ($params['vars']) {
         $vars = FormatJson::decode($params['vars'], true);
     } elseif ($params['rcid']) {
         $dbr = wfGetDB(DB_SLAVE);
         $row = $dbr->selectRow('recentchanges', '*', array('rc_id' => $params['rcid']), __METHOD__);
         if (!$row) {
             $this->dieUsageMsg(array('nosuchrcid', $params['rcid']));
         }
         $vars = AbuseFilter::getVarsFromRCRow($row);
     } elseif ($params['logid']) {
         $dbr = wfGetDB(DB_SLAVE);
         $row = $dbr->selectRow('abuse_filter_log', '*', array('afl_id' => $params['logid']), __METHOD__);
         if (!$row) {
             $this->dieUsage("There is no abuselog entry with the id ``{$params['logid']}''", 'nosuchlogid');
         }
         $vars = AbuseFilter::loadVarDump($row->afl_var_dump);
     }
     if (AbuseFilter::checkSyntax($params['filter']) !== true) {
         $this->dieUsage('The filter has invalid syntax', 'badsyntax');
     }
     $result = AbuseFilter::checkConditions($params['filter'], $vars);
     $this->getResult()->addValue(null, $this->getModuleName(), array('result' => $result));
 }
Example #15
0
 /**
  * @return DatabaseBase
  */
 public function getDB()
 {
     if ($this->database === null) {
         $this->database = wfGetDB(DB_SLAVE);
     }
     return $this->database;
 }
 public function initialize()
 {
     $dbr = wfGetDB(DB_MASTER);
     $res = $dbr->select('categorylinks', array('cl_to', 'COUNT(*) AS count'), array(), __METHOD__, array('GROUP BY' => 'cl_to', 'ORDER BY' => 'count DESC', 'LIMIT' => $this->limit));
     wfSuppressWarnings();
     // prevent PHP from bitching about strtotime()
     foreach ($res as $row) {
         $tag_name = Title::makeTitle(NS_CATEGORY, $row->cl_to);
         $tag_text = $tag_name->getText();
         if (strtotime($tag_text) == '') {
             // don't want dates to show up
             if ($row->count > $this->tags_highest_count) {
                 $this->tags_highest_count = $row->count;
             }
             $this->tags[$tag_text] = array('count' => $row->count);
         }
     }
     wfRestoreWarnings();
     // sort tag array by key (tag name)
     if ($this->tags_highest_count == 0) {
         return;
     }
     ksort($this->tags);
     /* and what if we have _1_ category? like on a new wiki with nteen articles, mhm? */
     if ($this->tags_highest_count == 1) {
         $coef = $this->tags_max_pts - $this->tags_min_pts;
     } else {
         $coef = ($this->tags_max_pts - $this->tags_min_pts) / (($this->tags_highest_count - 1) * 2);
     }
     foreach ($this->tags as $tag => $att) {
         $this->tags[$tag]['size'] = $this->tags_min_pts + ($this->tags[$tag]['count'] - 1) * $coef;
     }
 }
 function getSQL()
 {
     $dbr = wfGetDB(DB_SLAVE);
     list($page, $redirect) = $dbr->tableNamesN('page', 'redirect');
     $sql = "SELECT 'BrokenRedirects'  AS type,\r\n\t\t                p1.page_namespace AS namespace,\r\n\t\t                p1.page_title     AS title,\r\n\t\t                rd_namespace,\r\n\t\t                rd_title\r\n\t\t           FROM {$redirect} AS rd\r\n                   JOIN {$page} p1 ON (rd.rd_from=p1.page_id)\r\n\t\t      LEFT JOIN {$page} AS p2 ON (rd_namespace=p2.page_namespace AND rd_title=p2.page_title )\r\n\t\t\t  \t  WHERE rd_namespace >= 0\r\n\t\t\t\t    AND p2.page_namespace IS NULL";
     return $sql;
 }
 function getSQL()
 {
     $dbr =& wfGetDB(DB_SLAVE);
     extract($dbr->tableNames('page', 'categorylinks'));
     $name = $dbr->addQuotes($this->getName());
     return "SELECT {$name} as type, page_namespace AS namespace, page_title AS title, page_title AS value " . "FROM {$page} LEFT JOIN {$categorylinks} ON page_id=cl_from " . "WHERE cl_from IS NULL AND page_namespace={$this->requestedNamespace} AND page_is_redirect=0";
 }
Example #19
0
 protected function setUp()
 {
     parent::setUp();
     $dbw = wfGetDB(DB_MASTER);
     $dbw->replace('interwiki', ['iw_prefix'], ['iw_prefix' => 'linksupdatetest', 'iw_url' => 'http://testing.com/wiki/$1', 'iw_api' => 'http://testing.com/w/api.php', 'iw_local' => 0, 'iw_trans' => 0, 'iw_wikiid' => 'linksupdatetest']);
     $this->setMwGlobals('wgRCWatchCategoryMembership', true);
 }
 function getSQL()
 {
     $dbr = wfGetDB(DB_SLAVE);
     list($page, $templatelinks) = $dbr->tableNamesN('page', 'templatelinks');
     $sql = "SELECT 'Unusedtemplates' AS type, page_title AS title,\n\t\t\tpage_namespace AS namespace, 0 AS value\n\t\t\tFROM {$page}\n\t\t\tLEFT JOIN {$templatelinks}\n\t\t\tON page_namespace = tl_namespace AND page_title = tl_title\n\t\t\tWHERE page_namespace = 10 AND tl_from IS NULL\n\t\t\tAND page_is_redirect = 0";
     return $sql;
 }
Example #21
0
 public function execute()
 {
     global $wgUser;
     # Change to current working directory
     $oldCwd = getcwd();
     chdir($oldCwd);
     # Options processing
     $user = $this->getOption('u', 'Delete page script');
     $reason = $this->getOption('r', '');
     $interval = $this->getOption('i', 0);
     if ($this->hasArg()) {
         $file = fopen($this->getArg(), 'r');
     } else {
         $file = $this->getStdin();
     }
     # Setup
     if (!$file) {
         $this->error("Unable to read file, exiting", true);
     }
     $wgUser = User::newFromName($user);
     $dbw = wfGetDB(DB_MASTER);
     # Handle each entry
     for ($linenum = 1; !feof($file); $linenum++) {
         $line = trim(fgets($file));
         if ($line == '') {
             continue;
         }
         $page = Title::newFromText($line);
         if (is_null($page)) {
             $this->output("Invalid title '{$line}' on line {$linenum}\n");
             continue;
         }
         if (!$page->exists()) {
             $this->output("Skipping nonexistent page '{$line}'\n");
             continue;
         }
         $this->output($page->getPrefixedText());
         $dbw->begin();
         if ($page->getNamespace() == NS_FILE) {
             $art = new ImagePage($page);
             $img = wfFindFile($art->mTitle);
             if (!$img || !$img->isLocal() || !$img->delete($reason)) {
                 $this->output(" FAILED to delete image file... ");
             }
         } else {
             $art = new Article($page);
         }
         $success = $art->doDeleteArticle($reason);
         $dbw->commit();
         if ($success) {
             $this->output(" Deleted!\n");
         } else {
             $this->output(" FAILED to delete article\n");
         }
         if ($interval) {
             sleep($interval);
         }
         wfWaitForSlaves();
     }
 }
Example #22
0
 public function execute()
 {
     global $wgExternalSharedDB;
     $isDryRun = $this->hasOption('dry-run');
     $this->output("Looking for wikis matching '" . self::WIKI_PREFIX . "' prefix...");
     $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
     $langPrefixes = explode(' ', self::LANG_PREFIXES);
     $langPrefixes[] = '';
     // English wikis do not have a prefix in dbname
     foreach ($langPrefixes as $langPrefix) {
         $this->output("Checking wikis with '{$langPrefix}' language prefix...");
         $res = $dbr->select('city_list', array('city_id', 'city_dbname', 'city_url', 'city_factory_timestamp'), array('city_public' => 1, 'city_dbname ' . $dbr->buildLike($langPrefix . self::WIKI_PREFIX, $dbr->anyString())), __METHOD__);
         $this->output("\n\n");
         while ($wiki = $res->fetchObject()) {
             $this->output("* {$wiki->city_dbname} <{$wiki->city_url}>... ");
             if (!$isDryRun) {
                 if ($this->markWikiAsClosed($wiki->city_id)) {
                     $this->output("done\n");
                 } else {
                     $this->output("err!\n");
                 }
             } else {
                 $this->output("skipping, dry run\n");
             }
             sleep(0.1);
         }
     }
     $this->output("\nDone!\n");
 }
 /**
  * @param Skin $skin
  * @param object $result Result row
  * @return string
  */
 function formatResult($skin, $result)
 {
     $titleA = Title::makeTitle($result->namespace, $result->title);
     // If only titleA is in the query, it means this came from
     // querycache (which only saves 3 columns).
     // That does save the bulk of the query cost, but now we need to
     // get a little more detail about each individual entry quickly
     // using the filter of reallyGetQueryInfo.
     if ($result && !isset($result->nsb)) {
         $dbr = wfGetDB(DB_SLAVE);
         $qi = $this->reallyGetQueryInfo($result->namespace, $result->title);
         $res = $dbr->select($qi['tables'], $qi['fields'], $qi['conds'], __METHOD__);
         if ($res) {
             $result = $dbr->fetchObject($res);
         }
     }
     if (!$result) {
         return '<del>' . Linker::link($titleA, null, array(), array('redirect' => 'no')) . '</del>';
     }
     $titleB = Title::makeTitle($result->nsb, $result->tb);
     $titleC = Title::makeTitle($result->nsc, $result->tc, '', $result->iwc);
     $linkA = Linker::linkKnown($titleA, null, array(), array('redirect' => 'no'));
     $edit = Linker::linkKnown($titleA, $this->msg('parentheses', $this->msg('editlink')->text())->escaped(), array(), array('action' => 'edit'));
     $linkB = Linker::linkKnown($titleB, null, array(), array('redirect' => 'no'));
     $linkC = Linker::linkKnown($titleC);
     $lang = $this->getLanguage();
     $arr = $lang->getArrow() . $lang->getDirMark();
     return "{$linkA} {$edit} {$arr} {$linkB} {$arr} {$linkC}";
 }
 public function getData($offset, $button_name = '', $next_letter_alphabet = '')
 {
     global $wgNewManuscriptOptions;
     $max_on_page = $wgNewManuscriptOptions['max_on_page'];
     $dbr = wfGetDB(DB_SLAVE);
     $page_data = array();
     $next_offset = null;
     if (isset($this->user_name)) {
         $conditions = array('manuscripts_user = '******'manuscripts_collection = ' . $dbr->addQuotes('none'));
     } else {
         $conditions = array('manuscripts_lowercase_title >= ' . $dbr->addQuotes($button_name), 'manuscripts_lowercase_title < ' . $dbr->addQuotes($next_letter_alphabet), 'manuscripts_collection =' . $dbr->addQuotes('none'));
     }
     $res = $dbr->select('manuscripts', array('manuscripts_title', 'manuscripts_user', 'manuscripts_url', 'manuscripts_date', 'manuscripts_signature', 'manuscripts_lowercase_title'), $conditions, __METHOD__, array('ORDER BY' => array('CAST(manuscripts_lowercase_title AS UNSIGNED)', 'manuscripts_lowercase_title'), 'LIMIT' => $max_on_page + 1, 'OFFSET' => $offset));
     if ($res->numRows() > 0) {
         //while there are still titles in this query
         while ($s = $res->fetchObject()) {
             //add titles to the title array as long as it is not bigger than max_on_page
             if (count($page_data) < $max_on_page) {
                 $page_data[] = array('manuscripts_title' => $s->manuscripts_title, 'manuscripts_user' => $s->manuscripts_user, 'manuscripts_url' => $s->manuscripts_url, 'manuscripts_date' => $s->manuscripts_date, 'manuscripts_signature' => $s->manuscripts_signature);
             } else {
                 //if there is still a title to add (max_on_page+1 has been reached), it is possible to go to the next page
                 $next_offset = $offset + $max_on_page;
                 break;
             }
         }
     }
     return array($page_data, $next_offset);
 }
 /**
  * Adds users to watchlist if:
  * - User is watching parent page
  * - User has 'watchlistsubpages' turned on
  *
  * @param $watchers array of user ID
  * @param $title Title object
  * @param $editor User object
  * @param $notificationTimeoutSql string timeout to the watchlist
  *
  * @author Jakub Kurcek <*****@*****.**>
  */
 public static function NotifyOnSubPageChange($watchers, $title, $editor, $notificationTimeoutSql)
 {
     wfProfileIn(__METHOD__);
     // Gets parent data
     $arrTitle = explode('/', $title->getDBkey());
     if (empty($arrTitle)) {
         wfProfileOut(__METHOD__);
         return true;
     }
     // make Title
     $t = reset($arrTitle);
     $newTitle = Title::newFromDBkey($t);
     if (!$newTitle instanceof Title) {
         return true;
     }
     $dbw = wfGetDB(DB_MASTER);
     /** @var $dbw Database */
     $res = $dbw->select(array('watchlist'), array('wl_user'), array('wl_title' => $newTitle->getDBkey(), 'wl_namespace' => $newTitle->getNamespace(), 'wl_user != ' . intval($editor->getID()), $notificationTimeoutSql), __METHOD__);
     // Gets user settings
     $parentpageWatchers = array();
     while ($row = $dbw->fetchObject($res)) {
         $userId = intval($row->wl_user);
         $tmpUser = User::newFromId($userId);
         if ($tmpUser->getBoolOption(self::PREFERENCES_ENTRY)) {
             $parentpageWatchers[] = $userId;
         }
         unset($tmpUser);
     }
     // Updates parent watchlist timestamp for $parentOnlyWatchers.
     $parentOnlyWatchers = array_diff($parentpageWatchers, $watchers);
     $wl = WatchedItem::fromUserTitle($editor, $newTitle);
     $wl->updateWatch($parentOnlyWatchers);
     wfProfileOut(__METHOD__);
     return true;
 }
 public static function getBadge($badgeTypeId)
 {
     wfProfileIn(__METHOD__);
     global $wgExternalSharedDB;
     global $wgEnableAchievementsStoreLocalData;
     $badges = array();
     if (empty($wgEnableAchievementsStoreLocalData)) {
         $dbr = wfGetDB(DB_SLAVE, array(), $wgExternalSharedDB);
     } else {
         $dbr = wfGetDB(DB_SLAVE);
     }
     $res = $dbr->select('ach_custom_badges', array('id', 'enabled', 'sponsored', 'badge_tracking_url', 'hover_tracking_url', 'click_tracking_url'), array('id' => $badgeTypeId), __METHOD__);
     if ($row = $dbr->fetchObject($res)) {
         $badge = array();
         $image = wfFindFile(AchConfig::getInstance()->getBadgePictureName($row->id));
         if ($image) {
             $hoverImage = wfFindFile(AchConfig::getInstance()->getHoverPictureName($row->id));
             $badge['type_id'] = $row->id;
             $badge['enabled'] = $row->enabled;
             $badge['thumb_url'] = $image->createThumb(90);
             $badge['awarded_users'] = AchPlatinumService::getAwardedUserNames($row->id);
             $badge['is_sponsored'] = $row->sponsored;
             $badge['badge_tracking_url'] = $row->badge_tracking_url;
             $badge['hover_tracking_url'] = $row->hover_tracking_url;
             $badge['click_tracking_url'] = $row->click_tracking_url;
             $badge['hover_content_url'] = is_object($hoverImage) ? wfReplaceImageServer($hoverImage->getFullUrl()) : null;
             wfProfileOut(__METHOD__);
             return $badge;
         }
     }
     wfProfileOut(__METHOD__);
     return false;
 }
 function getSQL()
 {
     $dbr =& wfGetDB(DB_SLAVE);
     list($page, $pagelinks, $templatelinks) = $dbr->tableNamesN('page', 'pagelinks', 'templatelinks');
     $dMsgText = wfMsgForContent('disambiguationspage');
     $linkBatch = new LinkBatch();
     # If the text can be treated as a title, use it verbatim.
     # Otherwise, pull the titles from the links table
     $dp = Title::newFromText($dMsgText);
     if ($dp) {
         if ($dp->getNamespace() != NS_TEMPLATE) {
             # FIXME we assume the disambiguation message is a template but
             # the page can potentially be from another namespace :/
             wfDebug("Mediawiki:disambiguationspage message does not refer to a template!\n");
         }
         $linkBatch->addObj($dp);
     } else {
         # Get all the templates linked from the Mediawiki:Disambiguationspage
         $disPageObj = $this->getDisambiguationPageObj();
         $res = $dbr->select(array('pagelinks', 'page'), 'pl_title', array('page_id = pl_from', 'pl_namespace' => NS_TEMPLATE, 'page_namespace' => $disPageObj->getNamespace(), 'page_title' => $disPageObj->getDBkey()), 'DisambiguationsPage::getSQL');
         while ($row = $dbr->fetchObject($res)) {
             $linkBatch->addObj(Title::makeTitle(NS_TEMPLATE, $row->pl_title));
         }
         $dbr->freeResult($res);
     }
     $set = $linkBatch->constructSet('lb.tl', $dbr);
     if ($set === false) {
         $set = 'FALSE';
         # We must always return a valid sql query, but this way DB will always quicly return an empty result
         wfDebug("Mediawiki:disambiguationspage message does not link to any templates!\n");
     }
     $sql = "SELECT 'Disambiguations' AS \"type\", pb.page_namespace AS namespace," . " pb.page_title AS title, la.pl_from AS value" . " FROM {$templatelinks} AS lb, {$page} AS pb, {$pagelinks} AS la, {$page} AS pa" . " WHERE {$set}" . ' AND pa.page_id = la.pl_from' . ' AND pa.page_namespace = ' . NS_MAIN . ' AND pb.page_id = lb.tl_from' . ' AND pb.page_namespace = la.pl_namespace' . ' AND pb.page_title = la.pl_title' . ' ORDER BY lb.tl_namespace, lb.tl_title';
     return $sql;
 }
Example #28
0
 public function execute()
 {
     global $wgUser, $wgTranslateWorkflowStates;
     if (!$wgTranslateWorkflowStates) {
         $this->dieUsage('Message group review not in use', 'disabled');
     }
     if (!$wgUser->isallowed(self::$right)) {
         $this->dieUsage('Permission denied', 'permissiondenied');
     }
     $requestParams = $this->extractRequestParams();
     $group = MessageGroups::getGroup($requestParams['group']);
     if (!$group) {
         $this->dieUsageMsg(array('missingparam', 'group'));
     }
     $languages = Language::getLanguageNames(false);
     if (!isset($languages[$requestParams['language']])) {
         $this->dieUsageMsg(array('missingparam', 'language'));
     }
     $dbr = wfGetDB(DB_SLAVE);
     $groupid = $group->getId();
     $currentState = $dbr->selectField('translate_groupreviews', 'tgr_state', array('tgr_group' => $groupid, 'tgr_lang' => $requestParams['language']), __METHOD__);
     if ($currentState == $requestParams['state']) {
         $this->dieUsage('The requested state is identical to the current state', 'sameworkflowstate');
     }
     $dbw = wfGetDB(DB_MASTER);
     $table = 'translate_groupreviews';
     $row = array('tgr_group' => $groupid, 'tgr_lang' => $requestParams['language'], 'tgr_state' => $requestParams['state']);
     $index = array('tgr_group', 'tgr_language');
     $res = $dbw->replace($table, array($index), $row, __METHOD__);
     $logger = new LogPage('translationreview');
     $logParams = array($requestParams['language'], $group->getLabel(), $currentState, $requestParams['state']);
     $logger->addEntry('group', SpecialPage::getTitleFor('Translate', $groupid), '', $logParams, $wgUser);
     $output = array('review' => array('group' => $group->getId(), 'language' => $requestParams['language'], 'state' => $requestParams['state']));
     $this->getResult()->addValue(null, $this->getModuleName(), $output);
 }
 public function execute()
 {
     global $wgExternalDatawareDB;
     $conf = $this->getOption('conf');
     $test = $this->hasOption('test');
     if ($test) {
         $this->output("*** TEST MODE ***\n");
     }
     $dbs = wfGetDB(DB_SLAVE, array(), $wgExternalDatawareDB);
     if (!is_null($dbs)) {
         $this->output("== Finding wiki's with missattribution ... ");
         // Find all the distinct wikis that had videos migrated, about 45,000
         $query = "select distinct(wiki_id) as wiki_id " . "from video_imagetable_backup";
         $res = $dbs->query($query);
         $numRows = $dbs->numRows($res);
         $this->output("done ({$numRows} rows)\n");
         $curRow = 1;
         while ($row = $dbs->fetchObject($res)) {
             $this->output("== [{$curRow}/{$numRows}] Fixing wiki ID: " . $row->wiki_id . "\n");
             $this->fixForWiki($conf, $row->wiki_id, $test);
             $curRow++;
         }
         $dbs->freeResult($res);
     }
 }
	/**
	 * Inserts an entry into the database
	 *
	 * @param $channel ServerAdminLogChannel
	 * @param $user User|string
	 * @param $message string
	 * @return int ID of the new entry
	 */
	public static function create( ServerAdminLogChannel $channel, $user, $message ) {
		$db = wfGetDB( DB_MASTER );

		if ( $user instanceof User ) {
			$userId = $user->getId();
			$userText = null; // We use JOINs here
		} else {
			$userId = 0;
			$userText = $user;
		}

		$db->insert(
			'sal_entry',
			array(
				'sale_channel' => $channel->getId(),
				'sale_user' => $userId,
				'sale_user_text' => $userText,
				'sale_timestamp' => $db->timestamp(),
				'sale_comment' => $message,
			),
			__METHOD__
		);

		return $db->insertId();
	}