コード例 #1
0
function migrateGroup($group)
{
    $groups = parseGroupFile();
    if (!isset($groups[$group])) {
        return false;
    }
    $group = $groups[$group];
    global $wgAuth;
    $dbw = $wgAuth->getDB(DB_WRITE);
    if (false == $dbw->insert('groups', array('grp_name' => $group['name'], 'grp_password' => $group['password'], 'grp_gid' => $group['gid']), __METHOD__)) {
        return false;
    }
    foreach ($group['members'] as $user) {
        $pwd = posix_getpwnam($user);
        if (!$pwd) {
            return false;
        }
        print "Migrating {$pwd['name']}\n";
        if (false == $dbw->insert('group_membership', array('gm_group' => $group['name'], 'gm_user' => $pwd['uid']), __METHOD__)) {
            $dbw->rollback();
            return false;
        }
    }
    $dbw->commit();
    wfDoUpdates();
    return true;
}
コード例 #2
0
 public function execute()
 {
     wfProfileIn(__METHOD__);
     //run the download:
     Http::doSessionIdDownload($this->getOption('sid'), $this->getOption('usk'));
     // close up shop:
     // Execute any deferred updates
     wfDoUpdates();
     // Log what the user did, for book-keeping purposes.
     wfLogProfilingData();
     // Shut down the database before exit
     wfGetLBFactory()->shutdown();
     wfProfileOut(__METHOD__);
 }
コード例 #3
0
ファイル: cleanupSpam.php プロジェクト: puring0815/OpenKore
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();
    }
}
コード例 #4
0
function migrateUser($username, $email)
{
    $pwd = posix_getpwnam($username);
    if (!$pwd) {
        return false;
    }
    // PHP sucks
    list($password, $password_lastchange) = getspwd($username);
    if (is_null($password) || is_null($password_lastchange)) {
        return false;
    }
    global $wgAuth;
    $dbw = $wgAuth->getDB(DB_WRITE);
    if (false == $dbw->insert('passwd', array('pwd_uid' => $pwd['uid'], 'pwd_name' => $pwd['name'], 'pwd_password' => $password, 'pwd_password_lastchange' => $password_lastchange, 'pwd_gid' => $pwd['gid'], 'pwd_home' => $pwd['dir'], 'pwd_shell' => $pwd['shell'], 'pwd_active' => 'active', 'pwd_email' => $email), __METHOD__)) {
        return false;
    }
    if (false == $dbw->insert('user_props', array('up_timestamp' => $dbw->timestamp(), 'up_user' => $username, 'up_name' => 'email', 'up_value' => $email), __METHOD__)) {
        return false;
    }
    $dbw->commit();
    wfDoUpdates();
    return true;
}
コード例 #5
0
/** 
 * 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();
}
コード例 #6
0
ファイル: api.php プロジェクト: ui-libraries/TIRW
    $url = $_SERVER['PHP_SELF'];
}
if (strcmp("{$wgScriptPath}/api{$wgScriptExtension}", $url)) {
    wfHttpError(403, 'Forbidden', 'API must be accessed through the primary script entry point.');
    return;
}
// Verify that the API has not been disabled
if (!$wgEnableAPI) {
    echo 'MediaWiki API is not enabled for this site. Add the following line to your LocalSettings.php';
    echo '<pre><b>$wgEnableAPI=true;</b></pre>';
    die(1);
}
// So extensions can check whether they're running in API mode
define('MW_API', true);
// Set a dummy $wgTitle, because $wgTitle == null breaks various things
// In a perfect world this wouldn't be necessary
$wgTitle = Title::newFromText('API');
/* Construct an ApiMain with the arguments passed via the URL. What we get back
 * is some form of an ApiMain, possibly even one that produces an error message,
 * but we don't care here, as that is handled by the ctor.
 */
$processor = new ApiMain($wgRequest, $wgEnableWriteAPI);
// Process data & print results
$processor->execute();
// Execute any deferred updates
wfDoUpdates();
// Log what the user did, for book-keeping purposes.
wfProfileOut('api.php');
wfLogProfilingData();
// Shut down the database
wfGetLBFactory()->shutdown();
コード例 #7
0
ファイル: Wiki.php プロジェクト: GodelDesign/Godel
 /**
  * Cleaning up request by doing:
  ** deferred updates, DB transaction, and the output
  *
  * @param $output OutputPage
  */
 function finalCleanup(&$output)
 {
     wfProfileIn(__METHOD__);
     // Now commit any transactions, so that unreported errors after
     // output() don't roll back the whole DB transaction
     $factory = wfGetLBFactory();
     $factory->commitMasterChanges();
     // Output everything!
     $output->output();
     // Do any deferred jobs
     wfDoUpdates(true);
     $this->doJobs();
     wfProfileOut(__METHOD__);
 }
コード例 #8
0
ファイル: Article.php プロジェクト: GodelDesign/Godel
 /**
  * Article::doEdit()
  *
  * Change an existing article or create a new article. Updates RC and all necessary caches,
  * optionally via the deferred update array.
  *
  * $wgUser must be set before calling this function.
  *
  * @param $text String: new text
  * @param $summary String: edit summary
  * @param $flags Integer bitfield:
  *      EDIT_NEW
  *          Article is known or assumed to be non-existent, create a new one
  *      EDIT_UPDATE
  *          Article is known or assumed to be pre-existing, update it
  *      EDIT_MINOR
  *          Mark this edit minor, if the user is allowed to do so
  *      EDIT_SUPPRESS_RC
  *          Do not log the change in recentchanges
  *      EDIT_FORCE_BOT
  *          Mark the edit a "bot" edit regardless of user rights
  *      EDIT_DEFER_UPDATES
  *          Defer some of the updates until the end of index.php
  *      EDIT_AUTOSUMMARY
  *          Fill in blank summaries with generated text where possible
  *
  * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected.
  * If EDIT_UPDATE is specified and the article doesn't exist, the function will an
  * edit-gone-missing error. If EDIT_NEW is specified and the article does exist, an
  * edit-already-exists error will be returned. These two conditions are also possible with
  * auto-detection due to MediaWiki's performance-optimised locking strategy.
  *
  * @param $baseRevId the revision ID this edit was based off, if any
  * @param $user Optional user object, $wgUser will be used if not passed
  *
  * @return Status object. Possible errors:
  *     edit-hook-aborted:       The ArticleSave hook aborted the edit but didn't set the fatal flag of $status
  *     edit-gone-missing:       In update mode, but the article didn't exist
  *     edit-conflict:           In update mode, the article changed unexpectedly
  *     edit-no-change:          Warning that the text was the same as before
  *     edit-already-exists:     In creation mode, but the article already exists
  *
  *  Extensions may define additional errors.
  *
  *  $return->value will contain an associative array with members as follows:
  *     new:                     Boolean indicating if the function attempted to create a new article
  *     revision:                The revision object for the inserted revision, or null
  *
  *  Compatibility note: this function previously returned a boolean value indicating success/failure
  */
 public function doEdit($text, $summary, $flags = 0, $baseRevId = false, $user = null)
 {
     global $wgUser, $wgDBtransactions, $wgUseAutomaticEditSummaries;
     # Low-level sanity check
     if ($this->mTitle->getText() === '') {
         throw new MWException('Something is trying to edit an article with an empty title');
     }
     wfProfileIn(__METHOD__);
     $user = is_null($user) ? $wgUser : $user;
     $status = Status::newGood(array());
     # Load $this->mTitle->getArticleID() and $this->mLatest if it's not already
     $this->loadPageData();
     $flags = $this->checkFlags($flags);
     if (!wfRunHooks('ArticleSave', array(&$this, &$user, &$text, &$summary, $flags & EDIT_MINOR, null, null, &$flags, &$status))) {
         wfDebug(__METHOD__ . ": ArticleSave hook aborted save!\n");
         if ($status->isOK()) {
             $status->fatal('edit-hook-aborted');
         }
         wfProfileOut(__METHOD__);
         return $status;
     }
     # Silently ignore EDIT_MINOR if not allowed
     $isminor = $flags & EDIT_MINOR && $user->isAllowed('minoredit');
     $bot = $flags & EDIT_FORCE_BOT;
     $oldtext = $this->getRawText();
     // current revision
     $oldsize = strlen($oldtext);
     # Provide autosummaries if one is not provided and autosummaries are enabled.
     if ($wgUseAutomaticEditSummaries && $flags & EDIT_AUTOSUMMARY && $summary == '') {
         $summary = $this->getAutosummary($oldtext, $text, $flags);
     }
     $editInfo = $this->prepareTextForEdit($text);
     $text = $editInfo->pst;
     $newsize = strlen($text);
     $dbw = wfGetDB(DB_MASTER);
     $now = wfTimestampNow();
     $this->mTimestamp = $now;
     if ($flags & EDIT_UPDATE) {
         # Update article, but only if changed.
         $status->value['new'] = false;
         # Make sure the revision is either completely inserted or not inserted at all
         if (!$wgDBtransactions) {
             $userAbort = ignore_user_abort(true);
         }
         $changed = strcmp($text, $oldtext) != 0;
         if ($changed) {
             $this->mGoodAdjustment = (int) $this->isCountable($text) - (int) $this->isCountable($oldtext);
             $this->mTotalAdjustment = 0;
             if (!$this->mLatest) {
                 # Article gone missing
                 wfDebug(__METHOD__ . ": EDIT_UPDATE specified but article doesn't exist\n");
                 $status->fatal('edit-gone-missing');
                 wfProfileOut(__METHOD__);
                 return $status;
             }
             $revision = new Revision(array('page' => $this->getId(), 'comment' => $summary, 'minor_edit' => $isminor, 'text' => $text, 'parent_id' => $this->mLatest, 'user' => $user->getId(), 'user_text' => $user->getName()));
             $dbw->begin();
             $revisionId = $revision->insertOn($dbw);
             # Update page
             #
             # Note that we use $this->mLatest instead of fetching a value from the master DB
             # during the course of this function. This makes sure that EditPage can detect
             # edit conflicts reliably, either by $ok here, or by $article->getTimestamp()
             # before this function is called. A previous function used a separate query, this
             # creates a window where concurrent edits can cause an ignored edit conflict.
             $ok = $this->updateRevisionOn($dbw, $revision, $this->mLatest);
             if (!$ok) {
                 /* Belated edit conflict! Run away!! */
                 $status->fatal('edit-conflict');
                 # Delete the invalid revision if the DB is not transactional
                 if (!$wgDBtransactions) {
                     $dbw->delete('revision', array('rev_id' => $revisionId), __METHOD__);
                 }
                 $revisionId = 0;
                 $dbw->rollback();
             } else {
                 global $wgUseRCPatrol;
                 wfRunHooks('NewRevisionFromEditComplete', array($this, $revision, $baseRevId, $user));
                 # Update recentchanges
                 if (!($flags & EDIT_SUPPRESS_RC)) {
                     # Mark as patrolled if the user can do so
                     $patrolled = $wgUseRCPatrol && $this->mTitle->userCan('autopatrol');
                     # Add RC row to the DB
                     $rc = RecentChange::notifyEdit($now, $this->mTitle, $isminor, $user, $summary, $this->mLatest, $this->getTimestamp(), $bot, '', $oldsize, $newsize, $revisionId, $patrolled);
                     # Log auto-patrolled edits
                     if ($patrolled) {
                         PatrolLog::record($rc, true);
                     }
                 }
                 $user->incEditCount();
                 $dbw->commit();
             }
         } else {
             $status->warning('edit-no-change');
             $revision = null;
             // Keep the same revision ID, but do some updates on it
             $revisionId = $this->getRevIdFetched();
             // Update page_touched, this is usually implicit in the page update
             // Other cache updates are done in onArticleEdit()
             $this->mTitle->invalidateCache();
         }
         if (!$wgDBtransactions) {
             ignore_user_abort($userAbort);
         }
         // Now that ignore_user_abort is restored, we can respond to fatal errors
         if (!$status->isOK()) {
             wfProfileOut(__METHOD__);
             return $status;
         }
         # Invalidate cache of this article and all pages using this article
         # as a template. Partly deferred.
         Article::onArticleEdit($this->mTitle);
         # Update links tables, site stats, etc.
         $this->editUpdates($text, $summary, $isminor, $now, $revisionId, $changed);
     } else {
         # Create new article
         $status->value['new'] = true;
         # Set statistics members
         # We work out if it's countable after PST to avoid counter drift
         # when articles are created with {{subst:}}
         $this->mGoodAdjustment = (int) $this->isCountable($text);
         $this->mTotalAdjustment = 1;
         $dbw->begin();
         # Add the page record; stake our claim on this title!
         # This will return false if the article already exists
         $newid = $this->insertOn($dbw);
         if ($newid === false) {
             $dbw->rollback();
             $status->fatal('edit-already-exists');
             wfProfileOut(__METHOD__);
             return $status;
         }
         # Save the revision text...
         $revision = new Revision(array('page' => $newid, 'comment' => $summary, 'minor_edit' => $isminor, 'text' => $text, 'user' => $user->getId(), 'user_text' => $user->getName()));
         $revisionId = $revision->insertOn($dbw);
         $this->mTitle->resetArticleID($newid);
         # Update the page record with revision data
         $this->updateRevisionOn($dbw, $revision, 0);
         wfRunHooks('NewRevisionFromEditComplete', array($this, $revision, false, $user));
         # Update recentchanges
         if (!($flags & EDIT_SUPPRESS_RC)) {
             global $wgUseRCPatrol, $wgUseNPPatrol;
             # Mark as patrolled if the user can do so
             $patrolled = ($wgUseRCPatrol || $wgUseNPPatrol) && $this->mTitle->userCan('autopatrol');
             # Add RC row to the DB
             $rc = RecentChange::notifyNew($now, $this->mTitle, $isminor, $user, $summary, $bot, '', strlen($text), $revisionId, $patrolled);
             # Log auto-patrolled edits
             if ($patrolled) {
                 PatrolLog::record($rc, true);
             }
         }
         $user->incEditCount();
         $dbw->commit();
         # Update links, etc.
         $this->editUpdates($text, $summary, $isminor, $now, $revisionId, true);
         # Clear caches
         Article::onArticleCreate($this->mTitle);
         wfRunHooks('ArticleInsertComplete', array(&$this, &$user, $text, $summary, $flags & EDIT_MINOR, null, null, &$flags, $revision));
     }
     # Do updates right now unless deferral was requested
     if (!($flags & EDIT_DEFER_UPDATES)) {
         wfDoUpdates();
     }
     // Return the new revision (or null) to the caller
     $status->value['revision'] = $revision;
     wfRunHooks('ArticleSaveComplete', array(&$this, &$user, $text, $summary, $flags & EDIT_MINOR, null, null, &$flags, $revision, &$status, $baseRevId));
     wfProfileOut(__METHOD__);
     return $status;
 }
コード例 #9
0
ファイル: Article.php プロジェクト: negabaro/alfresco
 /**
  * Article::doEdit()
  *
  * Change an existing article or create a new article. Updates RC and all necessary caches, 
  * optionally via the deferred update array.
  *
  * $wgUser must be set before calling this function.
  *
  * @param string $text New text
  * @param string $summary Edit summary
  * @param integer $flags bitfield:
  *      EDIT_NEW
  *          Article is known or assumed to be non-existent, create a new one
  *      EDIT_UPDATE
  *          Article is known or assumed to be pre-existing, update it
  *      EDIT_MINOR
  *          Mark this edit minor, if the user is allowed to do so
  *      EDIT_SUPPRESS_RC
  *          Do not log the change in recentchanges
  *      EDIT_FORCE_BOT
  *          Mark the edit a "bot" edit regardless of user rights
  *      EDIT_DEFER_UPDATES
  *          Defer some of the updates until the end of index.php
  *      EDIT_AUTOSUMMARY
  *          Fill in blank summaries with generated text where possible
  * 
  * If neither EDIT_NEW nor EDIT_UPDATE is specified, the status of the article will be detected. 
  * If EDIT_UPDATE is specified and the article doesn't exist, the function will return false. If 
  * EDIT_NEW is specified and the article does exist, a duplicate key error will cause an exception
  * to be thrown from the Database. These two conditions are also possible with auto-detection due
  * to MediaWiki's performance-optimised locking strategy.
  *
  * @return bool success
  */
 function doEdit($text, $summary, $flags = 0)
 {
     global $wgUser, $wgDBtransactions;
     wfProfileIn(__METHOD__);
     $good = true;
     if (!($flags & EDIT_NEW) && !($flags & EDIT_UPDATE)) {
         $aid = $this->mTitle->getArticleID(GAID_FOR_UPDATE);
         if ($aid) {
             $flags |= EDIT_UPDATE;
         } else {
             $flags |= EDIT_NEW;
         }
     }
     if (!wfRunHooks('ArticleSave', array(&$this, &$wgUser, &$text, &$summary, $flags & EDIT_MINOR, null, null, &$flags))) {
         wfDebug(__METHOD__ . ": ArticleSave hook aborted save!\n");
         wfProfileOut(__METHOD__);
         return false;
     }
     # Silently ignore EDIT_MINOR if not allowed
     $isminor = $flags & EDIT_MINOR && $wgUser->isAllowed('minoredit');
     $bot = $wgUser->isAllowed('bot') || $flags & EDIT_FORCE_BOT;
     $oldtext = $this->getContent();
     $oldsize = strlen($oldtext);
     # Provide autosummaries if one is not provided.
     if ($flags & EDIT_AUTOSUMMARY && $summary == '') {
         $summary = $this->getAutosummary($oldtext, $text, $flags);
     }
     $text = $this->preSaveTransform($text);
     $newsize = strlen($text);
     $dbw =& wfGetDB(DB_MASTER);
     $now = wfTimestampNow();
     if ($flags & EDIT_UPDATE) {
         # Update article, but only if changed.
         # Make sure the revision is either completely inserted or not inserted at all
         if (!$wgDBtransactions) {
             $userAbort = ignore_user_abort(true);
         }
         $lastRevision = 0;
         $revisionId = 0;
         if (0 != strcmp($text, $oldtext)) {
             $this->mGoodAdjustment = (int) $this->isCountable($text) - (int) $this->isCountable($oldtext);
             $this->mTotalAdjustment = 0;
             $lastRevision = $dbw->selectField('page', 'page_latest', array('page_id' => $this->getId()));
             if (!$lastRevision) {
                 # Article gone missing
                 wfDebug(__METHOD__ . ": EDIT_UPDATE specified but article doesn't exist\n");
                 wfProfileOut(__METHOD__);
                 return false;
             }
             $revision = new Revision(array('page' => $this->getId(), 'comment' => $summary, 'minor_edit' => $isminor, 'text' => $text));
             $dbw->begin();
             $revisionId = $revision->insertOn($dbw);
             # Update page
             $ok = $this->updateRevisionOn($dbw, $revision, $lastRevision);
             if (!$ok) {
                 /* Belated edit conflict! Run away!! */
                 $good = false;
                 $dbw->rollback();
             } else {
                 # Update recentchanges
                 if (!($flags & EDIT_SUPPRESS_RC)) {
                     $rcid = RecentChange::notifyEdit($now, $this->mTitle, $isminor, $wgUser, $summary, $lastRevision, $this->getTimestamp(), $bot, '', $oldsize, $newsize, $revisionId);
                     # Mark as patrolled if the user can do so
                     if ($wgUser->isAllowed('autopatrol')) {
                         RecentChange::markPatrolled($rcid);
                     }
                 }
                 $wgUser->incEditCount();
                 $dbw->commit();
             }
         } else {
             // Keep the same revision ID, but do some updates on it
             $revisionId = $this->getRevIdFetched();
             // Update page_touched, this is usually implicit in the page update
             // Other cache updates are done in onArticleEdit()
             $this->mTitle->invalidateCache();
         }
         if (!$wgDBtransactions) {
             ignore_user_abort($userAbort);
         }
         if ($good) {
             # Invalidate cache of this article and all pages using this article
             # as a template. Partly deferred.
             Article::onArticleEdit($this->mTitle);
             # Update links tables, site stats, etc.
             $changed = strcmp($oldtext, $text) != 0;
             $this->editUpdates($text, $summary, $isminor, $now, $revisionId, $changed);
         }
     } else {
         # Create new article
         # Set statistics members
         # We work out if it's countable after PST to avoid counter drift
         # when articles are created with {{subst:}}
         $this->mGoodAdjustment = (int) $this->isCountable($text);
         $this->mTotalAdjustment = 1;
         $dbw->begin();
         # Add the page record; stake our claim on this title!
         # This will fail with a database query exception if the article already exists
         $newid = $this->insertOn($dbw);
         # Save the revision text...
         $revision = new Revision(array('page' => $newid, 'comment' => $summary, 'minor_edit' => $isminor, 'text' => $text));
         $revisionId = $revision->insertOn($dbw);
         $this->mTitle->resetArticleID($newid);
         # Update the page record with revision data
         $this->updateRevisionOn($dbw, $revision, 0);
         if (!($flags & EDIT_SUPPRESS_RC)) {
             $rcid = RecentChange::notifyNew($now, $this->mTitle, $isminor, $wgUser, $summary, $bot, '', strlen($text), $revisionId);
             # Mark as patrolled if the user can
             if ($wgUser->isAllowed('autopatrol')) {
                 RecentChange::markPatrolled($rcid);
             }
         }
         $wgUser->incEditCount();
         $dbw->commit();
         # Update links, etc.
         $this->editUpdates($text, $summary, $isminor, $now, $revisionId, true);
         # Clear caches
         Article::onArticleCreate($this->mTitle);
         wfRunHooks('ArticleInsertComplete', array(&$this, &$wgUser, $text, $summary, $flags & EDIT_MINOR, null, null, &$flags));
     }
     if ($good && !($flags & EDIT_DEFER_UPDATES)) {
         wfDoUpdates();
     }
     wfRunHooks('ArticleSaveComplete', array(&$this, &$wgUser, $text, $summary, $flags & EDIT_MINOR, null, null, &$flags));
     wfProfileOut(__METHOD__);
     return $good;
 }
コード例 #10
0
 function cleanupArticle($id, $domain, $link = "")
 {
     global $wgOut, $wgUser;
     $username = wfMsg('spambot_username');
     $fname = $username;
     $title = Title::newFromID($id);
     if (!$title) {
         return;
     }
     /* switch the user here */
     $OldUser = $wgUser;
     $wgUser = User::newFromName($username);
     /* Create the user if necessary */
     if (!$wgUser->getID()) {
         $wgUser->addToDatabase();
     }
     $rev = Revision::newFromTitle($title);
     $reverted = false;
     $revId = $rev->getId();
     $currentRevId = $revId;
     if ("" == $link) {
         $regex = $this->makeRegex($domain);
     } else {
         /* we had a regex ready */
         $regex = $domain;
         $domain = $link;
     }
     while ($rev && preg_match($regex, $rev->getText())) {
         $revId = $title->getPreviousRevisionID($revId);
         if ($revId) {
             $rev = Revision::newFromTitle($title, $revId);
         } else {
             $rev = false;
         }
     }
     if ($revId == $currentRevId) {
         /* ... */
     } else {
         $sk = $wgUser->getSkin();
         $page_link = $sk->makeKnownLinkObj($title, $title->getText());
         $dbw =& wfGetDB(DB_MASTER);
         $dbw->immediateBegin();
         if (!$rev) {
             /* no clean revision found, blank the article */
             $article = new SilentArticle($title);
             $article->updateArticle('', wfMsg('spam_blanking', $domain), false, false);
             $wgOut->addHTML("Article {$page_link} has been blanked.<br/>");
         } else {
             /* revert to last clean version  */
             $article = new SilentArticle($title);
             $article->updateArticle($rev->getText(), wfMsg('spam_reverting', $domain), false, false);
             $wgOut->addHTML("Article {$page_link} has been reverted to latest change not containing link to <b>" . $domain . "</b>.<br/>");
         }
         $dbw->commit();
         wfDoUpdates();
     }
     $wgUser = $OldUser;
 }
コード例 #11
0
ファイル: importDump.php プロジェクト: eFFemeer/seizamcore
 function showReport()
 {
     if ($this->mQuiet) {
         $delta = wfTime() - $this->startTime;
         if ($delta) {
             $rate = sprintf("%.2f", $this->pageCount / $delta);
             $revrate = sprintf("%.2f", $this->revCount / $delta);
         } else {
             $rate = '-';
             $revrate = '-';
         }
         # Logs dumps don't have page tallies
         if ($this->pageCount) {
             $this->progress("{$this->pageCount} ({$rate} pages/sec {$revrate} revs/sec)");
         } else {
             $this->progress("{$this->revCount} ({$revrate} revs/sec)");
         }
     }
     wfWaitForSlaves();
     // XXX: Don't let deferred jobs array get absurdly large (bug 24375)
     wfDoUpdates('commit');
 }
コード例 #12
0
ファイル: cleanupSpam.php プロジェクト: rocLv/conference
 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();
     }
 }
コード例 #13
0
ファイル: ProtectOwn.php プロジェクト: eFFemeer/seizamcore
function poArticleProtectComplete(&$article, &$user, $protect, $reason)
{
    // MediaWiki documentation indicates a fifth argument $moveonly (boolean whether it was
    // for move only or not), but there are only four args
    $title = $article->getTitle();
    wfDebugLog('ProtectOwn', 'ArticleProtectComplete: purging title cache' . ' title="' . $title->getPrefixedDBkey() . '"[' . $title->getArticleId() . ']');
    # purge page's restrictions
    $article->getTitle()->mRestrictions = array();
    $article->getTitle()->mRestrictionsLoaded = false;
    //$article->getTitle()->loadRestrictions();
    // Purge caches on page update etc
    WikiPage::onArticleEdit($title);
    // this put update in $wgDeferredUpdateList
    wfDoUpdates();
    // this execute all updates in $wgDeferredUpdateList
    // Update page_touched, this is usually implicit in the page update
    $title->invalidateCache();
    // ask mediawiki to reload search engine cache
    $u = new SearchUpdate($title->getArticleId(), $title->getPrefixedDBkey(), Revision::newFromTitle($title)->getText());
    $u->doUpdate();
    // will call wfRunHooks( 'SearchUpdate', array( $this->mId, $this->mNamespace, $this->mTitle, &$text ) );
    // continue hook processing
    return true;
}