/**
  * Check if the given local page title is a spam regex source.
  * @param Title $title
  * @return bool
  */
 function isLocalSource($title)
 {
     global $wgDBname;
     if ($title->getNamespace() == NS_MEDIAWIKI) {
         $sources = array("Spam-blacklist", "Spam-whitelist");
         if (in_array($title->getDBkey(), $sources)) {
             return true;
         }
     }
     $thisHttp = wfExpandUrl($title->getFullUrl('action=raw'), PROTO_HTTP);
     $thisHttpRegex = '/^' . preg_quote($thisHttp, '/') . '(?:&.*)?$/';
     foreach ($this->files as $fileName) {
         $matches = array();
         if (preg_match('/^DB: (\\w*) (.*)$/', $fileName, $matches)) {
             if ($wgDBname == $matches[1]) {
                 if ($matches[2] == $title->getPrefixedDbKey()) {
                     // Local DB fetch of this page...
                     return true;
                 }
             }
         } elseif (preg_match($thisHttpRegex, $fileName)) {
             // Raw view of this page
             return true;
         }
     }
     return false;
 }
/**
 * @param int   $level
 * @param Title $target
 * @param int   $limit
 * @param int   $offset
 * @access private
 */
function wfShowIndirectLinks($level, $target, $limit, $offset = 0)
{
    global $wgOut, $wgUser;
    $fname = 'wfShowIndirectLinks';
    $dbr =& wfGetDB(DB_READ);
    // Read one extra row as an at-end check
    $queryLimit = $limit + 1;
    $limitSql = $level == 0 ? "{$offset},{$queryLimit}" : $queryLimit;
    $res = $dbr->select(array('pagelinks', 'page'), array('page_id', 'page_namespace', 'page_title', 'page_is_redirect'), array('pl_from=page_id', 'pl_namespace' => $target->getNamespace(), 'pl_title' => $target->getDbKey()), $fname, array('LIMIT' => $limitSql));
    if (0 == $dbr->numRows($res)) {
        if (0 == $level) {
            $wgOut->addWikiText(wfMsg('nolinkshere'));
        }
        return;
    }
    if (0 == $level) {
        $wgOut->addWikiText(wfMsg('linkshere'));
    }
    $sk = $wgUser->getSkin();
    $isredir = ' (' . wfMsg('isredirect') . ")\n";
    if ($dbr->numRows($res) == 0) {
        return;
    }
    $atend = $dbr->numRows($res) <= $limit;
    if ($level == 0) {
        $specialTitle = Title::makeTitle(NS_SPECIAL, 'Whatlinkshere');
        $prevnext = wfViewPrevNext($offset, $limit, $specialTitle, 'target=' . urlencode($target->getPrefixedDbKey()), $atend);
        $wgOut->addHTML($prevnext);
    }
    $wgOut->addHTML('<ul>');
    $linksShown = 0;
    while ($row = $dbr->fetchObject($res)) {
        if (++$linksShown > $limit) {
            // Last row is for checks only; don't display it.
            break;
        }
        $nt = Title::makeTitle($row->page_namespace, $row->page_title);
        if ($row->page_is_redirect) {
            $extra = 'redirect=no';
        } else {
            $extra = '';
        }
        $link = $sk->makeKnownLinkObj($nt, '', $extra);
        $wgOut->addHTML('<li>' . $link);
        if ($row->page_is_redirect) {
            $wgOut->addHTML($isredir);
            if ($level < 2) {
                wfShowIndirectLinks($level + 1, $nt, 500);
            }
        }
        $wgOut->addHTML("</li>\n");
    }
    $wgOut->addHTML("</ul>\n");
    if ($level == 0) {
        $wgOut->addHTML($prevnext);
    }
}
	/**
	 * @return string
	 */
	function revisionFields() {
		$out = '';
		foreach( $this->mRevisions as $id ) {
			$out .= Html::hidden( 'revision[]', $id );
		}
		if( $this->mTarget ) {
			$out .= Html::hidden( 'target', $this->mTarget->getPrefixedDbKey() );
		}
		foreach( $this->mTimestamps as $timestamp ) {
			$out .= Html::hidden( 'timestamp[]', wfTimestamp( TS_MW, $timestamp ) );
		}
		return $out;
	}
	/**
	 * Check if the given local page title is a spam regex source.
	 *
	 * @param Title $title
	 * @return bool
	 */
	public static function isLocalSource( $title ) {
		global $wgDBname, $wgBlacklistSettings;

		if( $title->getNamespace() == NS_MEDIAWIKI ) {
			$sources = array();
			foreach ( self::$blacklistTypes as $type => $class ) {
				$type = ucfirst( $type );
				$sources += array(
					"$type-blacklist",
					"$type-whitelist"
				);
			}

			if( in_array( $title->getDBkey(), $sources ) ) {
				return true;
			}
		}

		$thisHttp = wfExpandUrl( $title->getFullUrl( 'action=raw' ), PROTO_HTTP );
		$thisHttpRegex = '/^' . preg_quote( $thisHttp, '/' ) . '(?:&.*)?$/';

		$files = array();
		foreach ( self::$blacklistTypes as $type => $class ) {
			if ( isset( $wgBlacklistSettings[$type]['files'] ) ) {
				$files += $wgBlacklistSettings[$type]['files'];
			}
		}

		foreach( $files as $fileName ) {
			$matches = array();
			if ( preg_match( '/^DB: (\w*) (.*)$/', $fileName, $matches ) ) {
				if ( $wgDBname == $matches[1] ) {
					if( $matches[2] == $title->getPrefixedDbKey() ) {
						// Local DB fetch of this page...
						return true;
					}
				}
			} elseif( preg_match( $thisHttpRegex, $fileName ) ) {
				// Raw view of this page
				return true;
			}
		}

		return false;
	}
Example #5
0
 private function showRevision($timestamp)
 {
     if (!preg_match('/[0-9]{14}/', $timestamp)) {
         return 0;
     }
     $archive = new PageArchive($this->mTargetObj);
     wfRunHooks('UndeleteForm::showRevision', array(&$archive, $this->mTargetObj));
     $rev = $archive->getRevision($timestamp);
     $out = $this->getOutput();
     $user = $this->getUser();
     if (!$rev) {
         $out->addWikiMsg('undeleterevision-missing');
         return;
     }
     if ($rev->isDeleted(Revision::DELETED_TEXT)) {
         if (!$rev->userCan(Revision::DELETED_TEXT, $user)) {
             $out->wrapWikiMsg("<div class='mw-warning plainlinks'>\n\$1\n</div>\n", 'rev-deleted-text-permission');
             return;
         } else {
             $out->wrapWikiMsg("<div class='mw-warning plainlinks'>\n\$1\n</div>\n", 'rev-deleted-text-view');
             $out->addHTML('<br />');
             // and we are allowed to see...
         }
     }
     if ($this->mDiff) {
         $previousRev = $archive->getPreviousRevision($timestamp);
         if ($previousRev) {
             $this->showDiff($previousRev, $rev);
             if ($this->mDiffOnly) {
                 return;
             } else {
                 $out->addHTML('<hr />');
             }
         } else {
             $out->addWikiMsg('undelete-nodiff');
         }
     }
     $link = Linker::linkKnown($this->getTitle($this->mTargetObj->getPrefixedDBkey()), htmlspecialchars($this->mTargetObj->getPrefixedText()));
     $lang = $this->getLanguage();
     // date and time are separate parameters to facilitate localisation.
     // $time is kept for backward compat reasons.
     $time = $lang->userTimeAndDate($timestamp, $user);
     $d = $lang->userDate($timestamp, $user);
     $t = $lang->userTime($timestamp, $user);
     $userLink = Linker::revUserTools($rev);
     if ($this->mPreview) {
         $openDiv = '<div id="mw-undelete-revision" class="mw-warning">';
     } else {
         $openDiv = '<div id="mw-undelete-revision">';
     }
     $out->addHTML($openDiv);
     // Revision delete links
     if (!$this->mDiff) {
         $revdel = Linker::getRevDeleteLink($user, $rev, $this->mTargetObj);
         if ($revdel) {
             $out->addHTML("{$revdel} ");
         }
     }
     $out->addHTML($this->msg('undelete-revision')->rawParams($link)->params($time)->rawParams($userLink)->params($d, $t)->parse() . '</div>');
     wfRunHooks('UndeleteShowRevision', array($this->mTargetObj, $rev));
     if ($this->mPreview) {
         // Hide [edit]s
         $popts = $out->parserOptions();
         $popts->setEditSection(false);
         $out->parserOptions($popts);
         $out->addWikiTextTitleTidy($rev->getText(Revision::FOR_THIS_USER, $user), $this->mTargetObj, true);
     }
     $out->addHTML(Xml::element('textarea', array('readonly' => 'readonly', 'cols' => intval($user->getGlobalPreference('cols')), 'rows' => intval($user->getGlobalPreference('rows'))), $rev->getText(Revision::FOR_THIS_USER, $user) . "\n") . Xml::openElement('div') . Xml::openElement('form', array('method' => 'post', 'action' => $this->getTitle()->getLocalURL(array('action' => 'submit')))) . Xml::element('input', array('type' => 'hidden', 'name' => 'target', 'value' => $this->mTargetObj->getPrefixedDbKey())) . Xml::element('input', array('type' => 'hidden', 'name' => 'timestamp', 'value' => $timestamp)) . Xml::element('input', array('type' => 'hidden', 'name' => 'wpEditToken', 'value' => $user->getEditToken())) . Xml::element('input', array('type' => 'submit', 'name' => 'preview', 'value' => $this->msg('showpreview')->text())) . Xml::element('input', array('name' => 'diff', 'type' => 'submit', 'value' => $this->msg('showdiff')->text())) . Xml::closeElement('form') . Xml::closeElement('div'));
 }
Example #6
0
 /**
  * Add a link for the title to the link cache
  * @param int $id
  * @param Title $title
  * @param int $len
  * @param int $redir
  */
 public function addGoodLinkObj($id, $title, $len = -1, $redir = NULL)
 {
     $dbkey = $title->getPrefixedDbKey();
     $this->mGoodLinks[$dbkey] = $id;
     $this->mGoodLinkFields[$dbkey] = array('length' => $len, 'redirect' => $redir);
 }
	/**
	 * Returns link attributes that enable javascript translation dialog.
	 * Will degrade gracefully if user does not have permissions or JavaScript
	 * is not enabled.
	 * @param $title Title Title object for the translatable message.
	 * @param $group \string The group in which this message belongs to.
	 *   Optional, but avoids a lookup later if provided.
	 * @return \array
	 */
	public static function jsEdit( Title $title, $group = "" ) {
		global $wgUser;

		if ( !$wgUser->getOption( 'translate-jsedit' ) ) {
			return array();
		}

		return array(
			'onclick' => Xml::encodeJsCall(
				'return mw.translate.openDialog', array( $title->getPrefixedDbKey(), $group ) ),
			'title' => wfMsg( 'translate-edit-title', $title->getPrefixedText() )
		);
	}
 /**
  * Returns link attributes that enable javascript translation dialog.
  * Will degrade gracefully if user does not have permissions or JavaScript
  * is not enabled.
  * @param $title Title Title object for the translatable message.
  * @param $group \string The group in which this message belongs to.
  *   Optional, but avoids a lookup later if provided.
  * @param $type \string Force the type of editor to be used. Use dialog
  *   where embedded editor is no applicable.
  * @return \array
  */
 public static function jsEdit(Title $title, $group = "", $type = 'default')
 {
     $context = RequestContext::getMain();
     if ($type === 'default') {
         $text = 'tqe-anchor-' . substr(sha1($title->getPrefixedText()), 0, 12);
         $onclick = "jQuery( '#{$text}' ).dblclick(); return false;";
     } else {
         $onclick = Xml::encodeJsCall('return mw.translate.openDialog', array($title->getPrefixedDbKey(), $group));
     }
     return array('onclick' => $onclick, 'title' => $context->msg('translate-edit-title', $title->getPrefixedText())->text());
 }
Example #9
0
 /**
  * Add a link for the title to the link cache
  * @param int $id
  * @param Title $title
  * @param int $len
  * @param int $redir
  */
 public function addGoodLinkObj($id, $title, $len = -1, $redir = null)
 {
     $dbkey = $title->getPrefixedDbKey();
     $this->mGoodLinks[$dbkey] = intval($id);
     $this->mGoodLinkFields[$dbkey] = array('length' => intval($len), 'redirect' => intval($redir));
 }