Example #1
0
 public function addArticle($month, $day, $year, $page)
 {
     $lines = array();
     $temp = "";
     $head = array();
     $article = new Article(Title::newFromText($page));
     if (!$article->exists()) {
         return "";
     }
     $redirectCount = 0;
     if ($article->isRedirect() && $this->setting('disableredirects')) {
         return '';
     }
     while ($article->isRedirect() && $redirectCount < 10) {
         $redirectedArticleTitle = Title::newFromRedirect($article->getContent());
         $article = new Article($redirectedArticleTitle);
         $redirectCount += 1;
     }
     $body = $article->fetchContent(0, false, false);
     if (strlen(trim($body)) == 0) {
         return "";
     }
     $lines = split("\n", $body);
     $cntLines = count($lines);
     // dont use section events... only line 1 of the page
     if ($this->setting('disablesectionevents')) {
         $key = $lines[0];
         //initalize the key
         $head[$key] = "";
         $cntLines = 0;
     }
     for ($i = 0; $i < $cntLines; $i++) {
         $line = $lines[$i];
         if (substr($line, 0, 2) == '==') {
             $arr = split("==", $line);
             $key = $arr[1];
             $head[$key] = "";
             $temp = "";
         } else {
             if ($i == 0) {
                 // $i=0  means this is a one event page no (==event==) data
                 $key = $line;
                 //initalize the key
                 $head[$key] = "";
             } else {
                 $temp .= "{$line}\n";
                 $head[$key] = Common::cleanWiki($temp);
             }
         }
     }
     while (list($event, $body) = each($head)) {
         $this->buildEvent($month, $day, $year, trim($event), $page, $body);
     }
 }
 function convert($newFormat, $pageName, $calName, $redirect, $go)
 {
     $search = "{$pageName}/{$calName}";
     $pages = PrefixSearch::titleSearch($search, 1000000);
     //search upto 1,000,000 events (no performace issue)
     $count = $erroredCount = 0;
     foreach ($pages as $page) {
         $retval = false;
         $newPage = $this->convertToNewPage($page, $newFormat);
         $article = new Article(Title::newFromText($page));
         if ($newPage != '') {
             $fromTitle = Title::newFromText($page);
             $toTitle = Title::newFromText($newPage);
             $articleNew = new Article(Title::newFromText($newPage));
             if (!$article->isRedirect() && !$articleNew->exists()) {
                 if ($go) {
                     $retval = $fromTitle->moveTo($toTitle, true, 'CalendarConversion', $redirect);
                 } else {
                     if ($count < 10) {
                         $testRun .= '&nbsp;&nbsp;' . $page . '  &rarr;&rarr;  ' . $newPage . '<br>';
                     }
                 }
             }
         }
     }
     unset($pages);
     if ($go) {
         $ret = "Conversion completed.";
     } else {
         $ret = "<b>Test Results, add '<i>go</i>' to the <i>dateConverter</i> tag to convert:</b><br>{$testRun}";
     }
     return $ret;
 }
 /**
  * Accepts an article and performs all necessary logic to also store a redirect
  * @param Article $article
  */
 public function __construct(Article $article)
 {
     $this->article = $article;
     if ($article->isRedirect()) {
         $target = $article->getRedirectTarget();
         if ($target instanceof Title) {
             $this->redirect = F::build('Article', array($target));
         }
     }
 }
 function getRelatedTopicsText($target)
 {
     global $wgOut, $wgUser, $wgLanguageCode;
     // INTL: Don't return related topics for non-english sites
     if ($wgLanguageCode != 'en') {
         return wfMsg('createpage_step1box_noresults', $s);
     }
     wfLoadExtensionMessages('CreatePage');
     $hits = array();
     $t = Title::newFromText(EditPageWrapper::formatTitle($target));
     $l = new LSearch();
     $hits = $l->googleSearchResultTitles($target, 0, 10);
     $count = 0;
     if ($t->getArticleID() > 0) {
         return $wgOut->parse(wfMsg('createpage-title-exists', $t->getFullText()) . "<br/><br/>") . "<a href='" . $t->getEditURL() . "'>" . wfMsg('createpage-edit-existing') . "</a><br/>";
     }
     if (sizeof($hits) > 0) {
         foreach ($hits as $hit) {
             $t1 = $hit;
             if ($count == 5) {
                 break;
             }
             if ($t1 == null) {
                 continue;
             }
             if ($t1->getNamespace() != NS_MAIN) {
                 continue;
             }
             // check if the result is a redirect
             $a = new Article($t1);
             if ($a && $a->isRedirect()) {
                 continue;
             }
             if ($wgUser->getID() > 0) {
                 $gatuser = '******';
             } else {
                 $gatuser = '******';
             }
             // check if the article exists
             if (strtolower($t1->getText()) == strtolower($target->getText())) {
                 return $wgOut->parse(wfMsg('createpage-title-exists', $t1->getFullText()) . "<br/><br/>") . "<a href='" . $t->getEditURL() . "'>" . wfMsg('createpage-edit-existing') . "</a><br/>";
             }
             $name = htmlspecialchars($target->getDBKey());
             $value = htmlspecialchars($t1->getDBKey());
             $s .= "<input type='radio' name='{$name}' value='{$value}' onchange='document.getElementById(\"cp_next\").disabled = false; gatTrack(\"{$gatuser}\",\"Create_redirect\");'>\n\t\t\t\t\t\t<a href='{$t1->getFullURL()}' target='new'>" . wfMsg('howto', $t1->getText()) . "</a><br/><br/>";
             $count++;
         }
         if ($count == 0) {
             return wfMsg('createpage_related_nomatches');
         }
         $html = wfMsg('createpage_related_head', $target->getText()) . "<div class='createpage_related_options'>" . $s . "<input type='radio' name='" . $target->getDBKey() . "' value='none' checked='checked' onchange='document.getElementById(\"cp_next\").disabled = false;' />\n\t\t\t\t\t<b>" . wfMsg('createpage_related_none') . "</b>" . "</div>";
         return $html;
     }
     return wfMsg('createpage_related_nomatches');
 }
Example #5
0
 function getRS()
 {
     global $wgMemc;
     $key_rs = wfMemcKey("risingstar-feed3:" . date('YmdG') . ":" . number_format(date('i') / 10, 0, '', ''));
     $rsOut = $wgMemc->get($key_rs);
     if (!empty($rsOut)) {
         return $rsOut;
     }
     $t = Title::newFromText('wikiHow:Rising-star-feed');
     if ($t->getArticleId() > 0) {
         $r = Revision::newFromTitle($t);
         $text = $r->getText();
     } else {
         return false;
     }
     //NOTE: temporary patch to handle archives.  the authoritative source for RS needs to be moved to the DB versus the feed article. add archive to array.
     $archives = array('wikiHow:Rising-star-feed/archive1');
     foreach ($archives as $archive) {
         $tarch = Title::newFromText($archive);
         if ($tarch->getArticleId() > 0) {
             $r = Revision::newFromTitle($tarch);
             $text = $r->getText() . "\n" . $text;
         }
     }
     $rsout = array();
     $rs = $text;
     $rs = preg_replace("/==\n/", ',', $rs);
     $rs = preg_replace("/^==/", "", $rs);
     $lines = preg_split("/\r|\n/", $rs, null, PREG_SPLIT_NO_EMPTY);
     $count = 0;
     foreach ($lines as $line) {
         if (preg_match('/^==(.*?),(.*?)$/', $line, $matches)) {
             $dt = $matches[1];
             $pattern = "/{$wgServer}/";
             $title = preg_replace("/http:\\/\\/www\\.wikihow\\.com\\//", "", $matches[2]);
             $title = preg_replace("/http:\\/\\/.*?\\.com\\//", "", $matches[2]);
             $t = Title::newFromText($title);
             if (!isset($t)) {
                 continue;
             }
             $a = new Article($t);
             if ($a->isRedirect()) {
                 $t = Title::newFromRedirect($a->fetchContent());
                 $a = new Article($t);
             }
             $rsout[$t->getPartialURL()] = $dt;
         }
     }
     // sort by most recent first
     $rsout = array_reverse($rsout);
     $wgMemc->set($key_rs, $rsout);
     return $rsout;
 }
 function execute()
 {
     global $wgRequest, $wgOut;
     if ($wgRequest->wasPosted()) {
         if ($this->save()) {
             $article = new Article($this->mTitle);
             $q = $article->isRedirect() ? 'redirect=no' : '';
             $wgOut->redirect($this->mTitle->getFullUrl($q));
         }
     } else {
         $this->show();
     }
 }
Example #7
0
 /**
 * Update the page record to point to a newly saved revision.
 *
 * @param Database $dbw
 * @param Revision $revision For ID number, and text used to set
                             length and redirect status fields
 * @param int $lastRevision If given, will not overwrite the page field
 *                          when different from the currently set value.
 *                          Giving 0 indicates the new page flag should
 *                          be set on.
 * @return bool true on success, false on failure
 * @private
 */
 function updateRevisionOn(&$dbw, $revision, $lastRevision = null)
 {
     wfProfileIn(__METHOD__);
     $conditions = array('page_id' => $this->getId());
     if (!is_null($lastRevision)) {
         # An extra check against threads stepping on each other
         $conditions['page_latest'] = $lastRevision;
     }
     $text = $revision->getText();
     $dbw->update('page', array('page_latest' => $revision->getId(), 'page_touched' => $dbw->timestamp(), 'page_is_new' => $lastRevision === 0 ? 1 : 0, 'page_is_redirect' => Article::isRedirect($text) ? 1 : 0, 'page_len' => strlen($text)), $conditions, __METHOD__);
     wfProfileOut(__METHOD__);
     return $dbw->affectedRows() != 0;
 }
/**
 * Converts an MArticle into a feed, echoing generated content directly.
 * @param Article $article Article to be converted to RSS or Atom feed.
 * @param String $feedFormat A format type - must be either 'rss' or 'atom'
 * @param Array $filterTags Tags to use in filtering out items.
 */
function wfGenerateWikiFeed( $article, $feedFormat = 'atom', $filterTags = null ) {
	global $wgOut, $wgServer, $wgFeedClasses, $wgVersion, $wgSitename;

	# Setup, handle redirects
	if ( $article->isRedirect() ) {
		$rtitle = Title::newFromRedirect( $article->getContent() );
		if ( $rtitle ) {
			$article = new Article( $rtitle );
		}
	}
	$title = $article->getTitle();
	$feedUrl = $title->getFullUrl();

	# Parse page into feed items.
	$content = $wgOut->parse( $article->getContent() . "\n__NOEDITSECTION__ __NOTOC__" );
	preg_match_all(
				   '/<!--\\s*FEED_START\\s*-->(.*?)<!--\\s*FEED_END\\s*-->/s',
				   $content,
				   $matches
				   );
	$feedContentSections = $matches[1];

	# Parse and process all feeds, collecting feed items
	$items = array();
	$feedDescription = '';
	foreach ( $feedContentSections as $feedKey => $feedContent ) {

		# Determine Feed item depth (what header level defines a feed)
		preg_match_all( '/<h(\\d)>/m', $feedContent, $matches );
		if ( empty( $matches[1] ) ) next;
		$lvl = $matches[1][0];
		foreach ( $matches[1] as $match ) {
			if ( $match < $lvl ) $lvl = $match;
		}

		$sectionRegExp = '#<h' . $lvl . '>\s*<span.+?id="(.*?)">\s*(.*?)\s*</span>\s*</h' . $lvl . '>#m';

		# Determine the item titles and default item links
		preg_match_all(
					   $sectionRegExp,
					   $feedContent,
					   $matches
					   );
		$itemLinks = $matches[1];
		$itemTitles = $matches[2];

		# Split content into segments
		$segments = preg_split( $sectionRegExp, $feedContent );
		$segDesc = trim( strip_tags( array_shift( $segments ) ) );
		if ( $segDesc ) {
			if ( !$feedDescription ) {
				$feedDescription = $segDesc;
			} else {

				$feedDescription = wfMsg( 'wikiarticlefeeds_combined_description' );
			}
		}

		# Loop over parsed segments and add all items to item array
		foreach ( $segments as $key => $seg ) {

			# Filter by tag (if any are present)
			$skip = false;
			$tags = null;
			if ( is_array( $filterTags ) && !empty( $filterTags ) ) {
				if ( preg_match_all( '/<!-- ITEM_TAGS ([0-9a-zA-Z\\+\\/]+=*) -->/m', $seg, $matches ) ) {
					$tags = array();
					foreach ( $matches[1] as $encodedString ) {
						$t = @unserialize( @base64_decode( $encodedString ) );
						if ( $t ) {
							$t = explode( ',', $t );
							array_walk( $t, 'trim' );
							sort( $t );
							$tags = array_merge( $tags, $t );
						}
					}
					$tags = array_unique( $tags );
					if ( !count( array_intersect( $tags, $filterTags ) ) ) $skip = true;
					$seg = preg_replace( '/<!-- ITEM_TAGS ([0-9a-zA-Z\\+\\/]+=*) -->/m', '', $seg );
				} else {
					$skip = true;
				}
			}
			if ( $skip ) continue;

			# Determine the item author and date
			$author = null;
			$date = null;
			$signatureRegExp = '#<a href=".+?User:.+?" title="User:.+?">(.*?)</a> (\d\d):(\d\d), (\d+) ([a-z]+) (\d{4}) \([A-Z]+\)#im';
			# Look for a regular ~~~~ sig
			$isAttributable = preg_match($signatureRegExp, $seg, $matches );

			# Parse it out - if we can
			if ( $isAttributable ) {
				list( $author, $hour, $min, $day, $monthName, $year ) = array_slice( $matches, 1 );
				$months = array(
								'January' => '01', 'February' => '02', 'March' => '03', 'April' => '04',
								'May' => '05', 'June' => '06', 'July' => '07', 'August' => '08',
								'September' => '09', 'October' => '10', 'November' => '11', 'December' => '12'
								);
				$month = $months[$monthName];
				$day = str_pad( $day, 2, '0', STR_PAD_LEFT );
				$date = $year . $month . $day . $hour . $min . '00';
			}

			# Set default 'article section' feed-link
			$url = $feedUrl . '#' . $itemLinks[$key];

			# Look for an alternative to the default link (unless default 'section linking' has been forced)
			global $wgForceArticleFeedSectionLinks;
			if ( !$wgForceArticleFeedSectionLinks ) {
				$strippedSeg = preg_replace($signatureRegExp, '', $seg );
				preg_match(
					'#<a [^>]*href=([\'"])(.*?)\\1[^>]*>(.*?)</a>#m',
					$strippedSeg,
					$matches
					);
				if ( $matches[2] ) {
					$url = $matches[2];
					if ( preg_match( '#^/#', $url ) ) {
						$url = $wgServer . $url;
					}
				}
			}

			# Create 'absolutified' segment - where all URLs are fully qualified
			$seg = preg_replace( '/ (href|src)=([\'"])\\//', ' $1=$2' . $wgServer . '/', $seg );

			# Create item and push onto item list
			$items[$date][] = new FeedItem( strip_tags( $itemTitles[$key] ), $seg, $url, $date, $author );
		}
	}

	# Programmatically determine the feed title and id.
	$feedTitle = $wgSitename . ' - ' . $title->getPrefixedText();
	$feedId = $title->getFullUrl();

	# Create feed
	$feed = new $wgFeedClasses[$feedFormat]( $feedTitle, $feedDescription, $feedId );

	# Push feed header
	$tempWgVersion = $wgVersion;
	$wgVersion .= ' via WikiArticleFeeds ' . WIKIARTICLEFEEDS_VERSION;
	$feed->outHeader();
	$wgVersion = $tempWgVersion;

	# Sort all items by date and push onto feed
	krsort( $items );
	foreach ( $items as $itemGroup ) {
		foreach ( $itemGroup as $item ) {
			$feed->outItem( $item );
		}
	}

	# Feed footer
	$feed->outFooter();
}
Example #9
0
 static function getAvatarRaw($name)
 {
     $u = User::newFromName($name);
     if (!$u) {
         return array('type' => 'df', 'url' => '');
     }
     $u->load();
     $dbr = wfGetDB(DB_SLAVE);
     // check for facebook
     if ($u->isFacebookUser()) {
         $row = $dbr->selectRow('avatar', array('av_image', 'av_patrol'), array('av_user' => $u->getID()), __METHOD__);
         if ($row->av_image && ($row->av_patrol == 0 || $row->av_patrol == 1)) {
             return array('type' => 'fb', 'url' => $row->av_image);
         }
     }
     //check for Google+
     if ($u->isGPlusUser()) {
         $row = $dbr->selectRow('avatar', array('av_image', 'av_patrol'), array('av_user' => $u->getID()), __METHOD__);
         if ($row->av_image && ($row->av_patrol == 0 || $row->av_patrol == 1)) {
             return array('type' => 'gp', 'url' => $row->av_image);
         }
     }
     //checks for redirects for users that go that route
     //rather than just changing the username
     $up = $u->getUserPage();
     $a = new Article($up, 0);
     //need to put 0 as the oldID b/c Article gets the old id out of the URL
     if ($a->isRedirect()) {
         $t = Title::newFromRedirect($a->fetchContent());
         if (!($u = User::newFromName($t->getText()))) {
             return array('type' => 'df', 'url' => '');
         }
     }
     $row = $dbr->selectRow('avatar', array('av_dateAdded'), array('av_user' => $u->getID(), 'av_patrol' => 0), __METHOD__);
     $filename = $u->getID() . ".jpg";
     $cropout = self::getAvatarOutFilePath($filename) . $filename;
     if ($row && $row->av_dateAdded) {
         return array('type' => 'av', 'url' => "{$filename}?" . $row->av_dateAdded);
     }
     return array('type' => 'df', 'url' => '');
 }
Example #10
0
 public function isRedirect($text = false)
 {
     $this->loadFile();
     if ($this->img->isLocal()) {
         return parent::isRedirect($text);
     }
     return (bool) $this->img->getRedirected();
 }
 /**
  * Get the contents to be preloaded into the box, either set by
  * an earlier setPreloadText() or by loading the given page.
  *
  * @param $preload String: representing the title to preload from.
  * @return String
  */
 protected function getPreloadedText($preload)
 {
     global $wgUser, $wgParser;
     if (!empty($this->mPreloadText)) {
         return $this->mPreloadText;
     } elseif ($preload !== '') {
         $title = Title::newFromText($preload);
         # Check for existence to avoid getting MediaWiki:Noarticletext
         if (isset($title) && $title->exists() && $title->userCanRead()) {
             $article = new Article($title);
             if ($article->isRedirect()) {
                 $title = Title::newFromRedirectRecurse($article->getContent());
                 # Redirects to missing titles are displayed, to hidden pages are followed
                 # Copying observed behaviour from ?action=view
                 if ($title->exists()) {
                     if ($title->userCanRead()) {
                         $article = new Article($title);
                     } else {
                         return "";
                     }
                 }
             }
             $parserOptions = ParserOptions::newFromUser($wgUser);
             return $wgParser->getPreloadText($article->getContent(), $title, $parserOptions);
         }
     }
     return '';
 }
 /**	
  * getNext
  * Get the next article to show
  **/
 function getNext()
 {
     global $wgRequest, $wgUser;
     $fname = "IntroImageAdder::getNext";
     wfProfileIn($fname);
     $dbm = wfGetDB(DB_MASTER);
     $dbr = wfGetDB(DB_SLAVE);
     // mark skipped
     if ($wgRequest->getVal('skip', null)) {
         $t = Title::newFromText($wgRequest->getVal('skip'));
         $id = $t->getArticleID();
         $dbm->update('imageadder', array('imageadder_skip=imageadder_skip+1', 'imageadder_skip_ts' => wfTimestampNow()), array('imageadder_page' => $id));
     }
     $a = array();
     for ($i = 0; $i < 30; $i++) {
         $timediff = date("YmdHis", strtotime("-1 day"));
         //24 hours ago
         //NOTE SQL Queries are excluding pageid 5791 cause it's a Categories page, don't know why it's not in wikihow NS.
         $opts = array("imageadder_last_viewed < '{$timediff}'", 'imageadder_page != 5791', 'imageadder_skip < 4', 'imageadder_hasimage' => 0);
         $tables = array('imageadder');
         if (mt_rand(0, 9) < 7) {
             //ORDER BY PAGE_COUNTER
             $pageid = $dbr->selectField($tables, 'imageadder_page', $opts, "IntroImageAdder::getNext", array("ORDER BY" => "imageadder_page_counter DESC", "LIMIT" => 1));
         } else {
             //ORDER BY PAGE_TOUCHED
             $pageid = $dbr->selectField($tables, array('imageadder_page'), $opts, "IntroImageAdder::getNext", array("ORDER BY" => "imageadder_page_touched DESC", "LIMIT" => 1));
         }
         //No articles need images?
         if (empty($pageid)) {
             continue;
         }
         /*
          * XXNOTE: One day when we can prefetch search terms we will do this instead of call the function
          * $sql = "SELECT imageadder_page,imageadder_terms from imageadder where imageadder_inuse != 1";
          * $res = $dbr->query($sql);
          */
         $dbm->update('imageadder', array('imageadder_last_viewed' => wfTimestampNow()), array('imageadder_page' => $pageid));
         $t = Title::newFromID($pageid);
         if (!$t) {
             continue;
         }
         //prove false
         $b_good = true;
         //valid article?
         if ($t->getArticleId() == 0) {
             $b_good = false;
         }
         //protected article?
         if ($t->isProtected()) {
             $b_good = false;
         }
         //check the wikitext for problems
         if ($this->hasProblems($t, $dbr)) {
             $b_good = false;
             $dbm->update('imageadder', array('imageadder_hasimage' => 1), array("imageadder_page" => $pageid));
         }
         //is this a redirect?
         $article = new Article($t);
         if ($article->isRedirect()) {
             $b_good = false;
         }
         if ($b_good) {
             $a['aid'] = $t->getArticleId();
             $a['title'] = $t->getText();
             $a['url'] = $t->getLocalURL();
             $a['terms'] = $this->getSearchTerms($t->getText());
             wfProfileOut($fname);
             return $a;
         } else {
             //not be good; mark it skipped
             $dbm->update('imageadder', array('imageadder_skip=imageadder_skip+1', 'imageadder_skip_ts' => wfTimestampNow()), array('imageadder_page' => $t->getArticleId()));
         }
     }
     //send error msg
     $a['aid'] = '0';
     $a['title'] = 'No articles need images';
     $a['url'] = '';
     $a['terms'] = 'fail whale';
     wfProfileOut($fname);
     return $a;
 }
 function getRelatedWikihowsFromSource($r, $num)
 {
     $text = $r->getText();
     $whow = WikihowArticleEditor::newFromText($text);
     $related = preg_replace("@^==.*@m", "", $whow->getSection('related wikihows'));
     $preg = "/\\|[^\\]]*/";
     $related = preg_replace($preg, "", $related);
     $rarray = split("\n", $related);
     $result = "";
     $count = 0;
     foreach ($rarray as $related) {
         preg_match("/\\[\\[(.*)\\]\\]/", $related, $rmatch);
         $t = Title::newFromText($rmatch[1]);
         if ($t) {
             $a = new Article($t);
             if (!$a->isRedirect()) {
                 $result .= self::formatRelated($t);
                 if (++$count == $num) {
                     break;
                 }
             }
         }
     }
     return $result;
 }
Example #14
0
 public static function followPollID($pollTitle)
 {
     $pollArticle = new Article($pollTitle);
     $pollWikiContent = $pollArticle->getContent();
     if ($pollArticle->isRedirect($pollWikiContent)) {
         $pollTitle = $pollArticle->followRedirect();
         return PollNYHooks::followPollID($pollTitle);
     } else {
         return $pollTitle;
     }
 }
 public static function checkArticlesInNfdTable()
 {
     $dbr = wfGetDB(DB_SLAVE);
     $count = 0;
     $results = array();
     $res = $dbr->select('nfd', array('nfd_id', 'nfd_page', 'nfd_reason'), array('nfd_patrolled' => '0', "(nfd_status = '" . NFDGuardian::NFD_AVAILABLE . "' OR nfd_status = '" . NFDGuardian::NFD_ADVANCED . "')"));
     while ($result = $dbr->fetchObject($res)) {
         $results[] = $result;
     }
     foreach ($results as $result) {
         $t = Title::newFromID($result->nfd_page);
         if ($t) {
             $a = new Article($t);
             /*if($result->nfd_reason == "dup"){
             			NFDProcessor::markPreviousAsInactive($result->nfd_page);
             			echo "Removing Dup: " . $t->getText() . "\n";
             			$count++;
             		}
             		else*/
             if ($a->isRedirect()) {
                 //check if its a redirect
                 NFDProcessor::markPreviousAsInactive($result->nfd_page);
                 echo "Removing Redirect: " . $t->getText() . "\n";
                 $count++;
             } else {
                 //check to see if it still has an NFD tag
                 $revision = Revision::newFromTitle($t);
                 if ($a && $revision) {
                     $l = new NFDProcessor($revision, $a);
                     $l->process(true);
                 }
             }
         } else {
             //title doesn't exist, so remove it from the db
             NFDProcessor::markPreviousAsInactive($result->nfd_page);
             echo "Title no longer exists: " . $result->nfd_page . "\n";
             $count++;
         }
     }
     //echo "Removed a total of " . $count . " articles from tool.\n";
 }
Example #16
0
 function updateArticle($title, $text, $summary)
 {
     global $wgUser, $wgRequest, $wgOut;
     if (!$wgUser->matchEditToken($wgRequest->getVal('token'))) {
         $wgOut->addWikiMsg('sessionfailure');
         return 'session failure';
     }
     $titleX = Title::newFromText($title);
     $permission_errors = $titleX->getUserPermissionsErrors('edit', $wgUser);
     if (count($permission_errors) == 0) {
         $articleX = new Article($titleX);
         $articleX->doEdit($text, $summary, EDIT_UPDATE | EDIT_DEFER_UPDATES | EDIT_AUTOSUMMARY);
         $wgOut->redirect($titleX->getFullUrl($articleX->isRedirect() ? 'redirect=no' : ''));
         return '';
     } else {
         $wgOut->showPermissionsErrorPage($permission_errors);
         return 'permission error';
     }
 }
 /**
  * Query for RisingStars Written
  **/
 function getRisingStar($starttimestamp, $lb_user = '', $getArticles = false)
 {
     global $wgMemc;
     if ($getArticles) {
         $key = "leaderboard:risingstars_received:{$starttimestamp}:{$lb_user}";
     } else {
         $key = "leaderboard:risingstars_received:{$starttimestamp}";
     }
     $cachekey = wfMemcKey($key);
     $val = $wgMemc->get($cachekey);
     if (is_array($val)) {
         return $val;
     }
     $dbr = wfGetDB(DB_SLAVE);
     $data = array();
     $bots = WikihowUser::getBotIDs();
     $bot = "";
     if (sizeof($bots) > 0) {
         $bot = " AND rc_user NOT IN (" . $dbr->makeList($bots) . ") ";
     }
     $sql = "SELECT distinct(rc_title) " . "FROM recentchanges  " . "WHERE rc_timestamp >= '{$starttimestamp}' AND rc_comment like 'Marking new article as a Rising Star from From%'   " . $bot . "AND rc_namespace=" . NS_TALK . " ";
     $res = $dbr->query($sql, __METHOD__);
     foreach ($res as $row) {
         $t = Title::newFromText($row->rc_title);
         $a = new Article($t);
         if ($a->isRedirect()) {
             $t = Title::newFromRedirect($a->fetchContent());
             $a = new Article($t);
         }
         $author = $a->getContributors()->current();
         $username = $author ? $author->getName() : '';
         if ($getArticles) {
             if ($lb_user == $username) {
                 $data[$t->getPartialURL()] = $t->getPrefixedText();
             }
         } else {
             $data[$username]++;
         }
     }
     $wgMemc->set($cachekey, $data, 3600);
     return $data;
 }
 function buildCurrentSlide($page, $notoc)
 {
     global $wgScript, $wgParser;
     if (trim($page) == "") {
         return "";
     }
     $link = $wgScript . "?title={$page}";
     $article = new Article(Title::newFromText($page));
     while ($article->isRedirect()) {
         $redirectedArticleTitle = Title::newFromRedirect($article->getContent());
         $article = new Article($redirectedArticleTitle);
     }
     if ($article->exists()) {
         $slideBody = $article->getContent() . $notoc . " __NOEDITSECTION__";
     } else {
         $slideBody = "The [[{$page}]] slide does not exist. Did you want to <b>[[{$page} | create]]</b> it?";
     }
     $this->currentPageLink = "<a href='{$link}'>{$page}</a>";
     //html
     $this->slideBody = $wgParser->recursiveTagParse($slideBody);
     //wiki markup converted to html
 }
     continue;
 }
 # get results from the Google Mini
 $l = new LSearch();
 $results = $l->googleSearchResultTitles('"' . $phrase . '"');
 $newresults = array();
 # filter out some of the results (links to their own pages, videos, etc)
 foreach ($results as $r) {
     if (strtolower($r->getText()) == strtolower($title)) {
         continue;
     }
     if ($r->getNamespace() != NS_MAIN || strpos($r->getText(), "Video/") !== false) {
         continue;
     }
     $a = new Article($r);
     if ($a->isRedirect()) {
         continue;
     }
     if (in_array(strtolower($r->getText()), $ignore_pages)) {
         continue;
     }
     $first_w_r = getFirstWord($r->getText());
     $first_w_p = getFirstWord($phrase);
     if ($first_w_r == $first_w_p) {
         #echo "The first words ({$first_w_p}, {$first_w_r}) match for phrase '{$phrase}' and result '{$r->getText()}', skipping...\n";
         continue;
     } else {
         #echo "({$first_w_p}, {$first_w_r}) DO NOT match for phrase {$phrase} and result {$r->getText()}\n";
     }
     $newresults[] = $r;
 }