Ejemplo n.º 1
0
 /**
  * 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;
     }
 }
Ejemplo n.º 2
0
 /**
  * process a single article for the subheaders
  */
 private static function processSubheaders($title, $csv)
 {
     list($wikitext, $stepsText, $sectionID) = self::getWikitext($title);
     if ($wikitext && $stepsText) {
         $subs = Wikitext::countAltMethods($stepsText);
         if ($subs > 1) {
             //we have some parts/methods/ways!
             $newstepsText = preg_replace('@(^\\s*===\\s*)(Method |Part )(.*?:|.*?\\.|\\s*===|)@im', '$1', $stepsText);
             //have we made a difference?
             if (strcmp($stepsText, $newstepsText) != 0) {
                 //it has changed; update the sub headers
                 $newWikitext = Wikitext::replaceStepsSection($wikitext, $sectionID, $newstepsText, true);
                 if ($newWikitext) {
                     //sub headers have been updated, add the "magic word"
                     list($newestWikitext, $magic_word) = self::addMagicWord($stepsText, $newWikitext);
                     if ($newestWikitext) {
                         $data = array();
                         Wikitext::saveWikitext($title, $newestWikitext, self::$comment);
                         $url = 'http://www.wikihow.com/' . $title->getDBKey();
                         $data[] = $url;
                         $data[] = $magic_word;
                         //rock! now a little logic to grab what changed...
                         preg_match('@^===.*===?@im', $stepsText, $m);
                         $data[] = $m[0];
                         preg_match('@^===.*===?@im', $newstepsText, $m);
                         $data[] = $m[0];
                         //show it
                         print $url . '	' . $magic_word . "\n";
                         //log it
                         self::logIt($url . '	' . $magic_word);
                         //write it to the csv
                         fputcsv($csv, $data, chr(9));
                         //good night, sweet prince...
                         usleep(self::SLEEPTIME);
                         return true;
                     }
                 }
             }
         }
     }
     return false;
 }
Ejemplo n.º 3
0
 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;
     }
 }
        $introChanged = false;
        $article = new Article($title);
        $revision = Revision::newFromTitle($title);
        $wikiText = $revision->getText();
        $intro = Wikitext::getIntro($wikiText, true);
        if ($intro != "") {
            $intro = replaceBrokenLinksInSection($intro, $introChanged, $title);
            if ($introChanged) {
                $wikiText = Wikitext::replaceIntro($wikiText, $intro, true);
            }
        }
        list($steps, $sectionID) = Wikitext::getStepsSection($wikiText, true);
        if ($steps != "") {
            $steps = replaceBrokenLinksInSection($steps, $stepsChanged, $title);
            if ($stepsChanged) {
                $wikiText = Wikitext::replaceStepsSection($wikiText, $sectionID, $steps, true);
            }
        }
        if ($stepsChanged || $introChanged) {
            $article->doEdit($wikiText, "Removing broken links");
        }
    }
}
function replaceBrokenLinksInSection($sectionText, &$changed, &$title)
{
    $matchesarray = array();
    $sectionText = preg_replace_callback("@<nowiki>[^<]*</nowiki>@i", 'handleNoWikiTags', $sectionText);
    preg_match_all('@\\[\\[([^\\]]*)\\]\\]@', $sectionText, $matchesarray);
    foreach ($matchesarray[1] as $match) {
        $linkParts = explode("|", $match);
        $zero = (int) 0;