/**
 * @param WikiPage $article
 * @param $user
 * @param $text
 * @param $summary
 * @param $minoredit
 * @param $watchthis
 * @param $sectionanchor
 * @param $flags
 * @param $revision
 * @param Status $status
 * @param $baseRevId
 * @return bool
 */
function efSharedHelpArticleCreation(&$article, &$user, $text, $summary, $minoredit, $watchthis, $sectionanchor, &$flags, $revision, &$status, $baseRevId)
{
    global $wgCityId, $wgHelpWikiId;
    // only run on help wikis
    if ($wgCityId !== $wgHelpWikiId) {
        return true;
    }
    // not likely if we got here, but... healthy paranoia ;)
    if (wfReadOnly()) {
        return true;
    }
    if ($article->mTitle->getNamespace() !== NS_HELP) {
        return true;
    }
    if (!$status->isOK()) {
        return true;
    }
    if (!($flags & EDIT_NEW)) {
        return true;
    }
    $talkTitle = Title::newFromText($article->mTitle->getText(), NS_HELP_TALK);
    if ($talkTitle->exists()) {
        return true;
    }
    $talkArticle = new Article($talkTitle);
    $redir = $article->getRedirectTarget();
    if ($redir) {
        $target = $redir->getTalkNsText() . ':' . $redir->getText();
        $talkArticle->doEdit("#REDIRECT [[{$target}]]", wfMsgForContent('sharedhelp-autotalkcreate-summary'));
    } else {
        $talkArticle->doEdit('{{talkheader}}', wfMsgForContent('sharedhelp-autotalkcreate-summary'));
    }
    return true;
}
 /**
  * Assuming the user's interface language is fi. Given input Page, it
  * returns Page/fi if it exists, otherwise Page. Given input Page/de,
  * it returns Page/fi if it exists, otherwise Page/de if it exists,
  * otherwise Page.
  *
  * @param string $par
  * @return Title|null
  */
 public function findTitle($par)
 {
     // base = title without language code suffix
     // provided = the title as it was given
     $base = $provided = Title::newFromText($par);
     if ($base && strpos($par, '/') !== false) {
         $pos = strrpos($par, '/');
         $basepage = substr($par, 0, $pos);
         $code = substr($par, $pos + 1);
         if (strlen($code) && Language::isKnownLanguageTag($code)) {
             $base = Title::newFromText($basepage);
         }
     }
     if (!$base) {
         return null;
     }
     if ($base->isRedirect()) {
         $page = new WikiPage($base);
         $base = $page->getRedirectTarget();
     }
     $uiCode = $this->getLanguage()->getCode();
     $proposed = $base->getSubpage($uiCode);
     if ($uiCode !== $this->getConfig()->get('LanguageCode') && $proposed && $proposed->exists()) {
         return $proposed;
     } elseif ($provided && $provided->exists()) {
         return $provided;
     } else {
         return $base;
     }
 }
Пример #3
0
	/**
	 * @return mixed|null|Title
	 */
	public function getRedirectTarget() {
		$this->loadFile();
		if ( $this->mFile->isLocal() ) {
			return parent::getRedirectTarget();
		}
		// Foreign image page
		$from = $this->mFile->getRedirected();
		$to = $this->mFile->getName();
		if ( $from == $to ) {
			return null;
		}
		return $this->mRedirectTarget = Title::makeTitle( NS_FILE, $to );
	}
 /**
  * Get target title if the current title is a redirect.
  * It doesn't handle
  *
  * @param $title Title|GlobalTitle
  * @return Title|GlobalTitle
  */
 protected function resolveRedirect($title)
 {
     $origTitle = $title;
     if ($title instanceof GlobalTitle) {
         if ($title->isRedirect()) {
             $target = $title->getRedirectTarget();
             if ($target) {
                 $title = $target;
             }
         }
     } else {
         if ($title instanceof Title) {
             if ($title->isRedirect()) {
                 $page = new WikiPage($title);
                 $target = $page->getRedirectTarget();
                 if ($target->exists()) {
                     $title = $target;
                 }
             }
         }
     }
     return $title;
 }
 /**
  * Get target title if the current title is a redirect.
  * It doesn't handle
  *
  * @param $title Title|GlobalTitle
  * @return Title|GlobalTitle
  */
 protected function resolveRedirect($title)
 {
     wfProfileIn(__METHOD__);
     if ($title instanceof GlobalTitle) {
         if ($title->isRedirect()) {
             $target = $title->getRedirectTarget();
             if ($target) {
                 $title = $target;
             }
         }
     } else {
         if ($title instanceof Title) {
             if ($title->isRedirect()) {
                 $page = new WikiPage($title);
                 $target = $page->getRedirectTarget();
                 if ($target->exists()) {
                     $title = $target;
                 }
             }
         }
     }
     wfProfileOut(__METHOD__);
     return $title;
 }
Пример #6
0
 static function getNextArticleToPatrolInner($rcid = null)
 {
     global $wgRequest, $wgUser, $wgCookiePrefix;
     $show_namespace = $wgRequest->getVal('namespace');
     $invert = $wgRequest->getVal('invert');
     $reverse = $wgRequest->getVal('reverse');
     $featured = $wgRequest->getVal('featured');
     $title = $wgRequest->getVal('target');
     $skiptitle = $wgRequest->getVal('skiptitle');
     $rc_user_filter = trim(urldecode($wgRequest->getVal('rc_user_filter')));
     // assert that current user is not anon
     if ($wgUser->isAnon()) {
         return null;
     }
     // In English, when a user rolls back an edit, it gives the edit a comment
     // like: "Reverted edits by ...", so MediaWiki:rollback_comment_prefix
     // is set to "Reverted" in English wikiHow.
     $rollbackCommentPrefix = wfMessage('rollback_comment_prefix')->plain();
     if (empty($rollbackCommentPrefix) || strpos($rollbackCommentPrefix, '&') === 0) {
         die("Cannot use RCPatrol feature until MediaWiki:rollback_comment_prefix is set up properly");
     }
     $t = null;
     if ($title) {
         $t = Title::newFromText($title);
     }
     $skip = null;
     if ($skiptitle) {
         $skip = Title::newFromText($skiptitle);
     }
     $dbr = wfGetDB(DB_MASTER);
     /*	DEPRECATED rc_moved_to_ns & rc_moved_to_title columns
     			$sql = "SELECT rc_id, rc_cur_id, rc_moved_to_ns, rc_moved_to_title, rc_new, 
     			  rc_namespace, rc_title, rc_last_oldid, rc_this_oldid 
     			FROM recentchanges 
     			LEFT OUTER JOIN page ON rc_cur_id = page_id AND rc_namespace = page_namespace 
     			WHERE ";*/
     $sql = "SELECT rc_id, rc_cur_id, rc_new, rc_namespace, rc_title, rc_last_oldid, rc_this_oldid \n\t\t\tFROM recentchanges \n\t\t\tLEFT OUTER JOIN page ON rc_cur_id = page_id AND rc_namespace = page_namespace \n\t\t\tWHERE ";
     if (!$wgRequest->getVal('ignore_rcid') && $rcid) {
         $sql .= " rc_id " . ($reverse == 1 ? " > " : " < ") . " {$rcid} and ";
     }
     // if we filter by user we show both patrolled and non-patrolled edits
     if ($rc_user_filter) {
         $sql .= " rc_user_text = " . $dbr->addQuotes($rc_user_filter);
         if ($rcid) {
             $sql .= " AND rc_id < " . $rcid;
         }
     } else {
         $sql .= " rc_patrolled = 0 ";
     }
     // can't patrol your own edits
     $sql .= " AND rc_user <> " . $wgUser->getID();
     // only featured?
     if ($featured) {
         $sql .= " AND page_is_featured = 1 ";
     }
     if ($show_namespace) {
         $sql .= " AND rc_namespace " . ($invert ? '<>' : '=') . $show_namespace;
     } else {
         // always ignore video
         $sql .= " AND rc_namespace <> " . NS_VIDEO;
     }
     // log entries have namespace = -1, we don't want to show those, hide bots too
     $sql .= " AND rc_namespace >= 0 AND rc_bot = 0 ";
     if ($t) {
         $sql .= " AND rc_title <> " . $dbr->addQuotes($t->getDBKey());
     }
     if ($skip) {
         $sql .= " AND rc_title <> " . $dbr->addQuotes($skip->getDBKey());
     }
     $sa = $wgRequest->getVal('sa');
     if ($sa) {
         $sa = Title::newFromText($sa);
         $sql .= " AND rc_title = " . $dbr->addQuotes($sa->getDBKey());
     }
     // has the user skipped any articles?
     $cookiename = $wgCookiePrefix . "Rcskip";
     $skipids = "";
     if (isset($_COOKIE[$cookiename])) {
         $cookie_ids = array_unique(split(",", $_COOKIE[$cookiename]));
         $ids = array();
         //safety first
         foreach ($cookie_ids as $id) {
             $id = intval($id);
             if ($id > 0) {
                 $ids[] = $id;
             }
         }
         if ($ids) {
             $skipids = " AND rc_cur_id NOT IN (" . implode(",", $ids) . ") ";
         }
     }
     $sql .= "{$skipids} ORDER BY rc_timestamp " . ($reverse == 1 ? "" : "DESC ") . "LIMIT 1";
     $res = $dbr->query($sql, __METHOD__);
     $row = $res->fetchObject();
     /*$show=true;
     if ($show){
     var_dump($_GET);
     var_dump($_POST);
     echo $sql;
     var_dump($row);
     exit;
     }*/
     if ($row) {
         $result = array();
         $t = Title::makeTitle($row->rc_namespace, $row->rc_title);
         if ($t->isRedirect()) {
             $wp = new WikiPage($t);
             $t = $wp->getRedirectTarget();
         }
         // if title has been deleted set $t to null so we will skip it
         if (!$t->exists()) {
             MWDebug::log("{$t} does not exist");
             $t = null;
         }
         $result['rc_cur_id'] = $row->rc_cur_id;
         if ($rc_user_filter) {
             $result['rchi'] = $result['rclo'] = $row->rc_id;
             $result['new'] = $dbr->selectField('recentchanges', array('rc_this_oldid'), array('rc_id' => $row->rc_id));
         } else {
             // always compare to current version
             $result['new'] = $dbr->selectField('revision', array('max(rev_id)'), array('rev_page' => $row->rc_cur_id));
             $result['rchi'] = $dbr->selectField('recentchanges', array('rc_id'), array('rc_this_oldid' => $result['new']));
             $result['rclo'] = $dbr->selectField('recentchanges', array('min(rc_id)'), array('rc_patrolled' => 0, "rc_cur_id" => $row->rc_cur_id));
             // do we have a reverted edit caught between these 2?
             // if so, only show the reversion, because otherwise you get the reversion trapped in the middle
             // and it shows a weird diff page.
             $hi = isset($result['rchi']) ? $result['rchi'] : $row->rc_id;
             if ($hi) {
                 $reverted_id = $dbr->selectField('recentchanges', array('min(rc_id)'), array('rc_comment like ' . $dbr->addQuotes($rollbackCommentPrefix . '%'), "rc_id < {$hi}", "rc_id >= {$result['rclo']}", "rc_cur_id" => $row->rc_cur_id));
                 if ($reverted_id) {
                     $result['rchi'] = $reverted_id;
                     $result['new'] = $dbr->selectField('recentchanges', array('rc_this_oldid'), array('rc_id' => $reverted_id));
                     $row->rc_id = $result['rchi'];
                 }
                 //} else {
                 //	$email = new MailAddress("*****@*****.**");
                 //	$subject = "Could not find hi variable " . date("r");
                 //	$body = print_r($_SERVER, true) . "\n\n" . $sql . "\n\n" . print_r($result, true) . "\n\n\$hi: " . $hi;
                 //	UserMailer::send($email, $email, $subject, $body);
             }
             if (!$result['rclo']) {
                 $result['rclo'] = $row->rc_id;
             }
             if (!$result['rchi']) {
                 $result['rchi'] = $row->rc_id;
             }
             // is the last patrolled edit a rollback? if so, show the diff starting at that edit
             // makes it more clear when someone has reverted vandalism
             $result['vandal'] = 0;
             $comm = $dbr->selectField('recentchanges', array('rc_comment'), array('rc_id' => $result['rclo']));
             if (strpos($comm, $rollbackCommentPrefix) === 0) {
                 $row2 = $dbr->selectRow('recentchanges', array('rc_id', 'rc_comment'), array("rc_id < {$result['rclo']}", 'rc_cur_id' => $row->rc_cur_id), __METHOD__, array("ORDER BY" => "rc_id desc", "LIMIT" => 1));
                 if ($row2) {
                     $result['rclo'] = $row2->rc_id;
                 }
                 $result['vandal'] = 1;
             }
         }
         $result['user'] = $dbr->selectField('recentchanges', array('rc_user_text'), array('rc_this_oldid' => $result['new']));
         $result['old'] = $dbr->selectField('recentchanges', array('rc_last_oldid'), array('rc_id' => $result['rclo']));
         $result['title'] = $t;
         $result['rcid'] = $row->rc_id;
         if ($result['rchi'] == $result['rclo']) {
             $conds = array('rc_id' => $result['rchi']);
         } else {
             $conds = array('rc_id <= ' . $result['rchi'], 'rc_id >= ' . $result['rclo']);
         }
         $result['count'] = $dbr->selectField('recentchanges', array('count(*)'), array("rc_id <= " . $result['rchi'], "rc_id >= " . $result['rclo'], "rc_patrolled" => 0, "rc_cur_id" => $row->rc_cur_id));
         $result = self::getListofEditors($result);
         return $result;
     } else {
         return null;
     }
 }