/** * Cycle through the url list to call the removeIntroImages function */ private static function removeIntroImagesUrls(&$urls, $px, $text) { $dbr = wfGetDB(DB_SLAVE); foreach ($urls as &$url) { $err = ''; $final_step = ''; if (!$url['title']) { $err = 'Unable to load article'; } else { $introText = ''; $wikitext = Wikitext::getWikitext($dbr, $url['title']); if ($wikitext) { $introText = Wikitext::getIntro($wikitext); } if (!$introText) { $err = 'Unable to load wikitext'; } else { //first, let's use the intro image for the final step if ($px > 0) { $new_final_step = self::makeFinalStep($introText, $px, $text); if ($new_final_step) { list($stepsText, $sectionID) = Wikitext::getStepsSection($wikitext, true); $stepsText = $stepsText . $new_final_step; $wikitext = Wikitext::replaceStepsSection($wikitext, $sectionID, $stepsText, true); if (preg_match("@[\r\n]+===[^=]*===@m", $stepsText)) { $final_step = 'x (alt)'; //success! (yay!) but has alt methods (boo!) } else { $final_step = 'x'; //success! } } } $prevIntroText = $introText; $introText = self::removeIntroImages($prevIntroText, $url['title']); if ($introText && $introText != $prevIntroText) { $wikitext = Wikitext::replaceIntro($wikitext, $introText, true); $comment = 'Removing intro images'; if ($final_step == 'x') { $comment .= '; Made final step out of former intro image'; } $err = Wikitext::saveWikitext($url['title'], $wikitext, $comment); if (empty($err)) { //make sure the intro image adder doesn't grab it $id = $url['title']->getArticleID(); if ($id) { $dbw = wfGetDB(DB_MASTER); $dbw->update('imageadder', array('imageadder_hasimage' => 1), array('imageadder_page' => $id)); } } } else { $err = 'Either no intro image or no intro found'; } } } $url['err'] = $err; $url['final_step'] = $final_step; } }
private static function getWikitext($title) { $dbr = wfGetDB(DB_SLAVE); $wikitext = Wikitext::getWikitext($dbr, $title); $stepsText = ''; if ($wikitext) { list($stepsText, ) = Wikitext::getStepsSection($wikitext, true); } return array($wikitext, $stepsText); }
/** * grab that wikitext */ private static function getWikitext($title) { $dbr = wfGetDB(DB_SLAVE); $wikitext = Wikitext::getWikitext($dbr, $title); $stepsText = ''; if ($wikitext) { list($stepsText, $sectionID) = Wikitext::getStepsSection($wikitext, true); //hack for illegal character if (strpos($wikitext, '‐')) { return array(); } } return array($wikitext, $stepsText, $sectionID); }
private function resizeImages($article) { global $wgServer; if (!$dbw) { $dbw = wfGetDB(DB_MASTER); } $err = ''; $title = Title::newFromURL($article); if (!$title || !$title->exists()) { return; } $wikitext = Wikitext::getWikitext($dbw, $title); if (!$wikitext) { $err = 'Unable to load wikitext'; } else { if (preg_match('@^#REDIRECT@m', $wikitext)) { $err = 'REDIRECT'; } else { list($stepsText, $sectionID) = Wikitext::getStepsSection($wikitext, true); list($stepsText, $err) = self::resizeEachImage($stepsText); if ($stepsText) { $wikitext = Wikitext::replaceStepsSection($wikitext, $sectionID, $stepsText, true); $comment = 'Resized images to the {{largeimage}} size.'; $err = Wikitext::saveWikitext($title, $wikitext, $comment); } } } if ($err) { $err .= chr(9) . $wgServer . '/' . $article; //print $err."\n"; self::logError($err); } elseif ($stepsText) { self::logIt($wgServer . '/' . $article); return $wgServer . '/' . $article; } }
function getDocData($row, $dbr, $printIntro = false) { $page_id = $row->page_id; $page_counter = $row->page_counter; $title = Title::newFromDBkey($row->page_title); if (!$title || !$title->exists()) { decho("unknown title for id", $page_id, false); return ""; } $wikitext = Wikitext::getWikitext($dbr, $title); $intro = Wikitext::getIntro($wikitext); //$intro = str_replace("{{toc}}", "", $intro); $intro = preg_replace('#\\{\\{.*?\\}\\}#s', '', $intro); $intro = trim(preg_replace('#\\[\\[.*?\\]\\]#s', '', $intro)); $intro = preg_replace('/\\s+/', ' ', trim($intro)); $intro = str_replace('<br>', '', $intro); //if (contains($intro, "Here's how:")) { if (stripos($intro, "here's how") !== FALSE || ":" == substr($intro, -1)) { //check the number of monthly page views... $data = getTitusData($row->page_id); if ($data->titus) { $ti30 = $data->titus->ti_30day_views; } if ($ti30 >= 5000 && $ti30 <= 6000) { echo $ti30 . " http://www.wikihow.com/" . $row->page_title . " "; if ($printIntro) { echo $intro; } echo "\n"; } } //echo $page_counter ." http://www.wikihow.com/".$row->page_title." ,> ".$intro."\n"; //echo "http://www.wikihow.com/".$row->page_title." ,> ".$intro."\n"; return $intro; }
function categorize($aid) { global $wgRequest; $t = Title::newFromId($aid); if ($t && $t->exists()) { $dbr = wfGetDB(DB_MASTER); $wikitext = Wikitext::getWikitext($dbr, $t); $intro = Wikitext::getIntro($wikitext); $intro = $this->stripCats($intro); $cats = array_reverse($wgRequest->getArray('cats', array())); $intro .= $this->getCatsWikiText($cats); $wikitext = Wikitext::replaceIntro($wikitext, $intro); $result = Wikitext::saveWikitext($t, $wikitext, 'categorization'); // Article saved successfully if ($result === '') { wfRunHooks("CategoryHelperSuccess", array()); } } }
function outputArticleReport() { global $wgRequest; $urls = split("\n", trim(Misc::getUrlDecodedData($wgRequest->getVal('data')))); $dbr = wfGetDB(DB_SLAVE); $articles = array(); foreach ($urls as $url) { $t = Title::newFromText(str_replace("http://www.wikihow.com/", "", $url)); if ($t && $t->exists()) { $articles[$t->getArticleId()] = array('url' => Misc::makeUrl($t->getText())); if ($this->slowQuery) { $wikitext = Wikitext::getWikitext($dbr, $t); $articles[$t->getArticleId()]['alts'] = $this->hasAlternateMethods($wikitext) ? "Yes" : "No"; $articles[$t->getArticleId()]['size'] = $this->getArticleSize($t); $articles[$t->getArticleId()]['imgs'] = $this->hasImages($wikitext); } } } $this->addPageCounts($articles); if ($wgRequest->getVal('format') == 'csv') { $output = $this->getArticleReportCSV($articles); $this->sendFile('article_stats', $output); } else { $output = $this->getArticleReportHtml($articles); $this->sendHtml($output); } }
function removeVideoSection(&$article) { $ret = false; $t = Title::newFromID($article['page_id']); if ($t) { $dbw = wfGetDB(DB_MASTER); $wikitext = Wikitext::getWikitext($dbw, $t); try { $wikitext = Wikitext::removeVideoSection($wikitext); $result = Wikitext::saveWikitext($t, $wikitext, "vidbot - removing video section"); printArticleRemoval($t); $ret = true; } catch (Exception $e) { error($e->getMessage() . ", Title: " . $t->getText() . "\n"); } } return $ret; }