function onArticleSaveComplete($article, $user, $text, $summary, $isminor, $iswatch, $section) { $this->createTableIfNotExists(); $titleObject = $article->getTitle(); $url = $titleObject->getFullURL(); $title = $titleObject->getText(); $userName = $user->getName(); $realName = $user->getRealName(); $email = $user->getEmail(); $now = wfTimestampNow(); $sql = "INSERT INTO wiki_dailychanges (dc_timestamp, dc_title, dc_summary, dc_url, dc_user, " . "dc_real_name, dc_mail, dc_minor) values ('" . mysql_real_escape_string($now) . "', '" . mysql_real_escape_string($title) . "', '" . mysql_real_escape_string($summary) . "', '" . mysql_real_escape_string($url) . "', '" . mysql_real_escape_string($userName) . "', '" . mysql_real_escape_string($realName) . "', '" . mysql_real_escape_string($email) . "', '" . mysql_real_escape_string($isminor) . "')"; wfQuery($sql, DB_MASTER); return true; }
function getUsers() { $users = array(); $sql = "SELECT user_name, user_real_name, user_email from user"; $res = wfQuery($sql, DB_SLAVE); while ($line = wfFetchObject($res, DB_SLAVE)) { if (strlen($line->user_email) == 0) { continue; } if (strlen($line->user_real_name) > 0) { $users[$line->user_real_name] = $line->user_email; } else { $users[$line->user_name] = $line->user_email; } } wfFreeResult($res, DB_SLAVE); return $users; }
function bb2_db_query($query) { $bb2_last_query = wfQuery($query, DB_WRITE); return $bb2_last_query; }
$sql = "DROP TABLE IF EXISTS watchlist"; wfQuery($sql, DB_MASTER); $sql = "CREATE TABLE watchlist (\n wl_user int(5) unsigned NOT NULL,\n wl_page int(8) unsigned NOT NULL,\n UNIQUE KEY (wl_user, wl_page)\n) ENGINE=MyISAM PACK_KEYS=1"; wfQuery($sql, DB_MASTER); $lc = new LinkCache(); # Now, convert! $sql = "SELECT user_id,user_watch FROM user"; $res = wfQuery($sql, DB_SLAVE); $nu = wfNumRows($res); $sql = "INSERT into watchlist (wl_user,wl_page) VALUES "; $i = $n = 0; while ($row = wfFetchObject($res)) { $list = explode("\n", $row->user_watch); $bits = array(); foreach ($list as $title) { if ($id = $lc->addLink($title) and !$bits[$id]++) { $sql .= ($i++ ? "," : "") . "({$row->user_id},{$id})"; } } if ($n++ % 100 == 0) { echo "{$n} of {$nu} users done...\n"; } } echo "{$n} users done.\n"; if ($i) { wfQuery($sql, DB_MASTER); } # Add index # is this necessary? $sql = "ALTER TABLE watchlist\n ADD INDEX wl_user (wl_user),\n ADD INDEX wl_page (wl_page)"; #wfQuery( $sql, DB_MASTER );
/** * an array of edit links by default used for the tabs * @return array * @access private */ function buildContentActionUrls() { global $wgContLang, $wgUseValidation, $wgDBprefix, $wgValidationForAnons; $fname = 'SkinTemplate::buildContentActionUrls'; wfProfileIn($fname); global $wgUser, $wgRequest; $action = $wgRequest->getText('action'); $section = $wgRequest->getText('section'); $oldid = $wgRequest->getVal('oldid'); $diff = $wgRequest->getVal('diff'); $content_actions = array(); if ($this->iscontent) { $nskey = $this->getNameSpaceKey(); $content_actions[$nskey] = $this->tabAction($this->mTitle->getSubjectPage(), $nskey, !$this->mTitle->isTalkPage(), '', true); $content_actions['talk'] = $this->tabAction($this->mTitle->getTalkPage(), 'talk', $this->mTitle->isTalkPage(), '', true); wfProfileIn("{$fname}-edit"); if ($this->mTitle->userCanEdit()) { $oid = $oldid && !isset($diff) ? '&oldid=' . IntVal($oldid) : false; $istalk = $this->mTitle->isTalkPage(); $istalkclass = $istalk ? ' istalk' : ''; $content_actions['edit'] = array('class' => ((($action == 'edit' or $action == 'submit') and $section != 'new') ? 'selected' : '') . $istalkclass, 'text' => wfMsg('edit'), 'href' => $this->mTitle->getLocalUrl('action=edit' . $oid)); if ($istalk) { $content_actions['addsection'] = array('class' => $section == 'new' ? 'selected' : false, 'text' => wfMsg('addsection'), 'href' => $this->mTitle->getLocalUrl('action=edit§ion=new')); } } else { $oid = $oldid && !isset($diff) ? '&oldid=' . IntVal($oldid) : ''; $content_actions['viewsource'] = array('class' => $action == 'edit' ? 'selected' : false, 'text' => wfMsg('viewsource'), 'href' => $this->mTitle->getLocalUrl('action=edit' . $oid)); } wfProfileOut("{$fname}-edit"); wfProfileIn("{$fname}-live"); if ($this->mTitle->getArticleId()) { $content_actions['history'] = array('class' => $action == 'history' ? 'selected' : false, 'text' => wfMsg('history_short'), 'href' => $this->mTitle->getLocalUrl('action=history')); if ($wgUser->isAllowed('protect')) { if (!$this->mTitle->isProtected()) { $content_actions['protect'] = array('class' => $action == 'protect' ? 'selected' : false, 'text' => wfMsg('protect'), 'href' => $this->mTitle->getLocalUrl('action=protect')); } else { $content_actions['unprotect'] = array('class' => $action == 'unprotect' ? 'selected' : false, 'text' => wfMsg('unprotect'), 'href' => $this->mTitle->getLocalUrl('action=unprotect')); } } if ($wgUser->isAllowed('delete')) { $content_actions['delete'] = array('class' => $action == 'delete' ? 'selected' : false, 'text' => wfMsg('delete'), 'href' => $this->mTitle->getLocalUrl('action=delete')); } if ($this->mTitle->userCanMove()) { $content_actions['move'] = array('class' => ($this->mTitle->getDbKey() == 'Movepage' and $this->mTitle->getNamespace == NS_SPECIAL) ? 'selected' : false, 'text' => wfMsg('move'), 'href' => $this->makeSpecialUrl("Movepage/{$this->thispage}")); } } else { //article doesn't exist or is deleted if ($wgUser->isAllowed('delete')) { if ($n = $this->mTitle->isDeleted()) { $content_actions['undelete'] = array('class' => false, 'text' => $n == 1 ? wfMsg('undelete_short1') : wfMsg('undelete_short', $n), 'href' => $this->makeSpecialUrl("Undelete/{$this->thispage}")); } } } wfProfileOut("{$fname}-live"); if ($this->loggedin) { if (!$this->mTitle->userIsWatching()) { $content_actions['watch'] = array('class' => ($action == 'watch' or $action == 'unwatch') ? 'selected' : false, 'text' => wfMsg('watch'), 'href' => $this->mTitle->getLocalUrl('action=watch')); } else { $content_actions['unwatch'] = array('class' => ($action == 'unwatch' or $action == 'watch') ? 'selected' : false, 'text' => wfMsg('unwatch'), 'href' => $this->mTitle->getLocalUrl('action=unwatch')); } } if ($wgUser->isLoggedIn() || $wgValidationForAnons) { # and $action != 'submit' ) { # Validate tab. TODO: add validation to logged-in user rights if ($wgUseValidation && ($action == "" || $action == 'view')) { # && $wgUser->isAllowed('validate')){ if ($oldid) { $oid = IntVal($oldid); } else { # Trying to get the current article revision through this weird stunt $tid = $this->mTitle->getArticleID(); $tns = $this->mTitle->getNamespace(); $sql = "SELECT page_latest FROM {$wgDBprefix}page WHERE page_id={$tid} AND page_namespace={$tns}"; $res = wfQuery($sql, DB_READ); if ($s = wfFetchObject($res)) { $oid = $s->page_latest; } else { $oid = ""; } # Something's wrong, like the article has been deleted in the last 10 ns } if ($oid != "") { $oid = "&revision={$oid}"; $content_actions['validate'] = array('class' => $action == 'validate' ? 'selected' : false, 'text' => wfMsg('val_tab'), 'href' => $this->mTitle->getLocalUrl("action=validate{$oid}")); } } } } else { /* show special page tab */ $content_actions['article'] = array('class' => 'selected', 'text' => wfMsg('specialpage'), 'href' => $wgRequest->getRequestURL()); } /* show links to different language variants */ global $wgDisableLangConversion; $variants = $wgContLang->getVariants(); if (!$wgDisableLangConversion && sizeof($variants) > 1) { $preferred = $wgContLang->getPreferredVariant(); $actstr = ''; if ($action) { $actstr = 'action=' . $action . '&'; } $vcount = 0; foreach ($variants as $code) { $varname = $wgContLang->getVariantname($code); if ($varname == 'disable') { continue; } $selected = $code == $preferred ? 'selected' : false; $content_actions['varlang-' . $vcount] = array('class' => $selected, 'text' => $varname, 'href' => $this->mTitle->getLocalUrl($actstr . 'variant=' . $code)); $vcount++; } } wfRunHooks('SkinTemplateContentActions', array(&$content_actions)); wfProfileOut($fname); return $content_actions; }
function renderRss($input) { global $wgOutputEncoding; $DefaultEncoding = "ISO-8859-1"; $VersionNote = "Mediawiki rss extension by mutante, Duesentrieb, Rdb and Mafs"; $VersionLink = "http://meta.wikimedia.org/wiki/User:Mafs/RSS"; $VersionNo = "0.1"; $DisableCache = true; if (!$input) { return ""; } #if <rss>-section is empty, return nothing #parse fields in rss-section $fields = explode("|", $input); $url = @$fields[0]; $args = array(); for ($i = 1; $i < sizeof($fields); $i++) { $f = $fields[$i]; if (strpos($f, "=") === False) { $args[strtolower(trim($f))] = False; } else { list($k, $v) = explode("=", $f, 2); if (trim($v) == False) { $args[strtolower(trim($k))] = False; } else { $args[strtolower(trim($k))] = trim($v); } } } #get charset from argument-array $charset = @$args["charset"]; if (!$charset) { $charset = $DefaultEncoding; } #get max number of headlines from argument-array $maxheads = @$args["max"]; $headcnt = 0; #get short-flag from argument-array #if short is set, no description text is printed if (isset($args["short"])) { $short = True; } else { $short = False; } #get reverse-flag from argument-array if (isset($args["reverse"])) { $reverse = True; } else { $reverse = False; } #get version-flag from argument-array if (isset($args["version"])) { $DisplayVersion = True; } else { $DisplayVersion = False; } #get highlight terms from argument-array $rssHighlight = @$args["highlight"]; $rssHighlight = str_replace(" ", " ", $rssHighlight); $rssHighlight = explode(" ", trim($rssHighlight)); #get filter terms from argument-array $rssFilter = @$args["filter"]; $rssFilter = str_replace(" ", " ", $rssFilter); $rssFilter = explode(" ", trim($rssFilter)); #fetch rss. may be cached locally. #Refer to the documentation of magpie for details. $rss = @fetch_rss($url); #check for errors. if ($rss->ERROR) { return "<div>Failed to load RSS feed from {$url}: " . $rss->ERROR . "</div>"; #localize... } if (!is_array($rss->items)) { return "<div>Failed to load RSS feed from {$url}!</div>"; #localize... } #Bild title line $title = iconv($charset, $wgOutputEncoding, $rss->channel['title']); if (isset($rss->channel['link'])) { $title = "<a href='" . $rss->channel['link'] . "'>{$title}</a>"; } $output = "<h3>{$title}</h3>"; if ($reverse) { $rss->items = array_reverse($rss->items); } $description = False; foreach ($rss->items as $item) { if (isset($item['description'])) { $description = True; break; } } #Bild items if (!$short and $description) { #full item list $output .= "<dl>"; foreach ($rss->items as $item) { $d_text = true; $d_title = true; $href = trim(iconv($charset, $wgOutputEncoding, $item['link'])); $title = trim(iconv($charset, $wgOutputEncoding, $item['title'])); $d_title = wfRssFilter($title, $rssFilter); $title = wfRssHighlight($title, $rssHighlight); #bild description text if desired if ($item["description"]) { $text = trim(iconv($charset, $wgOutputEncoding, $item['description'])); #avoid pre-tags $text = str_replace("\r", " ", $text); $text = str_replace("\n", " ", $text); $text = str_replace("\t", " ", $text); $d_text = wfRssFilter($text, $rssFilter); $text = wfRssHighlight($text, $rssHighlight); $display = $d_text or $d_title; } else { $text = ""; $display = $d_title; } if ($display) { $output .= "<dt><a href='{$href}'>{$title}</a></dt>"; if ($text) { $output .= "<dd>{$text}</dd>\n"; } } #Cut off output when maxheads is reached: if (++$headcnt == $maxheads) { break; } } $output .= "</dl>"; } else { #short item list $output .= "<ul>"; foreach ($rss->items as $item) { $href = trim(iconv($charset, $wgOutputEncoding, $item['link'])); $title = trim(iconv($charset, $wgOutputEncoding, $item['title'])); $d_title = wfRssFilter($title, $rssFilter); $title = wfRssHighlight($title, $rssHighlight); if ($d_title) { $output .= "<li><a href='{$href}'>{$title}</a></li>"; } #Cut off output when maxheads is reached: if (++$headcnt == $maxheads) { break; } } $output .= "</ul>"; } if ($DisableCache) { global $wgVersion; # Do not cache this wiki page. # for details see http://public.kitware.com/Wiki/User:Barre/MediaWiki/Extensions global $wgTitle, $wgDBprefix; $ts = mktime(); $now = gmdate("YmdHis", $ts + 120); $ns = $wgTitle->getNamespace(); $ti = wfStrencode($wgTitle->getDBkey()); $version = preg_replace("/^([1-9]).([1-9]).*/", "\\1\\2", $wgVersion); if ($version > 14) { $sql = "UPDATE {$wgDBprefix}" . "page SET page_touched='{$now}' WHERE page_namespace={$ns} AND page_title='{$ti}'"; } else { $sql = "UPDATE {$wgDBprefix}" . "cur SET cur_touched='{$now}' WHERE cur_namespace={$ns} AND cur_title='{$ti}'"; } wfQuery($sql, DB_WRITE, ""); } $VersionText = ""; if ($VersionNote) { $VersionText = $VersionNote; } if ($VersionLink and $VersionNo) { $VersionText = $VersionText . " - <a href=\"{$VersionLink}\" title=\"{$VersionLink}\">version {$VersionNo}</a>."; } if (!$VersionLink and $VersionNo) { $VersionText = $VersionText . " - version {$VersionNo}."; } if ($DisplayVersion and $VersionText) { $output = $output . "<div style=\"background-color: #E0E0E0; font-weight: bold; font-size: 60%; padding: 0em 0.5em 0em 0.5em;\" >{$VersionText}</div>"; } return $output; }
function getArticleList() { global $wgLang, $wgOut; $validationtypes = $wgLang->getValidationTypes(); $wgOut->setPageTitle(wfMsg('val_article_lists')); $html = ""; # Choices $choice = array(); $maxw = 0; foreach ($validationtypes as $idx => $data) { $x = explode("|", $data, 4); if ($x[3] > $maxw) { $maxw = $x[3]; } } foreach ($validationtypes as $idx => $data) { $choice[$idx] = array(); for ($a = 0; $a < $maxw; $a++) { $var = "cb_{$idx}_{$a}"; if (isset($_POST[$var])) { $choice[$idx][$a] = $_POST[$var]; } else { if (!isset($_POST["doit"])) { $choice[$idx][$a] = 1; } else { $choice[$idx][$a] = 0; } } # De-selected } } # The form $html .= "<form method='post'>\n"; $html .= "<table border='1' cellspacing='0' cellpadding='2'>"; foreach ($validationtypes as $idx => $data) { $x = explode("|", $data, 4); $html .= "<tr>"; $html .= "<th nowrap='nowrap'>{$x[0]}</th>"; $html .= "<td align='right' nowrap='nowrap'>{$x[1]}</td>"; for ($a = 0; $a < $maxw; $a++) { if ($a < $x[3]) { $td = "<input type='checkbox' name='cb_{$idx}_{$a}' value='1'"; if ($choice[$idx][$a] == 1) { $td .= " checked='checked'"; } $td .= " />"; } else { $td = ''; } $html .= "<td>{$td}</td>"; } $html .= "<td nowrap='nowrap'>{$x[2]}</td>"; $html .= "</tr>\n"; } $html .= "<tr><td colspan='" . ($maxw + 2) . "'></td>\n"; $html .= "<td align='right' valign='center'><input type='submit' name='doit' value=\"" . htmlspecialchars(wfMsg('ok')) . "\" /></td></tr>"; $html .= "</table>\n"; $html .= "</form>\n"; # The query $articles = array(); $sql = "SELECT DISTINCT val_title,val_timestamp,val_type,avg(val_value) AS avg FROM validate GROUP BY val_title,val_timestamp,val_type"; $res = wfQuery($sql, DB_READ); while ($s = wfFetchObject($res)) { $articles[$s->val_title][$s->val_timestamp][$s->val_type] = $s; } # The list $html .= "<ul>\n"; foreach ($articles as $dbkey => $timedata) { $title = Title::newFromDBkey($dbkey); $out = array(); krsort($timedata); foreach ($timedata as $timestamp => $typedata) { $showit = true; foreach ($typedata as $type => $data) { $avg = intval($data->avg + 0.5); if ($choice[$type][$avg] == 0) { $showit = false; } } if ($showit) { $out[] = "<li>" . $this->getVersionLink($title, $timestamp) . "</li>\n"; } } if (count($out) > 0) { $html .= "<li>\n"; $html .= htmlspecialchars($title->getText()) . "\n"; $html .= "<ul>\n"; $html .= implode("\n", $out); $html .= "</ul>\n</li>\n"; } } $html .= "</ul>\n"; return $html; }
/** * This doesn't really work anymore, because self-links are now displayed as * unlinked bold text, and are not entered into the link table. * * @deprecated */ function wfSpecialSelfLinks() { global $wgUser, $wgOut, $wgLang, $wgTitle; $fname = 'wfSpecialSelfLinks'; list($limit, $offset) = wfCheckLimits(); $sql = "SELECT page_namespace,page_title FROM page,links " . "WHERE l_from=l_to AND l_to=page_id " . "LIMIT {$offset}, {$limit}"; $res = wfQuery($sql, DB_SLAVE, $fname); $top = getMaintenancePageBacklink('selflinks'); $top .= '<p>' . wfMsg('selflinkstext') . "</p><br />\n"; $top .= wfShowingResults($offset, $limit); $wgOut->addHTML("<p>{$top}\n"); $sl = wfViewPrevNext($offset, $limit, 'REPLACETHIS'); $sl = str_replace('REPLACETHIS', sns() . ":Maintenance&subfunction=selflinks", $sl); $wgOut->addHTML("<br />{$sl}\n"); $sk = $wgUser->getSkin(); $s = '<ol start=' . ($offset + 1) . '>'; while ($obj = wfFetchObject($res)) { $title = Title::makeTitle($obj->page_namespace, $obj->page_title); $s .= "<li>" . $sk->makeKnownLinkObj($title) . "</li>\n"; } wfFreeResult($res); $s .= '</ol>'; $wgOut->addHTML($s); $wgOut->addHTML("<p>{$sl}\n"); }
function fixUserOptions() { print "Fixing user options..."; $res = wfQuery("SELECT user_id,user_options FROM user", DB_MASTER); $total = wfNumRows($res); $n = 0; print " ({$total} total)\n"; while ($row = wfFetchObject($res)) { $id = intval($row->user_id); $option = wfStrencode($this->rewriteUserOptions($row->user_options)); wfQuery("UPDATE user SET user_options='{$option}' WHERE user_id={$id} LIMIT 1", DB_MASTER); if (++$n % 50 == 0) { print "{$n}\n"; } } wfFreeResult($res); }