Ejemplo n.º 1
0
 /**
  * EXECUTE
  **/
 function execute($par)
 {
     global $wgRequest, $wgOut, $wgUser, $wgLang, $wgParser, $wgHooks, $wgTitle, $wgStarterPages;
     $wgHooks['ShowBreadCrumbs'][] = array($this, 'removeBreadCrumbsCallback');
     //$wgHooks['WrapBodyWithArticleInner'][] = array($this, 'wrapBodyWithArticleInner');
     wfLoadExtensionMessages('StarterTool');
     self::setTemplatePath();
     if ($wgUser->isBlocked()) {
         $wgOut->blockedPage();
         return;
     }
     $referral = $wgRequest->getVal('ref');
     //get contents
     if ($wgRequest->getVal('edit')) {
         $wgOut->setArticleBodyOnly(true);
         $sentenceNum = $wgRequest->getVal('starter_title');
         $sentence = $this->getSentence($sentenceNum);
         $sentence = preg_replace('@<[/]?(span|[ovwxp]:\\w+)[^>]*?>@', '', $sentence);
         $vars = array('sentence' => $sentence);
         $html = EasyTemplate::html('edit', $vars);
         $wgOut->addHTML($html);
         return;
     } elseif ($wgRequest->getVal('finish')) {
         $finishNum = "Finish-" . $wgRequest->getVal('finish');
         self::logInfo($finishNum);
     } elseif ($wgRequest->getVal('editNum')) {
         $editNum = "Edit-" . $wgRequest->getVal('editNum');
         self::logInfo($editNum);
         if ($wgRequest->getVal('getsome')) {
             $wgOut->setArticleBodyOnly(true);
             $sentence = self::getSentence();
             $wgOut->addHTML($sentence);
             return;
         }
     } elseif ($wgRequest->getVal('getsome')) {
         $wgOut->setArticleBodyOnly(true);
         $sentence = self::getSentence();
         $wgOut->addHTML($sentence);
         return;
     } elseif ($wgRequest->getVal('action') == 'submit') {
         $wgOut->setArticleBodyOnly(true);
         $t = Title::newFromText($wgRequest->getVal('starter-title'));
         $a = new Article($t);
         //internal log
         if ($referral != "") {
             self::logInfo("submit");
         }
         //log it
         $params = array();
         $log = new LogPage('Starter_Tool', false);
         // false - dont show in recentchanges
         $log->addEntry('', $t, 'Fixed a sentence with the Starter Tool.', $params);
         $text = $wgRequest->getVal('wpTextbox1');
         $sum = $wgRequest->getVal('wpSummary');
         //save the edit
         if ($a->doEdit($text, $sum, EDIT_SUPPRESS_RC)) {
             //revert the edit for the next user
             $minRev = self::getFirstArticleRevision($t->getArticleId());
             //don't log rollback for the user
             $oldglobal = $wgUser;
             $wgUser = User::newFromName("MasterSockPuppet421");
             $dbr = wfGetDB(DB_SLAVE);
             $r = Revision::loadFromId($dbr, $minRev);
             $a->doEdit($r->getText(), 'Auto-rollback from Starter Tool.', EDIT_SUPPRESS_RC);
             // reset the wguser var
             $wgUser = $oldglobal;
             wfRunHooks("StarterToolSaveComplete", array($a, $text, $sum, $wgUser, $efType));
         }
         return;
     } else {
         //default; get a sentence
         if ($referral != "") {
             //log that they came in from the specific ad
             self::logInfo("Ad-" . $referral);
             setcookie(StarterTool::COOKIE_NAME, 1, 0);
         }
         $wgOut->addScript(HtmlSnips::makeUrlTags('css', array('starter.css'), 'extensions/wikihow/starter', false));
         $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('starter.js'), 'extensions/wikihow/starter', false));
         $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('clientscript.js'), 'skins/common/', false));
         $wgOut->addScript(HtmlSnips::makeUrlTags('js', array('jquery.cookie.js'), 'extensions/wikihow/common', false));
         $sk = $wgUser->getSkin();
         $wgOut->setArticleBodyOnly(false);
         $vars = array('pagetitle' => wfMsg('app-name'), 'question' => wfMsg('fix-this'), 'yep' => wfMsg('yep'), 'nope' => wfMsg('nope'));
         $html = EasyTemplate::html('starter', $vars);
         $wgOut->addHTML($html);
     }
     $wgOut->setHTMLTitle(wfMsg('pagetitle', wfMsg('app-name')));
 }
Ejemplo n.º 2
0
 static function util_ResolveRevSpec($page_title, $page_id = 0, $rev_id = 0)
 {
     global $wgTitle;
     $dbr =& wfGetDB(DB_SLAVE);
     if ($rev_id && !$page_id) {
         $rev = Revision::loadFromId($dbr, $rev_id);
         if ($rev) {
             $page_id = $rev->getPage();
         }
     }
     if ($page_id && !$page_title) {
         $wgTitle = Title::newFromID($page_id);
     }
     if ($page_title) {
         $wgTitle = Title::newFromDBkey($page_title);
     }
     $article = new Article($wgTitle);
     $title_db = $wgTitle->getDBkey();
     $page_id_db = $wgTitle->getArticleID();
     $rev_id_db = $article->getLatest();
     if (!$page_id) {
         $page_id = $page_id_db;
     }
     if (!$rev_id) {
         $rev_id = $rev_id_db;
     }
     if (!$page_title) {
         $page_title = $title_db;
     }
     if ($page_id != $page_id_db) {
         wfWikiTrustWarn(__FILE__ . ":" . __LINE__ . ": mismatched pageId: {$page_id} != {$page_id_db}");
     }
     if ($page_title != $title_db) {
         wfWikiTrustWarn(__FILE__ . ":" . __LINE__ . ": mismatched title: {$page_title} != {$title_db}");
     }
     return array($page_title, $page_id, $rev_id);
 }
	/**
	 * Load current revision of comment wikitext.
	 */
	public function loadText() {
		$dbr = wfGetDB( DB_SLAVE );
		$rev = Revision::loadFromId( $dbr, $this->mCommentRev );
		if ( $rev ) {
			$this->mText = $rev->getText();
			$this->mTextChanged = false;
		}
	}
Ejemplo n.º 4
0
 /**
  * @param string|number|null|bool $sectionId Section identifier as a number or string
  * (e.g. 0, 1 or 'T-1'), null/false or an empty string for the whole page
  * or 'new' for a new section.
  * @param Content $sectionContent New content of the section.
  * @param string $sectionTitle New section's subject, only if $section is "new".
  * @param int|null $baseRevId
  *
  * @throws MWException
  * @return Content New complete article content, or null if error.
  *
  * @since 1.24
  */
 public function replaceSectionAtRev($sectionId, Content $sectionContent, $sectionTitle = '', $baseRevId = null)
 {
     wfProfileIn(__METHOD__);
     if (strval($sectionId) === '') {
         // Whole-page edit; let the whole text through
         $newContent = $sectionContent;
     } else {
         if (!$this->supportsSections()) {
             wfProfileOut(__METHOD__);
             throw new MWException("sections not supported for content model " . $this->getContentHandler()->getModelID());
         }
         // Bug 30711: always use current version when adding a new section
         if (is_null($baseRevId) || $sectionId === 'new') {
             $oldContent = $this->getContent();
         } else {
             // TODO: try DB_SLAVE first
             $dbw = wfGetDB(DB_MASTER);
             $rev = Revision::loadFromId($dbw, $baseRevId);
             if (!$rev) {
                 wfDebug(__METHOD__ . " asked for bogus section (page: " . $this->getId() . "; section: {$sectionId})\n");
                 wfProfileOut(__METHOD__);
                 return null;
             }
             $oldContent = $rev->getContent();
         }
         if (!$oldContent) {
             wfDebug(__METHOD__ . ": no page text\n");
             wfProfileOut(__METHOD__);
             return null;
         }
         $newContent = $oldContent->replaceSection($sectionId, $sectionContent, $sectionTitle);
     }
     wfProfileOut(__METHOD__);
     return $newContent;
 }
Ejemplo n.º 5
0
<?php

require_once 'commandLine.inc';
# Export list of alternative methods for a list of articles to CSV file
$filename = $argv[0];
$f = fopen($filename, 'r');
$contents = fread($f, filesize($filename));
fclose($f);
$pages = preg_split('@[\\r\\n]+@', $contents);
foreach ($pages as $page) {
    $t = Title::newFromText($page);
    $gr = GoodRevision::newFromTitle($t);
    if ($gr) {
        $dbr = wfGetDB(DB_SLAVE);
        $lr = $gr->latestGood();
        $r = Revision::loadFromId($dbr, $lr);
        if ($r) {
            $text = Wikitext::getStepsSection($r->getText(), true);
            if (preg_match_all("@===([^=]+)===@", $text[0], $matches)) {
                print $page;
                foreach ($matches[1] as $m) {
                    if (!preg_match("@\r\n@", $m)) {
                        print ',' . $m;
                    }
                }
                print "\n";
            }
        }
    }
}
Ejemplo n.º 6
0
 public function calcPageStats(&$statsToCalc, &$row)
 {
     $dbr = $this->getWikiDB();
     $t = Title::newFromId($row->page_id);
     $goodRevision = GoodRevision::newFromTitle($t, $row->page_id);
     $revId = 0;
     if ($goodRevision) {
         $revId = $goodRevision->latestGood();
     }
     $r = $revId > 0 ? Revision::loadFromId($dbr, $revId) : Revision::loadFromPageId($dbr, $row->page_id);
     $fields = array();
     if ($r && $t && $t->exists()) {
         foreach ($statsToCalc as $stat => $isOn) {
             if ($isOn) {
                 $statCalculator = $this->getStatClass($stat);
                 $fields = array_merge($fields, $statCalculator->calc($dbr, $r, $t, $row));
             }
         }
     }
     return $fields;
 }