本文整理汇总了PHP中Article::isRedirect方法的典型用法代码示例。如果您正苦于以下问题:PHP Article::isRedirect方法的具体用法?PHP Article::isRedirect怎么用?PHP Article::isRedirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Article
的用法示例。
在下文中一共展示了Article::isRedirect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addArticle
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);
}
}
示例2: convert
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 .= ' ' . $page . ' →→ ' . $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;
}
示例3: __construct
/**
* 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));
}
}
}
示例4: getRelatedTopicsText
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 = 'Registered_Editing';
} else {
$gatuser = 'Anon_Editing';
}
// 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');
}
示例5: getRS
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;
}
示例6: execute
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();
}
}
示例7: updateRevisionOn
/**
* 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;
}
示例8: wfGenerateWikiFeed
/**
* 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 ) {
//.........这里部分代码省略.........
示例9: getAvatarRaw
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' => '');
}
示例10: isRedirect
public function isRedirect($text = false)
{
$this->loadFile();
if ($this->img->isLocal()) {
return parent::isRedirect($text);
}
return (bool) $this->img->getRedirected();
}
示例11: getPreloadedText
/**
* 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 '';
}
示例12: getNext
/**
* 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;
}
示例13: getRelatedWikihowsFromSource
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;
}
示例14: followPollID
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;
}
}
示例15: checkArticlesInNfdTable
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";
}