Example #1
0
 function notifyRequests($article, $user, $text, $summary, $p5, $p6, $p7)
 {
     global $wgContLang;
     require_once 'Request.php';
     notifyRequester($article, $user, $user, $text, $summary);
     // is the article brandnew
     $t = $article->getTitle();
     if ($t->getNamespace() == NS_MAIN) {
         $dbr = wfGetDB(DB_SLAVE);
         $num_revisions = $dbr->selectField('revision', 'count(*)', array('rev_page=' . $article->getId()));
         if ($num_revisions == 1) {
             // new article
             $r = Title::makeTitle(NS_ARTICLE_REQUEST, $t->getText());
             if ($r->getArticleID() < 0) {
                 $r = Title::makeTitle(NS_ARTICLE_REQUEST, EditPageWrapper::formatTitle($t->getText()));
             }
             if ($r->getArticleID() > 0) {
                 $revision = Revision::newFromTitle($r);
                 $text = $revision->getText();
                 if (strpos($text, wfMsg('answered-requests')) === false) {
                     $ra = new Article($r);
                     $text = ereg_replace("[\\[]+Category\\:([- ]*[.]?[a-zA-Z0-9_/-?&%])*[]]+", "", $text);
                     $text .= "\n[[" . $wgContLang->getNSText(NS_CATEGORY) . ":" . wfMsg('answered-requests') . "]]";
                     $ra->updateArticle($text, wfMsg('request-now-answered'), true, false);
                 }
             }
         }
     }
     return true;
 }
 function upload()
 {
     $details = null;
     $this->content = 'error';
     $up = new UploadFromFile();
     $up->initializeFromRequest($this->wg->request);
     $permErrors = $up->verifyPermissions($this->wg->user);
     if ($permErrors !== true) {
         $this->status = self::UPLOAD_PERMISSION_ERROR;
         $this->statusMessage = $this->uploadMessage($this->status, null);
     } else {
         if (empty($this->wg->EnableUploads)) {
             // BugId:6122
             $this->statusMessage = wfMsg('uploaddisabled');
         } else {
             $details = $up->verifyUpload();
             $this->status = is_array($details) ? $details['status'] : UploadBase::UPLOAD_VERIFICATION_ERROR;
             $this->statusMessage = '';
             if ($this->status > 0) {
                 $this->statusMessage = $this->uploadMessage($this->status, $details);
             } else {
                 $titleText = $this->request->getVal('title');
                 $sectionNumber = $this->request->getVal('section', 0);
                 $this->status = $up->performUpload('', '', '', $this->wg->user);
                 $mainArticle = new Article(Title::newFromText($titleText));
                 if ($sectionNumber == 0) {
                     $mainArticle->updateArticle($this->getWikiText($up->getTitle()->getText(), self::LEFT) . $mainArticle->getRawText(), '', false, false);
                 } else {
                     $firstSectionText = $mainArticle->getSection($mainArticle->getRawText(), $sectionNumber);
                     $matches = array();
                     if (preg_match('/={2,3}[^=]+={2,3}/', $firstSectionText, $matches)) {
                         $firstSectionText = trim(str_replace($matches[0], '', $firstSectionText));
                         $newSectionText = $mainArticle->replaceSection($sectionNumber, $matches[0] . "\n" . $this->getWikiText($up->getTitle()->getText(), self::LEFT) . $firstSectionText);
                         $mainArticle->updateArticle($newSectionText, '', false, false);
                     }
                 }
                 $this->content = $this->renderImage($up->getTitle()->getText(), self::LEFT);
             }
         }
     }
 }
 function execute($par)
 {
     global $wgUser, $wgOut, $wgContLang;
     if (wfReadOnly()) {
         $wgOut->readOnlyPage();
     }
     if ($wgUser->isAnon()) {
         $this->errjump(0);
     }
     $artid = "";
     $spice = "";
     $artname = "";
     $cat = "";
     if (isset($_POST["id"])) {
         $artid = $_POST["id"];
     }
     if (isset($_POST["spice"])) {
         $spice = $_POST["spice"];
     }
     if (isset($_POST["artname"])) {
         $artname = $_POST["artname"];
     }
     if (isset($_POST["cat"])) {
         $cat = $_POST["cat"];
     }
     if (!$spice || !$artname || !$cat) {
         $this->errjump(1);
     }
     # FIXME: mimic CategorySelect here
     $myspice = sha1("Kroko-katMeNot-{$artid}-{$artname}-NotMekat-Schnapp");
     if ($spice != $myspice) {
         $this->errjump(2);
     }
     $title = Title::newFromText($artname);
     if (!is_object($title)) {
         $this->errjump(3);
     }
     $rev = Revision::newFromTitle($title);
     $emptycat = '[[' . $wgContLang->getNsText(NS_CATEGORY) . ':' . wfMsgForContent('fastcat-marker-category') . ']]';
     if ($rev && strstr($rev->getText(), $emptycat)) {
         $newtext = str_replace($emptycat, "[[" . $wgContLang->getNsText(NS_CATEGORY) . ':' . $cat . "]]", $rev->getText());
         if (strcmp($newtext, $rev->getText())) {
             $article = new Article($title);
             $article->updateArticle($newtext, wfMsgForContent('fastcat-edit-comment', $cat), false, false);
             $wgOut->redirect($title->getFullUrl());
         }
     } else {
         $this->errjump(4);
     }
 }
Example #4
0
function cleanupArticle($id, $domain)
{
    $title = Title::newFromID($id);
    if (!$title) {
        print "Internal error: no page for ID {$id}\n";
        return;
    }
    print $title->getPrefixedDBkey() . " ...";
    $rev = Revision::newFromTitle($title);
    $reverted = false;
    $revId = $rev->getId();
    $currentRevId = $revId;
    $regex = LinkFilter::makeRegex($domain);
    while ($rev && preg_match($regex, $rev->getText())) {
        # Revision::getPrevious can't be used in this way before MW 1.6 (Revision.php 1.26)
        #$rev = $rev->getPrevious();
        $revId = $title->getPreviousRevisionID($revId);
        if ($revId) {
            $rev = Revision::newFromTitle($title, $revId);
        } else {
            $rev = false;
        }
    }
    if ($revId == $currentRevId) {
        // The regex didn't match the current article text
        // This happens e.g. when a link comes from a template rather than the page itself
        print "False match\n";
    } else {
        $dbw =& wfGetDB(DB_MASTER);
        $dbw->immediateBegin();
        if (!$rev) {
            // Didn't find a non-spammy revision, blank the page
            print "blanking\n";
            $article = new Article($title);
            $article->updateArticle('', wfMsg('spam_blanking', $domain), false, false);
        } else {
            // Revert to this revision
            print "reverting\n";
            $article = new Article($title);
            $article->updateArticle($rev->getText(), wfMsg('spam_reverting', $domain), false, false);
        }
        $dbw->immediateCommit();
        wfDoUpdates();
    }
}
/** 
 * Find the latest revision of the article that does not contain spam and revert to it
 */
function cleanupArticle($rev, $regex)
{
    $title = $rev->getTitle();
    $reverted = false;
    $revId = $rev->getId();
    while ($rev && preg_match($regex, $rev->getText())) {
        # Revision::getPrevious can't be used in this way before MW 1.6 (Revision.php 1.26)
        #$rev = $rev->getPrevious();
        $revId = $title->getPreviousRevisionID($revId);
        if ($revId) {
            $rev = Revision::newFromTitle($title, $revId);
        } else {
            $rev = false;
        }
    }
    $dbw =& wfGetDB(DB_MASTER);
    $dbw->immediateBegin();
    if (!$rev) {
        // Didn't find a non-spammy revision, delete the page
        /*
        		print "All revisions are spam, deleting...\n";
        		$article = new Article( $title );
        		$article->doDeleteArticle( "All revisions matched the spam blacklist" );
        */
        // Too scary, blank instead
        print "All revisions are spam, blanking...\n";
        $article = new Article($title);
        $article->updateArticle('', 'All revisions matched the spam blacklist, blanking', false, false);
    } else {
        // Revert to this revision
        $article = new Article($title);
        $article->updateArticle($rev->getText(), "Revert spam", false, false);
    }
    $dbw->immediateCommit();
    wfDoUpdates();
}
Example #6
0
 function execute($par)
 {
     global $wgRequest, $wgOut, $wgTitle;
     $param = $wgRequest->getText('param');
     $parcheck = $wgRequest->getText('parcheck');
     $action = $wgTitle->getFullURL();
     $description = wfMsgExt('checksite-description', array('parse'));
     $label = wfMsgExt('checksite-label', array('parseinline'));
     $submit = wfMsg('checksite-submit');
     $post = "\n\t\t\t<form action=\"{$action}\" method=\"get\">\n\t\t\t{$description}\n\t\t\t{$label}\n\t\t\t<input type=\"text\" name=\"parcheck\" value=\"{$param}\" size=\"40\" maxlength=\"80\" />\n\t\t\t<input type=\"submit\" value=\"{$submit}\" />\n\t\t\t</form>";
     $this->setHeaders();
     if (!isset($parcheck) || strlen($parcheck) < 5) {
         $wgOut->addHTML($post);
         return;
     }
     $newdom = check_validate_domain($parcheck);
     if (!$newdom) {
         $parcheck = htmlspecialchars($parcheck);
         $wgOut->addWikiMsg('checksite-cant-check', $parcheck);
         return;
     }
     $newpage = $newdom;
     $newpage[0] = strtoupper($newpage[0]);
     $title = Title::newFromUrl($newpage);
     if (!is_object($title)) {
         $wgOut->addWikiMsg('checksite-not-found', $newpage);
         return;
     }
     if (!$title->exists()) {
         $wgOut->addWikiMsg('checksite-not-exist', $newpage);
         return;
     }
     $newhost = check_get_host($newdom);
     if (!$newhost) {
         $wgOut->addWikiMsg('checksite-url-not-found', $newdom);
         return;
     }
     if ($rob = @fopen("http://{$newhost}/robots.txt", 'r')) {
         $txt = fread($rob, 4096);
         while (!feof($rob)) {
             $txt .= fread($rob, 4096);
             if (strlen($txt) > 20000) {
                 break;
             }
         }
         fclose($rob);
         if (eregi("User-agent:[ \t\n]*WebsiteWiki[ \t\r\n]*Disallow:[ \t\r\n]*/", $txt)) {
             global $wgUser;
             $output = wfMsg('checksite-robots', $newhost, $newpage);
             $orgUser = $wgUser;
             //TODO: should this hardcoded user be here?
             $wgUser = User::newFromName('Sysop');
             $article = new Article($title);
             $restrict = array('edit' => 'sysop', 'move' => 'sysop');
             $article->updateRestrictions($restrict, $output);
             $redirectUrl = wfMsg('checksite-redirect-url');
             $redirectComment = wfMsg('checksite-redirect-comment');
             $article->updateArticle("#REDIRECT [[{$redirectUrl}]]", $redirectComment, false, false);
             $wgUser = $orgUser;
             return;
         }
     }
     //TODO: check if this hardcoded URL should remain here
     if (stristr($newhost, 'duckshop.de')) {
         $wgOut->addWikiMsg('checksite-screenshot-error');
         return;
     }
     $output = wfMsg('checksite-screenshot-updating', $newpage);
     /**
      * @todo -- lines below do nothing, so why they are there?
      * 
      * $url = fopen("http://thumbs.websitewiki.de/newthumb.php?name=$newdom", 'r');
      * fclose($url);
      */
     # Output
     $wgOut->addHTML($output);
 }
Example #7
0
<?php

require_once "../../classes/article_class.php";
$postdata = file_get_contents("php://input");
$data = json_decode($postdata);
if (!empty($data->title) && !empty($data->category) && !empty($data->content)) {
    $article = new Article($data->alias, $data->title, $data->category, $data->content, $data->url, $data->img_url, $data->meta_title, $data->meta_description, $data->meta_keywords);
    if ($article->articleExists()) {
        $article->updateArticle();
        http_response_code("200");
        echo json_encode(array("message" => "Article with title " . $article->getArticleName() . " as been updated."));
    } else {
        $article->addNewArticle();
        http_response_code("200");
        echo json_encode(array("message" => "Article with title " . $article->getArticleName() . " added to the database"));
    }
} else {
    // redirect to write the article
    http_response_code("400");
    echo json_encode(array("error" => "Title,Content and Category must be filled"));
}
Example #8
0
 function reject($uid, $reason, $message)
 {
     global $wgUser, $wgOut, $wgLang;
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     if (!in_array('sysop', $wgUser->getGroups())) {
         $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext');
         return;
     }
     $wgOut->setArticleBodyOnly(true);
     $dbw = wfGetDB(DB_MASTER);
     //REMOVE PICTURE
     $ret = $this->removePicture($uid);
     if (preg_match('/FAILED/', $ret, $matches)) {
         wfDebug("Avatar removePicture failed: " . $ret . "\n");
     }
     //UPDATE DB RECORD
     $sql = "UPDATE avatar SET av_patrol=-1, av_patrolledBy=" . $wgUser->getID() . ", av_patrolledDate='" . wfTimestampNow() . "', av_rejectReason='" . $dbw->addQuotes($reason) . "' WHERE av_user="******"";
     $text = "";
     $article = "";
     if ($message) {
         $comment = $message . "\n";
     }
     if ($comment) {
         $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $user, $real_name, $comment);
         if ($user_talk->getArticleId() > 0) {
             $r = Revision::newFromTitle($user_talk);
             $text = $r->getText();
         }
         $article = new Article($user_talk);
         $text .= "\n\n{$formattedComment}\n\n";
         $watch = false;
         if ($wgUser->getID() > 0) {
             $watch = $wgUser->isWatched($user_talk);
         }
         if ($user_talk->getArticleId() > 0) {
             $article->updateArticle($text, wfMsg('avatar-rejection-usertalk-editsummary'), true, $watch);
         } else {
             $article->insertNewArticle($text, wfMsg('avatar-rejection-usertalk-editsummary'), true, $watch, false, false, true);
         }
     }
     return "SUCCESS";
 }
Example #9
0
<?php

require_once "../../common.php";
require_once "../classes/class.Article.php";
$log = new System\Login(1);
if (isset($_GET['a'])) {
    $articleID = trim(htmlentities($_GET['a'], ENT_QUOTES, "UTF-8"));
    $articleID = $GLOBALS['DB']->escapeString($articleID);
    $articleData = $GLOBALS['DB']->query("SELECT * FROM article WHERE articleID = '{$articleID}' ", true);
    if ($articleData->num_rows == 1) {
        $article = new Article();
        $article->updateArticle($articleID);
        System\HTML::printHead();
        System\HTML::printHeader();
        ?>

<div role="main" class="main">

  <section class="page-top">
    <div class="container">
      <div class="row">
        <div class="span12">
          <ul class="breadcrumb">
            <li><a href="../../index.php">Startseite</a> <span class="divider">/</span></li>
            <li class="active">Angebot editieren</li>
            </ul>
          </div>
        </div>
        <div class="row">
          <div class="span12">
            <h2>Angebot editieren</h2>
Example #10
0
$wgUser->setId(1236204);
$dbr =& wfGetDB(DB_SLAVE);
$res = $dbr->query('select page_title, page_namespace, page_id  from templatelinks, page  where tl_from=page_id and tl_title=\'Fac\';');
while ($row = $dbr->fetchObject($res)) {
    $title = Title::makeTitle($row->page_namespace, $row->page_title);
    $res2 = $dbr->query("select rev_id, rev_timestamp from revision where rev_page={$row->page_id} order by rev_id;");
    while ($row2 = $dbr->fetchObject($res2)) {
        $r = Revision::newFromId($row2->rev_id);
        if (strpos($r->getText(), "{{fac") !== false) {
            $lt = $row2->rev_timestamp;
            $last_id = $row2->rev_id;
            break;
        } else {
        }
    }
    $dbr->freeResult($res2);
    $d = substr($lt, 0, 4) . "-" . substr($lt, 4, 2) . "-" . substr($lt, 6, 2);
    //echo "{$title->getFullURL()} first revision with {{fac}} was {$d}\n";
    $revision = Revision::newFromTitle($title);
    $text = $revision->getText();
    if (strpos($text, "{{fac|date=") === false) {
        $text = str_replace("{{fac}}", "{{fac|date={$d}}}", $text);
        //echo $text;
        $a = new Article(&$title);
        $a->updateArticle($text, "Adding date to {{fac}}", true, false);
        echo "updating {$title->getFullURL()}\n";
    } else {
        echo "NOT UPDATING {$title->getFullURL()}\n";
    }
}
$dbr->freeResult($res);
Example #11
0
function notifyRequester($article, $user, $user, $text, $summary)
{
    global $wgTitle, $wgRequest;
    $requested = $wgRequest->getVal('requested', null);
    if ($requested != null && $summary != "Request now answered.") {
        $actualTitleObj = Title::newFromDBKey("Request:" . $wgTitle->getDBKey());
        $actualkey = $wgTitle->getDBKey();
        if ($requested != $actualkey) {
            $ot = Title::newFromDBKey("Request:" . $requested);
            $nt = Title::newFromDBKey("Request:" . $actualkey);
            $error = $ot->moveTo($nt);
            if ($error !== true) {
                echo $error;
            }
            $actualTitleObj = $nt;
        }
        Request::notifyRequest($wgTitle, $actualTitleObj);
        // strip categories
        $at = new Article($actualTitleObj);
        $text = $at->getContent(true);
        //echo $t->getFullText();
        $text = ereg_replace("[\\[]+Category\\:([- ]*[.]?[a-zA-Z0-9_/-?&%])*[]]+", "", $text);
        $text .= "[[Category:Answered Requests]]";
        $at->updateArticle($text, "Request now answered.", true, false);
    }
    return true;
}
    function execute($par)
    {
        global $wgUser, $wgOut, $wgLang, $wgTitle, $wgMemc, $wgDBname;
        global $wgRequest, $wgSitename, $wgLanguageCode, $IP;
        global $wgScript, $wgFilterCallback, $wgScriptPath;
        $this->setHeaders();
        require_once "{$IP}/extensions/wikihow/EditPageWrapper.php";
        require_once "{$IP}/includes/EditPage.php";
        $target = isset($par) ? $par : $wgRequest->getVal('target');
        if (!$target) {
            $wgOut->addHTML("No target specified. In order to thank a group of authors, a page must be provided.");
            return;
        }
        $title = Title::newFromDBKey($target);
        $me = Title::makeTitle(NS_SPECIAL, "ThankAuthors");
        if (!$wgRequest->getVal('token')) {
            $sk = $wgUser->getSkin();
            $talk_page = $title->getTalkPage();
            $token = $this->getToken1();
            $thanks_msg = wfMsg('thank-you-kudos', $title->getFullURL(), wfMsg('howto', $title->getText()));
            // add the form HTML
            $wgOut->addHTML(<<<EOHTML
\t\t\t\t<script type='text/javascript'>
\t\t\t\t\tfunction submitThanks () {
\t\t\t\t\t\tvar message = \$('#details').val();
\t\t\t\t\t\tif(message == "") {
\t\t\t\t\t\t\talert("Please enter a message.");
\t\t\t\t\t\t\treturn false;
\t\t\t\t\t\t}
\t\t\t\t\t\tvar url = '{$me->getFullURL()}?token=' + \$('#token')[0].value + '&target=' + \$('#target')[0].value + '&details=' + \$('#details')[0].value;
\t\t\t\t\t\tvar form = \$('#thanks_form');
\t\t\t\t\t\tform.html(\$('#thanks_response').html());
\t\t\t\t\t\t\$.get(url);
\t\t\t\t\t\treturn true;
\t\t\t\t\t}
\t\t\t\t</script>

\t\t\t\t<div id="thanks_response" style="display:none;">{$thanks_msg}</div>
\t\t\t\t<div id="thanks_form"><div class="section_text">
EOHTML
);
            $wgOut->addWikiText(wfMsg('enjoyed-reading-article', $title->getFullText(), $talk_page->getFullText()));
            $wgOut->addHTML("<input id=\"target\" type=\"hidden\" name=\"target\" value=\"{$target}\"/>\n\t\t\t\t<input id=\"token\" type=\"hidden\" name=\"{$token}\" value=\"{$token}\"/>\n\t\t\t\t");
            $wgOut->addHTML("<br />\n\t\t\t\t<textarea style='width:98%;' id=\"details\" rows=\"5\" cols=\"100\" name=\"details\"></textarea><br/>\n\t\t\t\t<br /><button onclick='submitThanks();' class='button primary'>" . wfMsg('submit') . "</button>\n\t\t\t\t</div></div>");
        } else {
            // this is a post, accept the POST data and create the
            // Request article
            wfLoadExtensionMessages('PostComment');
            $wgOut->setArticleBodyOnly(true);
            $user = $wgUser->getName();
            $real_name = User::whoIsReal($wgUser->getID());
            if ($real_name == "") {
                $real_name = $user;
            }
            $dateStr = $wgLang->timeanddate(wfTimestampNow());
            $comment = $wgRequest->getVal("details");
            $text = $title->getFullText();
            wfDebug("STA: got text...");
            // filter out links
            $preg = "/[^\\s]*\\.[a-z][a-z][a-z]?[a-z]?/i";
            $matches = array();
            if (preg_match($preg, $comment, $matches) > 0) {
                $wgOut->addHTML(wfMsg('no_urls_in_kudos', $matches[0]));
                return;
            }
            $comment = strip_tags($comment);
            $formattedComment = wfMsg('postcomment_formatted_thanks', $dateStr, $user, $real_name, $comment, $text);
            wfDebug("STA: comment {$formattedComment}\n");
            wfDebug("STA: Checking blocks...");
            $tmp = "";
            if ($wgUser->isBlocked()) {
                $this->blockedIPpage();
                return;
            }
            if (!$wgUser->getID() && $wgWhitelistEdit) {
                $this->userNotLoggedInPage();
                return;
            }
            if ($target == "Spam-Blacklist") {
                $wgOut->readOnlyPage();
                return;
            }
            wfDebug("STA: checking read only\n");
            if (wfReadOnly()) {
                $wgOut->readOnlyPage();
                return;
            }
            wfDebug("STA: checking rate limiter\n");
            if ($wgUser->pingLimiter('userkudos')) {
                $wgOut->rateLimited();
                return;
            }
            wfDebug("STA: checking blacklist\n");
            if ($wgFilterCallback && $wgFilterCallback($title, $comment, "")) {
                // Error messages or other handling should be
                // performed by the filter function
                return;
            }
            wfDebug("STA: checking tokens\n");
            $usertoken = $wgRequest->getVal('token');
            $token1 = $this->getToken1();
            $token2 = $this->getToken2();
            if ($usertoken != $token1 && $usertoken != $token2) {
                wfDebug("STA: User kudos token doesn't match user: {$usertoken} token1: {$token1} token2: {$token2}");
                return;
            }
            wfDebug("STA: going through contributors\n");
            $article = new Article($title);
            //$contributors = $article->getContributors(0, 0, true);
            $contributors = ArticleAuthors::getAuthors($article->getID());
            foreach ($contributors as $k => $v) {
                $u = User::newFromName($k);
                $id = $u->getID();
                //$id = $c->getID();
                //$u = $c;
                wfDebug("STA: going through contributors {$u} {$id}\n");
                if ($id == "0") {
                    continue;
                }
                // forget the anon users.
                //notify via the echo notification system
                if (class_exists('EchoEvent')) {
                    EchoEvent::create(array('type' => 'kudos', 'title' => $title, 'extra' => array('kudoed-user-id' => $id), 'agent' => $wgUser));
                }
                $t = Title::newFromText("User_kudos:" . $u);
                $a = new Article($t);
                $update = $t->getArticleID() > 0;
                $text = "";
                if ($update) {
                    $text = $a->getContent(true);
                    $text .= "\n\n" . $formattedComment;
                    if ($wgFilterCallback && $wgFilterCallback($t, $text, $text)) {
                        // Error messages or other handling should be
                        // performed by the filter function
                        return;
                    }
                }
                if ($update) {
                    $a->updateArticle($text, "", true, false, false, '', false);
                } else {
                    $a->insertNewArticle($text, "", true, false, false, false, false);
                }
            }
            wfDebug("STA: done\n");
            $wgOut->addHTML("Done.");
            $wgOut->redirect('');
        }
    }
<?php

require_once "commandLine.inc";
$wgUser->setID(1236204);
$dbr =& wfGetDB(DB_SLAVE);
$dbw =& wfGetDB(DB_MASTER);
$res = $dbr->select('page', array('page_title', 'page_namespace'), array('page_is_redirect' => 0), "findInlineImages");
$count = 0;
while ($row = $dbr->fetchObject($res)) {
    $title = Title::makeTitle($row->page_namespace, $row->page_title);
    $wgTitle = $title;
    $revision = Revision::newFromTitle($title);
    $text = $revision->getText();
    if (preg_match('/^==[ ]*' . wfMsg('externallinks') . '[ ]*==/im', $text)) {
        $text = preg_replace('/^==[ ]*' . wfMsg('externallinks') . '[ ]*==/im', '== ' . wfMsg('sources') . ' ==', $text);
        $a = new Article($title);
        $a->updateArticle($text, "Changing External Links to Sources and Citations", false, false);
        echo "{$title->getFullURL()} updated\n";
        if ($count % 50 == 0) {
            echo "updating recentchanges to mark it all as patrolled...\n";
            $dbw->query("update recentchanges set rc_patrolled=1 where rc_user=1236204");
        }
        $count++;
        //exit;
    } else {
        //echo "no matches?\n";
    }
}
echo "found {$count} matching\n";
$dbr->freeResult($res);
        } else {
            $newtext .= substr($text, $j, strlen($text) - $j);
        }
        $text = $newtext;
        if ($now > 0) {
            echo "Adding link to {$t->getText()} pointing to {$x->getText()}\n";
        }
        $replacements += $now;
        #echo "now $now\n";
        $count++;
        #if ($replacements > 1)
        #	break;
        $dbw->query("update recentchanges set rc_patrolled=1 where rc_user_text='LinkTool'");
    }
    if ($replacements > 0) {
        $wgTitle = $t;
        $a = new Article($t);
        if (!$a->updateArticle($text, "LinkTool is sprinkling some links", true, false)) {
            echo "couldn't update article {$t->getText()}, exiting...\n";
            exit;
        }
        echo "updated {$t->getText()}\n";
        $wgTitle = null;
        $updated++;
    }
    if ($updated == 100) {
        echo "updated {$updated} articles, breaking...\n";
        break;
    }
}
echo "checked " . number_format($count) . " articles\n";
Example #15
0
 private function cleanupArticle($id, $domain)
 {
     $title = Title::newFromID($id);
     if (!$title) {
         $this->error("Internal error: no page for ID {$id}");
         return;
     }
     $this->output($title->getPrefixedDBkey() . " ...");
     $rev = Revision::newFromTitle($title);
     $revId = $rev->getId();
     $currentRevId = $revId;
     while ($rev && LinkFilter::matchEntry($rev->getText(), $domain)) {
         # Revision::getPrevious can't be used in this way before MW 1.6 (Revision.php 1.26)
         #$rev = $rev->getPrevious();
         $revId = $title->getPreviousRevisionID($revId);
         if ($revId) {
             $rev = Revision::newFromTitle($title, $revId);
         } else {
             $rev = false;
         }
     }
     if ($revId == $currentRevId) {
         // The regex didn't match the current article text
         // This happens e.g. when a link comes from a template rather than the page itself
         $this->output("False match\n");
     } else {
         $dbw = wfGetDB(DB_MASTER);
         $dbw->begin();
         if (!$rev) {
             // Didn't find a non-spammy revision, blank the page
             $this->output("blanking\n");
             $article = new Article($title);
             $article->updateArticle('', wfMsg('spam_blanking', $domain), false, false);
         } else {
             // Revert to this revision
             $this->output("reverting\n");
             $article = new Article($title);
             $article->updateArticle($rev->getText(), wfMsg('spam_reverting', $domain), false, false);
         }
         $dbw->commit();
         wfDoUpdates();
     }
 }
Example #16
0
require_once "commandLine.inc";
$wgUser = new User();
$wgUser->setName('KudosArchiver');
$dbr =& wfGetDB(DB_SLAVE);
$res = $dbr->select(array('page', 'user'), array('page_title', 'page_namespace', 'user_name'), array('page_namespace' => NS_USER_KUDOS, 'page_len>80000', 'page_title=user_name'), "archiveUserKuods");
while ($row = $dbr->fetchObject($res)) {
    try {
        $num_titles = 0;
        $ot = Title::makeTitle($row->page_namespace, $row->page_title);
        $links = array();
        for ($x = 1;; $x++) {
            $t = Title::makeTitle(NS_USER_KUDOS, wfMsg('user_kudos_archive_url', $row->user_name, $x));
            if ($t->getArticleID() == 0) {
                break;
            }
            $num_titles++;
            $links[] .= "[[{$t->getPrefixedText()}|{$x}]]";
        }
        $links[] .= "[[{$t->getPrefixedText()}|" . ($num_titles + 1) . "]]";
        $nt = Title::makeTitle(NS_USER_KUDOS, wfMsg('user_kudos_archive_url', $row->user_name, $num_titles + 1));
        print "Moving {$ot->getFullText()} to {$nt->getFullText()}\n";
        $ot->moveNoAuth($nt);
        $text = wfMsg('user_kudos_archive_title') . implode(", ", $links);
        $a = new Article(&$ot);
        $a->updateArticle(&$text, wfMsg('user_kudos_archive_summary'), false, false);
        print "Setting new text {$text}\n";
    } catch (Exception $e) {
    }
}
$dbr->freeResult($res);
 private function updatePage(&$title, &$data)
 {
     $article = new Article($title);
     return $article->updateArticle($data, '', false, false, '', null);
 }
Example #18
0
 function pbConfig()
 {
     global $wgUser, $wgRequest, $wgOut;
     $live = mysql_real_escape_string(strip_tags($wgRequest->getVal('live'), '<p><br><b><i>'));
     $occupation = mysql_real_escape_string(strip_tags($wgRequest->getVal('occupation'), '<p><br><b><i>'));
     $aboutme = mysql_real_escape_string(strip_tags($wgRequest->getVal('aboutme'), '<p><br><b><i>'));
     $t = Title::newFromText($wgUser->getUserPage() . '/profilebox-live');
     $article = new Article($t);
     if ($t->getArticleId() > 0) {
         $article->updateArticle($live, 'profilebox-live-update', true, $watch);
     } else {
         if ($live != '') {
             $article->insertNewArticle($live, 'profilebox-live-update', true, $watch, false, false, true);
         }
     }
     $t = Title::newFromText($wgUser->getUserPage() . '/profilebox-occupation');
     $article = new Article($t);
     if ($t->getArticleId() > 0) {
         $article->updateArticle($occupation, 'profilebox-occupation-update', true, $watch);
     } else {
         if ($occupation != '') {
             $article->insertNewArticle($occupation, 'profilebox-occupation-update', true, $watch, false, false, true);
         }
     }
     $t = Title::newFromText($wgUser->getUserPage() . '/profilebox-aboutme');
     $article = new Article($t);
     if ($t->getArticleId() > 0) {
         $article->updateArticle($aboutme, 'profilebox-aboutme-update', true, $watch);
     } else {
         if ($aboutme != '') {
             $article->insertNewArticle($aboutme, 'profilebox-aboutme-update', true, $watch, false, false, true);
         }
     }
     $userpageurl = $wgUser->getUserPage() . '';
     $t = Title::newFromText($userpageurl, NS_USER);
     $article = new Article($t);
     $userpage = " \n";
     if ($t->getArticleId() > 0) {
         /*
         $r = Revision::newFromTitle($t);
         $curtext .= $r->getText();
         
         if (!preg_match('/<!-- blank -->/',$curtext)) {
         	$userpage .= $curtext;
         	$article->updateArticle($userpage, 'profilebox-userpage-update', true, $watch);
         }
         */
     } else {
         $article->insertNewArticle($userpage, 'profilebox-userpage-update', true, $watch, false, false, true);
     }
     $wgUser->setOption('profilebox_fav1', $wgRequest->getVal('fav1'));
     $wgUser->setOption('profilebox_fav2', $wgRequest->getVal('fav2'));
     $wgUser->setOption('profilebox_fav3', $wgRequest->getVal('fav3'));
     if ($wgRequest->getVal('articleStats') == 'on') {
         $wgUser->setOption('profilebox_stats', 1);
     } else {
         $wgUser->setOption('profilebox_stats', 0);
     }
     if ($wgRequest->getVal('articleStartedEdited') == 'on') {
         $wgUser->setOption('profilebox_startedEdited', 1);
     } else {
         $wgUser->setOption('profilebox_startedEdited', 0);
     }
     /*
     		if ( ($wgRequest->getVal('articleFavs') == 'on') &&
     				($wgRequest->getVal('fav1') || $wgRequest->getVal('fav2') || $wgRequest->getVal('fav3')) )
     		{
     			$wgUser->setOption('profilebox_favs', 1);
     		} else {
     			$wgUser->setOption('profilebox_favs', 0);
     		}
     */
     $wgUser->setOption('profilebox_display', 1);
     $wgUser->saveSettings();
 }
 /**
  * NAB user flagged this article as a rising star in the Action section
  * of NAB'ing an article.
  */
 private function flagRisingStar($title)
 {
     global $wgLang, $wgUser, $wgRequest;
     if ($wgRequest->getVal('cb_risingstar', null) != "on") {
         return;
     }
     $dateStr = $wgLang->timeanddate(wfTimestampNow());
     $patrollerName = $wgUser->getName();
     $patrollerRealName = User::whoIsReal($wgUser->getID());
     if (!$patrollerRealName) {
         $patrollerRealName = $patrollerName;
     }
     // post to user talk page
     $contribUsername = $wgRequest->getVal('prevuser', '');
     if ($contribUsername) {
         $this->notifyUserOfRisingStar($title, $contribUsername);
     }
     // Give user a thumbs up. Set oldId to -1 as this should be the
     // first revision
     //if (class_exists('ThumbsUp')) {
     //	ThumbsUp::thumbNAB(-1, $title->getLatestRevID(), $title->getArticleID());
     //}
     // post to article discussion page
     $wikitext = "";
     $article = "";
     $contribUser = new User();
     $contribUser->setName($contribUsername);
     $contribUserPage = $contribUser->getUserPage();
     $contribUserName = $contribUser->getName();
     $patrolUserPage = $wgUser->getUserPage();
     $patrolUserName = $wgUser->getName();
     $talkPage = $title->getTalkPage();
     $comment = '{{Rising-star-discussion-msg-2|[[' . $contribUserPage . '|' . $contribUserName . ']]|[[' . $patrolUserPage . '|' . $patrolUserName . ']]}}' . "\n";
     $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $patrollerName, $patrollerRealName, $comment);
     wfRunHooks("MarkTitleAsRisingStar", array($title));
     if ($talkPage->getArticleId() > 0) {
         $rev = Revision::newFromTitle($talkPage);
         $wikitext = $rev->getText();
     }
     $article = new Article($talkPage);
     $wikitext = "{$comment}\n\n" . $wikitext;
     $watch = false;
     if ($wgUser->getID() > 0) {
         $watch = $wgUser->isWatched($talkPage);
     }
     if ($talkPage->getArticleId() > 0) {
         $article->updateArticle($wikitext, wfMsg('nab-rs-discussion-editsummary'), true, $watch);
     } else {
         $article->insertNewArticle($wikitext, wfMsg('nab-rs-discussion-editsummary'), true, $watch, false, false, true);
     }
     // add to fs feed page
     $wikitext = "";
     $article = "";
     $fsfeed = Title::newFromURL('wikiHow:Rising-star-feed');
     $rev = Revision::newFromTitle($fsfeed);
     $article = new Article($fsfeed);
     $wikitext = $rev->getText();
     $watch = false;
     if ($wgUser->getID() > 0) {
         $watch = $wgUser->isWatched($title->getTalkPage());
     }
     $wikitext .= "\n" . date('==Y-m-d==') . "\n" . $title->getFullURL() . "\n";
     $article->updateArticle($wikitext, wfMsg('nab-rs-feed-editsummary'), true, $watch);
 }
 function updateMainArticle($target, $editSummary)
 {
     global $wgOut, $wgRequest;
     $title = Title::makeTitle(NS_MAIN, $target);
     $vid = Title::makeTitle(NS_VIDEO, $target);
     $r = Revision::newFromTitle($title);
     $update = true;
     if (!$r) {
         $update = false;
         $text = "";
     } else {
         $text = $r->getText();
     }
     $tag = "{{" . $vid->getFullText() . "|}}";
     if ($wgRequest->getVal('description') != '') {
         $tag = "{{" . $vid->getFullText() . "|" . $wgRequest->getVal('description') . "}}";
     }
     $newsection .= "\n\n== " . wfMsg('video') . " ==\n{$tag}\n\n";
     $a = new Article($title);
     $newtext = "";
     // Check for existing video section in the target article
     preg_match("/^==[ ]*" . wfMsg('video') . "/im", $text, $matches, PREG_OFFSET_CAPTURE);
     if (sizeof($matches) > 0) {
         // There is an existing video section, replace it
         $i = $matches[0][1];
         preg_match("/^==/im", $text, $matches, PREG_OFFSET_CAPTURE, $i + 1);
         if (sizeof($matches) > 0) {
             $j = $matches[0][1];
             // == Video == was not the last section
             $newtext = trim(substr($text, 0, $i)) . $newsection . substr($text, $j, strlen($text));
         } else {
             // == Video == was the last section append it
             $newtext = trim($text) . $newsection;
         }
         // existing section, change it.
     } else {
         // There is not an existng video section, insert it after steps
         // This section could be cleaned up to handle it if there was an existing video section too I guess
         $arr = preg_split('/(^==[^=]*?==\\s*?$)/m', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
         $found = false;
         for ($i = 0; $i < sizeof($arr); $i++) {
             if (preg_match("/^==[ ]*" . wfMsg('steps') . "/", $arr[$i])) {
                 $newtext .= $arr[$i];
                 $i++;
                 if ($i < sizeof($arr)) {
                     $newtext .= $arr[$i];
                 }
                 $newtext = trim($newtext) . $newsection;
                 $found = true;
             } else {
                 $newtext .= $arr[$i];
             }
         }
         if (!$found) {
             $arr = preg_split('/(^==[^=]*?==\\s*?$)/m', $text, -1, PREG_SPLIT_DELIM_CAPTURE);
             $newtext = "";
             $newtext = trim($arr[0]) . $newsection;
             for ($i = 1; $i < sizeof($arr); $i++) {
                 $newtext .= $arr[$i];
             }
         }
     }
     if ($newtext == "") {
         $newtext = $newsection;
     }
     $watch = $title->userIsWatching();
     if ($update) {
         $a->updateArticle($newtext, $editSummary, false, $watch);
     } else {
         $a->insertNewArticle($newtext, $editSummary, false, $watch);
     }
     if ($wgRequest->getVal("popup") == "true") {
         $wgOut->clearHTML();
         $wgOut->disable();
         echo "<script type='text/javascript'>\n\t\t\tfunction onLoad() {\n\t\t\t\tvar e = document.getElementById('video_text');\n\t\t\t\te.value = \"" . htmlspecialchars($tag) . "\";\n\t\t\t\tpv_Preview();\n\t\t\t\tvar summary = document.getElementById('wpSummary');\n\t\t\t\tif (summary.value != '')\n\t\t\t\t\tsummary.value += ',  " . ($update ? wfMsg('importvideo_changingvideo_summary') : $editSummary) . "';\n\t\t\t\telse\n\t\t\t\t\tsummary.value = '" . ($update ? wfMsg('importvideo_changingvideo_summary') : $editSummary) . "';\n\t\t\t\tcloseModal();\n\t\t\t}\n\t\t\tonLoad();\n\t\t\t\t</script>\n\t\t\t\t";
     }
     $me = Title::makeTitle(NS_SPECIAL, "Importvideo");
     if ($wgRequest->getVal('wasnew') || $wgRequest->getVal('new')) {
         // log it, we track when someone uploads a video for a new article
         $params = array($title->getArticleID());
         $log = new LogPage('vidsfornew', false);
         $log->addEntry('added', $title, 'added');
         $wgOut->redirect($me->getFullURL() . "?new=1&skip=" . $title->getArticleID());
         return;
     } else {
         if ($wgRequest->getVal('category')) {
             // they added a video to a category, keep them in the category mode
             $wgOut->redirect($me->getFullURL() . "?category=" . urlencode($wgRequest->getVal('category')));
             return;
         }
     }
 }
function smartReplace($phrase, $title, $result, &$numreplace)
{
    #fake word boundary
    $fb = "[^a-zA-Z0-9_|\\[\\]]";
    #echo "Smart replace called on p: {$phrase}, t:{$title}, r:{$result->getText()}\n";
    $tObj = Title::newFromText($title);
    if (!$tObj || $tObj->getArticleID() == 0) {
        #echo "No article for $title\n";
        return;
    }
    $title = $tObj->getText();
    $rev = Revision::newFromTitle($result);
    if (!$rev) {
        return 0;
    }
    $text = $rev->getText();
    if (stripos($text, $phrase) === false) {
        return 0;
    }
    # @(\[{1,2}[^\]]*\]{1,2})@m
    $re = '\\[{1,2}[^\\]]*\\]{1,2}|' . '\\<[^>]*>|' . '\\{{1,2}[^\\}]*\\}{1,2}';
    $parts = preg_split('@(' . $re . ')@m', $text, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
    $ret = "";
    $replaced = 0;
    $inlink = false;
    // for hardcoded <a href=> links.
    while ($p = array_shift($parts)) {
        if (strpos($p, "[") === 0) {
        } else {
            if (strpos($p, "{") === 0) {
            } else {
                if (stripos($p, "<a") === 0) {
                    $inlink = true;
                } else {
                    if (stripos($p, "</a>") === 0) {
                        $inlink = false;
                    } else {
                        if (!$inklink) {
                            $p = preg_replace("@({$fb})({$phrase}[s]?)({$fb})@im", "\$1[[{$title}|\$2]]\$3", $p, 1, $replaced);
                        }
                    }
                }
            }
        }
        $ret .= $p;
        if ($replaced > 0) {
            break;
        }
    }
    // anything at the end?
    $ret .= implode("", $parts);
    if ($replaced > 0) {
        #debug this a bit
        $a = new Article($result);
        if (!recentlyEdited($result, $phrase)) {
            if ($ret == $text) {
                echo "No changes detected for {$result->getText()}, WTF?\n";
            } else {
                if ($a->updateArticle($ret, "Adding keyword links for phrase " . $phrase, true, false)) {
                    $numreplace = $replaced;
                    echo "{$phrase}\t{$title}\t{$result->getText()}\n";
                } else {
                    echo "Couldn't update article {$result->getText()}, WTF?\n";
                }
            }
        } else {
            #echo "{$result->getText()} was recently linked... skipping.\n";
        }
    } else {
        #echo "Couldn't find {$phrase} in this text\n\n";
        #echo "$text ------\n\n------\n\n";
    }
    return $ret;
}
            if ($a->updateArticle($text, "using {$target} instead of {$source}", true, true)) {
                echo "{$t->getFullText()} updated\n";
            } else {
                echo "{$t->getFullText()} not updated\n";
            }
        }
    }
    if (!$found && false) {
        echo "Found nothing for {$source}\n";
    } else {
        $r = Revision::newFromTitle($img);
        $text = $r->getText();
        if (strpos($text, "{{ifd") === false) {
            $text = "{{ifd|duplicate of [[:Image:{$dest->getText()}]]}}\n{$r->getText()}";
            $wgTitle = $img;
            $a = new Article($img);
            if ($a->updateArticle($text, "ifd, duplicate of {$dest->getFullText()}", false, false)) {
                echo "image article {$source} updated.\n";
            } else {
                echo "image article {$source} not updated.\n";
            }
            $updated++;
        } else {
            #echo "$source already if'd\n";
        }
    }
    if ($updated == 100) {
        #break;
    }
}
echo "{$updated} articles updated\n";
Example #23
0
 /**
  * Processes HTTP requests containing wikitext content
  */
 function processRequest()
 {
     global $wgOut, $wgRequest, $wgUser, $wgTitle, $wgSimpleFormsAllowRemoteAddr, $wgSimpleFormsAllowCreate, $wgSimpleFormsAllowEdit;
     $content = trim($wgRequest->getText(SIMPLEFORMS_CONTENT));
     $action = $wgRequest->getText('action');
     $title = $wgRequest->getText('title');
     # Handle content with action=raw case (allows templates=expand too)
     if ($action == 'raw' && isset($_REQUEST[SIMPLEFORMS_CONTENT])) {
         $this->raw($content);
     }
     # Handle content and title case (will either update or create an article)
     if ($title != SIMPLEFORMS_UNTITLED && isset($_REQUEST[SIMPLEFORMS_CONTENT])) {
         $title = Title::newFromText($wgRequest->getText('title'));
         if ($title->getNamespace() == NS_SPECIAL) {
             return;
         }
         if (!is_object($wgTitle)) {
             $wgTitle = $title;
         }
         # hack to stop DPL crashing
         $article = new Article($title);
         $allow = in_array($_SERVER['REMOTE_ADDR'], $wgSimpleFormsAllowRemoteAddr);
         $summary = $wgRequest->getText(SIMPLEFORMS_SUMMARY);
         $minor = $wgRequest->getText(SIMPLEFORMS_MINOR);
         $return = $wgRequest->getText(SIMPLEFORMS_RETURN);
         # If title exists and allowed to edit, prepend/append/replace content
         if ($title->exists()) {
             if ($wgSimpleFormsAllowEdit && ($allow || $wgUser->isAllowed('edit'))) {
                 $update = $this->updateTemplates($article->getContent(), $content);
                 $article->updateArticle($update, $summary ? $summary : wfMsg('sf_editsummary'), false, false);
             } else {
                 $wgOut->setPageTitle(wfMsg('whitelistedittitle'));
             }
         } else {
             if ($wgSimpleFormsAllowCreate && ($allow || $wgUser->isAllowed('edit'))) {
                 $article->insertNewArticle($content, $summary ? $summary : wfMsg('sf_editsummary', 'created'), false, false);
             } else {
                 $wgOut->setPageTitle(wfMsg('whitelistedittitle'));
             }
         }
         # If returnto is set, add a redirect header and die
         if ($return) {
             die(header('Location: ' . Title::newFromText($return)->getFullURL()));
         }
     }
 }
// is to "close" the non-existent connection then request another.
$db->close();
$db = wfGetDB(DB_SLAVE);
$db->ping();
// Check if any of these noembed vids have links on the site
$start = microtime(true);
foreach ($vids as $i => $vid) {
    if ($vid['noembed']) {
        $sql = "SELECT count(*) AS C\n\t\t\t\tFROM pagelinks LEFT JOIN page ON pl_from = page_id\n\t\t\t\tWHERE pl_namespace=" . NS_VIDEO . "\n\t\t\t\t\tAND pl_title=" . $db->addQuotes($vid['text']) . "\n\t\t\t\t\tAND page_namespace=0";
        $res = $db->query($sql);
        if ($row = $res->fetchObject()) {
            if ($row->C == 0) {
                echo "{$vid['full-text']} has no links...skipping\n";
                continue;
            }
        }
        $list .= "# [[{$vid['full-text']}]]\n";
    }
}
if ($list == "") {
    $list = "There are no videos at this time.";
}
$t = Title::makeTitle(NS_PROJECT, "Videos that can no longer be embedded");
$a = new Article($t);
$date = date("Y-m-d");
$text = wfMsg('no_more_embed_video') . "\n\n{$list}\nThis page was last updated {$date}\n";
if ($t->getArticleID() == 0) {
    $a->insertNewArticle($text, "list of videos that cannot be embedded", false, false);
} else {
    $a->updateArticle($text, "list of videos that cannot be embedded", false, false);
}
Example #25
0
 function execute($par)
 {
     global $wgRequest, $wgContLang, $wgOut, $wgSpamBlacklistArticle, $wgUser, $wgScript;
     $title = Title::newFromDBKey($wgRequest->getVal('target'));
     $diff = $wgRequest->getVal('diff2');
     $rcid = $wgRequest->getVal('rcid');
     $rdfrom = $wgRequest->getVal('rdfrom');
     $wgOut->setHTMLTitle(wfMsg('pagetitle', 'Spam Tool'));
     // can the user even edit this?
     $sb = Title::newFromDBKey($wgSpamBlacklistArticle);
     if (!$sb->userCanEdit()) {
         $wgOut->addHTML(wfMsg('spamdifftool_cantedit'));
         return;
     }
     // do the processing
     if ($wgRequest->wasPosted()) {
         if ($wgRequest->getVal('confirm', null) != null) {
             $t = Title::newFromDBKey($wgSpamBlacklistArticle);
             $a = new Article($t);
             $text = $a->getContent();
             // insert the before the <pre> at the bottom  if there is one
             $i = strrpos($text, "</pre>");
             if ($i !== false) {
                 $text = substr($text, 0, $i) . $wgRequest->getVal('newurls') . "\n" . substr($text, $i);
             } else {
                 $text .= "\n" . $wgRequest->getVal('newurls');
             }
             $watch = false;
             if ($wgUser->getID() > 0) {
                 $watch = $wgUser->isWatched($t);
             }
             $a->updateArticle($text, wfMsg('spamdifftool_summary'), false, $watch);
             $returnto = $wgRequest->getVal('returnto', null);
             if ($returnto != null && $returnto != '') {
                 $wgOut->redirect($wgScript . "?" . urldecode($returnto));
             }
             // clear the redirect set by updateArticle
             return;
         }
         $vals = $wgRequest->getValues();
         $text = '';
         $urls = array();
         $source = wfMsgForContent('top_level_domains');
         $tlds = split("\n", $source);
         foreach ($vals as $key => $value) {
             if (strpos($key, "http://") === 0) {
                 $url = str_replace("%2E", ".", $key);
                 if ($value == 'none') {
                     continue;
                 }
                 switch ($value) {
                     case 'domain':
                         $t = "";
                         foreach ($tlds as $tld) {
                             if (preg_match("/" . $tld . "/i", $url)) {
                                 $t = $tld;
                                 $url = preg_replace("/" . $tld . "/i", "", $url, 1);
                                 break;
                             }
                         }
                         $url = preg_replace("@^http://([^/]*\\.)?([^./]+\\.[^./]+).*\$@", "\$2", $url);
                         $url = str_replace(".", "\\.", $url);
                         // escape the periods
                         $url .= $t;
                         break;
                     case 'subdomain':
                         $url = str_replace("http://", "", $url);
                         $url = str_replace(".", "\\.", $url);
                         // escape the periods
                         $url = preg_replace("/^([^\\/]*)\\/.*/", "\$1", $url);
                         // trim everything after the slash
                         break;
                     case 'dir':
                         $url = str_replace("http://", "", $url);
                         $url = preg_replace("@^([^/]*\\.)?([^./]+\\.[^./]+(/[^/?]*)?).*\$@", "\$1\$2", $url);
                         // trim everything after the slash
                         $url = preg_replace("/^(.*)\\/\$/", "\$1", $url);
                         // trim trailing / if one exists
                         $url = str_replace(".", "\\.", $url);
                         // escape the periods
                         $url = str_replace("/", "\\/", $url);
                         // escape the slashes
                         break;
                 }
                 if (!isset($urls[$url])) {
                     $text .= "{$url}\n";
                     $urls[$url] = true;
                 }
             }
         }
         if (trim($text) == '') {
             $wgOut->addHTML(wfMsg('spamdifftool_notext', $wgScript . "?" . urldecode($wgRequest->getVal('returnto'))));
             return;
         }
         $wgOut->addHTML("<form method=POST>\n\t\t\t\t\t<input type='hidden' name='confirm' value='true'>\n\t\t\t\t\t<input type='hidden' name='newurls' value=\"" . htmlspecialchars($text) . "\">\n\t\t\t\t\t<input type='hidden' name='returnto' value=\"" . htmlspecialchars($wgRequest->getVal('returnto')) . "\">\n\t\t\t\t");
         $wgOut->addHTML(wfMsg('spamdifftool_confirm') . "<pre style='padding: 10px'>{$text}</pre>");
         $wgOut->addHTML("</table><input type=submit value=\"" . htmlspecialchars(wfMsg('submit')) . "\"></form>");
         return;
     }
     if (!is_null($diff)) {
         require_once 'DifferenceEngine.php';
         // Get the last edit not by this guy
         $current = Revision::newFromTitle($title);
         $dbw = wfGetDB(DB_MASTER);
         $user = intval($current->getUser());
         $user_text = $dbw->addQuotes($current->getUserText());
         $s = $dbw->selectRow('revision', array('rev_id', 'rev_timestamp'), array('rev_page' => $current->getPage(), "rev_user <> {$user} OR rev_user_text <> {$user_text}"), $fname, array('USE INDEX' => 'page_timestamp', 'ORDER BY' => 'rev_timestamp DESC'));
         if ($s) {
             // set oldid
             $oldid = $s->rev_id;
         }
         if ($wgRequest->getVal('oldid2') < $oldid) {
             $oldid = $wgRequest->getVal('oldid2');
         }
         $de = new DifferenceEngine($title, $oldid, $diff, $rcid);
         $de->loadText();
         $otext = $de->mOldtext;
         $ntext = $de->mNewtext;
         $ota = explode("\n", $wgContLang->segmentForDiff($otext));
         $nta = explode("\n", $wgContLang->segmentForDiff($ntext));
         $diffs = new Diff($ota, $nta);
         foreach ($diffs->edits as $edit) {
             if ($edit->type != 'copy' && $edit->closing != "") {
                 $text .= implode("\n", $edit->closing) . "\n";
             }
         }
     } else {
         if ($title != "") {
             $a = new Article($title);
             $text = $a->getContent(true);
         }
     }
     $matches = array();
     $preg = "/http:\\/\\/[^] \n'\"\\>\\<]*/im";
     preg_match_all($preg, $text, $matches);
     if (sizeof($matches[0]) == 0) {
         $wgOut->addHTML(wfMsg('spamdifftool_no_urls_detected', $wgScript . "?" . urldecode($wgRequest->getVal('returnto'))));
         return;
     }
     $wgOut->addHTML("\n\t\t\t<form method='POST'>\n\t\t\t\t\t<input type='hidden' name='returnto' value=\"" . htmlspecialchars($wgRequest->getVal('returnto')) . "\">\n\t\t\t\t<style type='text/css'>\n\t\t\t\t\t\ttd.spam-url-row {\n\t\t\t\t\t\t\tborder: 1px solid #ccc;\n\t\t\t\t\t\t}\n\t\t\t\t</style> " . wfMsg('spamdifftool_urls_detected') . "\n\t\t\t<br/><br/><table cellpadding='5px' width='100%'>");
     $urls = array();
     foreach ($matches as $match) {
         foreach ($match as $url) {
             if (isset($urls[$url])) {
                 continue;
             }
             // avoid dupes
             $urls[$url] = true;
             $name = htmlspecialchars(str_replace(".", "%2E", $url));
             $wgOut->addHTML("<tr>\n\t\t\t\t\t<td class='spam-url-row'><b>{$url}</b><br/>\n\t\t\t\t\t" . wfMsg('spamdifftool_block') . " &nbsp;&nbsp;\n\t\t\t\t\t<INPUT type='radio' name=\"" . $name . "\"\tvalue='domain' checked> " . wfMsg('spamdifftool_option_domain') . "\n\t\t\t\t\t<INPUT type='radio' name=\"" . $name . "\"\tvalue='subdomain'> " . wfMsg('spamdifftool_option_subdomain') . "\n\t\t\t\t\t<INPUT type='radio' name=\"" . $name . "\"\tvalue='dir'>" . wfMsg('spamdifftool_option_directory') . "\n\t\t\t\t\t<INPUT type='radio' name=\"" . $name . "\"\tvalue='none'>" . wfMsg('spamdifftool_option_none') . "\n\t\t\t\t</td>\n\t\t\t\t</tr>\n\t\t\t\t");
         }
     }
     $wgOut->addHTML("</table><input type=submit value=\"" . htmlspecialchars(wfMsg('submit')) . "\"></form>");
     // DifferenceEngine directly fetched the revision:
     $RevIdFetched = $de->mNewid;
 }
Example #26
0
    function execute($par)
    {
        global $wgRequest, $wgUser, $wgOut, $wgLang, $wgServer;
        wfLoadExtensionMessages('UserTalkTool');
        // CHECK FOR ADMIN STATUS
        if (!in_array('sysop', $wgUser->getGroups())) {
            $wgOut->setArticleRelated(false);
            $wgOut->setRobotpolicy('noindex,nofollow');
            $wgOut->errorpage('nosuchspecialpage', 'nospecialpagetext');
            return;
        }
        // MAKE SURE USER IS NOT BLOCKED
        if ($wgUser->isBlocked()) {
            $wgOut->blockedPage();
            return;
        }
        // CHECK FOR TARGET
        $target = isset($par) ? $par : $wgRequest->getVal('target');
        if ($target == null || $target == "") {
            $wgOut->addHTML('No target specified');
            return;
        }
        $dbw = wfGetDB(DB_MASTER);
        $dbr = wfGetDB(DB_SLAVE);
        $me = Title::makeTitle(NS_SPECIAL, "UserTalkTool");
        // PROCESS FORM
        //
        //
        if ($wgRequest->wasPosted()) {
            $wgOut->setArticleBodyOnly(true);
            $utmsg = $wgRequest->getVal('utmessage');
            if ($utmsg != "") {
                #$t = Title::newFromID($aid);
                $ts = wfTimestampNow();
                $user = $wgUser->getName();
                $real_name = User::whoIsReal($wgUser->getID());
                if ($real_name == "") {
                    $real_name = $user;
                }
                //User
                //
                //
                $utitem = $wgRequest->getVal('utuser');
                wfDebug("UTT: posting user: {$utitem}\n");
                wfDebug("UTT: by admin user: "******"\n");
                if ($utitem != "") {
                    // POST USER TALK PAGE
                    //
                    //
                    $text = "";
                    $aid = "";
                    $a = "";
                    $formattedComment = "";
                    $u = new User();
                    $u->setName($utitem);
                    $user_talk = $u->getTalkPage();
                    $dateStr = $wgLang->timeanddate(wfTimestampNow());
                    $formattedComment = wfMsg('postcomment_formatted_comment', $dateStr, $user, $real_name, mysql_real_escape_string($utmsg));
                    $aid = $user_talk->getArticleId();
                    if ($aid > 0) {
                        $r = Revision::newFromTitle($user_talk);
                        $text = $r->getText();
                    }
                    $a = new Article($user_talk);
                    $text .= "\n\n{$formattedComment}\n\n";
                    if ($aid > 0) {
                        $a->updateArticle($text, "", true, false, false, '', true);
                    } else {
                        $a->insertNewArticle($text, "", true, false, true, false, false);
                    }
                    // MARK CHANGES PATROLLED
                    //
                    //
                    $res = $dbr->select('recentchanges', 'max(rc_id) as rc_id', array('rc_title=\'' . mysql_real_escape_string($utitem) . '\'', 'rc_user='******'rc_cur_id=' . $aid, 'rc_patrolled=0'));
                    while ($row = $dbr->fetchObject($res)) {
                        wfDebug("UTT: mark patroll rcid: " . $row->rc_id . " \n");
                        RecentChange::markPatrolled($row->rc_id);
                        PatrolLog::record($row->rc_id, false);
                    }
                    $dbr->freeResult($res);
                    wfDebug("UTT: done\n");
                    wfDebug("UTT: Completed posting for [" . $utitem . "]\n");
                    $wgOut->addHTML("Completed posting for - " . $utitem);
                } else {
                    wfDebug("UTT: No user\n");
                    $wgOut->addHTML("UT_MSG ERROR: No user specified. \n");
                }
            } else {
                wfDebug("UTT: No message to post\n");
                $wgOut->addHTML("UT_MSG ERROR: No message to post for - " . $utitem . "\n");
                return;
            }
            $wgOut->redirect('');
        } else {
            $sk = $wgUser->getSkin();
            $wgOut->addHTML('
<script language="javascript" src="/extensions/wikihow/common/prototype1.8.2/prototype.js"></script>
<script language="javascript" src="/extensions/wikihow/common/prototype1.8.2/effects.js"></script>
<script language="javascript" src="/extensions/wikihow/common/prototype1.8.2/controls.js"></script>
		' . "\n");
            $wgOut->addHTML("\n\t\t\t<script type='text/javascript'>\n\t\t\t\tfunction utSend () {\n\n\t\t\t\t\t\$('formdiv').style.display = 'none';\n\t\t\t\t\t\$('resultdiv').innerHTML = 'Sending...<br />';\n\n\t\t\t\t\tliArray = document.getElementById('ut_ol').childNodes;\n\t\t\t\t\ti=0;\n\t\t\t\t\twhile(liArray[i]){\n\t\t\t\t\t\tif (document.getElementById(liArray[i].id)) {\n\t\t\t\t\t\t\tif (liArray[i].getAttribute('id').match(/^ut_li_/)) {\n\n\t\t\t\t\t\t\t\tdocument.forms['utForm'].utuser.value = liArray[i].getAttribute('id').replace('ut_li_','');\n\t\t\t\t\t\t\t\t\$('utForm').request({\n\t\t\t\t\t\t\t\t\tasynchronous: false,\n\t\t\t\t\t\t\t\t\tonComplete: function(transport) {\n\t\t\t\t\t\t\t\t\t\t\$('resultdiv').innerHTML += transport.responseText+'<br />';\n\t\t\t\t\t\t\t\t\t\tif (transport.responseText.match(/Completed posting for - /)){\n\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\t\t\tvar u = transport.responseText.replace(/Completed posting for - /,'');\n\t\t\t\t\t\t\t\t\t\t\t//\$('resultdiv').innerHTML += 'UID: '+u+'<br />';\n\t\t\t\t\t\t\t\t\t\t\t\$('ut_li_'+u).innerHTML +=  '  <img src=\"/skins/WikiHow/light_green_check.png\" height=\"15\" width=\"15\" />';\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tonFailure: function(transport) {\n\t\t\t\t\t\t\t\t\t\t\$('resultdiv').innerHTML += 'Sending returned error for '+liArray[i].id+' <br />';\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t//\$('resultdiv').innerHTML += 'Sending '+liArray[i].id+'<br />';\n\t\t\t\t\t\t \t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\ti++;\n\n\t\t\t\t\t}\n\t\t\t\t\t\n\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t</script>\n\t\t\t\n\t\t\t");
            // GET LIST OF RECIPIENTS
            //
            //
            if ($target) {
                $t = Title::newFromUrl($target);
                if ($t->getArticleId() <= 0) {
                    $wgOut->addHTML("Target not a valid article.");
                    return;
                } else {
                    $r = Revision::newFromTitle($t);
                    $text = $r->getText();
                    #$wgOut->addHTML( $text );
                    $utcount = preg_match_all('/\\[\\[User_talk:(.*?)[#\\]\\|]/', $text, $matches);
                    #print_r($matches);
                    $utlist = $matches[1];
                }
            }
            // DISPLAY COUNT OF USER TALK PAGES FOUND
            //
            //
            if (count($utlist) == 0) {
                $wgOut->addHTML(wfMsg('notalkpagesfound'));
                return;
            } else {
                $wgOut->addHTML(count($utlist) . ' ' . wfMsg('talkpagesfound') . "<br />");
            }
            // TEXTAREA and FORM
            //
            //
            $wgOut->addHTML('
<form id="utForm" method="post">
				');
            // DISPLAY LIST OF USER TALK PAGES
            //
            //
            $wgOut->addHTML('<div id="utlist" style="border: 1px grey solid;margin: 15px 0px 15px 0px;padding: 15px;height:215px;overflow:auto"><ol id="ut_ol">' . "\n");
            foreach ($utlist as $utitem) {
                $wgOut->addHTML('<li id="ut_li_' . preg_replace('/\\s/m', '-', $utitem) . '"><a href="/User_talk:' . $utitem . '">' . $utitem . '</a></li>' . "\n");
            }
            $wgOut->addHTML('</ol></div>' . "\n");
            // TEXTAREA and FORM
            //
            //
            $wgOut->addHTML('
<div id="formdiv">
' . wfMsg('sendbox') . '<br />
<textarea id="utmessage" name="utmessage" rows="6" style="margin: 5px 0px 5px 0px;"></textarea>
<input id="utuser" type="hidden" name="utuser" value="">

<input tabindex="4" type="button" value="Send" cl1ass="btn" id="postcommentbutton" style="font-size: 110%; font-weight:bold" onclick="utSend(); return false;" />


</form>
</div>
<div id="resultdiv"></div>' . "\n");
        }
    }
Example #27
0
<?php

require_once "commandLine.inc";
$wgUser->setId(1236204);
$dbr =& wfGetDB(DB_SLAVE);
$res = $dbr->query('select page_title, page_namespace, page_id  from templatelinks, page  where tl_from=page_id and tl_title=\'Nfd\';');
while ($row = $dbr->fetchObject($res)) {
    $title = Title::makeTitle($row->page_namespace, $row->page_title);
    $wgTitle = $title;
    $revision = Revision::newFromTitle($title);
    $text = $revision->getText();
    if (strpos($text, "{{nfd") !== false && strpos($text, "mo/day=") !== false) {
        $text = str_replace("mo/day=09/", "date=2007-09-", $text);
        //echo $text; break;
        $a = new Article(&$title);
        $a->updateArticle($text, "Changing format of NFD", true, false);
        echo "updating {$title->getFullURL()}\n";
        //break;
    } else {
        echo "NOT UPDATING {$title->getFullURL()}\n";
    }
}
$dbr->freeResult($res);